amf.c 65 KB

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