amf.c 65 KB

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