amf.c 63 KB

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