amf.c 65 KB

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