amf.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418
  1. /** @file exec/amf.c
  2. *
  3. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  4. * Author: Steven Dake (sdake@mvista.com)
  5. *
  6. * Copyright (c) 2006 Ericsson AB.
  7. * Author: Hans Feldt, Anders Eriksson, Lars Holm
  8. * Description:
  9. * - Introduced AMF B.02 information model
  10. * - Use DN in API and multicast messages
  11. * - (Re-)Introduction of event based multicast messages
  12. * - Refactoring of code into several AMF files
  13. * - AMF Synchronisation Control State Machine
  14. *
  15. * All rights reserved.
  16. *
  17. *
  18. * This software licensed under BSD license, the text of which follows:
  19. *
  20. * Redistribution and use in source and binary forms, with or without
  21. * modification, are permitted provided that the following conditions are met:
  22. *
  23. * - Redistributions of source code must retain the above copyright notice,
  24. * this list of conditions and the following disclaimer.
  25. * - Redistributions in binary form must reproduce the above copyright notice,
  26. * this list of conditions and the following disclaimer in the documentation
  27. * and/or other materials provided with the distribution.
  28. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  29. * contributors may be used to endorse or promote products derived from this
  30. * software without specific prior written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  33. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  34. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  35. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  36. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  37. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  38. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  39. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  40. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  42. * THE POSSIBILITY OF SUCH DAMAGE.
  43. *
  44. * AMF Main
  45. *
  46. * The functions in this file are responsible for:
  47. * - starting the AMF service (amf_exec_init_fn)
  48. * - build the information model from the configuration file or by
  49. * synchronizing the state with an already started AMF node
  50. * - receiving AMF library requests (message_handler_req_lib_*)
  51. * - multicast AMF library requests to the cluster
  52. * - receiving multicasts (message_handler_req_exec_*) and dispatch the
  53. * requests to a component instance
  54. * - send responses to the AMF library (return values for API calls)
  55. * - handling EVS configuration change events (node leave/join)
  56. * - handling node synchronisation events (sync_*)
  57. * - printing the AMF runtime attributes upon user request (USR2 signal)
  58. *
  59. * Some API requests are responded to directly in the lib message_handler.
  60. * This is normally done when the API request parameters are wrong, e.g. a
  61. * component cannot be found. In that case, the error handling must be taken
  62. * care of in the lib message handler.
  63. *
  64. * 1. AMF Synchronization Control State Machine
  65. * =========================================
  66. *
  67. * 1.1 State Transition Table
  68. *
  69. * State: Event: Action: New state:
  70. * ===========================================================================
  71. * - init[AMF disabled] UNCONFIGURED
  72. * - init IDLE
  73. * IDLE node_joined A0 PROBING-1
  74. * PROBING-1 timer1 timeout A1 PROBING-2
  75. * PROBING-1 SYNC_START A2 UPDATING_CLUSTER_MODEL
  76. * PROBING-1 node_joined A7 PROBING-1
  77. * PROBING-2 SYNC_START[From me] CREATING_CLUSTER_MODEL
  78. * PROBING-2 SYNC_START[From other] UPDATING_CLUSTER_MODEL
  79. * PROBING-2 node_joined A7 PROBING-2
  80. * CREATING_CLUSTER_MODEL Model created A8 SYNCHRONIZING
  81. * SYNCHRONIZING sync_activate A10 NORMAL_OPERATION
  82. * SYNCHRONIZING node_left[sync_master] A5 SYNCHRONIZING
  83. * SYNCHRONIZING node_joined[sync_master
  84. * == me] A1 SYNCHRONIZING
  85. * UPDATING_CLUSTER_MODEL SYNC_DATA A3 UPDATING_CLUSTER_MODEL
  86. * UPDATING_CLUSTER_MODEL sync_activate A4 NORMAL_OPERATION
  87. * UPDATING_CLUSTER_MODEL SYNC_START A5 UPDATING_CLUSTER_MODEL
  88. * UPDATING_CLUSTER_MODEL node_left[sync_master] PROBING-1
  89. * UPDATING_CLUSTER_MODEL node_joined A7 UPDATING_CLUSTER_MODEL
  90. * NORMAL_OPERATION sync_init SYNCHRONIZING
  91. * NORMAL_OPERATION node_left[sync_master] A6 NORMAL_OPERATION
  92. * NORMAL_OPERATION SYNC_REQUEST A8 NORMAL_OPERATION
  93. * Any SYNC_REQUEST A9 No change
  94. *
  95. * 1.2 State Description
  96. * =====================
  97. * IDLE - Waiting to join cluster.
  98. * PROBING-1 - Start timer1; wait for timer1 to expire or to get synchronised by
  99. * another node.
  100. * PROBING-2 - Waiting for SYNC_START
  101. * CREATING_CLUSTER_MODEL - Read configuration file and create cluster model
  102. * UPDATING_CLUSTER_MODEL - Save sync master node ID; receive SYNC_DATA,
  103. * deserialize and save.
  104. * SYNCHRONIZING - If sync master: multicast SYNC_START followed by encoded AMF
  105. * objects as SYNC_DATA;
  106. * NORMAL - Start cluster or node; wait for cluster changes
  107. *
  108. * 1.3 Action Description
  109. * ======================
  110. * A0 - Start timer1
  111. * A1 - Multicast SYNC_START message
  112. * A2 - Stop timer1
  113. * A3 - Decode AMF object and save
  114. * A4 - Create cluster model; cluster sync ready
  115. * A5 - Free received SYNC_DATA
  116. * A6 - Calculate new sync master
  117. * A7 - Multicast SYNC_REQUEST message
  118. * A8 - Update AMF node object(s) with CLM nodeid
  119. * A9 - Save CLM nodeid & hostname
  120. * A10- Delete CLM nodes; cluster sync ready
  121. */
  122. #include <sys/types.h>
  123. #include <sys/uio.h>
  124. #include <sys/socket.h>
  125. #include <sys/un.h>
  126. #include <sys/types.h>
  127. #include <sys/wait.h>
  128. #include <netinet/in.h>
  129. #include <arpa/inet.h>
  130. #include <unistd.h>
  131. #include <fcntl.h>
  132. #include <stdlib.h>
  133. #include <stdio.h>
  134. #include <errno.h>
  135. #include <signal.h>
  136. #include <string.h>
  137. #include <pthread.h>
  138. #include <assert.h>
  139. #include <netdb.h>
  140. #include <sys/stat.h>
  141. #include "../include/saAis.h"
  142. #include "../include/saAmf.h"
  143. #include "../include/ipc_gen.h"
  144. #include "../include/ipc_amf.h"
  145. #include "../include/list.h"
  146. #include "../lcr/lcr_comp.h"
  147. #include "totempg.h"
  148. #include "util.h"
  149. #include "amf.h"
  150. #include "main.h"
  151. #include "ipc.h"
  152. #include "service.h"
  153. #include "objdb.h"
  154. #include "print.h"
  155. #include "sync.h"
  156. #ifdef AMFTEST
  157. #define static
  158. #endif
  159. #ifndef HOST_NAME_MAX
  160. # define HOST_NAME_MAX 255
  161. #endif
  162. #define SYNCTRACE(format, args...) do { \
  163. TRACE6(">%s: " format, __FUNCTION__, ##args); \
  164. } while (0)
  165. /*
  166. * The time AMF will wait to get synchronised by another node
  167. * before it assumes it is alone in the cluster or the first
  168. * node to start.
  169. */
  170. #ifndef AMF_SYNC_TIMEOUT
  171. #define AMF_SYNC_TIMEOUT 3000
  172. #endif
  173. static void amf_confchg_fn (
  174. enum totem_configuration_type configuration_type,
  175. unsigned int *member_list, int member_list_entries,
  176. unsigned int *left_list, int left_list_entries,
  177. unsigned int *joined_list, int joined_list_entries,
  178. struct memb_ring_id *ring_id);
  179. static int amf_lib_exit_fn (void *conn);
  180. static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb);
  181. static int amf_lib_init_fn (void *conn);
  182. static void message_handler_req_lib_amf_componentregister (void *conn, void *msg);
  183. static void message_handler_req_lib_amf_componentunregister (void *conn, void *msg);
  184. static void message_handler_req_lib_amf_pmstart (void *conn, void *msg);
  185. static void message_handler_req_lib_amf_pmstop (void *conn, void *msg);
  186. static void message_handler_req_lib_amf_healthcheckstart (void *conn, void *msg);
  187. static void message_handler_req_lib_amf_healthcheckconfirm (void *conn, void *msg);
  188. static void message_handler_req_lib_amf_healthcheckstop (void *conn, void *msg);
  189. static void message_handler_req_lib_amf_hastateget (void *conn, void *message);
  190. static void message_handler_req_lib_amf_csiquiescingcomplete (void *conn, void *msg);
  191. static void message_handler_req_lib_amf_protectiongrouptrack (void *conn, void *msg);
  192. static void message_handler_req_lib_amf_protectiongrouptrackstop (void *conn, void *msg);
  193. static void message_handler_req_lib_amf_componenterrorreport (void *conn, void *msg);
  194. static void message_handler_req_lib_amf_componenterrorclear (void *conn, void *msg);
  195. static void message_handler_req_lib_amf_response (void *conn, void *msg);
  196. static void message_handler_req_exec_amf_comp_register (
  197. void *message, unsigned int nodeid);
  198. static void message_handler_req_exec_amf_comp_error_report (
  199. void *message, unsigned int nodeid);
  200. static void message_handler_req_exec_amf_comp_instantiate (
  201. void *message, unsigned int nodeid);
  202. static void message_handler_req_exec_amf_clc_cleanup_completed (
  203. void *message, unsigned int nodeid);
  204. static void message_handler_req_exec_amf_healthcheck_tmo (
  205. void *message, unsigned int nodeid);
  206. static void message_handler_req_exec_amf_response (
  207. void *message, unsigned int nodeid);
  208. static void message_handler_req_exec_amf_sync_start (
  209. void *message, unsigned int nodeid);
  210. static void message_handler_req_exec_amf_sync_data (
  211. void *message, unsigned int nodeid);
  212. static void message_handler_req_exec_amf_cluster_start_tmo (
  213. void *message, unsigned int nodeid);
  214. static void message_handler_req_exec_amf_sync_request (
  215. void *message, unsigned int nodeid);
  216. static void message_handler_req_exec_amf_comp_instantiate_tmo(
  217. void *message, unsigned int nodeid);
  218. static void message_handler_req_exec_amf_comp_cleanup_tmo(
  219. void *message, unsigned int nodeid);
  220. static void amf_dump_fn (void);
  221. static void amf_sync_init (void);
  222. static int amf_sync_process (void);
  223. static void amf_sync_abort (void);
  224. static void amf_sync_activate (void);
  225. struct amf_pd {
  226. struct amf_comp *comp;
  227. struct list_head list;
  228. };
  229. /*
  230. * Service Handler Definition
  231. */
  232. static struct openais_lib_handler amf_lib_service[] =
  233. {
  234. { /* 0 */
  235. .lib_handler_fn = message_handler_req_lib_amf_componentregister,
  236. .response_size = sizeof (struct res_lib_amf_componentregister),
  237. .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
  238. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  239. },
  240. { /* 1 */
  241. .lib_handler_fn = message_handler_req_lib_amf_componentunregister,
  242. .response_size = sizeof (struct res_lib_amf_componentunregister),
  243. .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
  244. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  245. },
  246. { /* 2 */
  247. .lib_handler_fn = message_handler_req_lib_amf_pmstart,
  248. .response_size = sizeof (struct res_lib_amf_pmstart),
  249. .response_id = MESSAGE_RES_AMF_PMSTART,
  250. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  251. },
  252. { /* 3 */
  253. .lib_handler_fn = message_handler_req_lib_amf_pmstop,
  254. .response_size = sizeof (struct res_lib_amf_pmstop),
  255. .response_id = MESSAGE_RES_AMF_PMSTOP,
  256. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  257. },
  258. { /* 4 */
  259. .lib_handler_fn = message_handler_req_lib_amf_healthcheckstart,
  260. .response_size = sizeof (struct res_lib_amf_healthcheckstart),
  261. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTART,
  262. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  263. },
  264. { /* 5 */
  265. .lib_handler_fn = message_handler_req_lib_amf_healthcheckconfirm,
  266. .response_size = sizeof (struct res_lib_amf_healthcheckconfirm),
  267. .response_id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM,
  268. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  269. },
  270. { /* 6 */
  271. .lib_handler_fn = message_handler_req_lib_amf_healthcheckstop,
  272. .response_size = sizeof (struct res_lib_amf_healthcheckstop),
  273. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTOP,
  274. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  275. },
  276. { /* 7 */
  277. .lib_handler_fn = message_handler_req_lib_amf_hastateget,
  278. .response_size = sizeof (struct res_lib_amf_hastateget),
  279. .response_id = MESSAGE_RES_AMF_HASTATEGET,
  280. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  281. },
  282. { /* 8 */
  283. .lib_handler_fn = message_handler_req_lib_amf_csiquiescingcomplete,
  284. .response_size = sizeof (struct res_lib_amf_csiquiescingcomplete),
  285. .response_id = MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE,
  286. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  287. },
  288. { /* 9 */
  289. .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrack,
  290. .response_size = sizeof (struct res_lib_amf_protectiongrouptrack),
  291. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK,
  292. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  293. },
  294. { /* 10 */
  295. .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstop,
  296. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
  297. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
  298. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  299. },
  300. { /* 11 */
  301. .lib_handler_fn = message_handler_req_lib_amf_componenterrorreport,
  302. .response_size = sizeof (struct res_lib_amf_componenterrorreport),
  303. .response_id = MESSAGE_RES_AMF_COMPONENTERRORREPORT,
  304. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  305. },
  306. { /* 12 */
  307. .lib_handler_fn = message_handler_req_lib_amf_componenterrorclear,
  308. .response_size = sizeof (struct res_lib_amf_componenterrorclear),
  309. .response_id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR,
  310. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  311. },
  312. { /* 13 */
  313. .lib_handler_fn = message_handler_req_lib_amf_response,
  314. .response_size = sizeof (struct res_lib_amf_response),
  315. .response_id = MESSAGE_RES_AMF_RESPONSE,
  316. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  317. },
  318. };
  319. /*
  320. * Multicast message handlers
  321. */
  322. static struct openais_exec_handler amf_exec_service[] = {
  323. {
  324. .exec_handler_fn = message_handler_req_exec_amf_comp_register,
  325. },
  326. {
  327. .exec_handler_fn = message_handler_req_exec_amf_comp_error_report,
  328. },
  329. {
  330. .exec_handler_fn = message_handler_req_exec_amf_comp_instantiate,
  331. },
  332. {
  333. .exec_handler_fn = message_handler_req_exec_amf_clc_cleanup_completed,
  334. },
  335. {
  336. .exec_handler_fn = message_handler_req_exec_amf_healthcheck_tmo,
  337. },
  338. {
  339. .exec_handler_fn = message_handler_req_exec_amf_response,
  340. },
  341. {
  342. .exec_handler_fn = message_handler_req_exec_amf_sync_start,
  343. },
  344. {
  345. .exec_handler_fn = message_handler_req_exec_amf_sync_data,
  346. },
  347. {
  348. .exec_handler_fn = message_handler_req_exec_amf_cluster_start_tmo,
  349. },
  350. {
  351. .exec_handler_fn = message_handler_req_exec_amf_sync_request,
  352. },
  353. {
  354. .exec_handler_fn = message_handler_req_exec_amf_comp_instantiate_tmo,
  355. },
  356. {
  357. .exec_handler_fn = message_handler_req_exec_amf_comp_cleanup_tmo,
  358. },
  359. };
  360. /*
  361. * Exports the interface for the service
  362. */
  363. static struct openais_service_handler amf_service_handler = {
  364. .name = "openais availability management framework B.01.01",
  365. .id = AMF_SERVICE,
  366. .private_data_size = sizeof (struct amf_pd),
  367. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED,
  368. .lib_init_fn = amf_lib_init_fn,
  369. .lib_exit_fn = amf_lib_exit_fn,
  370. .lib_service = amf_lib_service,
  371. .lib_service_count = sizeof (amf_lib_service) / sizeof (struct openais_lib_handler),
  372. .exec_init_fn = amf_exec_init_fn,
  373. .exec_service = amf_exec_service,
  374. .exec_service_count = sizeof (amf_exec_service) / sizeof (struct openais_exec_handler),
  375. .confchg_fn = amf_confchg_fn,
  376. .exec_dump_fn = amf_dump_fn,
  377. .sync_init = amf_sync_init,
  378. .sync_process = amf_sync_process,
  379. .sync_activate = amf_sync_activate,
  380. .sync_abort = amf_sync_abort,
  381. };
  382. struct amf_node *this_amf_node;
  383. struct amf_cluster *amf_cluster;
  384. static struct openais_service_handler *amf_get_handler_ver0 (void);
  385. static struct openais_service_handler_iface_ver0 amf_service_handler_iface = {
  386. .openais_get_service_handler_ver0 = amf_get_handler_ver0
  387. };
  388. static struct lcr_iface openais_amf_ver0[1] = {
  389. {
  390. .name = "openais_amf",
  391. .version = 0,
  392. .versions_replace = 0,
  393. .versions_replace_count = 0,
  394. .dependencies = 0,
  395. .dependency_count = 0,
  396. .constructor = NULL,
  397. .destructor = NULL,
  398. .interfaces = NULL
  399. }
  400. };
  401. static struct lcr_comp amf_comp_ver0 = {
  402. .iface_count = 1,
  403. .ifaces = openais_amf_ver0
  404. };
  405. static struct openais_service_handler *amf_get_handler_ver0 (void)
  406. {
  407. return (&amf_service_handler);
  408. }
  409. __attribute__ ((constructor)) static void register_this_component (void)
  410. {
  411. lcr_interfaces_set (&openais_amf_ver0[0], &amf_service_handler_iface);
  412. lcr_component_register (&amf_comp_ver0);
  413. }
  414. struct req_exec_amf_comp_register {
  415. mar_req_header_t header;
  416. SaNameT compName;
  417. SaNameT proxyCompName;
  418. };
  419. struct req_exec_amf_comp_error_report {
  420. mar_req_header_t header;
  421. SaNameT reportingComponent;
  422. SaNameT erroneousComponent;
  423. SaTimeT errorDetectionTime;
  424. SaAmfRecommendedRecoveryT recommendedRecovery;
  425. SaNtfIdentifierT ntfIdentifier;
  426. };
  427. struct req_exec_amf_response {
  428. mar_req_header_t header;
  429. SaUint32T interface;
  430. SaNameT dn;
  431. SaAmfHealthcheckKeyT healtcheck_key;
  432. SaAisErrorT error;
  433. SaAmfRecommendedRecoveryT recommendedRecovery;
  434. };
  435. struct req_exec_amf_sync_data {
  436. mar_req_header_t header;
  437. SaUint32T protocol_version;
  438. SaUint32T object_type;
  439. };
  440. struct req_exec_amf_sync_request {
  441. mar_req_header_t header;
  442. SaUint32T protocol_version;
  443. char hostname[HOST_NAME_MAX + 1];
  444. };
  445. typedef struct clm_node {
  446. unsigned int nodeid;
  447. char hostname[HOST_NAME_MAX + 1];
  448. struct clm_node *next;
  449. } clm_node_t;
  450. static const char *scsm_state_names[] = {
  451. "Unknown",
  452. "IDLE",
  453. "PROBING-1",
  454. "PROBING-2",
  455. "CREATING_CLUSTER_MODEL",
  456. "SYNCHRONIZING",
  457. "NORMAL_OPERATION",
  458. "UPDATING_CLUSTER_MODEL",
  459. "UNCONFIGURED"
  460. };
  461. /**
  462. * Storage for AMF Synchronisation Control State Machine (SCSM).
  463. */
  464. static struct scsm_descriptor scsm;
  465. static char hostname[HOST_NAME_MAX + 1];
  466. /*
  467. * List (implemented as an array) of nodes in the
  468. * cluster, only used for initial start since
  469. * before the AMF node object exist, we don't have
  470. * storage for the information received in
  471. * SYNC_REQUEST msg.
  472. */
  473. static clm_node_t *clm_node_list;
  474. static int clm_node_list_entries;
  475. /******************************************************************************
  476. * Internal (static) utility functions
  477. *****************************************************************************/
  478. /**
  479. * Returns true (1) if the key is a member of the list
  480. * @param nodeid
  481. * @param list
  482. * @param entries
  483. *
  484. * @return int
  485. */
  486. static int is_list_member (
  487. unsigned int key, unsigned int *list, unsigned int entries)
  488. {
  489. int i;
  490. for (i = 0; i < entries; i++) {
  491. if (list[i] == key) {
  492. return 1;
  493. }
  494. }
  495. return 0;
  496. }
  497. /**
  498. * Delete the CLM node list
  499. */
  500. static void clm_node_list_delete (void)
  501. {
  502. if (clm_node_list != NULL) {
  503. free (clm_node_list);
  504. clm_node_list = NULL;
  505. clm_node_list_entries = 0;
  506. }
  507. }
  508. /**
  509. * Update an CLM node list entry using nodeid as key.
  510. * Allocate and initialise new memory object if not found.
  511. * @param nodeid
  512. * @param hostname
  513. */
  514. static void clm_node_list_update (unsigned int nodeid, char *hostname)
  515. {
  516. int i;
  517. for (i = 0; i < clm_node_list_entries; i++) {
  518. if (clm_node_list[i].nodeid == nodeid) {
  519. strcpy (clm_node_list[i].hostname, hostname);
  520. return;
  521. }
  522. }
  523. /*
  524. * Not found, add at tail of list.
  525. */
  526. clm_node_list_entries++;
  527. clm_node_list = amf_realloc (clm_node_list,
  528. sizeof (clm_node_t) * clm_node_list_entries);
  529. clm_node_list[clm_node_list_entries - 1].nodeid = nodeid;
  530. strcpy (clm_node_list[clm_node_list_entries - 1].hostname, hostname);
  531. }
  532. /**
  533. * Returns true (1) if the nodeid is member of the CLM node list
  534. * @param nodeid
  535. *
  536. * @return int
  537. */
  538. static int clm_node_list_is_member (unsigned int nodeid)
  539. {
  540. int j;
  541. for (j = 0; j < clm_node_list_entries; j++) {
  542. if (nodeid == clm_node_list[j].nodeid)
  543. return 1;
  544. }
  545. return 0;
  546. }
  547. /**
  548. * Update the nodeid of each AMF node object using the
  549. * CLM node list.
  550. */
  551. static void nodeids_init (void)
  552. {
  553. int i;
  554. amf_node_t *amf_node;
  555. ENTER ("");
  556. if (amf_cluster == NULL) {
  557. return;
  558. }
  559. for (i = 0; i < clm_node_list_entries; i++) {
  560. /*
  561. * Iterate all AMF nodes if several AMF nodes are mapped to this
  562. * particular CLM node.
  563. */
  564. for (amf_node = amf_cluster->node_head; amf_node != NULL;
  565. amf_node = amf_node->next) {
  566. if (strcmp ((char*)amf_node->saAmfNodeClmNode.value,
  567. clm_node_list[i].hostname) == 0) {
  568. dprintf ("%s id set to %u", amf_node->name.value,
  569. clm_node_list[i].nodeid);
  570. amf_node->nodeid = clm_node_list[i].nodeid;
  571. }
  572. }
  573. }
  574. }
  575. /**
  576. * Return pointer to this AMF node object.
  577. *
  578. * @param cluster
  579. *
  580. * @return struct amf_node*
  581. */
  582. static struct amf_node *get_this_node_obj (void)
  583. {
  584. char hostname[HOST_NAME_MAX + 1];
  585. if (gethostname (hostname, sizeof(hostname)) == -1) {
  586. log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno);
  587. openais_exit_error (AIS_DONE_FATAL_ERR);
  588. }
  589. return amf_node_find_by_hostname (hostname);
  590. }
  591. /**
  592. * Prints old and new sync state, sets new state
  593. * @param state
  594. */
  595. static void sync_state_set (enum scsm_states state)
  596. {
  597. SYNCTRACE ("changing sync ctrl state from %s to %s",
  598. scsm_state_names[scsm.state], scsm_state_names[state]);
  599. scsm.state = state;
  600. }
  601. /**
  602. * Multicast SYNC_DATA message containing a model object.
  603. *
  604. * @param buf
  605. * @param len
  606. * @param object_type
  607. *
  608. * @return int
  609. */
  610. static int mcast_sync_data (
  611. void *buf, int len, amf_object_type_t object_type)
  612. {
  613. struct req_exec_amf_sync_data req_exec;
  614. struct iovec iov[2];
  615. int res;
  616. req_exec.header.size = sizeof (struct req_exec_amf_sync_data) + len;
  617. SYNCTRACE ("%d bytes, type %u", req_exec.header.size , object_type);
  618. req_exec.header.id =
  619. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_SYNC_DATA);
  620. req_exec.protocol_version = AMF_PROTOCOL_VERSION;
  621. req_exec.object_type = object_type;
  622. iov[0].iov_base = (char *)&req_exec;
  623. iov[0].iov_len = sizeof (struct req_exec_amf_sync_data);
  624. iov[1].iov_base = buf;
  625. iov[1].iov_len = len;
  626. res = totempg_groups_mcast_joined (
  627. openais_group_handle, iov, 2, TOTEMPG_AGREED);
  628. if (res != 0) {
  629. dprintf("Unable to send %d bytes of sync data\n", req_exec.header.size);
  630. }
  631. return res;
  632. }
  633. static void mcast_sync_request (char *hostname)
  634. {
  635. struct req_exec_amf_sync_request msg;
  636. memcpy (msg.hostname, hostname, strlen (hostname) + 1);
  637. msg.protocol_version = AMF_PROTOCOL_VERSION;
  638. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_REQUEST,
  639. &msg.protocol_version, sizeof (msg) - sizeof (mar_req_header_t));
  640. }
  641. /**
  642. * Timer callback function. The time waiting for external
  643. * synchronisation has expired, start competing with other
  644. * nodes to determine who should read config file.
  645. * @param data
  646. */
  647. static void timer_function_scsm_timer1_tmo (void *data)
  648. {
  649. SYNCTRACE ("");
  650. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_START, NULL, 0);
  651. sync_state_set (PROBING_2);
  652. }
  653. /**
  654. * Read the configuration file and create cluster model.
  655. */
  656. static int create_cluster_model (void)
  657. {
  658. char *error_string;
  659. SYNCTRACE("");
  660. amf_cluster = amf_config_read (&error_string);
  661. if (amf_cluster == NULL) {
  662. log_printf (LOG_LEVEL_ERROR, error_string);
  663. openais_exit_error (AIS_DONE_AMFCONFIGREAD);
  664. }
  665. log_printf (LOG_LEVEL_NOTICE, error_string);
  666. this_amf_node = get_this_node_obj ();
  667. if (this_amf_node == NULL) {
  668. log_printf (LOG_LEVEL_INFO,
  669. "Info: This node is not configured as an AMF node, disabling.");
  670. return -1;
  671. }
  672. this_amf_node->nodeid = totempg_my_nodeid_get();
  673. return 0;
  674. }
  675. /**
  676. * Calculate a sync master (has the lowest node ID) from the
  677. * members in the cluster. Possibly excluding some members
  678. * from the CLM node list.
  679. *
  680. * @param member_list
  681. * @param member_list_entries
  682. * @param exclude_list
  683. * @param exclude_list_entries
  684. *
  685. * @return int - node ID of new sync master
  686. */
  687. static unsigned int calc_sync_master (
  688. unsigned int *member_list, int member_list_entries)
  689. {
  690. int i;
  691. unsigned int master = totempg_my_nodeid_get(); /* assume this node is master */
  692. for (i = 0; i < member_list_entries; i++) {
  693. if (member_list[i] < master &&
  694. !clm_node_list_is_member(member_list[i])) {
  695. master = member_list[i];
  696. }
  697. }
  698. return master;
  699. }
  700. /*
  701. * Delete all received sync data
  702. */
  703. static void free_synced_data (void)
  704. {
  705. struct amf_node *node;
  706. struct amf_application *app;
  707. SYNCTRACE ("state %s", scsm_state_names[scsm.state]);
  708. if (scsm.cluster) {
  709. for (node = scsm.cluster->node_head; node != NULL;) {
  710. struct amf_node *tmp = node;
  711. node = node->next;
  712. free (tmp);
  713. }
  714. for (app = scsm.cluster->application_head; app != NULL;) {
  715. struct amf_application *tmp = app;
  716. app = app->next;
  717. amf_application_delete (tmp);
  718. }
  719. free (scsm.cluster);
  720. scsm.cluster = NULL;
  721. }
  722. }
  723. static int healthcheck_sync (struct amf_healthcheck *healthcheck)
  724. {
  725. char *buf;
  726. int len, res;
  727. SYNCTRACE ("%s", healthcheck->safHealthcheckKey.key);
  728. buf = amf_healthcheck_serialize (healthcheck, &len);
  729. res = mcast_sync_data (buf, len, AMF_HEALTHCHECK);
  730. free (buf);
  731. if (res != 0) {
  732. return 1; /* try again later */
  733. }
  734. return 0;
  735. }
  736. static int comp_sync (struct amf_comp *comp)
  737. {
  738. char *buf;
  739. int len, res;
  740. SYNCTRACE ("%s", comp->name.value);
  741. if (!scsm.comp_sync_completed) {
  742. buf = amf_comp_serialize (comp, &len);
  743. res = mcast_sync_data (buf, len, AMF_COMP);
  744. free (buf);
  745. if (res != 0) {
  746. return 1; /* try again later */
  747. }
  748. scsm.comp_sync_completed = 1;
  749. }
  750. if (scsm.healthcheck == NULL) {
  751. scsm.healthcheck = scsm.comp->healthcheck_head;
  752. }
  753. for (; scsm.healthcheck != NULL; scsm.healthcheck = scsm.healthcheck->next) {
  754. if (healthcheck_sync (scsm.healthcheck) != 0) {
  755. return 1; /* try again later */
  756. }
  757. }
  758. scsm.comp_sync_completed = 0;
  759. return 0;
  760. }
  761. static int su_sync (struct amf_su *su)
  762. {
  763. char *buf;
  764. int len, res;
  765. SYNCTRACE ("%s", su->name.value);
  766. if (!scsm.su_sync_completed) {
  767. buf = amf_su_serialize (su, &len);
  768. res = mcast_sync_data (buf, len, AMF_SU);
  769. free (buf);
  770. if (res != 0) {
  771. return 1; /* try again later */
  772. }
  773. scsm.su_sync_completed = 1;
  774. }
  775. if (scsm.comp == NULL) {
  776. scsm.comp = scsm.su->comp_head;
  777. }
  778. for (; scsm.comp != NULL; scsm.comp = scsm.comp->next) {
  779. if (comp_sync (scsm.comp) != 0) {
  780. return 1; /* try again later */
  781. }
  782. }
  783. scsm.su_sync_completed = 0;
  784. return 0;
  785. }
  786. static int sg_sync (struct amf_sg *sg)
  787. {
  788. char *buf;
  789. int len, res;
  790. SYNCTRACE ("%s", sg->name.value);
  791. if (!scsm.sg_sync_completed) {
  792. buf = amf_sg_serialize (sg, &len);
  793. res = mcast_sync_data (buf, len, AMF_SG);
  794. free (buf);
  795. if (res != 0) {
  796. return 1; /* try again later */
  797. }
  798. scsm.sg_sync_completed = 1;
  799. }
  800. if (scsm.su == NULL) {
  801. scsm.su = scsm.sg->su_head;
  802. }
  803. for (; scsm.su != NULL; scsm.su = scsm.su->next) {
  804. if (su_sync (scsm.su) != 0) {
  805. return 1; /* try again later */
  806. }
  807. }
  808. scsm.sg_sync_completed = 0;
  809. return 0;
  810. }
  811. static int csi_assignment_sync (struct amf_csi_assignment *csi_assignment)
  812. {
  813. char *buf;
  814. int len, res;
  815. SYNCTRACE ("%s", csi_assignment->name.value);
  816. buf = amf_csi_assignment_serialize (csi_assignment, &len);
  817. res = mcast_sync_data (buf, len, AMF_CSI_ASSIGNMENT);
  818. free (buf);
  819. if (res != 0) {
  820. return 1; /* try again later */
  821. }
  822. return 0;
  823. }
  824. static int csi_attribute_sync (struct amf_csi_attribute *csi_attribute)
  825. {
  826. char *buf;
  827. int len, res;
  828. SYNCTRACE ("%s", csi_attribute->name);
  829. buf = amf_csi_attribute_serialize (csi_attribute, &len);
  830. res = mcast_sync_data (buf, len, AMF_CSI_ATTRIBUTE);
  831. free (buf);
  832. if (res != 0) {
  833. return 1; /* try again later */
  834. }
  835. return 0;
  836. }
  837. static int csi_sync (struct amf_csi *csi)
  838. {
  839. char *buf;
  840. int len, res;
  841. SYNCTRACE ("%s", csi->name.value);
  842. if (!scsm.csi_sync_completed) {
  843. buf = amf_csi_serialize (csi, &len);
  844. res = mcast_sync_data (buf, len, AMF_CSI);
  845. free (buf);
  846. if (res != 0) {
  847. return 1; /* try again later */
  848. }
  849. scsm.csi_sync_completed = 1;
  850. }
  851. if (scsm.csi_assignment == NULL && scsm.csi_attribute == NULL) {
  852. scsm.csi_assignment = scsm.csi->assigned_csis;
  853. }
  854. for (; scsm.csi_assignment != NULL;
  855. scsm.csi_assignment = scsm.csi_assignment->next) {
  856. if (csi_assignment_sync (scsm.csi_assignment) != 0) {
  857. return 1; /* try again later */
  858. }
  859. }
  860. if (scsm.csi_attribute == NULL) {
  861. scsm.csi_attribute = scsm.csi->attributes_head;
  862. }
  863. for (; scsm.csi_attribute != NULL; scsm.csi_attribute = scsm.csi_attribute->next) {
  864. if (csi_attribute_sync (scsm.csi_attribute) != 0) {
  865. return 1; /* try again later */
  866. }
  867. }
  868. scsm.csi_sync_completed = 0;
  869. return 0;
  870. }
  871. static int si_assignment_sync (struct amf_si_assignment *si_assignment)
  872. {
  873. char *buf;
  874. int len, res;
  875. SYNCTRACE ("%s", si_assignment->name.value);
  876. buf = amf_si_assignment_serialize (si_assignment, &len);
  877. res = mcast_sync_data (buf, len, AMF_SI_ASSIGNMENT);
  878. free (buf);
  879. if (res != 0) {
  880. return 1; /* try again later */
  881. }
  882. return 0;
  883. }
  884. static int si_sync (struct amf_si *si)
  885. {
  886. char *buf;
  887. int len, res;
  888. SYNCTRACE ("%s", si->name.value);
  889. if (!scsm.si_sync_completed) {
  890. buf = amf_si_serialize (si, &len);
  891. res = mcast_sync_data (buf, len, AMF_SI);
  892. free (buf);
  893. if (res != 0) {
  894. return 1; /* try again later */
  895. }
  896. scsm.si_sync_completed = 1;
  897. }
  898. if (scsm.si_assignment == NULL && scsm.csi == NULL) {
  899. scsm.si_assignment = scsm.si->assigned_sis;
  900. }
  901. for (; scsm.si_assignment != NULL; scsm.si_assignment = scsm.si_assignment->next) {
  902. if (si_assignment_sync (scsm.si_assignment) != 0) {
  903. return 1; /* try again later */
  904. }
  905. }
  906. if (scsm.csi == NULL) {
  907. scsm.csi = scsm.si->csi_head;
  908. }
  909. for (; scsm.csi != NULL; scsm.csi = scsm.csi->next) {
  910. if (csi_sync (scsm.csi) != 0) {
  911. return 1; /* try again later */
  912. }
  913. }
  914. scsm.si_sync_completed = 0;
  915. return 0;
  916. }
  917. static int application_sync (struct amf_application *app)
  918. {
  919. char *buf;
  920. int len, res;
  921. SYNCTRACE ("%s", app->name.value);
  922. if (!scsm.app_sync_completed) {
  923. buf = amf_application_serialize (app, &len);
  924. res = mcast_sync_data (buf, len, AMF_APPLICATION);
  925. free (buf);
  926. if (res != 0) {
  927. return 1; /* try again later */
  928. }
  929. scsm.app_sync_completed = 1;
  930. }
  931. if (scsm.sg == NULL && scsm.si == NULL) {
  932. scsm.sg = scsm.app->sg_head;
  933. }
  934. for (; scsm.sg != NULL; scsm.sg = scsm.sg->next) {
  935. if (sg_sync (scsm.sg) != 0) {
  936. return 1; /* try again later */
  937. }
  938. }
  939. if (scsm.si == NULL) {
  940. scsm.si = scsm.app->si_head;
  941. }
  942. for (; scsm.si != NULL; scsm.si = scsm.si->next) {
  943. if (si_sync (scsm.si) != 0) {
  944. return 1; /* try again later */
  945. }
  946. }
  947. scsm.app_sync_completed = 0;
  948. return 0;
  949. }
  950. static int node_sync (struct amf_node *node)
  951. {
  952. char *buf;
  953. int len, res;
  954. SYNCTRACE ("%s", node->name.value);
  955. buf = amf_node_serialize (node, &len);
  956. res = mcast_sync_data (buf, len, AMF_NODE);
  957. free (buf);
  958. if (res != 0) {
  959. return 1; /* try again later */
  960. }
  961. return 0;
  962. }
  963. static int cluster_sync (struct amf_cluster *cluster)
  964. {
  965. char *buf;
  966. int len, res;
  967. SYNCTRACE ("%s", cluster->name.value);
  968. buf = amf_cluster_serialize (cluster, &len);
  969. res = mcast_sync_data (buf, len, AMF_CLUSTER);
  970. free (buf);
  971. if (res != 0) {
  972. return 1; /* try again later */
  973. }
  974. return 0;
  975. }
  976. /**
  977. * Start the AMF nodes that has joined
  978. */
  979. static void cluster_joined_nodes_start (void)
  980. {
  981. int i;
  982. struct amf_node *node;
  983. ENTER ("");
  984. log_printf(LOG_NOTICE, "AMF synchronisation ready, starting cluster");
  985. for (i = 0; i < clm_node_list_entries; i++) {
  986. node = amf_node_find_by_nodeid (clm_node_list[i].nodeid);
  987. if (node != NULL) {
  988. amf_cluster_sync_ready (amf_cluster, node);
  989. } else {
  990. log_printf (LOG_LEVEL_INFO,
  991. "Info: Node %u is not configured as an AMF node",
  992. clm_node_list[i].nodeid);
  993. }
  994. }
  995. }
  996. /******************************************************************************
  997. * AMF Framework callback implementation *
  998. *****************************************************************************/
  999. static void amf_sync_init (void)
  1000. {
  1001. SYNCTRACE ("state %s", scsm_state_names[scsm.state]);
  1002. switch (scsm.state) {
  1003. case UNCONFIGURED:
  1004. case PROBING_1:
  1005. case PROBING_2:
  1006. break;
  1007. case UPDATING_CLUSTER_MODEL:
  1008. case SYNCHRONIZING:
  1009. nodeids_init ();
  1010. break;
  1011. case NORMAL_OPERATION:
  1012. if (clm_node_list_entries > 0) {
  1013. sync_state_set (SYNCHRONIZING);
  1014. }
  1015. break;
  1016. default:
  1017. dprintf ("unknown state: %u", scsm.state);;
  1018. assert (0);
  1019. break;
  1020. }
  1021. if (scsm.state == SYNCHRONIZING && scsm.sync_master == totempg_my_nodeid_get()) {
  1022. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_START, NULL, 0);
  1023. assert (amf_cluster != NULL);
  1024. scsm.cluster = amf_cluster;
  1025. scsm.node = amf_cluster->node_head;
  1026. scsm.app = amf_cluster->application_head;
  1027. scsm.app_sync_completed = 0;
  1028. scsm.sg = NULL;
  1029. scsm.sg_sync_completed = 0;
  1030. scsm.su = NULL;
  1031. scsm.su_sync_completed = 0;
  1032. scsm.comp = NULL;
  1033. scsm.comp_sync_completed = 0;
  1034. scsm.healthcheck = NULL;
  1035. scsm.si = NULL;
  1036. scsm.si_sync_completed = 0;
  1037. scsm.si_assignment = NULL;
  1038. scsm.csi = NULL;
  1039. scsm.csi_sync_completed = 0;
  1040. scsm.csi_assignment = NULL;
  1041. scsm.csi_attribute = NULL;
  1042. }
  1043. }
  1044. /**
  1045. * SCSM state SYNCHRONIZING processing function. If in correct
  1046. * state, encode and send each object in the information model
  1047. * as a SYNC_DATA message. Depth first traversal to preserve
  1048. * parent/child relations.
  1049. *
  1050. * @return int
  1051. */
  1052. static int amf_sync_process (void)
  1053. {
  1054. SYNCTRACE ("state %s", scsm_state_names[scsm.state]);
  1055. if (scsm.state != SYNCHRONIZING || scsm.sync_master != totempg_my_nodeid_get()) {
  1056. return 0;
  1057. }
  1058. if (scsm.cluster) {
  1059. if (cluster_sync (scsm.cluster) != 0) {
  1060. return 1; /* try again later */
  1061. }
  1062. scsm.cluster = NULL; /* done with cluster object */
  1063. }
  1064. for (; scsm.node != NULL; scsm.node = scsm.node->next) {
  1065. if (node_sync (scsm.node) != 0) {
  1066. return 1; /* try again later */
  1067. }
  1068. }
  1069. #ifdef AMFTEST
  1070. {
  1071. /*
  1072. * Test code to generate the event "sync master died" in the
  1073. * middle of synchronization.
  1074. */
  1075. struct stat buf;
  1076. if (stat ("/tmp/amf_sync_master_crash", &buf) == 0) {
  1077. printf("bye...\n");
  1078. *((int*)NULL) = 0xbad;
  1079. }
  1080. /*
  1081. * Test code to delay the synchronization.
  1082. */
  1083. if (stat ("/tmp/amf_sync_delay", &buf) == 0) {
  1084. printf("delaying sync...\n");
  1085. return 1;
  1086. }
  1087. }
  1088. #endif
  1089. for (; scsm.app != NULL; scsm.app = scsm.app->next) {
  1090. if (application_sync (scsm.app) != 0) {
  1091. return 1; /* try again later */
  1092. }
  1093. }
  1094. SYNCTRACE ("ready");
  1095. return 0; /* ready */
  1096. }
  1097. /**
  1098. * Sync is aborted due to node leave/join. Free received sync
  1099. * data and stay in the same state.
  1100. */
  1101. static void amf_sync_abort (void)
  1102. {
  1103. SYNCTRACE ("state %s", scsm_state_names[scsm.state]);
  1104. free_synced_data ();
  1105. }
  1106. /**
  1107. * SCSM normal exit function for states SYNCHRONIZING &
  1108. * UPDATING_CLUSTER_MODEL. All synced objects are now
  1109. * commited, start node/cluster.
  1110. */
  1111. static void amf_sync_activate (void)
  1112. {
  1113. SYNCTRACE ("state %s", scsm_state_names[scsm.state]);
  1114. switch (scsm.state) {
  1115. case SYNCHRONIZING:
  1116. sync_state_set (NORMAL_OPERATION);
  1117. cluster_joined_nodes_start ();
  1118. clm_node_list_delete ();
  1119. break;
  1120. case UPDATING_CLUSTER_MODEL:
  1121. amf_cluster = scsm.cluster;
  1122. assert (amf_cluster != NULL);
  1123. scsm.cluster = NULL;
  1124. this_amf_node = get_this_node_obj ();
  1125. sync_state_set (NORMAL_OPERATION);
  1126. if (this_amf_node != NULL) {
  1127. this_amf_node->nodeid = totempg_my_nodeid_get();
  1128. cluster_joined_nodes_start ();
  1129. } else {
  1130. log_printf (LOG_LEVEL_INFO,
  1131. "Info: This node is not configured as an AMF node, disabling.");
  1132. sync_state_set (UNCONFIGURED);
  1133. }
  1134. clm_node_list_delete ();
  1135. break;
  1136. case UNCONFIGURED:
  1137. case PROBING_1:
  1138. case PROBING_2:
  1139. case NORMAL_OPERATION:
  1140. break;
  1141. default:
  1142. dprintf ("unknown state: %u", scsm.state);;
  1143. assert (0);
  1144. break;
  1145. }
  1146. SYNCTRACE ("");
  1147. }
  1148. /**
  1149. * First AMF function to be called by the framework. AMF
  1150. * execution continues when this node joins the cluster.
  1151. * @param objdb
  1152. *
  1153. * @return int
  1154. */
  1155. static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb)
  1156. {
  1157. log_init ("AMF");
  1158. if (gethostname (hostname, sizeof (hostname)) == -1) {
  1159. log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno);
  1160. openais_exit_error (AIS_DONE_FATAL_ERR);
  1161. }
  1162. if (objdb != NULL && !amf_enabled (objdb)) {
  1163. sync_state_set (UNCONFIGURED);
  1164. return 0;
  1165. }
  1166. sync_state_set (IDLE);
  1167. amf_cluster_init();
  1168. amf_node_init();
  1169. amf_application_init();
  1170. amf_sg_init();
  1171. amf_su_init();
  1172. amf_comp_init();
  1173. amf_si_init();
  1174. amf_util_init ();
  1175. return (0);
  1176. }
  1177. /**
  1178. * Cluster configuration change event handler
  1179. * @param configuration_type
  1180. * @param member_list
  1181. * @param member_list_entries
  1182. * @param left_list
  1183. * @param left_list_entries
  1184. * @param joined_list
  1185. * @param joined_list_entries
  1186. * @param ring_id
  1187. */
  1188. static void amf_confchg_fn (
  1189. enum totem_configuration_type configuration_type,
  1190. unsigned int *member_list, int member_list_entries,
  1191. unsigned int *left_list, int left_list_entries,
  1192. unsigned int *joined_list, int joined_list_entries,
  1193. struct memb_ring_id *ring_id)
  1194. {
  1195. ENTER ("mnum: %d, jnum: %d, lnum: %d, sync state: %s, ring ID %llu rep %s\n",
  1196. member_list_entries, joined_list_entries, left_list_entries,
  1197. scsm_state_names[scsm.state], ring_id->seq, totemip_print (&ring_id->rep));
  1198. switch (scsm.state) {
  1199. case UNCONFIGURED:
  1200. break;
  1201. case IDLE: {
  1202. sync_state_set (PROBING_1);
  1203. if (poll_timer_add (aisexec_poll_handle, AMF_SYNC_TIMEOUT, NULL,
  1204. timer_function_scsm_timer1_tmo, &scsm.timer_handle) != 0) {
  1205. openais_exit_error (AIS_DONE_FATAL_ERR);
  1206. }
  1207. break;
  1208. }
  1209. case PROBING_1:
  1210. /* fall-through */
  1211. case PROBING_2:
  1212. if (joined_list_entries > 0) {
  1213. mcast_sync_request (hostname);
  1214. }
  1215. break;
  1216. case UPDATING_CLUSTER_MODEL:
  1217. if (joined_list_entries > 0) {
  1218. mcast_sync_request (hostname);
  1219. }
  1220. if (!is_list_member (scsm.sync_master, member_list, member_list_entries)) {
  1221. free_synced_data ();
  1222. sync_state_set (PROBING_1);
  1223. if (poll_timer_add (aisexec_poll_handle, AMF_SYNC_TIMEOUT, NULL,
  1224. timer_function_scsm_timer1_tmo, &scsm.timer_handle) != 0) {
  1225. openais_exit_error (AIS_DONE_FATAL_ERR);
  1226. }
  1227. }
  1228. break;
  1229. case SYNCHRONIZING: {
  1230. if (joined_list_entries > 0 && scsm.sync_master == totempg_my_nodeid_get()) {
  1231. /* restart sync */
  1232. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_START, NULL, 0);
  1233. }
  1234. /* If the sync master left the cluster, calculate a new sync
  1235. * master between the remaining nodes in the cluster excluding
  1236. * the nodes we are just syncing.
  1237. */
  1238. if (!is_list_member (scsm.sync_master, member_list, member_list_entries)) {
  1239. scsm.sync_master =
  1240. calc_sync_master (member_list, member_list_entries);
  1241. if (scsm.sync_master == totempg_my_nodeid_get()) {
  1242. /* restart sync */
  1243. SYNCTRACE ("I am (new) sync master");
  1244. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_SYNC_START, NULL, 0);
  1245. }
  1246. }
  1247. break;
  1248. }
  1249. case NORMAL_OPERATION: {
  1250. /* If the sync master left the cluster, calculate a new sync
  1251. * master between the remaining nodes in the cluster.
  1252. */
  1253. if (!is_list_member (scsm.sync_master, member_list, member_list_entries)) {
  1254. scsm.sync_master =
  1255. calc_sync_master (member_list, member_list_entries);
  1256. if (scsm.sync_master == totempg_my_nodeid_get()) {
  1257. SYNCTRACE ("I am (new) sync master");
  1258. }
  1259. }
  1260. if (left_list_entries > 0) {
  1261. int i;
  1262. struct amf_node *node;
  1263. for (i = 0; i < left_list_entries; i++) {
  1264. node = amf_node_find_by_nodeid (left_list[i]);
  1265. if (node != NULL) {
  1266. amf_node_leave(node);
  1267. }
  1268. }
  1269. }
  1270. break;
  1271. }
  1272. default:
  1273. log_printf (LOG_LEVEL_ERROR, "unknown state: %u\n", scsm.state);
  1274. assert (0);
  1275. break;
  1276. }
  1277. }
  1278. static int amf_lib_exit_fn (void *conn)
  1279. {
  1280. struct amf_comp *comp;
  1281. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  1282. assert (amf_pd != NULL);
  1283. comp = amf_pd->comp;
  1284. /* Make sure this is not a new connection */
  1285. if (comp != NULL && comp->conn == conn ) {
  1286. comp->conn = NULL;
  1287. dprintf ("Lib exit from comp %s\n", getSaNameT (&comp->name));
  1288. }
  1289. return (0);
  1290. }
  1291. static int amf_lib_init_fn (void *conn)
  1292. {
  1293. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  1294. list_init (&amf_pd->list);
  1295. return (0);
  1296. }
  1297. static void amf_dump_fn (void)
  1298. {
  1299. if (amf_cluster == NULL) {
  1300. return;
  1301. }
  1302. amf_runtime_attributes_print (amf_cluster);
  1303. }
  1304. /******************************************************************************
  1305. * Executive Message Implementation
  1306. *****************************************************************************/
  1307. static void message_handler_req_exec_amf_comp_register (
  1308. void *message, unsigned int nodeid)
  1309. {
  1310. struct res_lib_amf_componentregister res_lib;
  1311. struct req_exec_amf_comp_register *req_exec = message;
  1312. struct amf_comp *comp;
  1313. SaAisErrorT error;
  1314. if (scsm.state != NORMAL_OPERATION) {
  1315. return;
  1316. }
  1317. comp = amf_comp_find (amf_cluster, &req_exec->compName);
  1318. assert (comp != NULL);
  1319. TRACE1 ("ComponentRegister: '%s'", comp->name.value);
  1320. error = amf_comp_register (comp);
  1321. if (amf_su_is_local (comp->su)) {
  1322. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1323. res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
  1324. res_lib.header.error = error;
  1325. openais_conn_send_response (
  1326. comp->conn, &res_lib, sizeof (struct res_lib_amf_componentregister));
  1327. }
  1328. }
  1329. static void message_handler_req_exec_amf_comp_error_report (
  1330. void *message, unsigned int nodeid)
  1331. {
  1332. struct req_exec_amf_comp_error_report *req_exec = message;
  1333. struct amf_comp *comp;
  1334. amf_comp_t *reporting_comp;
  1335. if (scsm.state != NORMAL_OPERATION) {
  1336. return;
  1337. }
  1338. comp = amf_comp_find (amf_cluster, &req_exec->erroneousComponent);
  1339. reporting_comp = amf_comp_find (amf_cluster, &req_exec->reportingComponent);
  1340. assert (comp != NULL);
  1341. amf_comp_error_report (comp, reporting_comp,req_exec->recommendedRecovery);
  1342. }
  1343. static void message_handler_req_exec_amf_comp_instantiate(
  1344. void *message, unsigned int nodeid)
  1345. {
  1346. struct req_exec_amf_comp_instantiate *req_exec = message;
  1347. struct amf_comp *component;
  1348. component = amf_comp_find (amf_cluster, &req_exec->compName);
  1349. if (component == NULL) {
  1350. log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value);
  1351. return;
  1352. }
  1353. amf_comp_instantiate_event (component);
  1354. }
  1355. static void message_handler_req_exec_amf_comp_instantiate_tmo(
  1356. void *message, unsigned int nodeid)
  1357. {
  1358. struct req_exec_amf_comp_instantiate_tmo *req_exec = message;
  1359. struct amf_comp *component;
  1360. component = amf_comp_find (amf_cluster, &req_exec->compName);
  1361. if (component == NULL) {
  1362. log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value);
  1363. return;
  1364. }
  1365. amf_comp_instantiate_tmo_event (component);
  1366. }
  1367. static void message_handler_req_exec_amf_comp_cleanup_tmo(
  1368. void *message, unsigned int nodeid)
  1369. {
  1370. struct req_exec_amf_comp_cleanup_tmo *req_exec = message;
  1371. struct amf_comp *component;
  1372. component = amf_comp_find (amf_cluster, &req_exec->compName);
  1373. if (component == NULL) {
  1374. log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value);
  1375. return;
  1376. }
  1377. amf_comp_cleanup_tmo_event (component);
  1378. }
  1379. static void message_handler_req_exec_amf_clc_cleanup_completed (
  1380. void *message, unsigned int nodeid)
  1381. {
  1382. struct req_exec_amf_clc_cleanup_completed *req_exec = message;
  1383. amf_comp_t *comp;
  1384. if (scsm.state != NORMAL_OPERATION) {
  1385. return;
  1386. }
  1387. comp = amf_comp_find (amf_cluster, &req_exec->compName);
  1388. ENTER ("%s",comp->name.value);
  1389. if (comp == NULL) {
  1390. log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value);
  1391. return;
  1392. }
  1393. if (req_exec->cleanup_exit_code != 0) {
  1394. amf_comp_cleanup_failed_completed (comp);
  1395. } else {
  1396. amf_comp_cleanup_completed (comp);
  1397. }
  1398. }
  1399. static void message_handler_req_exec_amf_healthcheck_tmo (
  1400. void *message, unsigned int nodeid)
  1401. {
  1402. struct req_exec_amf_healthcheck_tmo *req_exec = message;
  1403. struct amf_comp *comp;
  1404. struct amf_healthcheck *healthcheck;
  1405. if (scsm.state != NORMAL_OPERATION) {
  1406. return;
  1407. }
  1408. comp = amf_comp_find (amf_cluster, &req_exec->compName);
  1409. if (comp == NULL) {
  1410. log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value);
  1411. return;
  1412. }
  1413. ENTER ("%s", comp->name.value);
  1414. healthcheck = amf_comp_find_healthcheck (comp, &req_exec->safHealthcheckKey);
  1415. amf_comp_healthcheck_tmo (comp, req_exec->recommendedRecovery);
  1416. }
  1417. static void message_handler_req_exec_amf_response (
  1418. void *message, unsigned int nodeid)
  1419. {
  1420. struct req_exec_amf_response *req_exec = message;
  1421. struct amf_comp *comp;
  1422. struct res_lib_amf_response res_lib;
  1423. SaAisErrorT retval;
  1424. if (scsm.state != NORMAL_OPERATION) {
  1425. return;
  1426. }
  1427. TRACE1 ("AmfResponse: %s", req_exec->dn.value);
  1428. comp = amf_comp_response_2 (
  1429. req_exec->interface, &req_exec->dn, &req_exec->healtcheck_key,
  1430. req_exec->error, &retval, req_exec->recommendedRecovery);
  1431. assert (comp != NULL);
  1432. if (amf_su_is_local (comp->su)) {
  1433. res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
  1434. res_lib.header.size = sizeof (struct res_lib_amf_response);
  1435. res_lib.header.error = retval;
  1436. openais_conn_send_response (comp->conn, &res_lib, sizeof (res_lib));
  1437. }
  1438. }
  1439. static void message_handler_req_exec_amf_sync_start (
  1440. void *message, unsigned int nodeid)
  1441. {
  1442. SYNCTRACE ("from: %s", totempg_ifaces_print (nodeid));
  1443. switch (scsm.state) {
  1444. case IDLE:
  1445. break;
  1446. case PROBING_1:
  1447. poll_timer_delete (aisexec_poll_handle, scsm.timer_handle);
  1448. scsm.timer_handle = 0;
  1449. sync_state_set (UPDATING_CLUSTER_MODEL);
  1450. scsm.sync_master = nodeid;
  1451. break;
  1452. case PROBING_2:
  1453. if (totempg_my_nodeid_get() == nodeid) {
  1454. scsm.sync_master = nodeid;
  1455. sync_state_set (CREATING_CLUSTER_MODEL);
  1456. if (create_cluster_model() == 0) {
  1457. sync_state_set (SYNCHRONIZING);
  1458. sync_request (amf_service_handler.name);
  1459. } else {
  1460. /* TODO: I am sync master but not AMF node */
  1461. log_printf (LOG_LEVEL_ERROR,
  1462. "AMF sync error: I am sync master but not AMF node");
  1463. openais_exit_error (AIS_DONE_FATAL_ERR);
  1464. }
  1465. } else {
  1466. sync_state_set (UPDATING_CLUSTER_MODEL);
  1467. scsm.sync_master = nodeid;
  1468. }
  1469. break;
  1470. case SYNCHRONIZING:
  1471. break;
  1472. case UPDATING_CLUSTER_MODEL:
  1473. free_synced_data ();
  1474. scsm.sync_master = nodeid;
  1475. break;
  1476. case UNCONFIGURED:
  1477. break;
  1478. default:
  1479. dprintf ("unknown state %d", scsm.state);
  1480. assert (0);
  1481. break;
  1482. }
  1483. }
  1484. static void message_handler_req_exec_amf_sync_data (
  1485. void *message, unsigned int nodeid)
  1486. {
  1487. struct req_exec_amf_sync_data *req_exec = message;
  1488. char *tmp = ((char*)message) + sizeof (struct req_exec_amf_sync_data);
  1489. SYNCTRACE ("rec %d bytes, ptr %p, type %d", req_exec->header.size, message,
  1490. req_exec->object_type);
  1491. #if 0
  1492. if (req_exec->protocol_version != AMF_PROTOCOL_VERSION) {
  1493. log_printf (LOG_ERR, "Error: Protocol version not supported");
  1494. return;
  1495. }
  1496. #endif
  1497. if (scsm.state != UPDATING_CLUSTER_MODEL) {
  1498. return;
  1499. }
  1500. switch (req_exec->object_type)
  1501. {
  1502. case AMF_CLUSTER:
  1503. if ((scsm.cluster = amf_cluster_deserialize (tmp)) == NULL) {
  1504. openais_exit_error (AIS_DONE_FATAL_ERR);
  1505. }
  1506. SYNCTRACE ("Cluster '%s' deserialised", scsm.cluster->name.value);
  1507. break;
  1508. case AMF_NODE:
  1509. if ((scsm.node = amf_node_deserialize (scsm.cluster, tmp)) == NULL) {
  1510. openais_exit_error (AIS_DONE_FATAL_ERR);
  1511. }
  1512. SYNCTRACE ("Node '%s' deserialised", scsm.node->name.value);
  1513. break;
  1514. case AMF_APPLICATION:
  1515. if ((scsm.app = amf_application_deserialize (scsm.cluster, tmp)) == NULL) {
  1516. openais_exit_error (AIS_DONE_FATAL_ERR);
  1517. }
  1518. SYNCTRACE ("App '%s' deserialised", scsm.app->name.value);
  1519. break;
  1520. case AMF_SG:
  1521. if ((scsm.sg = amf_sg_deserialize (scsm.app, tmp)) == NULL) {
  1522. openais_exit_error (AIS_DONE_FATAL_ERR);
  1523. }
  1524. SYNCTRACE ("SG '%s' deserialised", scsm.sg->name.value);
  1525. break;
  1526. case AMF_SU:
  1527. if ((scsm.su = amf_su_deserialize (scsm.sg, tmp)) == NULL) {
  1528. openais_exit_error (AIS_DONE_FATAL_ERR);
  1529. }
  1530. SYNCTRACE ("SU '%s' deserialised", scsm.su->name.value);
  1531. break;
  1532. case AMF_COMP:
  1533. if ((scsm.comp = amf_comp_deserialize (scsm.su, tmp)) == NULL) {
  1534. openais_exit_error (AIS_DONE_FATAL_ERR);
  1535. }
  1536. SYNCTRACE ("Component '%s' deserialised", scsm.comp->name.value);
  1537. break;
  1538. case AMF_HEALTHCHECK:
  1539. if ((scsm.healthcheck = amf_healthcheck_deserialize (scsm.comp,
  1540. tmp)) == NULL) {
  1541. openais_exit_error (AIS_DONE_FATAL_ERR);
  1542. }
  1543. SYNCTRACE ("Healthcheck '%s' deserialised",
  1544. scsm.healthcheck->safHealthcheckKey.key);
  1545. break;
  1546. case AMF_SI:
  1547. if ((scsm.si = amf_si_deserialize (scsm.app, tmp)) == NULL) {
  1548. openais_exit_error (AIS_DONE_FATAL_ERR);
  1549. }
  1550. SYNCTRACE ("SI '%s' deserialised", scsm.si->name.value);
  1551. break;
  1552. case AMF_SI_ASSIGNMENT:
  1553. if ((scsm.si_assignment = amf_si_assignment_deserialize (scsm.si,
  1554. tmp)) == NULL) {
  1555. openais_exit_error (AIS_DONE_FATAL_ERR);
  1556. }
  1557. SYNCTRACE ("SI Ass '%s' deserialised",
  1558. scsm.si_assignment->name.value);
  1559. break;
  1560. case AMF_CSI:
  1561. if ((scsm.csi = amf_csi_deserialize (scsm.si,
  1562. tmp)) == NULL) {
  1563. openais_exit_error (AIS_DONE_FATAL_ERR);
  1564. }
  1565. SYNCTRACE ("CSI '%s' deserialised", scsm.csi->name.value);
  1566. break;
  1567. case AMF_CSI_ASSIGNMENT:
  1568. if ((scsm.csi_assignment = amf_csi_assignment_deserialize (
  1569. scsm.csi, tmp)) == NULL) {
  1570. openais_exit_error (AIS_DONE_FATAL_ERR);
  1571. }
  1572. SYNCTRACE ("CSI Ass '%s' deserialised",
  1573. scsm.csi_assignment->name.value);
  1574. break;
  1575. case AMF_CSI_ATTRIBUTE:
  1576. if ((scsm.csi_attribute = amf_csi_attribute_deserialize (scsm.csi,
  1577. tmp)) == NULL) {
  1578. openais_exit_error (AIS_DONE_FATAL_ERR);
  1579. }
  1580. SYNCTRACE ("CSI Attr '%s' deserialised",
  1581. scsm.csi_attribute->name);
  1582. break;
  1583. default:
  1584. dprintf ("unknown object: %u", req_exec->object_type);
  1585. assert (0);
  1586. break;
  1587. }
  1588. }
  1589. static void message_handler_req_exec_amf_cluster_start_tmo (
  1590. void *message, unsigned int nodeid)
  1591. {
  1592. struct req_exec_amf_cluster_start_tmo *req;
  1593. req = (struct req_exec_amf_cluster_start_tmo *)message;
  1594. if (scsm.state != NORMAL_OPERATION) {
  1595. return;
  1596. }
  1597. TRACE1("%s", req->sourceNodeName.value);
  1598. amf_cluster_start_tmo_event (nodeid == scsm.sync_master, amf_cluster,
  1599. &req->sourceNodeName);
  1600. }
  1601. static void message_handler_req_exec_amf_sync_request (
  1602. void *message, unsigned int nodeid)
  1603. {
  1604. struct req_exec_amf_sync_request *req_exec = message;
  1605. SYNCTRACE ("from: %s, name: %s, state %s", totempg_ifaces_print (nodeid),
  1606. req_exec->hostname, scsm_state_names[scsm.state]);
  1607. clm_node_list_update (nodeid, req_exec->hostname);
  1608. if (scsm.state == NORMAL_OPERATION) {
  1609. amf_node_t *amf_node = amf_cluster->node_head;
  1610. /*
  1611. * Iterate all AMF nodes if several AMF nodes are mapped to this
  1612. * particular CLM node.
  1613. */
  1614. for (; amf_node != NULL; amf_node = amf_node->next) {
  1615. if (strcmp ((char*)amf_node->saAmfNodeClmNode.value,
  1616. req_exec->hostname) == 0) {
  1617. amf_node->nodeid = nodeid;
  1618. }
  1619. }
  1620. }
  1621. }
  1622. /*****************************************************************************
  1623. * Library Interface Implementation
  1624. ****************************************************************************/
  1625. static void message_handler_req_lib_amf_componentregister (
  1626. void *conn,
  1627. void *msg)
  1628. {
  1629. struct req_lib_amf_componentregister *req_lib = msg;
  1630. struct amf_comp *comp;
  1631. assert (scsm.state == NORMAL_OPERATION);
  1632. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1633. if (comp) {
  1634. struct req_exec_amf_comp_register req_exec;
  1635. struct iovec iovec;
  1636. struct amf_pd *amf_pd = openais_conn_private_data_get (conn);
  1637. TRACE2("Comp register '%s'", req_lib->compName.value);
  1638. comp->conn = conn;
  1639. amf_pd->comp = comp;
  1640. req_exec.header.size = sizeof (struct req_exec_amf_comp_register);
  1641. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  1642. MESSAGE_REQ_EXEC_AMF_COMPONENT_REGISTER);
  1643. memcpy (&req_exec.compName, &req_lib->compName, sizeof (SaNameT));
  1644. memcpy (&req_exec.proxyCompName,
  1645. &req_lib->proxyCompName, sizeof (SaNameT));
  1646. iovec.iov_base = (char *)&req_exec;
  1647. iovec.iov_len = sizeof (req_exec);
  1648. assert (totempg_groups_mcast_joined (openais_group_handle,
  1649. &iovec, 1, TOTEMPG_AGREED) == 0);
  1650. } else {
  1651. struct res_lib_amf_componentregister res_lib;
  1652. log_printf (LOG_ERR, "Error: Comp register: '%s' not found", req_lib->compName.value);
  1653. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1654. res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
  1655. res_lib.header.error = SA_AIS_ERR_INVALID_PARAM;
  1656. openais_conn_send_response (
  1657. conn, &res_lib, sizeof (struct res_lib_amf_componentregister));
  1658. }
  1659. }
  1660. static void message_handler_req_lib_amf_componentunregister (
  1661. void *conn,
  1662. void *msg)
  1663. {
  1664. #ifdef COMPILE_OUT
  1665. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  1666. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  1667. struct iovec iovec;
  1668. struct amf_comp *component;
  1669. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  1670. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  1671. req_exec_amf_componentunregister.header.id =
  1672. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  1673. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  1674. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  1675. req_lib_amf_componentunregister,
  1676. sizeof (struct req_lib_amf_componentunregister));
  1677. component = amf_comp_find (amf_cluster, &req_lib_amf_componentunregister->compName);
  1678. if (component && component->registered && component->local) {
  1679. // component->probableCause = SA_AMF_NOT_RESPONDING;
  1680. }
  1681. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  1682. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  1683. assert (totempg_groups_mcast_joined (openais_group_handle,
  1684. &iovec, 1, TOTEMPG_AGREED) == 0);
  1685. #endif
  1686. }
  1687. static void message_handler_req_lib_amf_pmstart (
  1688. void *conn,
  1689. void *msg)
  1690. {
  1691. struct req_lib_amf_pmstart *req_lib = msg;
  1692. struct res_lib_amf_pmstart res_lib;
  1693. struct amf_comp *comp;
  1694. SaAisErrorT error = SA_AIS_OK;
  1695. TRACE2("PmStart msg: '%s', %llu %d %d %d",
  1696. req_lib->compName.value,
  1697. req_lib->processId,
  1698. req_lib->descendentsTreeDepth,
  1699. req_lib->pmErrors,
  1700. req_lib->recommendedRecovery);
  1701. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1702. if (comp != NULL) {
  1703. comp->conn = conn;
  1704. error = amf_comp_pm_start (comp, req_lib->processId,
  1705. req_lib->descendentsTreeDepth,
  1706. req_lib->pmErrors,
  1707. req_lib->recommendedRecovery);
  1708. } else {
  1709. log_printf (LOG_ERR, "PmStart: Component '%s' not found",
  1710. req_lib->compName.value);
  1711. error = SA_AIS_ERR_NOT_EXIST;
  1712. }
  1713. res_lib.header.id = MESSAGE_RES_AMF_PMSTART;
  1714. res_lib.header.size = sizeof (res_lib);
  1715. res_lib.header.error = error;
  1716. openais_conn_send_response (conn, &res_lib,
  1717. sizeof (struct res_lib_amf_pmstart));
  1718. }
  1719. static void message_handler_req_lib_amf_pmstop (
  1720. void *conn,
  1721. void *msg)
  1722. {
  1723. struct req_lib_amf_pmstop *req_lib = msg;
  1724. struct res_lib_amf_pmstop res_lib;
  1725. struct amf_comp *comp;
  1726. SaAisErrorT error = SA_AIS_OK;
  1727. TRACE2 ("PmStop msg: '%s', %llu %d %d",
  1728. req_lib->compName.value,
  1729. req_lib->processId,
  1730. req_lib->stopQualifier,
  1731. req_lib->pmErrors);
  1732. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1733. if (comp != NULL) {
  1734. comp->conn = conn;
  1735. error = amf_comp_pm_stop (comp,
  1736. req_lib->stopQualifier,
  1737. req_lib->processId,
  1738. req_lib->pmErrors);
  1739. } else {
  1740. log_printf (LOG_ERR, "PmStop: Component '%s' not found",
  1741. req_lib->compName.value);
  1742. error = SA_AIS_ERR_NOT_EXIST;
  1743. }
  1744. res_lib.header.id = MESSAGE_RES_AMF_PMSTOP;
  1745. res_lib.header.size = sizeof (res_lib);
  1746. res_lib.header.error = error;
  1747. openais_conn_send_response (conn, &res_lib,
  1748. sizeof (struct res_lib_amf_pmstop));
  1749. }
  1750. static void message_handler_req_lib_amf_healthcheckstart (
  1751. void *conn, void *msg)
  1752. {
  1753. struct req_lib_amf_healthcheckstart *req_lib = msg;
  1754. struct res_lib_amf_healthcheckstart res_lib;
  1755. struct amf_comp *comp;
  1756. SaAisErrorT error = SA_AIS_OK;
  1757. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1758. if (comp != NULL) {
  1759. comp->conn = conn;
  1760. error = amf_comp_healthcheck_start (
  1761. comp, &req_lib->healthcheckKey, req_lib->invocationType,
  1762. req_lib->recommendedRecovery);
  1763. } else {
  1764. log_printf (LOG_ERR, "Healthcheckstart: Component '%s' not found",
  1765. req_lib->compName.value);
  1766. error = SA_AIS_ERR_NOT_EXIST;
  1767. }
  1768. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
  1769. res_lib.header.size = sizeof (res_lib);
  1770. res_lib.header.error = error;
  1771. openais_conn_send_response (conn, &res_lib,
  1772. sizeof (struct res_lib_amf_healthcheckstart));
  1773. }
  1774. static void message_handler_req_lib_amf_healthcheckconfirm (
  1775. void *conn, void *msg)
  1776. {
  1777. struct req_lib_amf_healthcheckconfirm *req_lib = msg;
  1778. struct res_lib_amf_healthcheckconfirm res_lib;
  1779. struct amf_comp *comp;
  1780. SaAisErrorT error = SA_AIS_OK;
  1781. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1782. if (comp != NULL) {
  1783. error = amf_comp_healthcheck_confirm (
  1784. comp, &req_lib->healthcheckKey, req_lib->healthcheckResult);
  1785. } else {
  1786. log_printf (LOG_ERR, "Healthcheck confirm: Component '%s' not found",
  1787. req_lib->compName.value);
  1788. error = SA_AIS_ERR_NOT_EXIST;
  1789. }
  1790. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM;
  1791. res_lib.header.size = sizeof (res_lib);
  1792. res_lib.header.error = error;
  1793. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  1794. }
  1795. static void message_handler_req_lib_amf_healthcheckstop (
  1796. void *conn, void *msg)
  1797. {
  1798. struct req_lib_amf_healthcheckstop *req_lib = msg;
  1799. struct res_lib_amf_healthcheckstop res_lib;
  1800. struct amf_comp *comp;
  1801. SaAisErrorT error = SA_AIS_OK;
  1802. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1803. if (comp != NULL) {
  1804. error = amf_comp_healthcheck_stop (comp, &req_lib->healthcheckKey);
  1805. } else {
  1806. log_printf (LOG_ERR, "Healthcheckstop: Component '%s' not found",
  1807. req_lib->compName.value);
  1808. error = SA_AIS_ERR_NOT_EXIST;
  1809. }
  1810. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
  1811. res_lib.header.size = sizeof (res_lib);
  1812. res_lib.header.error = error;
  1813. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  1814. }
  1815. static void message_handler_req_lib_amf_hastateget (void *conn, void *msg)
  1816. {
  1817. struct req_lib_amf_hastateget *req_lib = msg;
  1818. struct res_lib_amf_hastateget res_lib;
  1819. struct amf_comp *comp;
  1820. SaAmfHAStateT ha_state;
  1821. SaAisErrorT error;
  1822. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1823. if (comp != NULL) {
  1824. error = amf_comp_hastate_get (comp, &req_lib->csiName, &ha_state);
  1825. res_lib.haState = ha_state;
  1826. res_lib.header.error = error;
  1827. } else {
  1828. log_printf (LOG_ERR, "HA state get: Component '%s' not found",
  1829. req_lib->compName.value);
  1830. error = SA_AIS_ERR_NOT_EXIST;
  1831. }
  1832. res_lib.header.id = MESSAGE_RES_AMF_HASTATEGET;
  1833. res_lib.header.size = sizeof (struct res_lib_amf_hastateget);
  1834. res_lib.header.error = error;
  1835. openais_conn_send_response (conn, &res_lib,
  1836. sizeof (struct res_lib_amf_hastateget));
  1837. }
  1838. static void message_handler_req_lib_amf_protectiongrouptrack (
  1839. void *conn,
  1840. void *msg)
  1841. {
  1842. #ifdef COMPILE_OUT
  1843. struct req_lib_amf_protectiongrouptrack *req_lib_amf_protectiongrouptrack = (struct req_lib_amf_protectiongrouptrack *)message;
  1844. struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
  1845. struct libamf_ci_trackentry *track = 0;
  1846. int i;
  1847. struct saAmfProtectionGroup *amfProtectionGroup;
  1848. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrack()\n");
  1849. amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrack->csiName);
  1850. if (amfProtectionGroup) {
  1851. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrack: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrack->csiName));
  1852. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1853. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  1854. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1855. break;
  1856. }
  1857. }
  1858. if (track == 0) {
  1859. grow_amf_track_table (conn_info, 1);
  1860. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1861. }
  1862. track->active = 1;
  1863. track->trackFlags = req_lib_amf_protectiongrouptrack->trackFlags;
  1864. track->notificationBufferAddress = req_lib_amf_protectiongrouptrack->notificationBufferAddress;
  1865. memcpy (&track->csiName,
  1866. &req_lib_amf_protectiongrouptrack->csiName, sizeof (SaNameT));
  1867. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  1868. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  1869. /*
  1870. * If SA_TRACK_CURRENT is specified, write out all current connections
  1871. */
  1872. } else {
  1873. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  1874. }
  1875. res_lib_amf_protectiongrouptrack.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK;
  1876. res_lib_amf_protectiongrouptrack.header.size = sizeof (struct res_lib_amf_protectiongrouptrack);
  1877. res_lib_amf_protectiongrouptrack.header.error = SA_ERR_NOT_EXIST;
  1878. if (amfProtectionGroup) {
  1879. res_lib_amf_protectiongrouptrack.header.error = SA_AIS_OK;
  1880. }
  1881. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrack,
  1882. sizeof (struct res_lib_amf_protectiongrouptrack));
  1883. if (amfProtectionGroup &&
  1884. req_lib_amf_protectiongrouptrack->trackFlags & SA_TRACK_CURRENT) {
  1885. protectiongroup_notification_send (conn_info,
  1886. track->notificationBufferAddress,
  1887. amfProtectionGroup,
  1888. 0,
  1889. 0,
  1890. SA_TRACK_CHANGES_ONLY);
  1891. track->trackFlags &= ~SA_TRACK_CURRENT;
  1892. }
  1893. #endif
  1894. }
  1895. static void message_handler_req_lib_amf_csiquiescingcomplete (
  1896. void *conn,
  1897. void *msg)
  1898. {
  1899. }
  1900. static void message_handler_req_lib_amf_protectiongrouptrackstop (
  1901. void *conn,
  1902. void *msg)
  1903. {
  1904. #ifdef COMPILE_OUT
  1905. struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
  1906. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  1907. struct libamf_ci_trackentry *track = 0;
  1908. int i;
  1909. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
  1910. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1911. if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
  1912. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  1913. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1914. }
  1915. }
  1916. if (track) {
  1917. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
  1918. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  1919. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  1920. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  1921. list_del (&conn_info->conn_list);
  1922. }
  1923. }
  1924. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  1925. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  1926. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  1927. if (track) {
  1928. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  1929. }
  1930. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstop,
  1931. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  1932. #endif
  1933. }
  1934. /**
  1935. * multicast a message out reporting a component error
  1936. * (to be called by passive monitoring)
  1937. */
  1938. void mcast_error_report_from_pm (
  1939. struct amf_comp *comp,
  1940. SaAmfRecommendedRecoveryT recommendedRecovery)
  1941. {
  1942. struct req_exec_amf_comp_error_report req_exec;
  1943. struct iovec iovec;
  1944. SaNameT erroneous_comp_name;
  1945. amf_comp_dn_make(comp, &erroneous_comp_name);
  1946. TRACE2("%s %s",comp->name.value, erroneous_comp_name.value);
  1947. req_exec.header.size = sizeof (struct req_exec_amf_comp_error_report);
  1948. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  1949. MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT);
  1950. memcpy (&req_exec.erroneousComponent, &erroneous_comp_name, sizeof (SaNameT));
  1951. memcpy (&req_exec.recommendedRecovery, &recommendedRecovery, sizeof (SaAmfRecommendedRecoveryT));
  1952. iovec.iov_base = (char *)&req_exec;
  1953. iovec.iov_len = sizeof (req_exec);
  1954. totempg_groups_mcast_joined (openais_group_handle,
  1955. &iovec, 1, TOTEMPG_AGREED);
  1956. }
  1957. static void message_handler_req_lib_amf_componenterrorreport (
  1958. void *conn,
  1959. void *msg)
  1960. {
  1961. struct req_lib_amf_componenterrorreport *req_lib = msg;
  1962. struct amf_comp *comp;
  1963. amf_comp_t *reporting_comp;
  1964. SaNameT reporting_comp_name;
  1965. assert (scsm.state == NORMAL_OPERATION);
  1966. comp = amf_comp_find (amf_cluster, &req_lib->erroneousComponent);
  1967. reporting_comp = amf_comp_find_from_conn_info (conn);
  1968. assert (reporting_comp);
  1969. if (comp != NULL) {
  1970. struct req_exec_amf_comp_error_report req_exec;
  1971. struct iovec iovec;
  1972. TRACE2("Lib comp error report for '%s'", comp->name.value);
  1973. req_exec.header.size = sizeof (struct req_exec_amf_comp_error_report);
  1974. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  1975. MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT);
  1976. amf_comp_dn_make(reporting_comp, &reporting_comp_name);
  1977. memcpy (&req_exec.reportingComponent, &reporting_comp_name,
  1978. sizeof (SaNameT));
  1979. memcpy (&req_exec.erroneousComponent, &req_lib->erroneousComponent,
  1980. sizeof (SaNameT));
  1981. memcpy (&req_exec.errorDetectionTime, &req_lib->errorDetectionTime,
  1982. sizeof (SaTimeT));
  1983. memcpy (&req_exec.recommendedRecovery, &req_lib->recommendedRecovery,
  1984. sizeof (SaAmfRecommendedRecoveryT));
  1985. memcpy (&req_exec.ntfIdentifier, &req_lib->ntfIdentifier,
  1986. sizeof (SaNtfIdentifierT));
  1987. iovec.iov_base = (char *)&req_exec;
  1988. iovec.iov_len = sizeof (req_exec);
  1989. assert (totempg_groups_mcast_joined (
  1990. openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  1991. } else {
  1992. struct res_lib_amf_componenterrorreport res_lib;
  1993. log_printf (LOG_ERR, "Component %s not found",
  1994. req_lib->erroneousComponent.value);
  1995. res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  1996. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  1997. res_lib.header.error = SA_AIS_ERR_NOT_EXIST;
  1998. openais_conn_send_response (conn, &res_lib,
  1999. sizeof (struct res_lib_amf_componenterrorreport));
  2000. }
  2001. }
  2002. static void message_handler_req_lib_amf_componenterrorclear (
  2003. void *conn,
  2004. void *msg)
  2005. {
  2006. #ifdef COMPILLE_OUT
  2007. struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
  2008. struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
  2009. struct iovec iovec;
  2010. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
  2011. req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
  2012. req_exec_amf_componenterrorclear.header.id =
  2013. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR);
  2014. message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
  2015. memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
  2016. req_lib_amf_componenterrorclear,
  2017. sizeof (struct req_lib_amf_componenterrorclear));
  2018. iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
  2019. iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
  2020. assert (totempg_groups_mcast_joined (openais_group_handle,
  2021. &iovec, 1, TOTEMPG_AGREED) == 0);
  2022. #endif
  2023. }
  2024. /**
  2025. * Handle a response from a component.
  2026. *
  2027. * Healthcheck responses are handled locally and directly. This
  2028. * way we do not get healthcheck duration timeouts during e.g.
  2029. * AMF sync.
  2030. *
  2031. * Other events need to be multicasted. If we are syncing, defer
  2032. * these event by returning TRY-AGAIN to the component.
  2033. *
  2034. * No flow control was requested by AMF from the IPC layer (on
  2035. * purpose) for this lib handler. It is needed to handle
  2036. * healthcheck responses if it takes longer to sync than the
  2037. * duration period.
  2038. *
  2039. * When multicasting, check for space in the TOTEM outbound
  2040. * queue and return TRY-AGAIN if the queue is full.
  2041. *
  2042. * @param conn
  2043. * @param msg
  2044. */
  2045. static void message_handler_req_lib_amf_response (void *conn, void *msg)
  2046. {
  2047. struct res_lib_amf_response res_lib;
  2048. struct req_lib_amf_response *req_lib = msg;
  2049. int multicast, send_ok;
  2050. SaAisErrorT retval;
  2051. SaUint32T interface;
  2052. SaNameT dn;
  2053. SaAmfHealthcheckKeyT healthcheck_key;
  2054. SaAmfRecommendedRecoveryT recommendedRecovery;
  2055. /*
  2056. * This is an optimisation to avoid multicast of healthchecks while keeping
  2057. * a nice design. We multicast and make lib responses from this file.
  2058. */
  2059. multicast = amf_comp_response_1 (req_lib->invocation, req_lib->error,
  2060. &retval, &interface, &dn, &healthcheck_key, &recommendedRecovery);
  2061. if (multicast) {
  2062. struct req_exec_amf_response req_exec;
  2063. struct iovec iovec;
  2064. if (scsm.state != NORMAL_OPERATION) {
  2065. retval = SA_AIS_ERR_TRY_AGAIN;
  2066. goto send_response;
  2067. }
  2068. req_exec.header.size = sizeof (struct req_exec_amf_response);
  2069. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  2070. MESSAGE_REQ_EXEC_AMF_RESPONSE);
  2071. req_exec.interface = interface;
  2072. memcpy (&req_exec.dn, &dn, sizeof (SaNameT));
  2073. memcpy (&req_exec.healtcheck_key, &healthcheck_key,
  2074. sizeof(SaAmfHealthcheckKeyT));
  2075. req_exec.recommendedRecovery = recommendedRecovery;
  2076. req_exec.error = req_lib->error;
  2077. iovec.iov_base = (char *)&req_exec;
  2078. iovec.iov_len = sizeof (req_exec);
  2079. send_ok = totempg_groups_send_ok_joined (openais_group_handle, &iovec, 1);
  2080. if (send_ok) {
  2081. if (totempg_groups_mcast_joined (
  2082. openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0) {
  2083. goto end;
  2084. } else {
  2085. openais_exit_error (AIS_DONE_FATAL_ERR);
  2086. }
  2087. } else {
  2088. /* TOTEM queue is full, try again later */
  2089. retval = SA_AIS_ERR_TRY_AGAIN;
  2090. }
  2091. }
  2092. send_response:
  2093. res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
  2094. res_lib.header.size = sizeof (struct res_lib_amf_response);
  2095. res_lib.header.error = retval;
  2096. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  2097. end:
  2098. return;
  2099. }