amf.c 65 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336
  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. if (amf_cluster == NULL) {
  1351. return;
  1352. }
  1353. amf_runtime_attributes_print (amf_cluster);
  1354. }
  1355. /******************************************************************************
  1356. * Executive Message Implementation
  1357. *****************************************************************************/
  1358. static void message_handler_req_exec_amf_comp_register (
  1359. void *message, unsigned int nodeid)
  1360. {
  1361. struct res_lib_amf_componentregister res_lib;
  1362. struct req_exec_amf_comp_register *req_exec = message;
  1363. struct amf_comp *comp;
  1364. SaAisErrorT error;
  1365. if (scsm.state != NORMAL_OPERATION) {
  1366. return;
  1367. }
  1368. comp = amf_comp_find (amf_cluster, &req_exec->compName);
  1369. assert (comp != NULL);
  1370. TRACE1 ("ComponentRegister: '%s'", comp->name.value);
  1371. error = amf_comp_register (comp);
  1372. if (amf_su_is_local (comp->su)) {
  1373. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1374. res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
  1375. res_lib.header.error = error;
  1376. openais_conn_send_response (
  1377. comp->conn, &res_lib, sizeof (struct res_lib_amf_componentregister));
  1378. }
  1379. }
  1380. static void message_handler_req_exec_amf_comp_error_report (
  1381. void *message, unsigned int nodeid)
  1382. {
  1383. struct req_exec_amf_comp_error_report *req_exec = message;
  1384. struct amf_comp *comp;
  1385. if (scsm.state != NORMAL_OPERATION) {
  1386. return;
  1387. }
  1388. comp = amf_comp_find (amf_cluster, &req_exec->erroneousComponent);
  1389. assert (comp != NULL);
  1390. amf_comp_error_report (comp, req_exec->recommendedRecovery);
  1391. }
  1392. static void message_handler_req_exec_amf_clc_cleanup_completed (
  1393. void *message, unsigned int nodeid)
  1394. {
  1395. struct req_exec_amf_clc_cleanup_completed *req_exec = message;
  1396. struct amf_comp *comp;
  1397. if (scsm.state != NORMAL_OPERATION) {
  1398. return;
  1399. }
  1400. comp = amf_comp_find (amf_cluster, &req_exec->compName);
  1401. if (comp == NULL) {
  1402. log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value);
  1403. return;
  1404. }
  1405. amf_comp_cleanup_completed (comp);
  1406. }
  1407. static void message_handler_req_exec_amf_healthcheck_tmo (
  1408. void *message, unsigned int nodeid)
  1409. {
  1410. struct req_exec_amf_healthcheck_tmo *req_exec = message;
  1411. struct amf_comp *comp;
  1412. struct amf_healthcheck *healthcheck;
  1413. if (scsm.state != NORMAL_OPERATION) {
  1414. return;
  1415. }
  1416. comp = amf_comp_find (amf_cluster, &req_exec->compName);
  1417. if (comp == NULL) {
  1418. log_printf (LOG_ERR, "Error: '%s' not found", req_exec->compName.value);
  1419. return;
  1420. }
  1421. ENTER ("%s", comp->name.value);
  1422. healthcheck = amf_comp_find_healthcheck (comp, &req_exec->safHealthcheckKey);
  1423. amf_comp_healthcheck_tmo (comp, healthcheck);
  1424. }
  1425. static void message_handler_req_exec_amf_response (
  1426. void *message, unsigned int nodeid)
  1427. {
  1428. struct req_exec_amf_response *req_exec = message;
  1429. struct amf_comp *comp;
  1430. struct res_lib_amf_response res_lib;
  1431. SaAisErrorT retval;
  1432. if (scsm.state != NORMAL_OPERATION) {
  1433. return;
  1434. }
  1435. TRACE1 ("AmfResponse: %s", req_exec->dn.value);
  1436. comp = amf_comp_response_2 (
  1437. req_exec->interface, &req_exec->dn, req_exec->error, &retval);
  1438. assert (comp != NULL);
  1439. if (amf_su_is_local (comp->su)) {
  1440. res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
  1441. res_lib.header.size = sizeof (struct res_lib_amf_response);
  1442. res_lib.header.error = retval;
  1443. openais_conn_send_response (comp->conn, &res_lib, sizeof (res_lib));
  1444. }
  1445. }
  1446. static void message_handler_req_exec_amf_sync_start (
  1447. void *message, unsigned int nodeid)
  1448. {
  1449. SYNCTRACE ("from: %s", totempg_ifaces_print (nodeid));
  1450. switch (scsm.state) {
  1451. case IDLE:
  1452. break;
  1453. case PROBING_1:
  1454. poll_timer_delete (aisexec_poll_handle, scsm.timer_handle);
  1455. scsm.timer_handle = 0;
  1456. sync_state_set (UPDATING_CLUSTER_MODEL);
  1457. scsm.sync_master = nodeid;
  1458. break;
  1459. case PROBING_2:
  1460. if (this_ip->nodeid == nodeid) {
  1461. scsm.sync_master = nodeid;
  1462. sync_state_set (CREATING_CLUSTER_MODEL);
  1463. if (create_cluster_model() == 0) {
  1464. sync_state_set (SYNCHRONIZING);
  1465. sync_request ();
  1466. } else {
  1467. /* TODO: I am sync master but not AMF node */
  1468. log_printf (LOG_LEVEL_ERROR,
  1469. "AMF sync error: I am sync master but not AMF node");
  1470. openais_exit_error (AIS_DONE_FATAL_ERR);
  1471. }
  1472. } else {
  1473. sync_state_set (UPDATING_CLUSTER_MODEL);
  1474. scsm.sync_master = nodeid;
  1475. }
  1476. break;
  1477. case SYNCHRONIZING:
  1478. break;
  1479. case UPDATING_CLUSTER_MODEL:
  1480. free_synced_data ();
  1481. scsm.sync_master = nodeid;
  1482. break;
  1483. case UNCONFIGURED:
  1484. break;
  1485. default:
  1486. dprintf ("unknown state %d", scsm.state);
  1487. assert (0);
  1488. }
  1489. }
  1490. static void message_handler_req_exec_amf_sync_data (
  1491. void *message, unsigned int nodeid)
  1492. {
  1493. struct req_exec_amf_sync_data *req_exec = message;
  1494. int sz = sizeof (struct req_exec_amf_sync_data);
  1495. SYNCTRACE ("rec %d bytes, type %d, ptr %p",
  1496. req_exec->header.size, req_exec->object_type, message);
  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 (
  1504. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1505. openais_exit_error (AIS_DONE_FATAL_ERR);
  1506. }
  1507. SYNCTRACE ("Cluster '%s' deserialised", scsm.cluster->name.value);
  1508. break;
  1509. case AMF_NODE:
  1510. if ((scsm.node = amf_node_deserialize (scsm.cluster,
  1511. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1512. openais_exit_error (AIS_DONE_FATAL_ERR);
  1513. }
  1514. SYNCTRACE ("Node '%s' deserialised", scsm.node->name.value);
  1515. break;
  1516. case AMF_APPLICATION:
  1517. if ((scsm.app = amf_application_deserialize (scsm.cluster,
  1518. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1519. openais_exit_error (AIS_DONE_FATAL_ERR);
  1520. }
  1521. SYNCTRACE ("App '%s' deserialised", scsm.app->name.value);
  1522. break;
  1523. case AMF_SG:
  1524. if ((scsm.sg = amf_sg_deserialize (scsm.app,
  1525. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1526. openais_exit_error (AIS_DONE_FATAL_ERR);
  1527. }
  1528. SYNCTRACE ("SG '%s' deserialised", scsm.sg->name.value);
  1529. break;
  1530. case AMF_SU:
  1531. if ((scsm.su = amf_su_deserialize (scsm.sg,
  1532. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1533. openais_exit_error (AIS_DONE_FATAL_ERR);
  1534. }
  1535. SYNCTRACE ("SU '%s' deserialised", scsm.su->name.value);
  1536. break;
  1537. case AMF_COMP:
  1538. if ((scsm.comp = amf_comp_deserialize (scsm.su,
  1539. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1540. openais_exit_error (AIS_DONE_FATAL_ERR);
  1541. }
  1542. SYNCTRACE ("Component '%s' deserialised", scsm.comp->name.value);
  1543. break;
  1544. case AMF_HEALTHCHECK:
  1545. if ((scsm.healthcheck = amf_healthcheck_deserialize (scsm.comp,
  1546. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1547. openais_exit_error (AIS_DONE_FATAL_ERR);
  1548. }
  1549. SYNCTRACE ("Healthcheck '%s' deserialised",
  1550. scsm.healthcheck->safHealthcheckKey.key);
  1551. break;
  1552. case AMF_SI:
  1553. if ((scsm.si = amf_si_deserialize (scsm.app,
  1554. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1555. openais_exit_error (AIS_DONE_FATAL_ERR);
  1556. }
  1557. SYNCTRACE ("SI '%s' deserialised", scsm.si->name.value);
  1558. break;
  1559. case AMF_SI_ASSIGNMENT:
  1560. if ((scsm.si_assignment = amf_si_assignment_deserialize (scsm.si,
  1561. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1562. openais_exit_error (AIS_DONE_FATAL_ERR);
  1563. }
  1564. SYNCTRACE ("SI Ass '%s' deserialised",
  1565. scsm.si_assignment->name.value);
  1566. break;
  1567. case AMF_CSI:
  1568. if ((scsm.csi = amf_csi_deserialize (scsm.si,
  1569. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1570. openais_exit_error (AIS_DONE_FATAL_ERR);
  1571. }
  1572. SYNCTRACE ("CSI '%s' deserialised", scsm.csi->name.value);
  1573. break;
  1574. case AMF_CSI_ASSIGNMENT:
  1575. if ((scsm.csi_assignment = amf_csi_assignment_deserialize (scsm.csi,
  1576. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1577. openais_exit_error (AIS_DONE_FATAL_ERR);
  1578. }
  1579. SYNCTRACE ("CSI Ass '%s' deserialised",
  1580. scsm.csi_assignment->name.value);
  1581. break;
  1582. case AMF_CSI_ATTRIBUTE:
  1583. if ((scsm.csi_attribute = amf_csi_attribute_deserialize (scsm.csi,
  1584. ((char*) req_exec) + sz, req_exec->header.size - sz)) == NULL) {
  1585. openais_exit_error (AIS_DONE_FATAL_ERR);
  1586. }
  1587. SYNCTRACE ("CSI Attr '%s' deserialised",
  1588. scsm.csi_attribute->name);
  1589. break;
  1590. default:
  1591. dprintf ("unknown object: %u", req_exec->object_type);
  1592. assert (0);
  1593. break;
  1594. }
  1595. }
  1596. /**
  1597. * Commit event handler for the previously received objects.
  1598. * Start this cluster/node now. Used at initial cluster start
  1599. * only.
  1600. * @param message
  1601. * @param nodeid
  1602. */
  1603. static void message_handler_req_exec_amf_sync_ready (
  1604. void *message, unsigned int nodeid)
  1605. {
  1606. SYNCTRACE ("from: %s", totempg_ifaces_print (nodeid));
  1607. amf_sync_activate ();
  1608. }
  1609. static void message_handler_req_exec_amf_cluster_start_tmo (
  1610. void *message, unsigned int nodeid)
  1611. {
  1612. if (scsm.state != NORMAL_OPERATION) {
  1613. return;
  1614. }
  1615. if (nodeid == scsm.sync_master) {
  1616. dprintf ("Cluster startup timeout, assigning workload");
  1617. amf_cluster_assign_workload (amf_cluster);
  1618. } else {
  1619. dprintf ("received CLUSTER_START_TMO from non sync-master, ignoring");
  1620. }
  1621. }
  1622. static void message_handler_req_exec_amf_sync_request (
  1623. void *message, unsigned int nodeid)
  1624. {
  1625. struct req_exec_amf_sync_request *req_exec = message;
  1626. clm_node_t *clm_node;
  1627. SYNCTRACE ("from: %s, name: %s, state %s", totempg_ifaces_print (nodeid),
  1628. req_exec->hostname, scsm_state_names[scsm.state]);
  1629. clm_node = clm_node_find_by_nodeid (nodeid);
  1630. assert (clm_node != NULL);
  1631. strcpy (clm_node->hostname, req_exec->hostname);
  1632. if (scsm.state == NORMAL_OPERATION) {
  1633. amf_node_t *amf_node = amf_cluster->node_head;
  1634. /*
  1635. * Iterate all AMF nodes if several AMF nodes are mapped to this
  1636. * particular CLM node.
  1637. */
  1638. for (; amf_node != NULL; amf_node = amf_node->next) {
  1639. if (strcmp ((char*)amf_node->saAmfNodeClmNode.value,
  1640. req_exec->hostname) == 0) {
  1641. amf_node->nodeid = nodeid;
  1642. }
  1643. }
  1644. }
  1645. }
  1646. /*****************************************************************************
  1647. * Library Interface Implementation
  1648. ****************************************************************************/
  1649. static void message_handler_req_lib_amf_componentregister (
  1650. void *conn,
  1651. void *msg)
  1652. {
  1653. struct req_lib_amf_componentregister *req_lib = msg;
  1654. struct amf_comp *comp;
  1655. assert (scsm.state == NORMAL_OPERATION);
  1656. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1657. if (comp) {
  1658. struct req_exec_amf_comp_register req_exec;
  1659. struct iovec iovec;
  1660. struct amf_pd *amf_pd = openais_conn_private_data_get (conn);
  1661. TRACE2("Comp register '%s'", req_lib->compName.value);
  1662. comp->conn = conn;
  1663. amf_pd->comp = comp;
  1664. req_exec.header.size = sizeof (struct req_exec_amf_comp_register);
  1665. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  1666. MESSAGE_REQ_EXEC_AMF_COMPONENT_REGISTER);
  1667. memcpy (&req_exec.compName, &req_lib->compName, sizeof (SaNameT));
  1668. memcpy (&req_exec.proxyCompName,
  1669. &req_lib->proxyCompName, sizeof (SaNameT));
  1670. iovec.iov_base = (char *)&req_exec;
  1671. iovec.iov_len = sizeof (req_exec);
  1672. assert (totempg_groups_mcast_joined (openais_group_handle,
  1673. &iovec, 1, TOTEMPG_AGREED) == 0);
  1674. } else {
  1675. struct res_lib_amf_componentregister res_lib;
  1676. log_printf (LOG_ERR, "Error: Comp register: '%s' not found", req_lib->compName.value);
  1677. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1678. res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
  1679. res_lib.header.error = SA_AIS_ERR_INVALID_PARAM;
  1680. openais_conn_send_response (
  1681. conn, &res_lib, sizeof (struct res_lib_amf_componentregister));
  1682. }
  1683. }
  1684. static void message_handler_req_lib_amf_componentunregister (
  1685. void *conn,
  1686. void *msg)
  1687. {
  1688. #ifdef COMPILE_OUT
  1689. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  1690. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  1691. struct iovec iovec;
  1692. struct amf_comp *component;
  1693. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  1694. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  1695. req_exec_amf_componentunregister.header.id =
  1696. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  1697. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  1698. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  1699. req_lib_amf_componentunregister,
  1700. sizeof (struct req_lib_amf_componentunregister));
  1701. component = amf_comp_find (amf_cluster, &req_lib_amf_componentunregister->compName);
  1702. if (component && component->registered && component->local) {
  1703. // component->probableCause = SA_AMF_NOT_RESPONDING;
  1704. }
  1705. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  1706. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  1707. assert (totempg_groups_mcast_joined (openais_group_handle,
  1708. &iovec, 1, TOTEMPG_AGREED) == 0);
  1709. #endif
  1710. }
  1711. static void message_handler_req_lib_amf_pmstart (
  1712. void *conn,
  1713. void *msg)
  1714. {
  1715. }
  1716. static void message_handler_req_lib_amf_pmstop (
  1717. void *conn,
  1718. void *msg)
  1719. {
  1720. }
  1721. static void message_handler_req_lib_amf_healthcheckstart (
  1722. void *conn, void *msg)
  1723. {
  1724. struct req_lib_amf_healthcheckstart *req_lib = msg;
  1725. struct res_lib_amf_healthcheckstart 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. comp->conn = conn;
  1731. error = amf_comp_healthcheck_start (
  1732. comp, &req_lib->healthcheckKey, req_lib->invocationType,
  1733. req_lib->recommendedRecovery);
  1734. } else {
  1735. log_printf (LOG_ERR, "Healthcheckstart: Component '%s' not found",
  1736. req_lib->compName.value);
  1737. error = SA_AIS_ERR_NOT_EXIST;
  1738. }
  1739. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
  1740. res_lib.header.size = sizeof (res_lib);
  1741. res_lib.header.error = error;
  1742. openais_conn_send_response (conn, &res_lib,
  1743. sizeof (struct res_lib_amf_healthcheckstart));
  1744. }
  1745. static void message_handler_req_lib_amf_healthcheckconfirm (
  1746. void *conn, void *msg)
  1747. {
  1748. struct req_lib_amf_healthcheckconfirm *req_lib = msg;
  1749. struct res_lib_amf_healthcheckconfirm res_lib;
  1750. struct amf_comp *comp;
  1751. SaAisErrorT error = SA_AIS_OK;
  1752. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1753. if (comp != NULL) {
  1754. error = amf_comp_healthcheck_confirm (
  1755. comp, &req_lib->healthcheckKey, req_lib->healthcheckResult);
  1756. } else {
  1757. log_printf (LOG_ERR, "Healthcheck confirm: Component '%s' not found",
  1758. req_lib->compName.value);
  1759. error = SA_AIS_ERR_NOT_EXIST;
  1760. }
  1761. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM;
  1762. res_lib.header.size = sizeof (res_lib);
  1763. res_lib.header.error = error;
  1764. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  1765. }
  1766. static void message_handler_req_lib_amf_healthcheckstop (
  1767. void *conn, void *msg)
  1768. {
  1769. struct req_lib_amf_healthcheckstop *req_lib = msg;
  1770. struct res_lib_amf_healthcheckstop res_lib;
  1771. struct amf_comp *comp;
  1772. SaAisErrorT error = SA_AIS_OK;
  1773. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1774. if (comp != NULL) {
  1775. error = amf_comp_healthcheck_stop (comp, &req_lib->healthcheckKey);
  1776. } else {
  1777. log_printf (LOG_ERR, "Healthcheckstop: Component '%s' not found",
  1778. req_lib->compName.value);
  1779. error = SA_AIS_ERR_NOT_EXIST;
  1780. }
  1781. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
  1782. res_lib.header.size = sizeof (res_lib);
  1783. res_lib.header.error = error;
  1784. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  1785. }
  1786. static void message_handler_req_lib_amf_hastateget (void *conn, void *msg)
  1787. {
  1788. struct req_lib_amf_hastateget *req_lib = msg;
  1789. struct res_lib_amf_hastateget res_lib;
  1790. struct amf_comp *comp;
  1791. SaAmfHAStateT ha_state;
  1792. SaAisErrorT error;
  1793. comp = amf_comp_find (amf_cluster, &req_lib->compName);
  1794. if (comp != NULL) {
  1795. error = amf_comp_hastate_get (comp, &req_lib->csiName, &ha_state);
  1796. res_lib.haState = ha_state;
  1797. res_lib.header.error = error;
  1798. } else {
  1799. log_printf (LOG_ERR, "HA state get: Component '%s' not found",
  1800. req_lib->compName.value);
  1801. error = SA_AIS_ERR_NOT_EXIST;
  1802. }
  1803. res_lib.header.id = MESSAGE_RES_AMF_HASTATEGET;
  1804. res_lib.header.size = sizeof (struct res_lib_amf_hastateget);
  1805. res_lib.header.error = error;
  1806. openais_conn_send_response (conn, &res_lib,
  1807. sizeof (struct res_lib_amf_hastateget));
  1808. }
  1809. static void message_handler_req_lib_amf_protectiongrouptrack (
  1810. void *conn,
  1811. void *msg)
  1812. {
  1813. #ifdef COMPILE_OUT
  1814. struct req_lib_amf_protectiongrouptrack *req_lib_amf_protectiongrouptrack = (struct req_lib_amf_protectiongrouptrack *)message;
  1815. struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
  1816. struct libamf_ci_trackentry *track = 0;
  1817. int i;
  1818. struct saAmfProtectionGroup *amfProtectionGroup;
  1819. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrack()\n");
  1820. amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrack->csiName);
  1821. if (amfProtectionGroup) {
  1822. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrack: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrack->csiName));
  1823. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1824. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  1825. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1826. break;
  1827. }
  1828. }
  1829. if (track == 0) {
  1830. grow_amf_track_table (conn_info, 1);
  1831. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1832. }
  1833. track->active = 1;
  1834. track->trackFlags = req_lib_amf_protectiongrouptrack->trackFlags;
  1835. track->notificationBufferAddress = req_lib_amf_protectiongrouptrack->notificationBufferAddress;
  1836. memcpy (&track->csiName,
  1837. &req_lib_amf_protectiongrouptrack->csiName, sizeof (SaNameT));
  1838. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  1839. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  1840. /*
  1841. * If SA_TRACK_CURRENT is specified, write out all current connections
  1842. */
  1843. } else {
  1844. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  1845. }
  1846. res_lib_amf_protectiongrouptrack.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK;
  1847. res_lib_amf_protectiongrouptrack.header.size = sizeof (struct res_lib_amf_protectiongrouptrack);
  1848. res_lib_amf_protectiongrouptrack.header.error = SA_ERR_NOT_EXIST;
  1849. if (amfProtectionGroup) {
  1850. res_lib_amf_protectiongrouptrack.header.error = SA_AIS_OK;
  1851. }
  1852. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrack,
  1853. sizeof (struct res_lib_amf_protectiongrouptrack));
  1854. if (amfProtectionGroup &&
  1855. req_lib_amf_protectiongrouptrack->trackFlags & SA_TRACK_CURRENT) {
  1856. protectiongroup_notification_send (conn_info,
  1857. track->notificationBufferAddress,
  1858. amfProtectionGroup,
  1859. 0,
  1860. 0,
  1861. SA_TRACK_CHANGES_ONLY);
  1862. track->trackFlags &= ~SA_TRACK_CURRENT;
  1863. }
  1864. #endif
  1865. }
  1866. static void message_handler_req_lib_amf_csiquiescingcomplete (
  1867. void *conn,
  1868. void *msg)
  1869. {
  1870. }
  1871. static void message_handler_req_lib_amf_protectiongrouptrackstop (
  1872. void *conn,
  1873. void *msg)
  1874. {
  1875. #ifdef COMPILE_OUT
  1876. struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
  1877. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  1878. struct libamf_ci_trackentry *track = 0;
  1879. int i;
  1880. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
  1881. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  1882. if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
  1883. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  1884. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  1885. }
  1886. }
  1887. if (track) {
  1888. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
  1889. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  1890. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  1891. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  1892. list_del (&conn_info->conn_list);
  1893. }
  1894. }
  1895. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  1896. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  1897. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  1898. if (track) {
  1899. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  1900. }
  1901. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstop,
  1902. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  1903. #endif
  1904. }
  1905. static void message_handler_req_lib_amf_componenterrorreport (
  1906. void *conn,
  1907. void *msg)
  1908. {
  1909. struct req_lib_amf_componenterrorreport *req_lib = msg;
  1910. struct amf_comp *comp;
  1911. assert (scsm.state == NORMAL_OPERATION);
  1912. comp = amf_comp_find (amf_cluster, &req_lib->erroneousComponent);
  1913. if (comp != NULL) {
  1914. struct req_exec_amf_comp_error_report req_exec;
  1915. struct iovec iovec;
  1916. TRACE2("Lib comp error report for '%s'", comp->name.value);
  1917. req_exec.header.size = sizeof (struct req_exec_amf_comp_error_report);
  1918. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  1919. MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT);
  1920. memcpy (&req_exec.reportingComponent, &req_lib->reportingComponent,
  1921. sizeof (SaNameT));
  1922. memcpy (&req_exec.erroneousComponent, &req_lib->erroneousComponent,
  1923. sizeof (SaNameT));
  1924. memcpy (&req_exec.errorDetectionTime, &req_lib->errorDetectionTime,
  1925. sizeof (SaTimeT));
  1926. memcpy (&req_exec.recommendedRecovery, &req_lib->recommendedRecovery,
  1927. sizeof (SaAmfRecommendedRecoveryT));
  1928. memcpy (&req_exec.ntfIdentifier, &req_lib->ntfIdentifier,
  1929. sizeof (SaNtfIdentifierT));
  1930. iovec.iov_base = (char *)&req_exec;
  1931. iovec.iov_len = sizeof (req_exec);
  1932. assert (totempg_groups_mcast_joined (
  1933. openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  1934. } else {
  1935. struct res_lib_amf_componenterrorreport res_lib;
  1936. log_printf (LOG_ERR, "Component %s not found",
  1937. req_lib->erroneousComponent.value);
  1938. res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  1939. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  1940. res_lib.header.error = SA_AIS_ERR_NOT_EXIST;
  1941. openais_conn_send_response (conn, &res_lib,
  1942. sizeof (struct res_lib_amf_componenterrorreport));
  1943. }
  1944. }
  1945. static void message_handler_req_lib_amf_componenterrorclear (
  1946. void *conn,
  1947. void *msg)
  1948. {
  1949. #ifdef COMPILLE_OUT
  1950. struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
  1951. struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
  1952. struct iovec iovec;
  1953. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
  1954. req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
  1955. req_exec_amf_componenterrorclear.header.id =
  1956. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR);
  1957. message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
  1958. memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
  1959. req_lib_amf_componenterrorclear,
  1960. sizeof (struct req_lib_amf_componenterrorclear));
  1961. iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
  1962. iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
  1963. assert (totempg_groups_mcast_joined (openais_group_handle,
  1964. &iovec, 1, TOTEMPG_AGREED) == 0);
  1965. #endif
  1966. }
  1967. /**
  1968. * Handle a response from a component.
  1969. *
  1970. * Healthcheck responses are handled locally and directly. This
  1971. * way we do not get healthcheck duration timeouts during e.g.
  1972. * AMF sync.
  1973. *
  1974. * Other events need to be multicasted. If we are syncing, defer
  1975. * these event by returning TRY-AGAIN to the component.
  1976. *
  1977. * No flow control was requested by AMF from the IPC layer (on
  1978. * purpose) for this lib handler. It is needed to handle
  1979. * healthcheck responses if it takes longer to sync than the
  1980. * duration period.
  1981. *
  1982. * When multicasting, check for space in the TOTEM outbound
  1983. * queue and return TRY-AGAIN if the queue is full.
  1984. *
  1985. * @param conn
  1986. * @param msg
  1987. */
  1988. static void message_handler_req_lib_amf_response (void *conn, void *msg)
  1989. {
  1990. struct res_lib_amf_response res_lib;
  1991. struct req_lib_amf_response *req_lib = msg;
  1992. int multicast, send_ok;
  1993. SaAisErrorT retval;
  1994. SaUint32T interface;
  1995. SaNameT dn;
  1996. /*
  1997. * This is an optimisation to avoid multicast of healthchecks while keeping
  1998. * a nice design. We multicast and make lib responses from this file.
  1999. */
  2000. multicast = amf_comp_response_1 (
  2001. req_lib->invocation, req_lib->error, &retval, &interface, &dn);
  2002. if (multicast) {
  2003. struct req_exec_amf_response req_exec;
  2004. struct iovec iovec;
  2005. if (scsm.state != NORMAL_OPERATION) {
  2006. retval = SA_AIS_ERR_TRY_AGAIN;
  2007. goto send_response;
  2008. }
  2009. req_exec.header.size = sizeof (struct req_exec_amf_response);
  2010. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  2011. MESSAGE_REQ_EXEC_AMF_RESPONSE);
  2012. req_exec.interface = interface;
  2013. memcpy (&req_exec.dn, &dn, sizeof (SaNameT));
  2014. req_exec.error = req_lib->error;
  2015. iovec.iov_base = (char *)&req_exec;
  2016. iovec.iov_len = sizeof (req_exec);
  2017. send_ok = totempg_groups_send_ok_joined (openais_group_handle, &iovec, 1);
  2018. if (send_ok) {
  2019. if (totempg_groups_mcast_joined (
  2020. openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0) {
  2021. goto end;
  2022. } else {
  2023. openais_exit_error (AIS_DONE_FATAL_ERR);
  2024. }
  2025. } else {
  2026. /* TOTEM queue is full, try again later */
  2027. retval = SA_AIS_ERR_TRY_AGAIN;
  2028. }
  2029. }
  2030. send_response:
  2031. res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
  2032. res_lib.header.size = sizeof (struct res_lib_amf_response);
  2033. res_lib.header.error = retval;
  2034. // ENTER ("");
  2035. if (openais_conn_send_response (conn, &res_lib, sizeof (res_lib)) != 0) {
  2036. openais_exit_error (AIS_DONE_FATAL_ERR);
  2037. }
  2038. end:
  2039. return;
  2040. }