amf.c 65 KB

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