amf.c 65 KB

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