amf.c 64 KB

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