amf.c 93 KB

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