amf.c 59 KB

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