amf.c 62 KB

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