amf.c 68 KB

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