amf.c 68 KB

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