amf.c 64 KB

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