amf.c 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872
  1. /*
  2. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <sys/types.h>
  35. #include <sys/uio.h>
  36. #include <sys/socket.h>
  37. #include <sys/un.h>
  38. #include <netinet/in.h>
  39. #include <arpa/inet.h>
  40. #include <unistd.h>
  41. #include <fcntl.h>
  42. #include <stdlib.h>
  43. #include <stdio.h>
  44. #include <errno.h>
  45. #include <signal.h>
  46. #include <string.h>
  47. #include "../include/ais_types.h"
  48. #include "../include/ipc_gen.h"
  49. #include "../include/ipc_amf.h"
  50. #include "../include/list.h"
  51. #include "../include/queue.h"
  52. #include "totempg.h"
  53. #include "aispoll.h"
  54. #include "mempool.h"
  55. #include "util.h"
  56. #include "main.h"
  57. #include "handlers.h"
  58. #define LOG_SERVICE LOG_SERVICE_AMF
  59. #include "print.h"
  60. #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
  61. #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
  62. #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
  63. struct invocation {
  64. struct conn_info *conn_info;
  65. int interface;
  66. int active;
  67. };
  68. struct invocation *invocation_entries = 0;
  69. int invocation_entries_size = 0;
  70. //TODO static void *tok_call_handle = NULL;
  71. static int recovery = 0;
  72. #ifdef INPARSEDOTH
  73. enum amfOperationalState {
  74. AMF_OPER_DISABLED,
  75. AMF_OPER_ENABLED
  76. };
  77. enum amfAdministrativeState {
  78. AMF_ADMIN_UNLOCKED,
  79. AMF_ADMIN_LOCKED,
  80. AMF_ADMIN_STOPPING
  81. };
  82. enum amfOperationalAdministrativeState {
  83. AMF_ENABLED_UNLOCKED,
  84. AMF_DISABLED_UNLOCKED,
  85. AMF_DISABLED_LOCKED,
  86. AMF_ENABLED_STOPPING
  87. };
  88. /*
  89. * State machines for states in AMF
  90. */
  91. enum amfEnabledUnlockedState {
  92. AMF_ENABLED_UNLOCKED_INITIAL,
  93. AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED,
  94. AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED,
  95. AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED,
  96. AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED,
  97. AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED,
  98. AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED,
  99. };
  100. enum amfDisabledUnlockedState {
  101. AMF_DISABLED_UNLOCKED_INITIAL,
  102. AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED,
  103. AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED,
  104. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED,
  105. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED
  106. };
  107. enum amfDisabledLockedState {
  108. AMF_DISABLED_LOCKED_INITIAL,
  109. AMF_DISABLED_LOCKED_QUIESCED_REQUESTED,
  110. AMF_DISABLED_LOCKED_QUIESCED_COMPLETED,
  111. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_REQUESTED
  112. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_COMPLETED
  113. };
  114. enum amfEnabledStoppingState {
  115. AMF_ENABLED_STOPPING_INITIAL,
  116. AMF_ENABLED_STOPPING_STOPPING_REQUESTED,
  117. AMF_ENABLED_STOPPING_STOPPING_COMPLETED
  118. };
  119. /*
  120. * Internal Functions
  121. */
  122. static void componentOutOfServiceSetNoApi (
  123. struct saAmfComponent *component);
  124. #endif
  125. static void grow_amf_track_table (
  126. struct conn_info *conn_info,
  127. int growby);
  128. static int activeServiceUnitsCount (
  129. struct saAmfGroup *saAmfGroup);
  130. static void component_unregister (
  131. struct saAmfComponent *component);
  132. static void enumerate_components (
  133. void (*function)(struct saAmfComponent *, void *data),
  134. void *data);
  135. #ifdef COMPILE_OUT
  136. static void CSIRemove (
  137. struct conn_info *conn_info);
  138. static void haStateSetClusterInit (
  139. struct conn_info *conn_info,
  140. struct saAmfComponent *saAmfComponent);
  141. #endif
  142. static void ha_state_api_set (
  143. struct saAmfComponent *saAmfComponent,
  144. SaAmfHAStateT haState);
  145. static void ha_state_group_set (
  146. struct saAmfComponent *saAmfComponent,
  147. SaAmfHAStateT haState);
  148. static void readiness_state_api_set (
  149. struct saAmfComponent *component,
  150. SaAmfReadinessStateT readinessState);
  151. #ifdef COMPILE_OUT
  152. static void readinessStateSetClusterInit (
  153. struct conn_info *conn_info,
  154. struct saAmfComponent *saAmfComponent);
  155. #endif
  156. static void readiness_state_group_set (
  157. struct saAmfComponent *saAmfComponent,
  158. SaAmfReadinessStateT readinessState);
  159. #ifdef COMPILE_OUT
  160. static void enumerateComponentsClusterInit (
  161. struct saAmfComponent *component,
  162. void *data);
  163. #endif
  164. static void dsm (
  165. struct saAmfComponent *saAmfComponent);
  166. #if 0 /* NOT IMPLEMENTED */
  167. static void componentTerminate (
  168. struct conn_info *conn_info);
  169. #endif
  170. static void timer_function_libamf_healthcheck (
  171. void *data);
  172. static struct saAmfProtectionGroup *protectiongroup_find (
  173. SaNameT *csiName);
  174. static struct saAmfComponent *component_in_protectiongroup_find (
  175. SaNameT *csiName,
  176. SaNameT *compName);
  177. static void protectiongroup_notifications_send (
  178. struct saAmfComponent *changedComponent,
  179. SaAmfProtectionGroupChangesT changeToComponent);
  180. static void protectiongroup_notification_send (
  181. struct conn_info *conn_info,
  182. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  183. struct saAmfProtectionGroup *amfProtectionGroup,
  184. struct saAmfComponent *changedComponent,
  185. SaAmfProtectionGroupChangesT changeToComponent,
  186. SaUint8T trackFlags);
  187. static void response_handler_readinessstatesetcallback (
  188. struct conn_info *conn_info,
  189. struct req_amf_response *req_amf_response);
  190. static void response_handler_csisetcallback (
  191. struct conn_info *conn_info,
  192. struct req_amf_response *req_amf_response);
  193. static void amf_confchg_nleave (
  194. struct saAmfComponent *component,
  195. void *data);
  196. static void amf_confchg_njoin (
  197. struct saAmfComponent *component,
  198. void *data);
  199. static int amf_confchg_fn (
  200. enum totem_configuration_type configuration_type,
  201. struct in_addr *member_list, int member_list_entries,
  202. struct in_addr *left_list, int left_list_entries,
  203. struct in_addr *joined_list, int joined_list_entries,
  204. struct memb_ring_id *ring_id);
  205. /***
  206. static void amf_dump (void);
  207. ***/
  208. static int amf_exit_fn (struct conn_info *conn_info);
  209. static int amf_exec_init_fn (struct openais_config *);
  210. static int amf_init_two_fn (struct conn_info *conn_info);
  211. static void amf_synchronize (void *message, struct in_addr source_addr);
  212. static int message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required);
  213. static int message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required);
  214. static int message_handler_req_exec_amf_errorreport (void *message, struct in_addr source_addr, int endian_conversion_required);
  215. static int message_handler_req_exec_amf_errorcancelall (void *message, struct in_addr source_addr, int endian_conversion_required);
  216. static int message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required);
  217. static int message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required);
  218. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message);
  219. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message);
  220. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message);
  221. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message);
  222. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message);
  223. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message);
  224. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message);
  225. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message);
  226. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info, void *message);
  227. static int message_handler_req_amf_response (struct conn_info *conn_info, void *message);
  228. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message);
  229. /*
  230. * Service Handler Definition
  231. */
  232. struct libais_handler amf_libais_handlers[] =
  233. {
  234. { /* 0 */
  235. .libais_handler_fn = message_handler_req_amf_componentregister,
  236. .response_size = sizeof (struct res_lib_amf_componentregister),
  237. .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
  238. .flow_control = FLOW_CONTROL_REQUIRED
  239. },
  240. { /* 1 */
  241. .libais_handler_fn = message_handler_req_amf_componentunregister,
  242. .response_size = sizeof (struct res_lib_amf_componentunregister),
  243. .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
  244. .flow_control = FLOW_CONTROL_REQUIRED
  245. },
  246. { /* 2 */
  247. .libais_handler_fn = message_handler_req_amf_readinessstateget,
  248. .response_size = sizeof (struct res_lib_amf_readinessstateget),
  249. .response_id = MESSAGE_RES_AMF_READINESSSTATEGET,
  250. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  251. },
  252. { /* 3 */
  253. .libais_handler_fn = message_handler_req_amf_hastateget,
  254. .response_size = sizeof (struct res_lib_amf_hastateget),
  255. .response_id = MESSAGE_RES_AMF_READINESSSTATEGET,
  256. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  257. },
  258. { /* 4 */
  259. .libais_handler_fn = message_handler_req_amf_protectiongrouptrackstart,
  260. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstart),
  261. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART,
  262. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  263. },
  264. { /* 5 */
  265. .libais_handler_fn = message_handler_req_amf_protectiongrouptrackstop,
  266. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
  267. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
  268. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  269. },
  270. { /* 6 */
  271. .libais_handler_fn = message_handler_req_amf_errorreport,
  272. .response_size = sizeof (struct res_lib_amf_errorreport),
  273. .response_id = MESSAGE_RES_AMF_ERRORREPORT,
  274. .flow_control = FLOW_CONTROL_REQUIRED
  275. },
  276. { /* 7 */
  277. .libais_handler_fn = message_handler_req_amf_errorcancelall,
  278. .response_size = sizeof (struct res_lib_amf_errorcancelall),
  279. .response_id = MESSAGE_RES_AMF_ERRORCANCELALL,
  280. .flow_control = FLOW_CONTROL_REQUIRED
  281. },
  282. { /* 8 */
  283. .libais_handler_fn = message_handler_req_amf_stoppingcomplete,
  284. .response_size = sizeof (struct res_lib_amf_stoppingcomplete),
  285. .response_id = MESSAGE_RES_AMF_STOPPINGCOMPLETE, // TODO
  286. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  287. },
  288. { /* 9 */
  289. .libais_handler_fn = message_handler_req_amf_response,
  290. .response_size = sizeof (struct res_lib_amf_response),
  291. .response_id = MESSAGE_RES_AMF_RESPONSE, // TODO
  292. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  293. },
  294. { /* 10 */
  295. .libais_handler_fn = message_handler_req_amf_componentcapabilitymodelget,
  296. .response_size = sizeof (struct res_lib_amf_componentcapabilitymodelget),
  297. .response_id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET,
  298. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  299. }
  300. };
  301. int (*amf_aisexec_handler_fns[]) (void *, struct in_addr source_addr, int endian_conversion_required) = {
  302. message_handler_req_exec_amf_componentregister,
  303. message_handler_req_exec_amf_componentunregister,
  304. message_handler_req_exec_amf_errorreport,
  305. message_handler_req_exec_amf_errorcancelall,
  306. message_handler_req_exec_amf_readinessstateset,
  307. message_handler_req_exec_amf_hastateset,
  308. };
  309. /*
  310. * Exports the interface for the service
  311. */
  312. struct service_handler amf_service_handler = {
  313. .libais_handlers = amf_libais_handlers,
  314. .libais_handlers_count = sizeof (amf_libais_handlers) / sizeof (struct libais_handler),
  315. .aisexec_handler_fns = amf_aisexec_handler_fns,
  316. .aisexec_handler_fns_count = sizeof (amf_aisexec_handler_fns) / sizeof (int (*)),
  317. .confchg_fn = amf_confchg_fn,
  318. .libais_init_two_fn = amf_init_two_fn,
  319. .libais_exit_fn = amf_exit_fn,
  320. .exec_init_fn = amf_exec_init_fn,
  321. .exec_dump_fn = amf_dump
  322. };
  323. struct req_exec_amf_componentregister {
  324. struct req_header header;
  325. struct message_source source;
  326. struct req_lib_amf_componentregister req_lib_amf_componentregister;
  327. SaAmfReadinessStateT currentReadinessState;
  328. SaAmfReadinessStateT newReadinessState;
  329. SaAmfHAStateT currentHAState;
  330. SaAmfHAStateT newHAState;
  331. } __attribute__((packed));
  332. struct req_exec_amf_componentunregister {
  333. struct req_header header;
  334. struct message_source source;
  335. struct req_lib_amf_componentunregister req_lib_amf_componentunregister;
  336. };
  337. struct req_exec_amf_readinessstateset {
  338. struct req_header header;
  339. SaNameT compName;
  340. SaAmfReadinessStateT readinessState;
  341. };
  342. struct req_exec_amf_hastateset {
  343. struct req_header header;
  344. SaNameT compName;
  345. SaAmfHAStateT haState;
  346. };
  347. struct req_exec_amf_errorreport {
  348. struct req_header header;
  349. struct message_source source;
  350. struct req_lib_amf_errorreport req_lib_amf_errorreport;
  351. };
  352. struct req_exec_amf_errorcancelall {
  353. struct req_header header;
  354. struct message_source source;
  355. struct req_lib_amf_errorcancelall req_lib_amf_errorcancelall;
  356. };
  357. static void grow_amf_track_table (struct conn_info *conn_info, int growby)
  358. {
  359. struct libamf_ci_trackentry *tracks;
  360. int newsize;
  361. int currsize = conn_info->ais_ci.u.libamf_ci.trackEntries;
  362. newsize = growby + currsize;
  363. if (newsize > currsize) {
  364. tracks = (struct libamf_ci_trackentry *)mempool_realloc (conn_info->ais_ci.u.libamf_ci.tracks,
  365. (newsize) * sizeof (struct libamf_ci_trackentry));
  366. if (tracks == 0) {
  367. #ifdef DEBUG
  368. printf ("grow_amf_track_table: out of memory, woops\n");
  369. #endif
  370. // TODO
  371. exit (1);
  372. }
  373. memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry));
  374. conn_info->ais_ci.u.libamf_ci.trackEntries = newsize;
  375. conn_info->ais_ci.u.libamf_ci.tracks = tracks;
  376. }
  377. }
  378. int req_amf_invocation_create (int interface,
  379. struct conn_info *conn_info)
  380. {
  381. struct invocation *invocation_addr = 0;
  382. struct invocation *invocation_temp;
  383. int i;
  384. int loc = 0;
  385. for (i = 0; i < invocation_entries_size; i++) {
  386. if (invocation_entries[i].active == 0) {
  387. invocation_addr = &invocation_entries[i];
  388. loc = i;
  389. break;
  390. }
  391. }
  392. if (invocation_addr == 0) {
  393. invocation_temp = (struct invocation *)realloc (invocation_entries,
  394. (invocation_entries_size + 1) * sizeof (struct invocation));
  395. if (invocation_temp == 0) {
  396. return (-1);
  397. }
  398. invocation_entries = invocation_temp;
  399. invocation_addr = &invocation_entries[invocation_entries_size];
  400. loc = invocation_entries_size;
  401. invocation_entries_size += 1;
  402. }
  403. invocation_addr->interface = interface;
  404. invocation_addr->conn_info = conn_info;
  405. invocation_addr->active = 1;
  406. return (loc);
  407. }
  408. int req_amf_invocation_get_and_destroy (int invocation, int *interface,
  409. struct conn_info **conn_info)
  410. {
  411. if (invocation > invocation_entries_size) {
  412. return (-1);
  413. }
  414. if (invocation_entries[invocation].active == 0) {
  415. return (-1);
  416. }
  417. *interface = invocation_entries[invocation].interface;
  418. *conn_info = invocation_entries[invocation].conn_info;
  419. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  420. return (0);
  421. }
  422. static void component_unregister (
  423. struct saAmfComponent *component)
  424. {
  425. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  426. struct iovec iovecs[2];
  427. /*
  428. * This only works on local components
  429. */
  430. if (component == 0 || component->local != 1) {
  431. return;
  432. }
  433. log_printf (LOG_LEVEL_ENTER_FUNC, "component_unregister: unregistering component %s\n",
  434. getSaNameT (&component->name));
  435. component->probableCause = SA_AMF_NOT_RESPONDING;
  436. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  437. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  438. req_exec_amf_componentunregister.source.conn_info = 0;
  439. req_exec_amf_componentunregister.source.in_addr.s_addr = 0;
  440. memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  441. 0, sizeof (struct req_lib_amf_componentunregister));
  442. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName,
  443. &component->name,
  444. sizeof (SaNameT));
  445. iovecs[0].iov_base = (char *)&req_exec_amf_componentunregister;
  446. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  447. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  448. }
  449. static void component_register (
  450. struct saAmfComponent *component)
  451. {
  452. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  453. struct iovec iovecs[2];
  454. /*
  455. * This only works on local components
  456. */
  457. if (component == 0 || component->local != 1) {
  458. return;
  459. }
  460. log_printf (LOG_LEVEL_ENTER_FUNC, "component_register: registering component %s\n",
  461. getSaNameT (&component->name));
  462. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  463. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  464. req_exec_amf_componentregister.source.conn_info = 0;
  465. req_exec_amf_componentregister.source.in_addr.s_addr = 0;
  466. req_exec_amf_componentregister.currentReadinessState = component->currentReadinessState;
  467. req_exec_amf_componentregister.newReadinessState = component->newReadinessState;
  468. req_exec_amf_componentregister.currentHAState = component->currentHAState;
  469. req_exec_amf_componentregister.newHAState = component->newHAState;
  470. memset (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  471. 0, sizeof (struct req_lib_amf_componentregister));
  472. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister.compName,
  473. &component->name,
  474. sizeof (SaNameT));
  475. iovecs[0].iov_base = (char *)&req_exec_amf_componentregister;
  476. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  477. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  478. }
  479. /***
  480. This should be used for a partition I think
  481. **/
  482. void enumerate_components (
  483. void (*function)(struct saAmfComponent *, void *data),
  484. void *data)
  485. {
  486. struct list_head *AmfGroupList;
  487. struct list_head *AmfUnitList;
  488. struct list_head *AmfComponentList;
  489. struct saAmfGroup *saAmfGroup;
  490. struct saAmfUnit *AmfUnit;
  491. struct saAmfComponent *AmfComponent;
  492. /*
  493. * Search all groups
  494. */
  495. for (AmfGroupList = saAmfGroupHead.next;
  496. AmfGroupList != &saAmfGroupHead;
  497. AmfGroupList = AmfGroupList->next) {
  498. saAmfGroup = list_entry (AmfGroupList,
  499. struct saAmfGroup, saAmfGroupList);
  500. /*
  501. * Search all units
  502. */
  503. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  504. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  505. AmfUnitList = AmfUnitList->next) {
  506. AmfUnit = list_entry (AmfUnitList,
  507. struct saAmfUnit, saAmfUnitList);
  508. /*
  509. * Search all components
  510. */
  511. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  512. AmfComponentList != &AmfUnit->saAmfComponentHead;
  513. AmfComponentList = AmfComponentList->next) {
  514. AmfComponent = list_entry (AmfComponentList,
  515. struct saAmfComponent, saAmfComponentList);
  516. function (AmfComponent, data);
  517. }
  518. }
  519. }
  520. }
  521. int activeServiceUnitsCount (struct saAmfGroup *saAmfGroup) {
  522. struct saAmfUnit *saAmfUnit;
  523. struct saAmfComponent *saAmfComponent;
  524. struct list_head *saAmfComponentList;
  525. struct list_head *saAmfUnitList;
  526. int activeServiceUnits = 0;
  527. int thisServiceUnitActive;
  528. /*
  529. * Search all units
  530. */
  531. for (activeServiceUnits = 0, saAmfUnitList = saAmfGroup->saAmfUnitHead.next;
  532. saAmfUnitList != &saAmfGroup->saAmfUnitHead;
  533. saAmfUnitList = saAmfUnitList->next) {
  534. saAmfUnit = list_entry (saAmfUnitList,
  535. struct saAmfUnit, saAmfUnitList);
  536. /*
  537. * Search all components
  538. */
  539. for (thisServiceUnitActive = 1, saAmfComponentList = saAmfUnit->saAmfComponentHead.next;
  540. saAmfComponentList != &saAmfUnit->saAmfComponentHead;
  541. saAmfComponentList = saAmfComponentList->next) {
  542. saAmfComponent = list_entry (saAmfComponentList,
  543. struct saAmfComponent, saAmfComponentList);
  544. if (saAmfComponent->newHAState != SA_AMF_ACTIVE) {
  545. thisServiceUnitActive = 0;
  546. }
  547. }
  548. /*
  549. * If all components are active in service unit, count service unit as active
  550. */
  551. if (thisServiceUnitActive) {
  552. activeServiceUnits += 1;
  553. }
  554. }
  555. return (activeServiceUnits);
  556. }
  557. #ifdef CONFIG_TODO
  558. This should be sent after a service unit is made out of service
  559. void CSIRemove (struct conn_info *conn_info)
  560. {
  561. struct res_lib_amf_csiremovecallback res_lib_amf_csiremovecallback;
  562. if (conn_info->active == 0 ||
  563. conn_info->service != AMF_SERVICE) {
  564. return;
  565. }
  566. log_printf (LOG_NOTICE_DEBUG, "executing CSI remove callback into API\n");
  567. res_lib_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  568. res_lib_amf_csiremovecallback.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  569. res_lib_amf_csiremovecallback.header.error = SA_OK;
  570. res_lib_amf_csiremovecallback.invocation =
  571. req_amf_response_set (
  572. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK,
  573. conn_info->fd);
  574. memcpy (&res_lib_amf_csiremovecallback.compName,
  575. &conn_info->component->name, sizeof (SaNameT));
  576. memcpy (&res_lib_amf_csiremovecallback.csiName,
  577. &conn_info->component->saAmfProtectionGroup->name, sizeof (SaNameT));
  578. res_lib_amf_csiremovecallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  579. libais_send_response (conn_info, &res_lib_amf_csiremovecallback,
  580. sizeof (struct res_lib_amf_csiremovecallback));
  581. }
  582. #endif
  583. void ha_state_api_set (struct saAmfComponent *component, SaAmfHAStateT haState)
  584. {
  585. struct res_lib_amf_csisetcallback res_lib_amf_csisetcallback;
  586. memset (&res_lib_amf_csisetcallback,0,sizeof(res_lib_amf_csisetcallback));
  587. log_printf (LOG_LEVEL_ENTER_FUNC, "sending ha state to API\n");
  588. if (component->local != 1) {
  589. return;
  590. }
  591. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  592. return;
  593. }
  594. /*
  595. * this should be an assertion
  596. */
  597. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  598. component->conn_info->service != AMF_SERVICE) {
  599. return;
  600. }
  601. res_lib_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  602. res_lib_amf_csisetcallback.header.size = sizeof (struct res_lib_amf_csisetcallback);
  603. res_lib_amf_csisetcallback.header.error = SA_OK;
  604. res_lib_amf_csisetcallback.invocation =
  605. req_amf_invocation_create (
  606. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK,
  607. component->conn_info);
  608. if (res_lib_amf_csisetcallback.invocation == -1) {
  609. printf ("TODO set callback\n");
  610. }
  611. memcpy (&res_lib_amf_csisetcallback.compName,
  612. &component->name, sizeof (SaNameT));
  613. memcpy (&res_lib_amf_csisetcallback.csiName,
  614. &component->saAmfProtectionGroup->name, sizeof (SaNameT));
  615. res_lib_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  616. res_lib_amf_csisetcallback.haState = haState;
  617. // TODO set activeCompName to correct component name
  618. memcpy (&res_lib_amf_csisetcallback.activeCompName,
  619. &component->name, sizeof (SaNameT));
  620. res_lib_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN;
  621. component->newHAState = haState;
  622. libais_send_response (component->conn_info->conn_info_partner,
  623. &res_lib_amf_csisetcallback,
  624. sizeof (struct res_lib_amf_csisetcallback));
  625. }
  626. static void ha_state_group_set (
  627. struct saAmfComponent *component,
  628. SaAmfHAStateT haState)
  629. {
  630. struct req_exec_amf_hastateset req_exec_amf_hastateset;
  631. struct iovec iovecs[2];
  632. req_exec_amf_hastateset.header.id = MESSAGE_REQ_EXEC_AMF_HASTATESET;
  633. req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset);
  634. memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT));
  635. req_exec_amf_hastateset.haState = haState;
  636. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name));
  637. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState);
  638. iovecs[0].iov_base = (char *)&req_exec_amf_hastateset;
  639. iovecs[0].iov_len = sizeof (req_exec_amf_hastateset);
  640. totempg_mcast (iovecs, 1, TOTEMPG_AGREED);
  641. }
  642. void readiness_state_api_set (struct saAmfComponent *component,
  643. SaAmfReadinessStateT readinessState)
  644. {
  645. struct res_lib_amf_readinessstatesetcallback res_lib_amf_readinessstatesetcallback;
  646. memset (&res_lib_amf_readinessstatesetcallback,0,sizeof(res_lib_amf_readinessstatesetcallback));
  647. /*
  648. * If component is local, don't request service from API
  649. */
  650. if (component->local != 1) {
  651. return;
  652. }
  653. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  654. return;
  655. }
  656. /*
  657. * this should be an assertion
  658. */
  659. if (component->conn_info->state != CONN_STATE_ACTIVE ||
  660. component->conn_info->service != AMF_SERVICE) {
  661. return;
  662. }
  663. res_lib_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK;
  664. res_lib_amf_readinessstatesetcallback.header.size = sizeof (struct res_lib_amf_readinessstatesetcallback);
  665. res_lib_amf_readinessstatesetcallback.header.error = SA_OK;
  666. res_lib_amf_readinessstatesetcallback.invocation =
  667. req_amf_invocation_create (
  668. MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK,
  669. component->conn_info);
  670. if (res_lib_amf_readinessstatesetcallback.invocation == -1) {
  671. printf ("TODO readiness set callback\n");
  672. }
  673. memcpy (&res_lib_amf_readinessstatesetcallback.compName,
  674. &component->name, sizeof (SaNameT));
  675. res_lib_amf_readinessstatesetcallback.readinessState = readinessState;
  676. component->newReadinessState = readinessState;
  677. log_printf (LOG_LEVEL_DEBUG, "Setting conn_info %p to readiness state %d\n", component->conn_info, readinessState);
  678. libais_send_response (component->conn_info->conn_info_partner,
  679. &res_lib_amf_readinessstatesetcallback,
  680. sizeof (struct res_lib_amf_readinessstatesetcallback));
  681. }
  682. static void readiness_state_group_set (
  683. struct saAmfComponent *component,
  684. SaAmfReadinessStateT readinessState)
  685. {
  686. struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset;
  687. struct iovec iovecs[2];
  688. req_exec_amf_readinessstateset.header.id = MESSAGE_REQ_EXEC_AMF_READINESSSTATESET;
  689. req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset);
  690. memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT));
  691. req_exec_amf_readinessstateset.readinessState = readinessState;
  692. log_printf (LOG_LEVEL_ENTER_FUNC, "Sending message to all cluster nodes to set readiness state of component %s\n",
  693. getSaNameT (&component->name));
  694. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState);
  695. iovecs[0].iov_base = (char *)&req_exec_amf_readinessstateset;
  696. iovecs[0].iov_len = sizeof (req_exec_amf_readinessstateset);
  697. totempg_mcast (iovecs, 1, TOTEMPG_AGREED);
  698. }
  699. static void dsmDisabledUnlockedRegisteredOrErrorCancel (
  700. struct saAmfComponent *component)
  701. {
  702. struct saAmfUnit *unit;
  703. struct list_head *list;
  704. int serviceUnitEnabled;
  705. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n",
  706. getSaNameT (&component->name));
  707. unit = component->saAmfUnit;
  708. for (serviceUnitEnabled = 1, list = unit->saAmfComponentHead.next;
  709. list != &unit->saAmfComponentHead;
  710. list = list->next) {
  711. component = list_entry (list,
  712. struct saAmfComponent, saAmfComponentList);
  713. if (component->registered == 0 ||
  714. component->probableCause) {
  715. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n");
  716. serviceUnitEnabled = 0;
  717. break;
  718. }
  719. }
  720. if (serviceUnitEnabled == 1) {
  721. log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n");
  722. component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED;
  723. component->disabledUnlockedState = -1; // SHOULD BE INVALID
  724. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  725. dsm (component);
  726. }
  727. }
  728. static void dsmDisabledUnlockedFailedComponent (
  729. struct saAmfComponent *component)
  730. {
  731. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailedComponent: for %s.\n",
  732. getSaNameT (&component->name));
  733. switch (component->enabledUnlockedState) {
  734. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  735. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  736. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  737. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  738. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  739. } else {
  740. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  741. }
  742. break;
  743. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  744. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  745. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  746. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  747. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  748. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  749. ha_state_group_set (component, SA_AMF_QUIESCED);
  750. } else {
  751. ha_state_api_set (component, SA_AMF_QUIESCED);
  752. }
  753. poll_timer_delete (aisexec_poll_handle,
  754. component->timer_healthcheck);
  755. component->timer_healthcheck = 0;
  756. break;
  757. default:
  758. log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState);
  759. break;
  760. }
  761. }
  762. static void dsmDisabledUnlockedFailed (
  763. struct saAmfComponent *component)
  764. {
  765. struct saAmfUnit *unit;
  766. struct list_head *list;
  767. unit = component->saAmfUnit;
  768. for (list = unit->saAmfComponentHead.next;
  769. list != &unit->saAmfComponentHead;
  770. list = list->next) {
  771. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  772. dsmDisabledUnlockedFailedComponent (component);
  773. }
  774. return;
  775. }
  776. static void dsmDisabledUnlockedQuiescedRequested (
  777. struct saAmfComponent *component)
  778. {
  779. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  780. dsm (component);
  781. }
  782. static void dsmDisabledUnlockedQuiescedCompleted (
  783. struct saAmfComponent *component)
  784. {
  785. struct saAmfUnit *unit;
  786. struct list_head *list;
  787. int serviceUnitQuiesced;
  788. unit = component->saAmfUnit;
  789. for (serviceUnitQuiesced = 1, list = unit->saAmfComponentHead.next;
  790. list != &unit->saAmfComponentHead;
  791. list = list->next) {
  792. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  793. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  794. if (component->currentHAState != SA_AMF_QUIESCED) {
  795. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  796. serviceUnitQuiesced = 0;
  797. break;
  798. }
  799. }
  800. }
  801. if (serviceUnitQuiesced == 1) {
  802. log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n");
  803. for (list = unit->saAmfComponentHead.next;
  804. list != &unit->saAmfComponentHead;
  805. list = list->next) {
  806. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  807. log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n",
  808. getSaNameT (&component->name));
  809. if ( component->probableCause == SA_AMF_NOT_RESPONDING ) {
  810. readiness_state_group_set (component, SA_AMF_OUT_OF_SERVICE);
  811. } else {
  812. readiness_state_api_set (component, SA_AMF_OUT_OF_SERVICE);
  813. }
  814. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  815. }
  816. }
  817. }
  818. static void dsmDisabledUnlockedOutOfServiceRequested (
  819. struct saAmfComponent *component)
  820. {
  821. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  822. dsm (component);
  823. }
  824. static void dsmDisabledUnlockedOutOfServiceCompleted (
  825. struct saAmfComponent *component)
  826. {
  827. struct saAmfUnit *unit;
  828. struct list_head *list;
  829. int serviceUnitOutOfService;
  830. struct saAmfGroup *group = 0;
  831. struct list_head *comp_list = 0;
  832. struct list_head *unit_list = 0;
  833. int serviceUnitInStandby = 0;
  834. int activeServiceUnits = 0;
  835. /*
  836. * Once all components of a service unit are out of service,
  837. * activate another service unit in standby
  838. */
  839. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  840. /*
  841. * Determine if all components have responded to going out of service
  842. */
  843. unit = component->saAmfUnit;
  844. for (serviceUnitOutOfService = 1, list = unit->saAmfComponentHead.next;
  845. list != &unit->saAmfComponentHead;
  846. list = list->next) {
  847. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  848. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  849. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  850. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n");
  851. serviceUnitOutOfService = 0;
  852. break;
  853. }
  854. }
  855. if ( component->registered == 0 ) {
  856. protectiongroup_notifications_send (component, SA_AMF_PROTECTION_GROUP_REMOVED);
  857. }
  858. }
  859. group = unit->saAmfGroup;
  860. activeServiceUnits = activeServiceUnitsCount(group);
  861. if (activeServiceUnits>=group->saAmfActiveUnitsDesired) {
  862. return;
  863. }
  864. if (serviceUnitOutOfService == 1) {
  865. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  866. /*
  867. * Search all units
  868. */
  869. for (unit_list = group->saAmfUnitHead.next;
  870. unit_list != &group->saAmfUnitHead;
  871. unit_list = unit_list->next) {
  872. unit = list_entry (unit_list,
  873. struct saAmfUnit, saAmfUnitList);
  874. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  875. /*
  876. * Search all components
  877. */
  878. for (serviceUnitInStandby = 1,
  879. comp_list = unit->saAmfComponentHead.next;
  880. comp_list != &unit->saAmfComponentHead;
  881. comp_list = comp_list->next) {
  882. component = list_entry (comp_list,
  883. struct saAmfComponent, saAmfComponentList);
  884. if (component->currentHAState != SA_AMF_STANDBY) {
  885. serviceUnitInStandby = 0;
  886. break; /* for iteration of service unit components */
  887. }
  888. }
  889. if (serviceUnitInStandby) {
  890. break; /* for iteration of service group's service units */
  891. }
  892. }
  893. /*
  894. * All components in service unit are standby, activate standby service unit
  895. */
  896. if (serviceUnitInStandby) {
  897. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  898. for (list = unit->saAmfComponentHead.next;
  899. list != &unit->saAmfComponentHead;
  900. list = list->next) {
  901. component = list_entry (list,
  902. struct saAmfComponent, saAmfComponentList);
  903. ha_state_api_set (component, SA_AMF_ACTIVE);
  904. }
  905. } else {
  906. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  907. }
  908. }
  909. }
  910. static void dsmEnabledUnlockedInitial (
  911. struct saAmfComponent *component)
  912. {
  913. struct saAmfUnit *unit;
  914. struct list_head *list;
  915. unit = component->saAmfUnit;
  916. for (list = unit->saAmfComponentHead.next;
  917. list != &unit->saAmfComponentHead;
  918. list = list->next) {
  919. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  920. readiness_state_api_set (component, SA_AMF_IN_SERVICE);
  921. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  922. getSaNameT (&component->name));
  923. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  924. }
  925. }
  926. static void dsmEnabledUnlockedInServiceRequested (
  927. struct saAmfComponent *component)
  928. {
  929. struct saAmfUnit *unit;
  930. struct list_head *list;
  931. int in_service;
  932. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  933. unit = component->saAmfUnit;
  934. for (in_service = 1, list = unit->saAmfComponentHead.next;
  935. list != &unit->saAmfComponentHead;
  936. list = list->next) {
  937. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  938. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  939. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  940. in_service = 0;
  941. break;
  942. }
  943. }
  944. if (in_service) {
  945. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  946. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  947. dsm (component);
  948. }
  949. }
  950. static void dsmEnabledUnlockedInServiceCompleted (
  951. struct saAmfComponent *component)
  952. {
  953. struct saAmfUnit *unit;
  954. struct list_head *list;
  955. SaAmfHAStateT newHaState;
  956. int activeServiceUnits;
  957. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  958. unit = component->saAmfUnit;
  959. for (list = unit->saAmfComponentHead.next;
  960. list != &unit->saAmfComponentHead;
  961. list = list->next) {
  962. component = list_entry (list,
  963. struct saAmfComponent, saAmfComponentList);
  964. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n");
  965. /*
  966. * Count number of active service units
  967. */
  968. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  969. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  970. newHaState = SA_AMF_ACTIVE;
  971. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  972. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  973. } else {
  974. newHaState = SA_AMF_STANDBY;
  975. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  976. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  977. }
  978. ha_state_api_set (component, newHaState);
  979. }
  980. }
  981. static void dsmEnabledUnlockedActiveRequested (
  982. struct saAmfComponent *component)
  983. {
  984. if (component->local == 1) {
  985. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer1\n");
  986. poll_timer_add (aisexec_poll_handle,
  987. component->healthcheckInterval,
  988. (void *)component->conn_info,
  989. timer_function_libamf_healthcheck,
  990. &component->timer_healthcheck);
  991. }
  992. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  993. }
  994. static void dsmEnabledUnlockedStandbyRequested (
  995. struct saAmfComponent *component)
  996. {
  997. if (component->local == 1) {
  998. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer2\n");
  999. poll_timer_add (aisexec_poll_handle,
  1000. component->healthcheckInterval,
  1001. (void *)component->conn_info,
  1002. timer_function_libamf_healthcheck,
  1003. &component->timer_healthcheck);
  1004. }
  1005. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  1006. }
  1007. static void dsmEnabledUnlockedTransitionDisabledUnlocked (
  1008. struct saAmfComponent *component)
  1009. {
  1010. struct saAmfUnit *unit;
  1011. struct list_head *list;
  1012. unit = component->saAmfUnit;
  1013. for (list = unit->saAmfComponentHead.next;
  1014. list != &unit->saAmfComponentHead;
  1015. list = list->next) {
  1016. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  1017. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  1018. getSaNameT (&component->name));
  1019. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  1020. }
  1021. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  1022. dsm (component);
  1023. }
  1024. static void dsmSynchronizeStaus (
  1025. struct saAmfComponent *component)
  1026. {
  1027. enum amfOperationalAdministrativeState unit_status = AMF_DISABLED_UNLOCKED;
  1028. struct saAmfUnit *unit;
  1029. struct saAmfGroup *group;
  1030. struct list_head *list;
  1031. int activeServiceUnits;
  1032. if (component->currentReadinessState == component->newReadinessState) {
  1033. if (component->currentReadinessState == SA_AMF_OUT_OF_SERVICE) {
  1034. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1035. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1036. } else if (component->currentReadinessState == SA_AMF_IN_SERVICE) {
  1037. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1038. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  1039. unit_status = AMF_ENABLED_UNLOCKED;
  1040. } else if (component->currentReadinessState == SA_AMF_QUIESCED) {
  1041. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  1042. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1043. }
  1044. } else {
  1045. if (component->newReadinessState == SA_AMF_OUT_OF_SERVICE) {
  1046. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  1047. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1048. } else if (component->newReadinessState == SA_AMF_IN_SERVICE) {
  1049. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1050. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  1051. unit_status = AMF_ENABLED_UNLOCKED;
  1052. } else {
  1053. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  1054. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1055. }
  1056. }
  1057. if (component->currentHAState == component->newHAState) {
  1058. if (component->currentHAState == SA_AMF_ACTIVE) {
  1059. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1060. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  1061. unit_status = AMF_ENABLED_UNLOCKED;
  1062. } else if (component->currentHAState == SA_AMF_STANDBY) {
  1063. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1064. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  1065. unit_status = AMF_ENABLED_UNLOCKED;
  1066. } else {
  1067. /* depend on readiness status */
  1068. }
  1069. } else {
  1070. if (component->newHAState == SA_AMF_ACTIVE) {
  1071. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1072. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  1073. unit_status = AMF_ENABLED_UNLOCKED;
  1074. } else if (component->newHAState == SA_AMF_STANDBY) {
  1075. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1076. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  1077. unit_status = AMF_ENABLED_UNLOCKED;
  1078. } else {
  1079. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  1080. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1081. }
  1082. }
  1083. /* Syncronize Operational AdministrativeState */
  1084. component->saAmfUnit->operationalAdministrativeState = unit_status;
  1085. unit = component->saAmfUnit;
  1086. group = unit->saAmfGroup;
  1087. for (list = unit->saAmfComponentHead.next; list != &unit->saAmfComponentHead; list = list->next) {
  1088. activeServiceUnits = activeServiceUnitsCount(group);
  1089. if (activeServiceUnits <= group->saAmfActiveUnitsDesired) {
  1090. break;
  1091. }
  1092. if (component->currentHAState != SA_AMF_ACTIVE) {
  1093. continue;
  1094. }
  1095. ha_state_api_set (component, SA_AMF_STANDBY);
  1096. }
  1097. return;
  1098. }
  1099. static void dsmEnabledUnlocked (
  1100. struct saAmfComponent *component)
  1101. {
  1102. switch (component->enabledUnlockedState) {
  1103. case AMF_ENABLED_UNLOCKED_INITIAL:
  1104. dsmEnabledUnlockedInitial (component);
  1105. break;
  1106. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  1107. dsmEnabledUnlockedInServiceRequested (component);
  1108. break;
  1109. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  1110. dsmEnabledUnlockedInServiceCompleted (component);
  1111. break;
  1112. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  1113. dsmEnabledUnlockedActiveRequested (component);
  1114. break;
  1115. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  1116. /* noop - operational state */
  1117. break;
  1118. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  1119. dsmEnabledUnlockedStandbyRequested (component);
  1120. break;
  1121. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  1122. /* noop - operational state */
  1123. break;
  1124. default:
  1125. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  1126. }
  1127. }
  1128. static void dsmDisabledUnlocked (
  1129. struct saAmfComponent *component)
  1130. {
  1131. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  1132. getSaNameT (&component->name),
  1133. component->disabledUnlockedState);
  1134. switch (component->disabledUnlockedState) {
  1135. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  1136. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  1137. break;
  1138. case AMF_DISABLED_UNLOCKED_FAILED:
  1139. dsmDisabledUnlockedFailed (component);
  1140. break;
  1141. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  1142. dsmDisabledUnlockedQuiescedRequested (component);
  1143. break;
  1144. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  1145. dsmDisabledUnlockedQuiescedCompleted (component);
  1146. break;
  1147. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  1148. dsmDisabledUnlockedOutOfServiceRequested (component);
  1149. break;
  1150. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  1151. dsmDisabledUnlockedOutOfServiceCompleted (component);
  1152. break;
  1153. default:
  1154. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  1155. }
  1156. }
  1157. static void dsm (
  1158. struct saAmfComponent *component)
  1159. {
  1160. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  1161. switch (component->saAmfUnit->operationalAdministrativeState) {
  1162. case AMF_DISABLED_UNLOCKED:
  1163. dsmDisabledUnlocked (component);
  1164. break;
  1165. case AMF_ENABLED_UNLOCKED:
  1166. dsmEnabledUnlocked (component);
  1167. break;
  1168. /*
  1169. AMF_DISABLED_LOCKED,
  1170. AMF_ENABLED_STOPPING
  1171. */
  1172. default:
  1173. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  1174. }
  1175. }
  1176. #if 0
  1177. /*
  1178. * This is currently unused, but executes the componentterminatecallback
  1179. * callback in the AMF api.
  1180. */
  1181. void componentTerminate (struct conn_info *conn_info)
  1182. {
  1183. struct res_lib_amf_componentterminatecallback res_lib_amf_componentterminatecallback;
  1184. res_lib_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  1185. res_lib_amf_componentterminatecallback.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  1186. res_lib_amf_componentterminatecallback.header.error = SA_OK;
  1187. res_lib_amf_componentterminatecallback.invocation =
  1188. req_amf_response_set (
  1189. MESSAGE_REQ_AMF_RESPONSE_SAAMFCOMPONENTTERMINATECALLBACK,
  1190. fd);
  1191. memcpy (&res_lib_amf_componentterminatecallback.compName,
  1192. &connections[fd].component->name, sizeof (SaNameT));
  1193. connections[fd].component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1194. log_printf (LOG_LEVEL_DEBUG, "terminating component on fd %d\n", fd);
  1195. libais_send_response (fd, &res_lib_amf_componentterminatecallback,
  1196. sizeof (struct res_lib_amf_componentterminatecallback));
  1197. }
  1198. #endif /* Not currently implemented */
  1199. void error_report (
  1200. struct saAmfComponent *component,
  1201. SaAmfProbableCauseT probableCause)
  1202. {
  1203. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  1204. struct iovec iovecs[2];
  1205. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  1206. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  1207. req_exec_amf_errorreport.source.conn_info = 0;
  1208. req_exec_amf_errorreport.source.in_addr.s_addr = 0;
  1209. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport.erroneousComponent,
  1210. &component->name,
  1211. sizeof (SaNameT));
  1212. req_exec_amf_errorreport.req_lib_amf_errorreport.errorDescriptor.probableCause = probableCause;
  1213. iovecs[0].iov_base = (char *)&req_exec_amf_errorreport;
  1214. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  1215. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1216. }
  1217. int healthcheck_instance = 0;
  1218. void timer_function_libamf_healthcheck (void *data) {
  1219. struct conn_info *conn_info = (struct conn_info *)data;
  1220. struct res_lib_amf_healthcheckcallback res_lib_amf_healthcheckcallback;
  1221. memset (&res_lib_amf_healthcheckcallback, 0, sizeof(res_lib_amf_healthcheckcallback));
  1222. res_lib_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  1223. res_lib_amf_healthcheckcallback.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  1224. res_lib_amf_healthcheckcallback.header.error = SA_OK;
  1225. log_printf (LOG_LEVEL_DEBUG, "checking healthcheck on component %s\n",
  1226. getSaNameT (&conn_info->component->name));
  1227. if (conn_info->component->healthcheck_outstanding == 1) {
  1228. log_printf (LOG_LEVEL_DEBUG, "Healthcheck timed out on component %s\n",
  1229. getSaNameT (&conn_info->component->name));
  1230. /*
  1231. * Report the error to the rest of the cluster using the normal state machine
  1232. */
  1233. error_report (conn_info->component, SA_AMF_NOT_RESPONDING);
  1234. conn_info->component->healthcheck_outstanding = 2;
  1235. } else
  1236. if (conn_info->component->healthcheck_outstanding == 0) {
  1237. conn_info->component->healthcheck_outstanding = 1;
  1238. /*
  1239. * Send healthcheck message
  1240. */
  1241. res_lib_amf_healthcheckcallback.invocation =
  1242. req_amf_invocation_create (
  1243. MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK,
  1244. conn_info);
  1245. if (res_lib_amf_healthcheckcallback.invocation == -1) {
  1246. printf ("TODO healthcheck set callback\n");
  1247. }
  1248. memcpy (&res_lib_amf_healthcheckcallback.compName,
  1249. &conn_info->component->name,
  1250. sizeof (SaNameT));
  1251. res_lib_amf_healthcheckcallback.checkType = SA_AMF_HEARTBEAT;
  1252. log_printf (LOG_LEVEL_DEBUG, "Sending instance %d\n", healthcheck_instance);
  1253. res_lib_amf_healthcheckcallback.instance = healthcheck_instance++;
  1254. libais_send_response (conn_info->conn_info_partner,
  1255. &res_lib_amf_healthcheckcallback,
  1256. sizeof (struct res_lib_amf_healthcheckcallback));
  1257. poll_timer_add (aisexec_poll_handle,
  1258. conn_info->component->healthcheckInterval,
  1259. (void *)conn_info,
  1260. timer_function_libamf_healthcheck,
  1261. &conn_info->component->timer_healthcheck);
  1262. }
  1263. }
  1264. struct saAmfProtectionGroup *protectiongroup_find (
  1265. SaNameT *csiName)
  1266. {
  1267. struct list_head *AmfGroupList;
  1268. struct list_head *AmfProtectionGroupList;
  1269. struct saAmfGroup *saAmfGroup;
  1270. struct saAmfProtectionGroup *AmfProtectionGroup;
  1271. /*
  1272. * Search all groups
  1273. */
  1274. for (AmfGroupList = saAmfGroupHead.next;
  1275. AmfGroupList != &saAmfGroupHead;
  1276. AmfGroupList = AmfGroupList->next) {
  1277. saAmfGroup = list_entry (AmfGroupList,
  1278. struct saAmfGroup, saAmfGroupList);
  1279. /*
  1280. * Search all protection groups
  1281. */
  1282. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1283. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1284. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1285. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1286. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1287. if (name_match (csiName, &AmfProtectionGroup->name)) {
  1288. return (AmfProtectionGroup);
  1289. }
  1290. }
  1291. }
  1292. return (0);
  1293. }
  1294. struct saAmfComponent *component_in_protectiongroup_find (
  1295. SaNameT *csiName,
  1296. SaNameT *compName)
  1297. {
  1298. struct list_head *AmfGroupList = 0;
  1299. struct list_head *AmfProtectionGroupList = 0;
  1300. struct list_head *AmfComponentList = 0;
  1301. struct saAmfGroup *saAmfGroup = 0;
  1302. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  1303. struct saAmfComponent *AmfComponent = 0;
  1304. int found = 0;
  1305. /*
  1306. * Search all groups
  1307. */
  1308. for (AmfGroupList = saAmfGroupHead.next;
  1309. AmfGroupList != &saAmfGroupHead;
  1310. AmfGroupList = AmfGroupList->next) {
  1311. saAmfGroup = list_entry (AmfGroupList,
  1312. struct saAmfGroup, saAmfGroupList);
  1313. /*
  1314. * Search all protection groups
  1315. */
  1316. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1317. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1318. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1319. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1320. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1321. if (name_match (csiName, &AmfProtectionGroup->name)) {
  1322. /*
  1323. * Search all components
  1324. */
  1325. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  1326. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  1327. AmfComponentList = AmfComponentList->next) {
  1328. AmfComponent = list_entry (AmfComponentList,
  1329. struct saAmfComponent, saAmfProtectionGroupList);
  1330. if (name_match (compName, &AmfComponent->name)) {
  1331. found = 1;
  1332. }
  1333. }
  1334. }
  1335. }
  1336. }
  1337. if (found) {
  1338. return (AmfComponent);
  1339. } else {
  1340. return (0);
  1341. }
  1342. }
  1343. DECLARE_LIST_INIT (library_notification_send_listhead);
  1344. // TODO static totempg_recovery_plug_handle amf_recovery_plug_handle;
  1345. static void protectiongroup_notifications_send (
  1346. struct saAmfComponent *changedComponent,
  1347. SaAmfProtectionGroupChangesT changeToComponent)
  1348. {
  1349. int i;
  1350. struct conn_info *conn_info;
  1351. struct list_head *list;
  1352. log_printf (LOG_LEVEL_ENTER_FUNC, "protectiongroup_notifications_send: sending PGs to API.\n");
  1353. /*
  1354. * Iterate all tracked connections
  1355. */
  1356. for (list = library_notification_send_listhead.next;
  1357. list != &library_notification_send_listhead;
  1358. list = list->next) {
  1359. conn_info = list_entry (list, struct conn_info, conn_list);
  1360. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1361. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active) {
  1362. if (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length
  1363. != changedComponent->saAmfProtectionGroup->name.length) {
  1364. continue;
  1365. }
  1366. if (memcmp (conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.value,
  1367. changedComponent->saAmfProtectionGroup->name.value,
  1368. conn_info->ais_ci.u.libamf_ci.tracks[i].csiName.length)) {
  1369. continue;
  1370. }
  1371. protectiongroup_notification_send (conn_info,
  1372. conn_info->ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  1373. changedComponent->saAmfProtectionGroup,
  1374. changedComponent,
  1375. changeToComponent,
  1376. conn_info->ais_ci.u.libamf_ci.tracks[i].trackFlags);
  1377. } /* if track flags active */
  1378. } /* for all track entries */
  1379. } /* for all connection entries */
  1380. }
  1381. static int make_protectiongroup_notification_allcomponent (
  1382. struct saAmfComponent *changedComponent,
  1383. SaAmfProtectionGroupChangesT changeToComponent,
  1384. SaAmfProtectionGroupNotificationT **notification )
  1385. {
  1386. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1387. int notifyEntries = 0;
  1388. struct saAmfComponent *component;
  1389. struct list_head *AmfGroupList;
  1390. struct list_head *AmfUnitList;
  1391. struct list_head *AmfComponentList;
  1392. struct saAmfGroup *saAmfGroup;
  1393. struct saAmfUnit *AmfUnit;
  1394. for (AmfGroupList = saAmfGroupHead.next; AmfGroupList != &saAmfGroupHead; AmfGroupList = AmfGroupList->next) {
  1395. saAmfGroup = list_entry (AmfGroupList, struct saAmfGroup, saAmfGroupList);
  1396. /*
  1397. * Search all units
  1398. */
  1399. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  1400. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  1401. AmfUnitList = AmfUnitList->next) {
  1402. AmfUnit = list_entry (AmfUnitList, struct saAmfUnit, saAmfUnitList);
  1403. /*
  1404. * Search all components
  1405. */
  1406. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  1407. AmfComponentList != &AmfUnit->saAmfComponentHead;
  1408. AmfComponentList = AmfComponentList->next) {
  1409. component = list_entry (AmfComponentList, struct saAmfComponent, saAmfComponentList);
  1410. protectionGroupNotification =
  1411. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1412. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1413. memset (&protectionGroupNotification[notifyEntries],
  1414. 0,sizeof (SaAmfProtectionGroupNotificationT));
  1415. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1416. &component->name, sizeof (SaNameT));
  1417. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1418. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1419. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1420. &component->currentHAState, sizeof (SaAmfHAStateT));
  1421. if (component == changedComponent) {
  1422. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1423. } else {
  1424. protectionGroupNotification[notifyEntries].change
  1425. = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1426. }
  1427. notifyEntries += 1;
  1428. }
  1429. }
  1430. }
  1431. if (notifyEntries) {
  1432. *notification = protectionGroupNotification;
  1433. }
  1434. return (notifyEntries);
  1435. }
  1436. static int make_protectiongroup_notification (
  1437. struct saAmfProtectionGroup *amfProtectionGroup,
  1438. struct saAmfComponent *changedComponent,
  1439. SaAmfProtectionGroupChangesT changeToComponent,
  1440. SaAmfProtectionGroupNotificationT **notification )
  1441. {
  1442. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1443. int notifyEntries = 0;
  1444. struct saAmfComponent *component;
  1445. struct list_head *componentList;
  1446. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1447. memset (&res_lib_amf_protectiongrouptrackcallback,0,sizeof(res_lib_amf_protectiongrouptrackcallback));
  1448. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  1449. componentList != &amfProtectionGroup->saAmfMembersHead;
  1450. componentList = componentList->next) {
  1451. component = list_entry (componentList, struct saAmfComponent, saAmfProtectionGroupList);
  1452. protectionGroupNotification =
  1453. (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1454. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1455. memset (&protectionGroupNotification[notifyEntries],0,sizeof (SaAmfProtectionGroupNotificationT));
  1456. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1457. &component->name, sizeof (SaNameT));
  1458. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1459. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1460. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1461. &component->currentHAState, sizeof (SaAmfHAStateT));
  1462. if (component == changedComponent) {
  1463. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1464. } else {
  1465. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1466. }
  1467. notifyEntries += 1;
  1468. } /* for */
  1469. if (notifyEntries) {
  1470. *notification = protectionGroupNotification;
  1471. }
  1472. return (notifyEntries);
  1473. }
  1474. static void protectiongroup_notification_send (struct conn_info *conn_info,
  1475. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  1476. struct saAmfProtectionGroup *amfProtectionGroup,
  1477. struct saAmfComponent *changedComponent,
  1478. SaAmfProtectionGroupChangesT changeToComponent,
  1479. SaUint8T trackFlags)
  1480. {
  1481. struct res_lib_amf_protectiongrouptrackcallback res_lib_amf_protectiongrouptrackcallback;
  1482. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1483. int notifyEntries;
  1484. /*
  1485. * Step through all components and generate protection group list for csi
  1486. */
  1487. memset (&res_lib_amf_protectiongrouptrackcallback, 0, sizeof(res_lib_amf_protectiongrouptrackcallback));
  1488. if ( trackFlags == SA_TRACK_CHANGES ) {
  1489. notifyEntries = make_protectiongroup_notification_allcomponent (changedComponent,
  1490. changeToComponent, &protectionGroupNotification);
  1491. }else if (trackFlags == SA_TRACK_CHANGES_ONLY) {
  1492. notifyEntries = make_protectiongroup_notification (amfProtectionGroup,
  1493. changedComponent, changeToComponent, &protectionGroupNotification );
  1494. }else{
  1495. notifyEntries = 0;
  1496. }
  1497. /*
  1498. * Send track callback
  1499. */
  1500. if (notifyEntries) {
  1501. res_lib_amf_protectiongrouptrackcallback.header.size =
  1502. sizeof (struct res_lib_amf_protectiongrouptrackcallback) +
  1503. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  1504. res_lib_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  1505. res_lib_amf_protectiongrouptrackcallback.header.error = SA_OK;
  1506. res_lib_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  1507. res_lib_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  1508. memcpy (&res_lib_amf_protectiongrouptrackcallback.csiName,
  1509. &amfProtectionGroup->name, sizeof (SaNameT));
  1510. res_lib_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1511. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackcallback,
  1512. sizeof (struct res_lib_amf_protectiongrouptrackcallback));
  1513. libais_send_response (conn_info, protectionGroupNotification,
  1514. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1515. mempool_free (protectionGroupNotification);
  1516. }
  1517. }
  1518. /*
  1519. * The response handler for readiness state set callback
  1520. */
  1521. static void response_handler_readinessstatesetcallback (struct conn_info *conn_info,
  1522. struct req_amf_response *req_amf_response)
  1523. {
  1524. if (req_amf_response->error == SA_OK && conn_info->component) {
  1525. log_printf (LOG_LEVEL_ENTER_FUNC, "CALLBACK sending readiness state to %s\n",
  1526. getSaNameT (&conn_info->component->name));
  1527. readiness_state_group_set (conn_info->component, conn_info->component->newReadinessState);
  1528. }
  1529. }
  1530. /*
  1531. * iterate service unit components
  1532. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  1533. */
  1534. static void response_handler_csisetcallback (struct conn_info *conn_info,
  1535. struct req_amf_response *req_amf_response)
  1536. {
  1537. if (req_amf_response->error == SA_OK && conn_info->component) {
  1538. ha_state_group_set (conn_info->component, conn_info->component->newHAState);
  1539. }
  1540. }
  1541. static int amf_exec_init_fn (struct openais_config *openais_config)
  1542. {
  1543. #ifdef TODO
  1544. int res;
  1545. res = totempg_recovery_plug_create (&amf_recovery_plug_handle);
  1546. if (res != 0) {
  1547. log_printf(LOG_LEVEL_ERROR,
  1548. "Could not create recovery plug for amf service.\n");
  1549. return (-1);
  1550. }
  1551. #endif
  1552. return (0);
  1553. }
  1554. void amf_confchg_njoin (struct saAmfComponent *component ,void *data)
  1555. {
  1556. if (component->source_addr.s_addr != this_ip->sin_addr.s_addr) {
  1557. return;
  1558. }
  1559. component_register (component);
  1560. return;
  1561. }
  1562. void amf_confchg_nleave (struct saAmfComponent *component ,void *data)
  1563. {
  1564. struct in_addr *source_addr = (struct in_addr *)data;
  1565. struct saAmfUnit *unit;
  1566. struct list_head *list;
  1567. struct saAmfComponent *leave_component = NULL;
  1568. enum amfDisabledUnlockedState disablestate = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  1569. if (component->source_addr.s_addr != source_addr->s_addr) {
  1570. return;
  1571. }
  1572. if (!component->registered) {
  1573. return;
  1574. }
  1575. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_confchg_nleave(%s)\n", getSaNameT (&(component->name)));
  1576. /* Component status Initialize */
  1577. unit = component->saAmfUnit;
  1578. for (list = unit->saAmfComponentHead.next; list != &unit->saAmfComponentHead; list = list->next) {
  1579. component = list_entry (list,
  1580. struct saAmfComponent, saAmfComponentList);
  1581. if (component->source_addr.s_addr != source_addr->s_addr) {
  1582. disablestate = AMF_DISABLED_UNLOCKED_FAILED;
  1583. continue;
  1584. }
  1585. component->registered = 0;
  1586. component->local = 0;
  1587. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1588. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  1589. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1590. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1591. component->newHAState = SA_AMF_QUIESCED;
  1592. component->currentHAState = SA_AMF_QUIESCED;
  1593. component->source_addr.s_addr = 0;
  1594. leave_component = component;
  1595. }
  1596. if (leave_component == NULL) {
  1597. return;
  1598. }
  1599. leave_component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  1600. leave_component->disabledUnlockedState = disablestate;
  1601. dsm (leave_component);
  1602. leave_component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1603. return;
  1604. }
  1605. static int amf_confchg_fn (
  1606. enum totem_configuration_type configuration_type,
  1607. struct in_addr *member_list, int member_list_entries,
  1608. struct in_addr *left_list, int left_list_entries,
  1609. struct in_addr *joined_list, int joined_list_entries,
  1610. struct memb_ring_id *ring_id)
  1611. {
  1612. int i;
  1613. log_printf (LOG_LEVEL_FROM_GMI, "Executive: amf_confchg_fn : type = %d,mnum = %d,jnum = %d,lnum = %d\n", configuration_type,member_list_entries,joined_list_entries,left_list_entries);
  1614. recovery = 1;
  1615. /*
  1616. * If node join, component register
  1617. */
  1618. if ( joined_list_entries > 0 ) {
  1619. enumerate_components (amf_confchg_njoin, NULL);
  1620. }
  1621. /*
  1622. * If node leave, component unregister
  1623. */
  1624. for (i = 0; i<left_list_entries ; i++) {
  1625. enumerate_components (amf_confchg_nleave, (void *)&(left_list[i]));
  1626. }
  1627. #ifdef TODO
  1628. if (configuration_type == TOTEMPG_CONFIGURATION_REGULAR) {
  1629. totempg_recovery_plug_unplug (amf_recovery_plug_handle);
  1630. recovery = 0;
  1631. }
  1632. #endif
  1633. return (0);
  1634. }
  1635. int amf_exit_fn (struct conn_info *conn_info)
  1636. {
  1637. /*
  1638. * Unregister all components registered to this file descriptor
  1639. */
  1640. if (conn_info->service == AMF_SERVICE) {
  1641. component_unregister (conn_info->conn_info_partner->component);
  1642. if (conn_info->conn_info_partner->component &&
  1643. conn_info->conn_info_partner->component->timer_healthcheck) {
  1644. poll_timer_delete (aisexec_poll_handle,
  1645. conn_info->conn_info_partner->component->timer_healthcheck);
  1646. conn_info->conn_info_partner->component->timer_healthcheck = 0;
  1647. }
  1648. if (conn_info->conn_info_partner->ais_ci.u.libamf_ci.tracks) {
  1649. mempool_free (conn_info->conn_info_partner->ais_ci.u.libamf_ci.tracks);
  1650. conn_info->conn_info_partner->ais_ci.u.libamf_ci.tracks = 0;
  1651. list_del (&conn_info->conn_info_partner->conn_list);
  1652. }
  1653. }
  1654. return (0);
  1655. }
  1656. static int message_handler_req_exec_amf_componentregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  1657. {
  1658. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1659. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1660. struct saAmfComponent *component;
  1661. struct saAmfComponent *amfProxyComponent;
  1662. SaErrorT error;
  1663. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ComponentRegister for component %s\n",
  1664. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1665. /*
  1666. * Determine if proxy isn't registered
  1667. */
  1668. error = SA_OK;
  1669. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1670. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1671. /*
  1672. * If a node is joining menber ship ,Component States Synchronize
  1673. */
  1674. if (req_exec_amf_componentregister->source.in_addr.s_addr == 0) {
  1675. amf_synchronize (message, source_addr);
  1676. return (0);
  1677. }
  1678. /*
  1679. * If component not in configuration files, return error
  1680. */
  1681. if (component == 0) {
  1682. error = SA_ERR_NOT_EXIST;
  1683. }
  1684. /*
  1685. * If proxy doesn't exist and isn't registered, return error
  1686. */
  1687. if ((amfProxyComponent == 0 &&
  1688. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  1689. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  1690. error = SA_ERR_NOT_EXIST;
  1691. }
  1692. /*
  1693. * If component already registered, return error
  1694. */
  1695. if (error == SA_OK) {
  1696. if (component->registered) {
  1697. error = SA_ERR_EXIST;
  1698. }
  1699. }
  1700. /*
  1701. * Finally register component and setup links for proxy if
  1702. * proxy present
  1703. */
  1704. if (error == SA_OK) {
  1705. component->local = 0;
  1706. component->registered = 1;
  1707. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  1708. component->source_addr = source_addr;
  1709. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1710. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1711. component->currentHAState = 0;
  1712. component->newHAState = 0;
  1713. component->probableCause = 0;
  1714. component->enabledUnlockedState = 0;
  1715. component->disabledUnlockedState = 0;
  1716. component->healthcheck_outstanding = 0;
  1717. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1718. component->saAmfProxyComponent = amfProxyComponent;
  1719. }
  1720. }
  1721. /*
  1722. * If this node originated the request to the cluster, respond back
  1723. * to the AMF library
  1724. */
  1725. if (message_source_is_local(&req_exec_amf_componentregister->source)) {
  1726. if (error == SA_OK) {
  1727. component->local = 1;
  1728. req_exec_amf_componentregister->source.conn_info->component = component;
  1729. }
  1730. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n",
  1731. req_exec_amf_componentregister->source.conn_info->fd);
  1732. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1733. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1734. res_lib_amf_componentregister.header.error = error;
  1735. libais_send_response (req_exec_amf_componentregister->source.conn_info,
  1736. &res_lib_amf_componentregister,
  1737. sizeof (struct res_lib_amf_componentregister));
  1738. }
  1739. /*
  1740. * If no error on registration, determine if we should enter new state
  1741. */
  1742. if (error == SA_OK) {
  1743. dsm (component);
  1744. }
  1745. return (0);
  1746. }
  1747. static void amf_synchronize (void *message, struct in_addr source_addr)
  1748. {
  1749. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1750. struct saAmfComponent *component;
  1751. struct saAmfComponent *amfProxyComponent;
  1752. log_printf (LOG_LEVEL_ENTER_FUNC, "amf_synchronize%s\n",
  1753. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1754. /* Find Component */
  1755. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1756. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1757. /* If this processor is component owner */
  1758. if (component->source_addr.s_addr == this_ip->sin_addr.s_addr) {
  1759. /* No Operation */
  1760. return;
  1761. }
  1762. /* If this isn't synchronizing target processor */
  1763. if (!(component->local == 0 && component->registered == 0)){
  1764. /* No Operation */
  1765. return;
  1766. }
  1767. /* Synchronize Status */
  1768. component->local = 0;
  1769. component->registered = 1;
  1770. component->conn_info = req_exec_amf_componentregister->source.conn_info;
  1771. component->source_addr = source_addr;
  1772. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1773. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1774. component->currentHAState = SA_AMF_QUIESCED;
  1775. component->newHAState = SA_AMF_QUIESCED;
  1776. component->probableCause = 0;
  1777. component->enabledUnlockedState = 0;
  1778. component->disabledUnlockedState = 0;
  1779. component->currentReadinessState = req_exec_amf_componentregister->currentReadinessState;
  1780. component->newReadinessState = req_exec_amf_componentregister->newReadinessState;
  1781. component->currentHAState = req_exec_amf_componentregister->currentHAState;
  1782. component->newHAState = req_exec_amf_componentregister->newHAState;
  1783. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1784. component->saAmfProxyComponent = amfProxyComponent;
  1785. }
  1786. /*
  1787. * Determine if we should enter new state
  1788. */
  1789. dsmSynchronizeStaus (component);
  1790. return;
  1791. }
  1792. static int message_handler_req_exec_amf_componentunregister (void *message, struct in_addr source_addr, int endian_conversion_required)
  1793. {
  1794. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  1795. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  1796. struct saAmfComponent *component;
  1797. struct saAmfComponent *amfProxyComponent;
  1798. SaErrorT error;
  1799. log_printf (LOG_LEVEL_FROM_GMI, "Executive: Component_unregister for %s\n",
  1800. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  1801. component = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  1802. amfProxyComponent = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  1803. /*
  1804. * Check for proxy and component not existing in system
  1805. */
  1806. error = SA_OK;
  1807. if (component == 0) {
  1808. error = SA_ERR_NOT_EXIST;
  1809. }
  1810. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  1811. if (amfProxyComponent) {
  1812. if (amfProxyComponent->registered == 0) {
  1813. error = SA_ERR_NOT_EXIST;
  1814. }
  1815. } else {
  1816. error = SA_ERR_NOT_EXIST;
  1817. }
  1818. }
  1819. /*
  1820. * If there is a proxycompname, make sure it is the proxy
  1821. * of compName
  1822. */
  1823. if (error == SA_OK && amfProxyComponent) {
  1824. if (component->saAmfProxyComponent != amfProxyComponent) {
  1825. error = SA_ERR_BAD_OPERATION;
  1826. }
  1827. }
  1828. /*
  1829. * Finally unregister the component
  1830. */
  1831. if (error == SA_OK) {
  1832. component->registered = 0;
  1833. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1834. }
  1835. /*
  1836. * If this node originated the request to the cluster, respond back
  1837. * to the AMF library
  1838. */
  1839. if (message_source_is_local (&req_exec_amf_componentunregister->source)) {
  1840. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  1841. req_exec_amf_componentunregister->source.conn_info->fd);
  1842. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  1843. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  1844. res_lib_amf_componentunregister.header.error = error;
  1845. libais_send_response (req_exec_amf_componentunregister->source.conn_info,
  1846. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  1847. }
  1848. return (0);
  1849. }
  1850. static int message_handler_req_exec_amf_errorreport (void *message, struct in_addr source_addr, int endian_conversion_required)
  1851. {
  1852. struct req_exec_amf_errorreport *req_exec_amf_errorreport = (struct req_exec_amf_errorreport *)message;
  1853. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  1854. struct saAmfComponent *component;
  1855. SaErrorT error = SA_ERR_BAD_OPERATION;
  1856. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorReport for %s\n",
  1857. getSaNameT (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent));
  1858. component = findComponent (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent);
  1859. if (component && component->registered) {
  1860. component->probableCause = req_exec_amf_errorreport->req_lib_amf_errorreport.errorDescriptor.probableCause;
  1861. /*
  1862. * One registered component left, so transition
  1863. * SU to failed operational state
  1864. */
  1865. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1866. error = SA_OK;
  1867. }
  1868. /*
  1869. * If this node originated the request to the cluster, respond back
  1870. * to the AMF library
  1871. */
  1872. if (message_source_is_local (&req_exec_amf_errorreport->source)) {
  1873. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1874. req_exec_amf_errorreport->source.conn_info->fd);
  1875. res_lib_amf_errorreport.header.size = sizeof (struct res_lib_amf_errorreport);
  1876. res_lib_amf_errorreport.header.id = MESSAGE_RES_AMF_ERRORREPORT;
  1877. res_lib_amf_errorreport.header.error = error;
  1878. libais_send_response (req_exec_amf_errorreport->source.conn_info,
  1879. &res_lib_amf_errorreport, sizeof (struct res_lib_amf_errorreport));
  1880. }
  1881. return (0);
  1882. }
  1883. static int message_handler_req_exec_amf_errorcancelall (void *message, struct in_addr source_addr, int endian_conversion_required)
  1884. {
  1885. struct req_exec_amf_errorcancelall *req_exec_amf_errorcancelall = (struct req_exec_amf_errorcancelall *)message;
  1886. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  1887. struct saAmfComponent *component;
  1888. SaErrorT error = SA_ERR_BAD_OPERATION;
  1889. log_printf (LOG_LEVEL_FROM_GMI, "Executive: ErrorCancelAll for %s\n",
  1890. getSaNameT (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName));
  1891. component = findComponent (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName);
  1892. if (component && component->registered) {
  1893. /*
  1894. * Mark component in service if its a AMF service
  1895. * connected to this aisexec
  1896. */
  1897. if (component->probableCause) {
  1898. component->probableCause = 0;
  1899. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1900. dsm (component);
  1901. }
  1902. error = SA_OK;
  1903. }
  1904. /*
  1905. * If this node originated the request to the cluster, respond back
  1906. * to the AMF library
  1907. */
  1908. if (message_source_is_local (&req_exec_amf_errorcancelall->source)) {
  1909. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1910. req_exec_amf_errorcancelall->source.conn_info->fd);
  1911. res_lib_amf_errorcancelall.header.size = sizeof (struct res_lib_amf_errorcancelall);
  1912. res_lib_amf_errorcancelall.header.id = MESSAGE_RES_AMF_ERRORCANCELALL;
  1913. res_lib_amf_errorcancelall.header.error = error;
  1914. libais_send_response (req_exec_amf_errorcancelall->source.conn_info,
  1915. &res_lib_amf_errorcancelall, sizeof (struct res_lib_amf_errorcancelall));
  1916. }
  1917. return (0);
  1918. }
  1919. /*
  1920. * If receiving this message from another cluster node, another cluster node
  1921. * has selected a readiness state for a component connected to _that_ cluster
  1922. * node. That cluster node API has verified the readiness state, so its time to let
  1923. * the rest of the cluster nodes know about the readiness state change.
  1924. */
  1925. static int message_handler_req_exec_amf_readinessstateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1926. {
  1927. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  1928. struct saAmfComponent *component;
  1929. component = findComponent (&req_exec_amf_readinessstateset->compName);
  1930. if (component) {
  1931. log_printf (LOG_LEVEL_FROM_GMI,
  1932. "Executive: message_handler_req_exec_amf_readinessstateset (%s, RD:%d)\n",
  1933. getSaNameT (&component->name), req_exec_amf_readinessstateset->readinessState);
  1934. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  1935. component->newReadinessState = component->currentReadinessState;
  1936. dsm (component);
  1937. }
  1938. return (0);
  1939. }
  1940. /*
  1941. * If receiving this message from another cluster node, another cluster node
  1942. * has selected a ha state for a component connected to _that_ cluster
  1943. * node. That cluster node API has verified the ha state, so its time to let
  1944. * the rest of the cluster nodes know about the HA state change.
  1945. */
  1946. static int message_handler_req_exec_amf_hastateset (void *message, struct in_addr source_addr, int endian_conversion_required)
  1947. {
  1948. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  1949. struct saAmfComponent *component;
  1950. SaAmfProtectionGroupChangesT changeToComponent = SA_AMF_PROTECTION_GROUP_STATE_CHANGE;
  1951. component = findComponent (&req_exec_amf_hastateset->compName);
  1952. if (!component) {
  1953. return (0);
  1954. }
  1955. log_printf (LOG_LEVEL_FROM_GMI,
  1956. "Executive: message_handler_req_exec_amf_hastateset (%s, HA:%d)\n",
  1957. getSaNameT (&component->name), req_exec_amf_hastateset->haState);
  1958. if ( component->currentHAState == 0 ) {
  1959. if ( req_exec_amf_hastateset->haState == SA_AMF_ACTIVE
  1960. || req_exec_amf_hastateset->haState == SA_AMF_STANDBY ) {
  1961. changeToComponent = SA_AMF_PROTECTION_GROUP_ADDED;
  1962. }
  1963. } else {
  1964. if (component->currentHAState == req_exec_amf_hastateset->haState) {
  1965. changeToComponent = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1966. }
  1967. }
  1968. component->currentHAState = req_exec_amf_hastateset->haState;
  1969. component->newHAState = component->currentHAState;
  1970. dsm (component);
  1971. if( changeToComponent != SA_AMF_PROTECTION_GROUP_NO_CHANGE ) {
  1972. protectiongroup_notifications_send (component, changeToComponent);
  1973. }
  1974. return (0);
  1975. }
  1976. static int amf_init_two_fn (struct conn_info *conn_info)
  1977. {
  1978. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize availability management framework service.\n");
  1979. list_init (&conn_info->conn_list);
  1980. return (0);
  1981. }
  1982. static int message_handler_req_amf_componentregister (struct conn_info *conn_info, void *message)
  1983. {
  1984. struct req_lib_amf_componentregister *req_lib_amf_componentregister = (struct req_lib_amf_componentregister *)message;
  1985. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  1986. struct iovec iovecs[2];
  1987. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentregister()\n");
  1988. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  1989. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  1990. message_source_set (&req_exec_amf_componentregister.source, conn_info);
  1991. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  1992. req_lib_amf_componentregister,
  1993. sizeof (struct req_lib_amf_componentregister));
  1994. iovecs[0].iov_base = (char *)&req_exec_amf_componentregister;
  1995. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  1996. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  1997. return (0);
  1998. }
  1999. static int message_handler_req_amf_componentunregister (struct conn_info *conn_info, void *message)
  2000. {
  2001. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  2002. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  2003. struct iovec iovecs[2];
  2004. struct saAmfComponent *component;
  2005. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentunregister()\n");
  2006. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  2007. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  2008. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  2009. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  2010. req_lib_amf_componentunregister,
  2011. sizeof (struct req_lib_amf_componentunregister));
  2012. component = findComponent (&req_lib_amf_componentunregister->compName);
  2013. if (component && component->registered && component->local) {
  2014. component->probableCause = SA_AMF_NOT_RESPONDING;
  2015. }
  2016. iovecs[0].iov_base = (char *)&req_exec_amf_componentunregister;
  2017. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  2018. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2019. return (0);
  2020. }
  2021. static int message_handler_req_amf_readinessstateget (struct conn_info *conn_info, void *message)
  2022. {
  2023. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  2024. struct res_lib_amf_readinessstateget res_lib_amf_readinessstateget;
  2025. struct saAmfComponent *component;
  2026. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_readinessstateget()\n");
  2027. res_lib_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  2028. res_lib_amf_readinessstateget.header.size = sizeof (struct res_lib_amf_readinessstateget);
  2029. res_lib_amf_readinessstateget.header.error = SA_ERR_NOT_EXIST;
  2030. component = findComponent (&req_amf_readinessstateget->compName);
  2031. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  2032. if (component) {
  2033. memcpy (&res_lib_amf_readinessstateget.readinessState,
  2034. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  2035. res_lib_amf_readinessstateget.header.error = SA_OK;
  2036. }
  2037. libais_send_response (conn_info, &res_lib_amf_readinessstateget, sizeof (struct res_lib_amf_readinessstateget));
  2038. return (0);
  2039. }
  2040. static int message_handler_req_amf_hastateget (struct conn_info *conn_info, void *message)
  2041. {
  2042. struct req_amf_hastateget *req_amf_hastateget = (struct req_amf_hastateget *)message;
  2043. struct res_lib_amf_hastateget res_lib_amf_hastateget;
  2044. struct saAmfComponent *component;
  2045. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_hastateget()\n");
  2046. res_lib_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  2047. res_lib_amf_hastateget.header.size = sizeof (struct res_lib_amf_hastateget);
  2048. res_lib_amf_hastateget.header.error = SA_ERR_NOT_EXIST;
  2049. component = component_in_protectiongroup_find (&req_amf_hastateget->csiName, &req_amf_hastateget->compName);
  2050. if (component) {
  2051. memcpy (&res_lib_amf_hastateget.haState,
  2052. &component->currentHAState, sizeof (SaAmfHAStateT));
  2053. res_lib_amf_hastateget.header.error = SA_OK;
  2054. }
  2055. libais_send_response (conn_info, &res_lib_amf_hastateget, sizeof (struct res_lib_amf_hastateget));
  2056. return (0);
  2057. }
  2058. static int message_handler_req_amf_protectiongrouptrackstart (struct conn_info *conn_info, void *message)
  2059. {
  2060. struct req_amf_protectiongrouptrackstart *req_amf_protectiongrouptrackstart = (struct req_amf_protectiongrouptrackstart *)message;
  2061. struct res_lib_amf_protectiongrouptrackstart res_lib_amf_protectiongrouptrackstart;
  2062. struct libamf_ci_trackentry *track = 0;
  2063. int i;
  2064. struct saAmfProtectionGroup *amfProtectionGroup;
  2065. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstart()\n");
  2066. amfProtectionGroup = protectiongroup_find (&req_amf_protectiongrouptrackstart->csiName);
  2067. if (amfProtectionGroup) {
  2068. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  2069. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2070. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  2071. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2072. break;
  2073. }
  2074. }
  2075. if (track == 0) {
  2076. grow_amf_track_table (conn_info, 1);
  2077. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2078. }
  2079. track->active = 1;
  2080. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  2081. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  2082. memcpy (&track->csiName,
  2083. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  2084. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  2085. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  2086. /*
  2087. * If SA_TRACK_CURRENT is specified, write out all current connections
  2088. */
  2089. } else {
  2090. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  2091. }
  2092. res_lib_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  2093. res_lib_amf_protectiongrouptrackstart.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstart);
  2094. res_lib_amf_protectiongrouptrackstart.header.error = SA_ERR_NOT_EXIST;
  2095. if (amfProtectionGroup) {
  2096. res_lib_amf_protectiongrouptrackstart.header.error = SA_OK;
  2097. }
  2098. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstart,
  2099. sizeof (struct res_lib_amf_protectiongrouptrackstart));
  2100. if (amfProtectionGroup &&
  2101. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  2102. protectiongroup_notification_send (conn_info,
  2103. track->notificationBufferAddress,
  2104. amfProtectionGroup,
  2105. 0,
  2106. 0,
  2107. SA_TRACK_CHANGES_ONLY);
  2108. track->trackFlags &= ~SA_TRACK_CURRENT;
  2109. }
  2110. return (0);
  2111. }
  2112. static int message_handler_req_amf_protectiongrouptrackstop (struct conn_info *conn_info, void *message)
  2113. {
  2114. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  2115. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  2116. struct libamf_ci_trackentry *track = 0;
  2117. int i;
  2118. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_protectiongrouptrackstop()\n");
  2119. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  2120. if (name_match (&req_amf_protectiongrouptrackstop->csiName,
  2121. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  2122. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  2123. }
  2124. }
  2125. if (track) {
  2126. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  2127. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  2128. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  2129. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  2130. list_del (&conn_info->conn_list);
  2131. }
  2132. }
  2133. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  2134. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  2135. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  2136. if (track) {
  2137. res_lib_amf_protectiongrouptrackstop.header.error = SA_OK;
  2138. }
  2139. libais_send_response (conn_info, &res_lib_amf_protectiongrouptrackstop,
  2140. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  2141. return (0);
  2142. }
  2143. static int message_handler_req_amf_errorreport (struct conn_info *conn_info, void *message)
  2144. {
  2145. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  2146. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  2147. struct iovec iovecs[2];
  2148. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorreport()\n");
  2149. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  2150. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  2151. message_source_set (&req_exec_amf_errorreport.source, conn_info);
  2152. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  2153. req_lib_amf_errorreport,
  2154. sizeof (struct req_lib_amf_errorreport));
  2155. iovecs[0].iov_base = (char *)&req_exec_amf_errorreport;
  2156. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  2157. // iovecs[0].iov_len = sizeof (req_exec_amf_errorreport) - sizeof (req_lib_amf_errorreport);
  2158. // iovecs[1].iov_base = (char *)&req_lib_amf_errorreport;
  2159. // iovecs[1].iov_len = sizeof (req_lib_amf_errorreport);
  2160. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2161. return (0);
  2162. }
  2163. static int message_handler_req_amf_errorcancelall (struct conn_info *conn_info, void *message)
  2164. {
  2165. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  2166. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  2167. struct iovec iovecs[2];
  2168. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_errorcancelall()\n");
  2169. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  2170. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  2171. message_source_set (&req_exec_amf_errorcancelall.source, conn_info);
  2172. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  2173. req_lib_amf_errorcancelall,
  2174. sizeof (struct req_lib_amf_errorcancelall));
  2175. iovecs[0].iov_base = (char *)&req_exec_amf_errorcancelall;
  2176. iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall);
  2177. // iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall) - sizeof (req_lib_amf_errorcancelall);
  2178. // iovecs[1].iov_base = (char *)&req_lib_amf_errorcancelall;
  2179. // iovecs[1].iov_len = sizeof (req_lib_amf_errorcancelall);
  2180. assert (totempg_mcast (iovecs, 1, TOTEMPG_AGREED) == 0);
  2181. return (0);
  2182. }
  2183. static int message_handler_req_amf_stoppingcomplete (struct conn_info *conn_info_notused,
  2184. void *message)
  2185. {
  2186. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  2187. struct conn_info *inv_conn_info;
  2188. int interface;
  2189. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_stoppingcomplete()\n");
  2190. req_amf_invocation_get_and_destroy (req_amf_stoppingcomplete->invocation,
  2191. &interface, &inv_conn_info);
  2192. inv_conn_info->component->currentReadinessState = inv_conn_info->component->newReadinessState;
  2193. readiness_state_group_set (inv_conn_info->component, SA_AMF_STOPPING);
  2194. protectiongroup_notifications_send (inv_conn_info->component,SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  2195. return (0);
  2196. }
  2197. void response_handler_healthcheckcallback (struct conn_info *conn_info,
  2198. struct req_amf_response *req_amf_response) {
  2199. if (req_amf_response->error == SA_OK) {
  2200. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  2201. conn_info->component->healthcheck_outstanding = 0;
  2202. }
  2203. }
  2204. static int message_handler_req_amf_response (struct conn_info *conn_info_nouse, void *message)
  2205. {
  2206. struct req_amf_response *req_amf_response = (struct req_amf_response *)message;
  2207. struct res_lib_amf_response res_lib_amf_response;
  2208. struct conn_info *conn_info;
  2209. int interface;
  2210. int res;
  2211. log_printf (LOG_LEVEL_DEBUG, "Handle : message_handler_req_amf_response()\n");
  2212. res = req_amf_invocation_get_and_destroy (req_amf_response->invocation,
  2213. &interface, &conn_info);
  2214. log_printf (LOG_LEVEL_DEBUG, "handling response connection %p interface %x\n", conn_info, interface);
  2215. switch (interface) {
  2216. case MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK:
  2217. response_handler_healthcheckcallback (conn_info, req_amf_response);
  2218. break;
  2219. case MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK:
  2220. response_handler_readinessstatesetcallback (conn_info, req_amf_response);
  2221. break;
  2222. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK:
  2223. response_handler_csisetcallback (conn_info, req_amf_response);
  2224. break;
  2225. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK:
  2226. break;
  2227. default:
  2228. // TODO
  2229. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_amf_response->invocation);
  2230. break;
  2231. }
  2232. res_lib_amf_response.header.id = MESSAGE_RES_AMF_RESPONSE;
  2233. res_lib_amf_response.header.size = sizeof (struct res_lib_amf_response);
  2234. res_lib_amf_response.header.error = SA_OK;
  2235. libais_send_response (conn_info_nouse, &res_lib_amf_response,
  2236. sizeof (struct res_lib_amf_response));
  2237. return (0);
  2238. }
  2239. static int message_handler_req_amf_componentcapabilitymodelget (struct conn_info *conn_info, void *message)
  2240. {
  2241. struct req_amf_componentcapabilitymodelget *req_amf_componentcapabilitymodelget = (struct req_amf_componentcapabilitymodelget *)message;
  2242. struct res_lib_amf_componentcapabilitymodelget res_lib_amf_componentcapabilitymodelget;
  2243. struct saAmfComponent *component;
  2244. SaErrorT error = SA_OK;
  2245. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_amf_componentcapabilitymodelget()\n");
  2246. memset( &res_lib_amf_componentcapabilitymodelget,0,sizeof(res_lib_amf_componentcapabilitymodelget));
  2247. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_amf_componentcapabilitymodelget->compName));
  2248. component = findComponent (&req_amf_componentcapabilitymodelget->compName);
  2249. if (component && component->registered) {
  2250. memcpy (&res_lib_amf_componentcapabilitymodelget.componentCapabilityModel,
  2251. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  2252. } else {
  2253. error = SA_ERR_NOT_EXIST;
  2254. }
  2255. res_lib_amf_componentcapabilitymodelget.header.size = sizeof (struct res_lib_amf_componentcapabilitymodelget);
  2256. res_lib_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  2257. res_lib_amf_componentcapabilitymodelget.header.error = error;
  2258. libais_send_response (conn_info, &res_lib_amf_componentcapabilitymodelget,
  2259. sizeof (struct res_lib_amf_componentcapabilitymodelget));
  2260. return (0);
  2261. }
  2262. static char disabled_unlocked_state_text[6][64] = {
  2263. "AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL",
  2264. "AMF_DISABLED_UNLOCKED_FAILED",
  2265. "AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED",
  2266. "AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED",
  2267. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED",
  2268. "AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED"
  2269. };
  2270. static char *disabledunlockedstate_ntoa (int state)
  2271. {
  2272. static char str[64];
  2273. if (state >= 0 && state < 6) {
  2274. sprintf (str, "%s(%d)", disabled_unlocked_state_text[state], state);
  2275. }else{
  2276. sprintf (str, "Unknown(%d)", state);
  2277. }
  2278. return (str);
  2279. }
  2280. static char enabled_unlocked_state_text[7][64] = {
  2281. "AMF_ENABLED_UNLOCKED_INITIAL",
  2282. "AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED",
  2283. "AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED",
  2284. "AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED",
  2285. "AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED",
  2286. "AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED",
  2287. "AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED"
  2288. };
  2289. static char *enabledunlockedstate_ntoa (int state)
  2290. {
  2291. static char str[64];
  2292. if (state >= 0 && state < 7) {
  2293. sprintf (str, "%s(%d)", enabled_unlocked_state_text[state], state);
  2294. }else{
  2295. sprintf (str, "Unknown(%d)", state);
  2296. }
  2297. return (str);
  2298. }
  2299. static char readiness_state_text[4][32] = {
  2300. "Unknown",
  2301. "SA_AMF_OUT_OF_SERVICE",
  2302. "SA_AMF_IN_SERVICE",
  2303. "SA_AMF_QUIESCED",
  2304. };
  2305. static char *readinessstate_ntoa (int state)
  2306. {
  2307. static char str[32];
  2308. if (state > 0 && state < 4) {
  2309. sprintf (str, "%s(%d)", readiness_state_text[state], state);
  2310. }else{
  2311. sprintf (str, "Unknown(%d)", state);
  2312. }
  2313. return (str);
  2314. }
  2315. static char ha_state_text[4][32] = {
  2316. "Unknown",
  2317. "SA_AMF_ACTIVE",
  2318. "SA_AMF_STANDBY",
  2319. "SA_AMF_QUIESCED",
  2320. };
  2321. static char *hastate_ntoa (SaAmfHAStateT state)
  2322. {
  2323. static char str[32];
  2324. if (state > 0 && state < 4) {
  2325. sprintf (str, "%s(%d)", ha_state_text[state], state);
  2326. }else{
  2327. sprintf (str, "Unknown(%d)", state);
  2328. }
  2329. return (str);
  2330. }
  2331. static void amf_dump_comp (struct saAmfComponent *component ,void *data)
  2332. {
  2333. char name[64];
  2334. int level = LOG_LEVEL_NOTICE;
  2335. data = NULL;
  2336. log_printf (level, "----------------\n" );
  2337. log_printf (level, "registered = %d\n" ,component->registered);
  2338. log_printf (level, "local = %d\n" ,component->local );
  2339. log_printf (level, "source_addr = %s\n" ,inet_ntoa (component->source_addr));
  2340. memset (name, 0 , sizeof(name));
  2341. memcpy (name, component->name.value, component->name.length);
  2342. log_printf (level, "name = %s\n" ,name );
  2343. log_printf (level, "currentReadinessState = %s\n" ,readinessstate_ntoa (component->currentReadinessState));
  2344. log_printf (level, "newReadinessState = %s\n" ,readinessstate_ntoa (component->newReadinessState));
  2345. log_printf (level, "currentHAState = %s\n" ,hastate_ntoa (component->currentHAState));
  2346. log_printf (level, "newHAState = %s\n" ,hastate_ntoa (component->newHAState));
  2347. log_printf (level, "enabledUnlockedState = %s\n" ,enabledunlockedstate_ntoa (component->enabledUnlockedState));
  2348. log_printf (level, "disabledUnlockedState = %s\n" ,disabledunlockedstate_ntoa (component->disabledUnlockedState));
  2349. log_printf (level, "probableCause = %d\n" ,component->probableCause );
  2350. }
  2351. void amf_dump ( )
  2352. {
  2353. enumerate_components (amf_dump_comp, NULL);
  2354. fflush (stderr);
  2355. return;
  2356. }