amf.c 62 KB

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