amf.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176
  1. /*
  2. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <sys/poll.h>
  35. #include <sys/types.h>
  36. #include <sys/socket.h>
  37. #include <sys/un.h>
  38. #include <sys/sysinfo.h>
  39. #include <netinet/in.h>
  40. #include <linux/if.h>
  41. #include <linux/sockios.h>
  42. #include <unistd.h>
  43. #include <fcntl.h>
  44. #include <stdlib.h>
  45. #include <stdio.h>
  46. #include <errno.h>
  47. #include <signal.h>
  48. #include "../include/ais_types.h"
  49. #include "../include/ais_msg.h"
  50. #include "../include/list.h"
  51. #include "../include/queue.h"
  52. #include "gmi.h"
  53. #include "poll.h"
  54. #include "mempool.h"
  55. #include "parse.h"
  56. #include "main.h"
  57. #include "print.h"
  58. #include "handlers.h"
  59. #ifdef INPARSEDOTH
  60. enum amfOperationalState {
  61. AMF_OPER_DISABLED,
  62. AMF_OPER_ENABLED
  63. };
  64. enum amfAdministrativeState {
  65. AMF_ADMIN_UNLOCKED,
  66. AMF_ADMIN_LOCKED,
  67. AMF_ADMIN_STOPPING
  68. };
  69. enum amfOperationalAdministrativeState {
  70. AMF_ENABLED_UNLOCKED,
  71. AMF_DISABLED_UNLOCKED,
  72. AMF_DISABLED_LOCKED,
  73. AMF_ENABLED_STOPPING
  74. };
  75. /*
  76. * State machines for states in AMF
  77. */
  78. enum amfEnabledUnlockedState {
  79. AMF_ENABLED_UNLOCKED_INITIAL,
  80. AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED,
  81. AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED,
  82. AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED,
  83. AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED,
  84. AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED,
  85. AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED,
  86. };
  87. enum amfDisabledUnlockedState {
  88. AMF_DISABLED_UNLOCKED_INITIAL,
  89. AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED,
  90. AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED,
  91. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED,
  92. AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED
  93. };
  94. enum amfDisabledLockedState {
  95. AMF_DISABLED_LOCKED_INITIAL,
  96. AMF_DISABLED_LOCKED_QUIESCED_REQUESTED,
  97. AMF_DISABLED_LOCKED_QUIESCED_COMPLETED,
  98. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_REQUESTED
  99. AMF_DISABLED_LOCKED_OUT_OF_SERVICE_COMPLETED,
  100. };
  101. enum amfEnabledStoppingState {
  102. AMF_ENABLED_STOPPING_INITIAL,
  103. AMF_ENABLED_STOPPING_STOPPING_REQUESTED,
  104. AMF_ENABLED_STOPPING_STOPPING_COMPLETED,
  105. };
  106. /*
  107. * Internal Functions
  108. */
  109. static void componentOutOfServiceSetNoApi (
  110. struct saAmfComponent *component);
  111. #endif
  112. static void grow_amf_track_table (
  113. int fd,
  114. int growby);
  115. static void sendProtectionGroupNotification (
  116. int fd,
  117. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  118. struct saAmfProtectionGroup *amfProtectionGroup,
  119. struct saAmfComponent *changedComponent,
  120. SaAmfProtectionGroupChangesT changeToComponent,
  121. SaUint8T trackFlags);
  122. static int activeServiceUnitsCount (
  123. struct saAmfGroup *saAmfGroup);
  124. #ifdef COMPILE_OUT
  125. static void enumerateComponents (
  126. void (*function)(struct saAmfComponent *, void *data),
  127. void *data);
  128. static void CSIRemove (
  129. int fd);
  130. static void haStateSetClusterInit (
  131. int fd,
  132. struct saAmfComponent *saAmfComponent);
  133. #endif
  134. static void haStateSetCluster (
  135. struct saAmfComponent *saAmfComponent,
  136. SaAmfHAStateT haState);
  137. static void readinessStateSetApi (
  138. struct saAmfComponent *component,
  139. SaAmfReadinessStateT readinessState);
  140. #ifdef COMPILE_OUT
  141. static void readinessStateSetClusterInit (
  142. int fd,
  143. struct saAmfComponent *saAmfComponent);
  144. #endif
  145. static void readinessStateSetCluster (
  146. struct saAmfComponent *saAmfComponent,
  147. SaAmfReadinessStateT readinessState);
  148. #ifdef COMPILE_OUT
  149. static void enumerateComponentsClusterInit (
  150. struct saAmfComponent *component,
  151. void *data);
  152. #endif
  153. static void dsm (
  154. struct saAmfComponent *saAmfComponent);
  155. #if 0 /* NOT IMPLEMENTED */
  156. static void componentTerminate (
  157. int fd);
  158. #endif
  159. static void timer_function_libamf_healthcheck (
  160. void *data);
  161. static struct saAmfProtectionGroup *findProtectionGroup (
  162. SaNameT *csiName);
  163. static struct saAmfComponent *findComponentInProtectionGroup (
  164. SaNameT *csiName,
  165. SaNameT *compName);
  166. static void sendProtectionGroupNotifications (
  167. struct saAmfComponent *changedComponent,
  168. SaAmfProtectionGroupChangesT changeToComponent);
  169. static void sendProtectionGroupNotification (
  170. int fd,
  171. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  172. struct saAmfProtectionGroup *amfProtectionGroup,
  173. struct saAmfComponent *changedComponent,
  174. SaAmfProtectionGroupChangesT changeToComponent,
  175. SaUint8T trackFlags);
  176. static void response_handler_readinessstatesetcallback (
  177. int connection,
  178. struct req_amf_response *req_amf_response);
  179. static void response_handler_csisetcallback (
  180. int connection,
  181. struct req_amf_response *req_amf_response);
  182. static int amfApiFinalize (int fd);
  183. static int amfExecutiveInitialize (void);
  184. static int message_handler_req_exec_amf_componentregister (int fd, void *message);
  185. static int message_handler_req_exec_amf_componentunregister (int fd, void *message);
  186. static int message_handler_req_exec_amf_errorreport (int fd, void *message);
  187. static int message_handler_req_exec_amf_errorcancelall (int fd, void *message);
  188. static int message_handler_req_exec_amf_readinessstateset (int fd, void *message);
  189. static int message_handler_req_exec_amf_hastateset (int fd, void *message);
  190. static int message_handler_req_amf_init (int fd, void *message);
  191. static int message_handler_req_amf_activatepoll (int fd, void *message);
  192. static int message_handler_req_amf_componentregister (int fd, void *message);
  193. static int message_handler_req_amf_componentunregister (int fd, void *message);
  194. static int message_handler_req_amf_readinessstateget (int fd, void *message);
  195. static int message_handler_req_amf_hastateget (int fd, void *message);
  196. static int message_handler_req_amf_protectiongrouptrackstart (int fd, void *message);
  197. static int message_handler_req_amf_protectiongrouptrackstop (int fd, void *message);
  198. static int message_handler_req_amf_errorreport (int fd, void *message);
  199. static int message_handler_req_amf_errorcancelall (int fd, void *message);
  200. static int message_handler_req_amf_stoppingcomplete (int fd, void *message);
  201. static int message_handler_req_amf_response (int fd, void *message);
  202. static int message_handler_req_amf_componentcapabilitymodelget (int fd, void *message);
  203. int (*amf_libais_handler_fns[]) (int fd, void *) = {
  204. message_handler_req_amf_activatepoll,
  205. message_handler_req_amf_componentregister,
  206. message_handler_req_amf_componentunregister,
  207. message_handler_req_amf_readinessstateget,
  208. message_handler_req_amf_hastateget,
  209. message_handler_req_amf_protectiongrouptrackstart,
  210. message_handler_req_amf_protectiongrouptrackstop,
  211. message_handler_req_amf_errorreport,
  212. message_handler_req_amf_errorcancelall,
  213. message_handler_req_amf_stoppingcomplete,
  214. message_handler_req_amf_response,
  215. message_handler_req_amf_componentcapabilitymodelget
  216. };
  217. int (*amf_aisexec_handler_fns[]) (int fd, void *) = {
  218. message_handler_req_exec_amf_componentregister,
  219. message_handler_req_exec_amf_componentunregister,
  220. message_handler_req_exec_amf_errorreport,
  221. message_handler_req_exec_amf_errorcancelall,
  222. message_handler_req_exec_amf_readinessstateset,
  223. message_handler_req_exec_amf_hastateset,
  224. };
  225. /*
  226. * Exports the interface for the service
  227. */
  228. struct service_handler amf_service_handler = {
  229. libais_handler_fns: amf_libais_handler_fns,
  230. libais_handler_fns_count: sizeof (amf_libais_handler_fns) / sizeof (int (*)),
  231. aisexec_handler_fns: amf_aisexec_handler_fns,
  232. aisexec_handler_fns_count: sizeof (amf_aisexec_handler_fns) / sizeof (int (*)),
  233. confchg_fn: 0,
  234. libais_init_fn: message_handler_req_amf_init,
  235. libais_exit_fn: amfApiFinalize,
  236. aisexec_init_fn: amfExecutiveInitialize
  237. };
  238. static void grow_amf_track_table (int fd, int growby)
  239. {
  240. struct libamf_ci_trackentry *tracks;
  241. int newsize;
  242. int currsize = connections[fd].ais_ci.u.libamf_ci.trackEntries;
  243. newsize = growby + currsize;
  244. if (newsize > currsize) {
  245. tracks = (struct libamf_ci_trackentry *)mempool_realloc (connections[fd].ais_ci.u.libamf_ci.tracks,
  246. (newsize) * sizeof (struct libamf_ci_trackentry));
  247. if (tracks == 0) {
  248. #ifdef DEBUG
  249. printf ("grow_amf_track_table: out of memory, woops\n");
  250. #endif
  251. // TODO
  252. exit (1);
  253. }
  254. memset (&tracks[currsize], 0, growby * sizeof (struct libamf_ci_trackentry));
  255. connections[fd].ais_ci.u.libamf_ci.trackEntries = newsize;
  256. connections[fd].ais_ci.u.libamf_ci.tracks = tracks;
  257. }
  258. }
  259. void componentUnregister (
  260. struct saAmfComponent *component)
  261. {
  262. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  263. struct iovec iovecs[2];
  264. /*
  265. * This only works on local components
  266. */
  267. if (component == 0 || component->local != 1) {
  268. return;
  269. }
  270. log_printf (LOG_LEVEL_DEBUG, "componentUnregister: unregistering component %s\n",
  271. getSaNameT (&component->name));
  272. component->probableCause = SA_AMF_NOT_RESPONDING;
  273. req_exec_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  274. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  275. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  276. req_exec_amf_componentunregister.source.fd = 0;
  277. req_exec_amf_componentunregister.source.in_addr.s_addr = 0;
  278. memset (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  279. 0, sizeof (struct req_lib_amf_componentunregister));
  280. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister.compName,
  281. &component->name,
  282. sizeof (SaNameT));
  283. iovecs[0].iov_base = &req_exec_amf_componentunregister;
  284. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  285. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  286. }
  287. #ifdef COMPILE_OUT
  288. This should be used for a partition I think
  289. // This should be used for partition changes
  290. void enumerateComponents (
  291. void (*function)(struct saAmfComponent *, void *data),
  292. void *data)
  293. {
  294. struct list_head *AmfGroupList;
  295. struct list_head *AmfUnitList;
  296. struct list_head *AmfComponentList;
  297. struct saAmfGroup *saAmfGroup;
  298. struct saAmfUnit *AmfUnit;
  299. struct saAmfComponent *AmfComponent;
  300. /*
  301. * Search all groups
  302. */
  303. for (AmfGroupList = saAmfGroupHead.next;
  304. AmfGroupList != &saAmfGroupHead;
  305. AmfGroupList = AmfGroupList->next) {
  306. saAmfGroup = list_entry (AmfGroupList,
  307. struct saAmfGroup, saAmfGroupList);
  308. /*
  309. * Search all units
  310. */
  311. for (AmfUnitList = saAmfGroup->saAmfUnitHead.next;
  312. AmfUnitList != &saAmfGroup->saAmfUnitHead;
  313. AmfUnitList = AmfUnitList->next) {
  314. AmfUnit = list_entry (AmfUnitList,
  315. struct saAmfUnit, saAmfUnitList);
  316. /*
  317. * Search all components
  318. */
  319. for (AmfComponentList = AmfUnit->saAmfComponentHead.next;
  320. AmfComponentList != &AmfUnit->saAmfComponentHead;
  321. AmfComponentList = AmfComponentList->next) {
  322. AmfComponent = list_entry (AmfComponentList,
  323. struct saAmfComponent, saAmfComponentList);
  324. function (AmfComponent, data);
  325. }
  326. }
  327. }
  328. }
  329. #endif
  330. int activeServiceUnitsCount (struct saAmfGroup *saAmfGroup) {
  331. struct saAmfUnit *saAmfUnit;
  332. struct saAmfComponent *saAmfComponent;
  333. struct list_head *saAmfComponentList;
  334. struct list_head *saAmfUnitList;
  335. int activeServiceUnits = 0;
  336. int thisServiceUnitActive;
  337. /*
  338. * Search all units
  339. */
  340. for (activeServiceUnits = 0, saAmfUnitList = saAmfGroup->saAmfUnitHead.next;
  341. saAmfUnitList != &saAmfGroup->saAmfUnitHead;
  342. saAmfUnitList = saAmfUnitList->next) {
  343. saAmfUnit = list_entry (saAmfUnitList,
  344. struct saAmfUnit, saAmfUnitList);
  345. /*
  346. * Search all components
  347. */
  348. for (thisServiceUnitActive = 1, saAmfComponentList = saAmfUnit->saAmfComponentHead.next;
  349. saAmfComponentList != &saAmfUnit->saAmfComponentHead;
  350. saAmfComponentList = saAmfComponentList->next) {
  351. saAmfComponent = list_entry (saAmfComponentList,
  352. struct saAmfComponent, saAmfComponentList);
  353. if (saAmfComponent->currentHAState != SA_AMF_ACTIVE) {
  354. thisServiceUnitActive = 0;
  355. }
  356. }
  357. /*
  358. * If all components are active in service unit, count service unit as active
  359. */
  360. if (thisServiceUnitActive) {
  361. activeServiceUnits += 1;
  362. }
  363. }
  364. return (activeServiceUnits);
  365. }
  366. #ifdef CONFIG_TODO
  367. This should be sent after a service unit is made out of service
  368. void CSIRemove (int fd)
  369. {
  370. struct res_amf_csiremovecallback res_amf_csiremovecallback;
  371. if (connections[fd].active == 0 ||
  372. connections[fd].service != SOCKET_SERVICE_AMF) {
  373. return;
  374. }
  375. log_printf (LOG_NOTICE_DEBUG, "executing CSI remove callback into API\n");
  376. res_amf_csiremovecallback.header.magic = MESSAGE_MAGIC;
  377. res_amf_csiremovecallback.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  378. res_amf_csiremovecallback.header.size = sizeof (struct res_amf_csiremovecallback);
  379. res_amf_csiremovecallback.invocation =
  380. req_amf_response_set (
  381. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK,
  382. fd);
  383. memcpy (&res_amf_csiremovecallback.compName,
  384. &connections[fd].component->name, sizeof (SaNameT));
  385. memcpy (&res_amf_csiremovecallback.csiName,
  386. &connections[fd].component->saAmfProtectionGroup->name, sizeof (SaNameT));
  387. res_amf_csiremovecallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  388. libais_send_response (fd, &res_amf_csiremovecallback,
  389. sizeof (struct res_amf_csiremovecallback));
  390. }
  391. #endif
  392. void haStateSetApi (struct saAmfComponent *component, SaAmfHAStateT haState)
  393. {
  394. struct res_amf_csisetcallback res_amf_csisetcallback;
  395. log_printf (LOG_LEVEL_DEBUG, "sending ha state to API\n");
  396. if (component->local != 1) {
  397. return;
  398. }
  399. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  400. return;
  401. }
  402. /*
  403. * this should be an assertion
  404. */
  405. if (connections[component->fd].active == 0 ||
  406. connections[component->fd].service != SOCKET_SERVICE_AMF) {
  407. return;
  408. }
  409. res_amf_csisetcallback.header.magic = MESSAGE_MAGIC;
  410. res_amf_csisetcallback.header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  411. res_amf_csisetcallback.header.size = sizeof (struct res_amf_csisetcallback);
  412. res_amf_csisetcallback.invocation =
  413. req_amf_response_set (
  414. MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK,
  415. component->fd);
  416. memcpy (&res_amf_csisetcallback.compName,
  417. &component->name, sizeof (SaNameT));
  418. memcpy (&res_amf_csisetcallback.csiName,
  419. &component->saAmfProtectionGroup->name, sizeof (SaNameT));
  420. res_amf_csisetcallback.csiFlags = SA_AMF_CSI_ALL_INSTANCES;
  421. res_amf_csisetcallback.haState = haState;
  422. // TODO set activeCompName to correct component name
  423. memcpy (&res_amf_csisetcallback.activeCompName,
  424. &component->name, sizeof (SaNameT));
  425. res_amf_csisetcallback.transitionDescriptor = SA_AMF_CSI_NEW_ASSIGN;
  426. component->newHAState = haState;
  427. libais_send_response (component->fd, &res_amf_csisetcallback,
  428. sizeof (struct res_amf_csisetcallback));
  429. }
  430. #ifdef COMPILE_OUT
  431. void haStateSetClusterInit (
  432. int fd,
  433. struct saAmfComponent *saAmfComponent)
  434. {
  435. struct req_exec_amf_hastatesetcluster req_exec_amf_hastatesetcluster;
  436. return;
  437. req_exec_amf_hastatesetcluster.header.magic = MESSAGE_MAGIC;
  438. req_exec_amf_hastatesetcluster.header.id = MESSAGE_REQ_EXEC_AMF_HASTATESET;
  439. req_exec_amf_hastatesetcluster.header.size = sizeof (struct req_exec_amf_hastatesetcluster);
  440. memcpy (&req_exec_amf_hastatesetcluster.compName,
  441. &saAmfComponent->name, sizeof (SaNameT));
  442. req_exec_amf_hastatesetcluster.haState = saAmfComponent->currentHAState;
  443. log_printf (LOG_LEVEL_DEBUG, "Sending init ha state message to cluster node to set ha state of component %s\n", getSaNameT (&saAmfComponent->name));
  444. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", saAmfComponent->currentHAState);
  445. libais_send_response (fd, &req_exec_amf_hastatesetcluster,
  446. sizeof (struct req_exec_amf_hastatesetcluster));
  447. }
  448. #endif
  449. void haStateSetCluster (
  450. struct saAmfComponent *component,
  451. SaAmfHAStateT haState)
  452. {
  453. struct req_exec_amf_hastateset req_exec_amf_hastateset;
  454. struct iovec iovecs[2];
  455. req_exec_amf_hastateset.header.magic = MESSAGE_MAGIC;
  456. req_exec_amf_hastateset.header.id = MESSAGE_REQ_EXEC_AMF_HASTATESET;
  457. req_exec_amf_hastateset.header.size = sizeof (struct req_exec_amf_hastateset);
  458. memcpy (&req_exec_amf_hastateset.compName, &component->name, sizeof (SaNameT));
  459. req_exec_amf_hastateset.haState = haState;
  460. log_printf (LOG_LEVEL_DEBUG, "Sending ha state to cluster for component %s\n", getSaNameT (&component->name));
  461. log_printf (LOG_LEVEL_DEBUG, "ha state is %d\n", haState);
  462. iovecs[0].iov_base = &req_exec_amf_hastateset;
  463. iovecs[0].iov_len = sizeof (req_exec_amf_hastateset);
  464. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  465. }
  466. void readinessStateSetApi (struct saAmfComponent *component,
  467. SaAmfReadinessStateT readinessState)
  468. {
  469. struct res_amf_readinessstatesetcallback res_amf_readinessstatesetcallback;
  470. /*
  471. * If component is local, don't request service from API
  472. */
  473. if (component->local != 1) {
  474. return;
  475. }
  476. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  477. return;
  478. }
  479. /*
  480. * this should be an assertion
  481. */
  482. if (connections[component->fd].active == 0 ||
  483. connections[component->fd].service != SOCKET_SERVICE_AMF) {
  484. return;
  485. }
  486. res_amf_readinessstatesetcallback.header.magic = MESSAGE_MAGIC;
  487. res_amf_readinessstatesetcallback.header.id = MESSAGE_RES_AMF_READINESSSTATESETCALLBACK;
  488. res_amf_readinessstatesetcallback.header.size = sizeof (struct res_amf_readinessstatesetcallback);
  489. res_amf_readinessstatesetcallback.invocation =
  490. req_amf_response_set (
  491. MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK,
  492. component->fd);
  493. memcpy (&res_amf_readinessstatesetcallback.compName,
  494. &connections[component->fd].component->name, sizeof (SaNameT));
  495. res_amf_readinessstatesetcallback.readinessState = readinessState;
  496. connections[component->fd].component->newReadinessState = readinessState;
  497. log_printf (LOG_LEVEL_DEBUG, "Setting component->fd %d to readiness state %d\n", component->fd, readinessState);
  498. libais_send_response (component->fd, &res_amf_readinessstatesetcallback,
  499. sizeof (struct res_amf_readinessstatesetcallback));
  500. }
  501. #ifdef COMPILE_OUT
  502. void readinessStateSetClusterInit (
  503. int fd,
  504. struct saAmfComponent *saAmfComponent)
  505. {
  506. struct req_exec_amf_readinessstatesetcluster req_exec_amf_readinessstatesetcluster;
  507. return;
  508. req_exec_amf_readinessstatesetcluster.header.magic = MESSAGE_MAGIC;
  509. req_exec_amf_readinessstatesetcluster.header.id = MESSAGE_REQ_EXEC_AMF_READINESSSTATESET;
  510. req_exec_amf_readinessstatesetcluster.header.size = sizeof (struct req_exec_amf_readinessstateset);
  511. memcpy (&req_exec_amf_readinessstatesetcluster.compName,
  512. &saAmfComponent->name, sizeof (SaNameT));
  513. req_exec_amf_readinessstatesetcluster.readinessState = saAmfComponent->currentReadinessState;
  514. log_printf (LOG_LEVEL_DEBUG, "Sending init message to one cluster node to set readiness state of component %s\n", getSaNameT (&saAmfComponent->name));
  515. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", saAmfComponent->currentReadinessState);
  516. libais_send_response (fd, &req_exec_amf_readinessstatesetcluster,
  517. sizeof (struct req_exec_amf_readinessstatesetcluster));
  518. }
  519. #endif
  520. void readinessStateSetCluster (
  521. struct saAmfComponent *component,
  522. SaAmfReadinessStateT readinessState)
  523. {
  524. struct req_exec_amf_readinessstateset req_exec_amf_readinessstateset;
  525. struct iovec iovecs[2];
  526. req_exec_amf_readinessstateset.header.magic = MESSAGE_MAGIC;
  527. req_exec_amf_readinessstateset.header.id = MESSAGE_REQ_EXEC_AMF_READINESSSTATESET;
  528. req_exec_amf_readinessstateset.header.size = sizeof (struct req_exec_amf_readinessstateset);
  529. memcpy (&req_exec_amf_readinessstateset.compName, &component->name, sizeof (SaNameT));
  530. req_exec_amf_readinessstateset.readinessState = readinessState;
  531. log_printf (LOG_LEVEL_DEBUG, "Sending message to all cluster nodes to set readiness state of component %s\n",
  532. getSaNameT (&component->name));
  533. log_printf (LOG_LEVEL_DEBUG, "readiness state is %d\n", readinessState);
  534. iovecs[0].iov_base = &req_exec_amf_readinessstateset;
  535. iovecs[0].iov_len = sizeof (req_exec_amf_readinessstateset);
  536. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  537. }
  538. #ifdef CMOPILE_OUT
  539. void enumerateComponentsClusterInit (
  540. struct saAmfComponent *component,
  541. void *data)
  542. {
  543. int fd = (int)data;
  544. return;
  545. readinessStateSetClusterInit (fd, component);
  546. haStateSetClusterInit (fd, component);
  547. }
  548. #endif
  549. static void dsmDisabledUnlockedRegisteredOrErrorCancel (
  550. struct saAmfComponent *component)
  551. {
  552. struct saAmfUnit *unit;
  553. struct list_head *list;
  554. int serviceUnitEnabled;
  555. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedRegisteredOrErrorCancel for %s\n",
  556. getSaNameT (&component->name));
  557. unit = component->saAmfUnit;
  558. for (serviceUnitEnabled = 1, list = unit->saAmfComponentHead.next;
  559. list != &unit->saAmfComponentHead;
  560. list = list->next) {
  561. component = list_entry (list,
  562. struct saAmfComponent, saAmfComponentList);
  563. if (component->registered == 0 ||
  564. component->probableCause) {
  565. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not registered or failed.\n", getSaNameT (&component->name));
  566. serviceUnitEnabled = 0;
  567. break;
  568. }
  569. }
  570. if (serviceUnitEnabled == 1) {
  571. log_printf (LOG_LEVEL_DEBUG, "dsm entering AMF_ENABLED_UNLOCKED state.\n");
  572. component->saAmfUnit->operationalAdministrativeState = AMF_ENABLED_UNLOCKED;
  573. component->disabledUnlockedState = -1; // SHOULD BE INVALID
  574. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_INITIAL;
  575. dsm (component);
  576. }
  577. }
  578. static void dsmDisabledUnlockedFailed (
  579. struct saAmfComponent *component)
  580. {
  581. struct saAmfUnit *unit;
  582. struct list_head *list;
  583. unit = component->saAmfUnit;
  584. for (list = unit->saAmfComponentHead.next;
  585. list != &unit->saAmfComponentHead;
  586. list = list->next) {
  587. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  588. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedFailed: for %s.\n",
  589. getSaNameT (&component->name));
  590. switch (component->enabledUnlockedState) {
  591. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  592. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  593. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  594. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  595. readinessStateSetCluster (component, SA_AMF_OUT_OF_SERVICE);
  596. } else {
  597. readinessStateSetApi (component, SA_AMF_OUT_OF_SERVICE);
  598. }
  599. break;
  600. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  601. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  602. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  603. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  604. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED;
  605. if (component->probableCause == SA_AMF_NOT_RESPONDING) {
  606. haStateSetCluster (component, SA_AMF_QUIESCED);
  607. } else {
  608. haStateSetApi (component, SA_AMF_QUIESCED);
  609. }
  610. poll_timer_delete (aisexec_poll_handle,
  611. component->timer_healthcheck);
  612. component->timer_healthcheck = 0;
  613. break;
  614. default:
  615. log_printf (LOG_LEVEL_DEBUG, "invalid case 5 %d\n", component->enabledUnlockedState);
  616. break;
  617. }
  618. }
  619. }
  620. static void dsmDisabledUnlockedQuiescedRequested (
  621. struct saAmfComponent *component)
  622. {
  623. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED;
  624. dsm (component);
  625. }
  626. static void dsmDisabledUnlockedQuiescedCompleted (
  627. struct saAmfComponent *component)
  628. {
  629. struct saAmfUnit *unit;
  630. struct list_head *list;
  631. int serviceUnitQuiesced;
  632. unit = component->saAmfUnit;
  633. for (serviceUnitQuiesced = 1, list = unit->saAmfComponentHead.next;
  634. list != &unit->saAmfComponentHead;
  635. list = list->next) {
  636. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  637. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  638. if (component->currentHAState != SA_AMF_QUIESCED) {
  639. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n", getSaNameT (&component->name));
  640. serviceUnitQuiesced = 0;
  641. break;
  642. }
  643. }
  644. }
  645. if (serviceUnitQuiesced == 1) {
  646. log_printf (LOG_LEVEL_DEBUG, "All components have quiesced, Quiescing completed\n");
  647. for (list = unit->saAmfComponentHead.next;
  648. list != &unit->saAmfComponentHead;
  649. list = list->next) {
  650. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  651. log_printf (LOG_LEVEL_DEBUG, "dsm: Sending readiness state set to OUTOFSERVICE for comp %s.\n",
  652. getSaNameT (&component->name));
  653. readinessStateSetApi (component, SA_AMF_OUT_OF_SERVICE);
  654. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED;
  655. }
  656. }
  657. }
  658. static void dsmDisabledUnlockedOutOfServiceRequested (
  659. struct saAmfComponent *component)
  660. {
  661. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED;
  662. dsm (component);
  663. }
  664. static void dsmDisabledUnlockedOutOfServiceCompleted (
  665. struct saAmfComponent *component)
  666. {
  667. struct saAmfUnit *unit;
  668. struct list_head *list;
  669. int serviceUnitOutOfService;
  670. struct saAmfGroup *group = 0;
  671. struct list_head *comp_list = 0;
  672. struct list_head *unit_list = 0;
  673. int serviceUnitInStandby = 0;
  674. /*
  675. * Once all components of a service unit are out of service,
  676. * activate another service unit in standby
  677. */
  678. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlockedOutOfServiceCompleted: component out of service %s\n", getSaNameT (&component->name));
  679. /*
  680. * Determine if all components have responded to going out of service
  681. */
  682. unit = component->saAmfUnit;
  683. for (serviceUnitOutOfService = 1, list = unit->saAmfComponentHead.next;
  684. list != &unit->saAmfComponentHead;
  685. list = list->next) {
  686. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  687. if (component->probableCause != SA_AMF_NOT_RESPONDING && component->registered) {
  688. if (component->currentReadinessState != SA_AMF_OUT_OF_SERVICE) {
  689. log_printf (LOG_LEVEL_DEBUG, "dsm: Can't transition states, found component not quiesced.\n", getSaNameT (&component->name));
  690. serviceUnitOutOfService = 0;
  691. break;
  692. }
  693. }
  694. }
  695. group = unit->saAmfGroup;
  696. if (serviceUnitOutOfService == 1) {
  697. log_printf (LOG_LEVEL_DEBUG, "SU has gone out of service.\n");
  698. /*
  699. * Search all units
  700. */
  701. for (unit_list = group->saAmfUnitHead.next;
  702. unit_list != &group->saAmfUnitHead;
  703. unit_list = unit_list->next) {
  704. unit = list_entry (unit_list,
  705. struct saAmfUnit, saAmfUnitList);
  706. log_printf (LOG_LEVEL_DEBUG, "Checking if service unit is in standby %s\n", getSaNameT (&unit->name));
  707. /*
  708. * Search all components
  709. */
  710. for (serviceUnitInStandby = 1,
  711. comp_list = unit->saAmfComponentHead.next;
  712. comp_list != &unit->saAmfComponentHead;
  713. comp_list = comp_list->next) {
  714. component = list_entry (comp_list,
  715. struct saAmfComponent, saAmfComponentList);
  716. if (component->currentHAState != SA_AMF_STANDBY) {
  717. serviceUnitInStandby = 0;
  718. break; /* for iteration of service unit components */
  719. }
  720. }
  721. if (serviceUnitInStandby) {
  722. break; /* for iteration of service group's service units */
  723. }
  724. }
  725. /*
  726. * All components in service unit are standby, activate standby service unit
  727. */
  728. if (serviceUnitInStandby) {
  729. log_printf (LOG_LEVEL_DEBUG, "unit in standby\n");
  730. for (list = unit->saAmfComponentHead.next;
  731. list != &unit->saAmfComponentHead;
  732. list = list->next) {
  733. component = list_entry (list,
  734. struct saAmfComponent, saAmfComponentList);
  735. haStateSetApi (component, SA_AMF_ACTIVE);
  736. }
  737. } else {
  738. log_printf (LOG_LEVEL_DEBUG, "Can't activate standby service unit because no standby is available.\n");
  739. }
  740. }
  741. }
  742. static void dsmEnabledUnlockedInitial (
  743. struct saAmfComponent *component)
  744. {
  745. struct saAmfUnit *unit;
  746. struct list_head *list;
  747. unit = component->saAmfUnit;
  748. for (list = unit->saAmfComponentHead.next;
  749. list != &unit->saAmfComponentHead;
  750. list = list->next) {
  751. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  752. readinessStateSetApi (component, SA_AMF_IN_SERVICE);
  753. log_printf (LOG_LEVEL_DEBUG, "dsm: telling component %s to enter SA_AMF_IN_SERVICE.\n",
  754. getSaNameT (&component->name));
  755. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED;
  756. }
  757. }
  758. static void dsmEnabledUnlockedInServiceRequested (
  759. struct saAmfComponent *component)
  760. {
  761. struct saAmfUnit *unit;
  762. struct list_head *list;
  763. int in_service;
  764. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceRequested %s.\n", getSaNameT (&component->name));
  765. unit = component->saAmfUnit;
  766. for (in_service = 1, list = unit->saAmfComponentHead.next;
  767. list != &unit->saAmfComponentHead;
  768. list = list->next) {
  769. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  770. if (component->currentReadinessState != SA_AMF_IN_SERVICE) {
  771. log_printf (LOG_LEVEL_DEBUG, "dsm: Found atleast one component not in service\n");
  772. in_service = 0;
  773. break;
  774. }
  775. }
  776. if (in_service) {
  777. log_printf (LOG_LEVEL_DEBUG, "DSM determined component is in service\n");
  778. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED;
  779. dsm (component);
  780. }
  781. }
  782. static void dsmEnabledUnlockedInServiceCompleted (
  783. struct saAmfComponent *component)
  784. {
  785. struct saAmfUnit *unit;
  786. struct list_head *list;
  787. SaAmfHAStateT newHaState;
  788. int activeServiceUnits;
  789. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlockedInServiceCompleted %s.\n", getSaNameT (&component->name));
  790. unit = component->saAmfUnit;
  791. for (list = unit->saAmfComponentHead.next;
  792. list != &unit->saAmfComponentHead;
  793. list = list->next) {
  794. component = list_entry (list,
  795. struct saAmfComponent, saAmfComponentList);
  796. log_printf (LOG_LEVEL_DEBUG, "Requesting component go active.\n", getSaNameT (&component->name));
  797. /*
  798. * Count number of active service units
  799. */
  800. activeServiceUnits = activeServiceUnitsCount (component->saAmfUnit->saAmfGroup);
  801. if (activeServiceUnits < component->saAmfUnit->saAmfGroup->saAmfActiveUnitsDesired) {
  802. newHaState = SA_AMF_ACTIVE;
  803. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_ACTIVE\n", getSaNameT (&component->name));
  804. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED;
  805. } else {
  806. newHaState = SA_AMF_STANDBY;
  807. log_printf (LOG_LEVEL_DEBUG, "Setting ha state of component %s to SA_AMF_STANDBY\n", getSaNameT (&component->name));
  808. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED;
  809. }
  810. haStateSetApi (component, newHaState);
  811. }
  812. }
  813. void dsmEnabledUnlockedActiveRequested (
  814. struct saAmfComponent *component)
  815. {
  816. if (component->local == 1) {
  817. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  818. poll_timer_add (aisexec_poll_handle,
  819. component->healthcheckInterval,
  820. (void *)component->fd,
  821. timer_function_libamf_healthcheck,
  822. &component->timer_healthcheck);
  823. }
  824. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED;
  825. }
  826. void dsmEnabledUnlockedStandbyRequested (
  827. struct saAmfComponent *component)
  828. {
  829. if (component->local == 1) {
  830. log_printf (LOG_LEVEL_DEBUG, "Adding healthcheck timer\n");
  831. poll_timer_add (aisexec_poll_handle,
  832. component->healthcheckInterval,
  833. (void *)component->fd,
  834. timer_function_libamf_healthcheck,
  835. &component->timer_healthcheck);
  836. }
  837. component->enabledUnlockedState = AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED;
  838. }
  839. void dsmEnabledUnlockedTransitionDisabledUnlocked (
  840. struct saAmfComponent *component)
  841. {
  842. struct saAmfUnit *unit;
  843. struct list_head *list;
  844. unit = component->saAmfUnit;
  845. for (list = unit->saAmfComponentHead.next;
  846. list != &unit->saAmfComponentHead;
  847. list = list->next) {
  848. component = list_entry (list, struct saAmfComponent, saAmfComponentList);
  849. log_printf (LOG_LEVEL_DEBUG, "Requesting component %s transition to disabled.\n",
  850. getSaNameT (&component->name));
  851. component->saAmfUnit->operationalAdministrativeState = AMF_DISABLED_UNLOCKED;
  852. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_FAILED;
  853. }
  854. dsm (component);
  855. }
  856. static void dsmEnabledUnlocked (
  857. struct saAmfComponent *component)
  858. {
  859. switch (component->enabledUnlockedState) {
  860. case AMF_ENABLED_UNLOCKED_INITIAL:
  861. dsmEnabledUnlockedInitial (component);
  862. break;
  863. case AMF_ENABLED_UNLOCKED_IN_SERVICE_REQUESTED:
  864. dsmEnabledUnlockedInServiceRequested (component);
  865. break;
  866. case AMF_ENABLED_UNLOCKED_IN_SERVICE_COMPLETED:
  867. dsmEnabledUnlockedInServiceCompleted (component);
  868. break;
  869. case AMF_ENABLED_UNLOCKED_ACTIVE_REQUESTED:
  870. dsmEnabledUnlockedActiveRequested (component);
  871. break;
  872. case AMF_ENABLED_UNLOCKED_ACTIVE_COMPLETED:
  873. /* noop - operational state */
  874. break;
  875. case AMF_ENABLED_UNLOCKED_STANDBY_REQUESTED:
  876. dsmEnabledUnlockedActiveRequested (component);
  877. break;
  878. case AMF_ENABLED_UNLOCKED_STANDBY_COMPLETED:
  879. /* noop - operational state */
  880. break;
  881. default:
  882. log_printf (LOG_LEVEL_DEBUG, "dsmEnabledUnlocked: unkown state machine value.\n");
  883. }
  884. }
  885. static void dsmDisabledUnlocked (
  886. struct saAmfComponent *component)
  887. {
  888. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked for %s state %d\n",
  889. getSaNameT (&component->name),
  890. component->disabledUnlockedState);
  891. switch (component->disabledUnlockedState) {
  892. case AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL:
  893. dsmDisabledUnlockedRegisteredOrErrorCancel (component);
  894. break;
  895. case AMF_DISABLED_UNLOCKED_FAILED:
  896. dsmDisabledUnlockedFailed (component);
  897. break;
  898. case AMF_DISABLED_UNLOCKED_QUIESCED_REQUESTED:
  899. dsmDisabledUnlockedQuiescedRequested (component);
  900. break;
  901. case AMF_DISABLED_UNLOCKED_QUIESCED_COMPLETED:
  902. dsmDisabledUnlockedQuiescedCompleted (component);
  903. break;
  904. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_REQUESTED:
  905. dsmDisabledUnlockedOutOfServiceRequested (component);
  906. break;
  907. case AMF_DISABLED_UNLOCKED_OUT_OF_SERVICE_COMPLETED:
  908. dsmDisabledUnlockedOutOfServiceCompleted (component);
  909. break;
  910. default:
  911. log_printf (LOG_LEVEL_DEBUG, "dsmDisabledUnlocked: unkown state machine value %d.\n", component->disabledUnlockedState);
  912. }
  913. }
  914. static void dsm (
  915. struct saAmfComponent *component)
  916. {
  917. log_printf (LOG_LEVEL_DEBUG, "dsm for component %s\n", getSaNameT (&component->name));
  918. switch (component->saAmfUnit->operationalAdministrativeState) {
  919. case AMF_DISABLED_UNLOCKED:
  920. dsmDisabledUnlocked (component);
  921. break;
  922. case AMF_ENABLED_UNLOCKED:
  923. dsmEnabledUnlocked (component);
  924. break;
  925. /*
  926. AMF_DISABLED_LOCKED,
  927. AMF_ENABLED_STOPPING
  928. */
  929. default:
  930. log_printf (LOG_LEVEL_DEBUG, "dsm: unknown state machine value.\n");
  931. }
  932. }
  933. #if 0
  934. /*
  935. * This is currently unused, but executes the componentterminatecallback
  936. * callback in the AMF api.
  937. */
  938. void componentTerminate (int fd)
  939. {
  940. struct res_amf_componentterminatecallback res_amf_componentterminatecallback;
  941. res_amf_componentterminatecallback.header.magic = MESSAGE_MAGIC;
  942. res_amf_componentterminatecallback.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  943. res_amf_componentterminatecallback.header.size = sizeof (struct res_amf_componentterminatecallback);
  944. res_amf_componentterminatecallback.invocation =
  945. req_amf_response_set (
  946. MESSAGE_REQ_AMF_RESPONSE_SAAMFCOMPONENTTERMINATECALLBACK,
  947. fd);
  948. memcpy (&res_amf_componentterminatecallback.compName,
  949. &connections[fd].component->name, sizeof (SaNameT));
  950. connections[fd].component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  951. log_printf (LOG_LEVEL_DEBUG, "terminating component on fd %d\n", fd);
  952. libais_send_response (fd, &res_amf_componentterminatecallback,
  953. sizeof (struct res_amf_componentterminatecallback));
  954. }
  955. #endif /* Not currently implemented */
  956. void errorReport (
  957. struct saAmfComponent *component,
  958. SaAmfProbableCauseT probableCause)
  959. {
  960. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  961. struct iovec iovecs[2];
  962. req_exec_amf_errorreport.header.magic = MESSAGE_MAGIC;
  963. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  964. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  965. req_exec_amf_errorreport.source.fd = 0;
  966. req_exec_amf_errorreport.source.in_addr.s_addr = 0;
  967. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport.erroneousComponent,
  968. &component->name,
  969. sizeof (SaNameT));
  970. req_exec_amf_errorreport.req_lib_amf_errorreport.errorDescriptor.probableCause = probableCause;
  971. iovecs[0].iov_base = &req_exec_amf_errorreport;
  972. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  973. gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  974. }
  975. int healthcheck_instance = 0;
  976. void timer_function_libamf_healthcheck (void *data) {
  977. struct res_amf_healthcheckcallback res_amf_healthcheckcallback;
  978. int connection = (int)data;
  979. res_amf_healthcheckcallback.header.magic = MESSAGE_MAGIC;
  980. res_amf_healthcheckcallback.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  981. res_amf_healthcheckcallback.header.size = sizeof (struct res_amf_healthcheckcallback);
  982. log_printf (LOG_LEVEL_DEBUG, "checking healthcheck on component %s\n",
  983. getSaNameT (&connections[connection].component->name));
  984. if (connections[connection].component->healthcheck_outstanding == 1) {
  985. log_printf (LOG_LEVEL_DEBUG, "Healthcheck timed out on component %s\n",
  986. getSaNameT (&connections[connection].component->name));
  987. /*
  988. * Report the error to the rest of the cluster using the normal state machine
  989. */
  990. errorReport (connections[connection].component, SA_AMF_NOT_RESPONDING);
  991. connections[connection].component->healthcheck_outstanding = 2;
  992. } else
  993. if (connections[connection].component->healthcheck_outstanding == 0) {
  994. connections[connection].component->healthcheck_outstanding = 1;
  995. /*
  996. * Send healthcheck message
  997. */
  998. res_amf_healthcheckcallback.invocation =
  999. req_amf_response_set (
  1000. MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK,
  1001. connection);
  1002. memcpy (&res_amf_healthcheckcallback.compName,
  1003. &connections[connection].component->name,
  1004. sizeof (SaNameT));
  1005. res_amf_healthcheckcallback.checkType = SA_AMF_HEARTBEAT;
  1006. log_printf (LOG_LEVEL_DEBUG, "Sending instance %d\n", healthcheck_instance);
  1007. res_amf_healthcheckcallback.instance = healthcheck_instance++;
  1008. libais_send_response (connection,
  1009. &res_amf_healthcheckcallback,
  1010. sizeof (struct res_amf_healthcheckcallback));
  1011. poll_timer_add (aisexec_poll_handle,
  1012. connections[connection].component->healthcheckInterval,
  1013. (void *)connection,
  1014. timer_function_libamf_healthcheck,
  1015. &connections[connection].component->timer_healthcheck);
  1016. }
  1017. }
  1018. struct saAmfProtectionGroup *findProtectionGroup (
  1019. SaNameT *csiName)
  1020. {
  1021. struct list_head *AmfGroupList;
  1022. struct list_head *AmfProtectionGroupList;
  1023. struct saAmfGroup *saAmfGroup;
  1024. struct saAmfProtectionGroup *AmfProtectionGroup;
  1025. /*
  1026. * Search all groups
  1027. */
  1028. for (AmfGroupList = saAmfGroupHead.next;
  1029. AmfGroupList != &saAmfGroupHead;
  1030. AmfGroupList = AmfGroupList->next) {
  1031. saAmfGroup = list_entry (AmfGroupList,
  1032. struct saAmfGroup, saAmfGroupList);
  1033. /*
  1034. * Search all protection groups
  1035. */
  1036. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1037. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1038. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1039. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1040. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1041. if (SaNameTisNameT (csiName, &AmfProtectionGroup->name)) {
  1042. return (AmfProtectionGroup);
  1043. }
  1044. }
  1045. }
  1046. return (0);
  1047. }
  1048. struct saAmfComponent *findComponentInProtectionGroup (
  1049. SaNameT *csiName,
  1050. SaNameT *compName)
  1051. {
  1052. struct list_head *AmfGroupList = 0;
  1053. struct list_head *AmfProtectionGroupList = 0;
  1054. struct list_head *AmfComponentList = 0;
  1055. struct saAmfGroup *saAmfGroup = 0;
  1056. struct saAmfProtectionGroup *AmfProtectionGroup = 0;
  1057. struct saAmfComponent *AmfComponent = 0;
  1058. int found = 0;
  1059. /*
  1060. * Search all groups
  1061. */
  1062. for (AmfGroupList = saAmfGroupHead.next;
  1063. AmfGroupList != &saAmfGroupHead;
  1064. AmfGroupList = AmfGroupList->next) {
  1065. saAmfGroup = list_entry (AmfGroupList,
  1066. struct saAmfGroup, saAmfGroupList);
  1067. /*
  1068. * Search all protection groups
  1069. */
  1070. for (AmfProtectionGroupList = saAmfGroup->saAmfProtectionGroupHead.next;
  1071. AmfProtectionGroupList != &saAmfGroup->saAmfProtectionGroupHead;
  1072. AmfProtectionGroupList = AmfProtectionGroupList->next) {
  1073. AmfProtectionGroup = list_entry (AmfProtectionGroupList,
  1074. struct saAmfProtectionGroup, saAmfProtectionGroupList);
  1075. if (SaNameTisNameT (csiName, &AmfProtectionGroup->name)) {
  1076. /*
  1077. * Search all components
  1078. */
  1079. for (AmfComponentList = AmfProtectionGroup->saAmfMembersHead.next;
  1080. AmfComponentList != &AmfProtectionGroup->saAmfMembersHead;
  1081. AmfComponentList = AmfComponentList->next) {
  1082. AmfComponent = list_entry (AmfComponentList,
  1083. struct saAmfComponent, saAmfProtectionGroupList);
  1084. if (SaNameTisNameT (compName, &AmfComponent->name)) {
  1085. found = 1;
  1086. }
  1087. }
  1088. }
  1089. }
  1090. }
  1091. if (found) {
  1092. return (AmfComponent);
  1093. } else {
  1094. return (0);
  1095. }
  1096. }
  1097. void sendProtectionGroupNotifications (
  1098. struct saAmfComponent *changedComponent,
  1099. SaAmfProtectionGroupChangesT changeToComponent)
  1100. {
  1101. int fd;
  1102. int i;
  1103. log_printf (LOG_LEVEL_DEBUG, "sendProtectionGroupNotifications: sending PGs to API.\n");
  1104. for (fd = 0; fd < connection_entries; fd++) {
  1105. if (connections[fd].active &&
  1106. connections[fd].service == SOCKET_SERVICE_AMF) {
  1107. for (i = 0; i < connections[fd].ais_ci.u.libamf_ci.trackEntries; i++) {
  1108. if (connections[fd].ais_ci.u.libamf_ci.tracks[i].active) {
  1109. sendProtectionGroupNotification (fd,
  1110. connections[fd].ais_ci.u.libamf_ci.tracks[i].notificationBufferAddress,
  1111. changedComponent->saAmfProtectionGroup,
  1112. changedComponent,
  1113. changeToComponent,
  1114. connections[fd].ais_ci.u.libamf_ci.tracks[i].trackFlags);
  1115. } /* if active */
  1116. } /* for all track entries */
  1117. } /* if connection active and service is AMF */
  1118. } /* for all connection entries */
  1119. }
  1120. void sendProtectionGroupNotification (int fd,
  1121. SaAmfProtectionGroupNotificationT *notificationBufferAddress,
  1122. struct saAmfProtectionGroup *amfProtectionGroup,
  1123. struct saAmfComponent *changedComponent,
  1124. SaAmfProtectionGroupChangesT changeToComponent,
  1125. SaUint8T trackFlags)
  1126. {
  1127. struct res_amf_protectiongrouptrackcallback res_amf_protectiongrouptrackcallback;
  1128. SaAmfProtectionGroupNotificationT *protectionGroupNotification = 0;
  1129. int notifyEntries = 0;
  1130. struct saAmfComponent *component;
  1131. struct list_head *componentList;
  1132. /*
  1133. * Step through all components and generate protection group list for csi
  1134. */
  1135. for (componentList = amfProtectionGroup->saAmfMembersHead.next;
  1136. componentList != &amfProtectionGroup->saAmfMembersHead;
  1137. componentList = componentList->next) {
  1138. component = list_entry (componentList,
  1139. struct saAmfComponent, saAmfProtectionGroupList);
  1140. /*
  1141. * Generate new track entry for following cases:
  1142. * 1. If this component is the changed component and
  1143. * SA_TRACK_CHANGES_ONLY is set
  1144. * 2. If track flags indicate SA_TRACK_CURRENT or SA_TRACK_CHANGES
  1145. */
  1146. if (component == changedComponent ||
  1147. (trackFlags & (SA_TRACK_CURRENT | SA_TRACK_CHANGES))) {
  1148. protectionGroupNotification = (SaAmfProtectionGroupNotificationT *)mempool_realloc (protectionGroupNotification,
  1149. sizeof (SaAmfProtectionGroupNotificationT) * (notifyEntries + 1));
  1150. memcpy (&protectionGroupNotification[notifyEntries].member.compName,
  1151. &component->name, sizeof (SaNameT));
  1152. memcpy (&protectionGroupNotification[notifyEntries].member.readinessState,
  1153. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1154. memcpy (&protectionGroupNotification[notifyEntries].member.haState,
  1155. &component->currentHAState, sizeof (SaAmfHAStateT));
  1156. if (component == changedComponent) {
  1157. protectionGroupNotification[notifyEntries].change = changeToComponent;
  1158. } else {
  1159. protectionGroupNotification[notifyEntries].change = SA_AMF_PROTECTION_GROUP_NO_CHANGE;
  1160. }
  1161. notifyEntries += 1;
  1162. }
  1163. } /* for */
  1164. /*
  1165. * Send track callback
  1166. */
  1167. if (notifyEntries) {
  1168. res_amf_protectiongrouptrackcallback.header.magic = MESSAGE_MAGIC;
  1169. res_amf_protectiongrouptrackcallback.header.size =
  1170. sizeof (struct res_amf_protectiongrouptrackcallback) +
  1171. (notifyEntries * sizeof (SaAmfProtectionGroupNotificationT));
  1172. res_amf_protectiongrouptrackcallback.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKCALLBACK;
  1173. res_amf_protectiongrouptrackcallback.numberOfItems = notifyEntries;
  1174. res_amf_protectiongrouptrackcallback.numberOfMembers = notifyEntries;
  1175. memcpy (&res_amf_protectiongrouptrackcallback.csiName,
  1176. &amfProtectionGroup->name, sizeof (SaNameT));
  1177. res_amf_protectiongrouptrackcallback.notificationBufferAddress = notificationBufferAddress;
  1178. libais_send_response (fd, &res_amf_protectiongrouptrackcallback,
  1179. sizeof (struct res_amf_protectiongrouptrackcallback));
  1180. libais_send_response (fd, protectionGroupNotification,
  1181. sizeof (SaAmfProtectionGroupNotificationT) * notifyEntries);
  1182. mempool_free (protectionGroupNotification);
  1183. }
  1184. }
  1185. /*
  1186. * The response handler for readiness state set callback
  1187. */
  1188. static void response_handler_readinessstatesetcallback (int connection,
  1189. struct req_amf_response *req_amf_response)
  1190. {
  1191. if (req_amf_response->error == SA_OK && connections[connection].component) {
  1192. log_printf (LOG_LEVEL_DEBUG, "CALLBACK sending readiness state to %s\n",
  1193. getSaNameT (&connections[connection].component->name));
  1194. readinessStateSetCluster (connections[connection].component,
  1195. connections[connection].component->newReadinessState);
  1196. }
  1197. }
  1198. /*
  1199. * iterate service unit components
  1200. * telling all components not already QUIESCING to enter SA_AMF_QUIESCED state
  1201. */
  1202. static void response_handler_csisetcallback (int connection,
  1203. struct req_amf_response *req_amf_response)
  1204. {
  1205. if (req_amf_response->error == SA_OK && connections[connection].component) {
  1206. haStateSetCluster (connections[connection].component,
  1207. connections[connection].component->newHAState);
  1208. }
  1209. }
  1210. int amfExecutiveInitialize (void)
  1211. {
  1212. return (0);
  1213. }
  1214. int amfApiFinalize (int fd)
  1215. {
  1216. /*
  1217. * Unregister all components registered to this file descriptor
  1218. */
  1219. if (connections[fd].service == SOCKET_SERVICE_AMF) {
  1220. componentUnregister (connections[fd].component);
  1221. if (connections[fd].component && connections[fd].component->timer_healthcheck) {
  1222. poll_timer_delete (aisexec_poll_handle,
  1223. connections[fd].component->timer_healthcheck);
  1224. connections[fd].component->timer_healthcheck = 0;
  1225. }
  1226. if (connections[fd].ais_ci.u.libamf_ci.tracks) {
  1227. mempool_free (connections[fd].ais_ci.u.libamf_ci.tracks);
  1228. connections[fd].ais_ci.u.libamf_ci.tracks = 0;
  1229. }
  1230. }
  1231. return (0);
  1232. }
  1233. static int message_handler_req_exec_amf_componentregister (int fd, void *message)
  1234. {
  1235. struct req_exec_amf_componentregister *req_exec_amf_componentregister = (struct req_exec_amf_componentregister *)message;
  1236. struct res_lib_amf_componentregister res_lib_amf_componentregister;
  1237. struct saAmfComponent *component;
  1238. struct saAmfComponent *amfProxyComponent;
  1239. SaErrorT error;
  1240. log_printf (LOG_LEVEL_DEBUG, "Executive: ComponentRegister for component %s\n",
  1241. getSaNameT (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName));
  1242. /*
  1243. * Determine if proxy isn't registered
  1244. */
  1245. error = SA_OK;
  1246. component = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.compName);
  1247. amfProxyComponent = findComponent (&req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName);
  1248. /*
  1249. * If component not in configuration files, return error
  1250. */
  1251. if (component == 0) {
  1252. error = SA_ERR_NOT_EXIST;
  1253. }
  1254. /*
  1255. * If proxy doesn't exist and isn't registered, return error
  1256. */
  1257. if ((amfProxyComponent == 0 &&
  1258. req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) ||
  1259. (amfProxyComponent && amfProxyComponent->registered == 0)) {
  1260. error = SA_ERR_NOT_EXIST;
  1261. }
  1262. /*
  1263. * If component already registered, return error
  1264. */
  1265. if (error == SA_OK) {
  1266. if (component->registered) {
  1267. error = SA_ERR_EXIST;
  1268. }
  1269. }
  1270. /*
  1271. * Finally register component and setup links for proxy if
  1272. * proxy present
  1273. */
  1274. if (error == SA_OK) {
  1275. component->local = 0;
  1276. component->registered = 1;
  1277. component->fd = req_exec_amf_componentregister->source.fd;
  1278. component->currentReadinessState = SA_AMF_OUT_OF_SERVICE;
  1279. component->newReadinessState = SA_AMF_OUT_OF_SERVICE;
  1280. component->currentHAState = SA_AMF_QUIESCED;
  1281. component->newHAState = SA_AMF_QUIESCED;
  1282. component->probableCause = 0;
  1283. component->enabledUnlockedState = 0;
  1284. component->disabledUnlockedState = 0;
  1285. if (req_exec_amf_componentregister->req_lib_amf_componentregister.proxyCompName.length > 0) {
  1286. component->saAmfProxyComponent = amfProxyComponent;
  1287. }
  1288. }
  1289. /*
  1290. * If this node originated the request to the cluster, respond back
  1291. * to the AMF library
  1292. */
  1293. if (req_exec_amf_componentregister->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1294. if (error == SA_OK) {
  1295. component->local = 1;
  1296. connections[req_exec_amf_componentregister->source.fd].component = component;
  1297. }
  1298. log_printf (LOG_LEVEL_DEBUG, "sending component register response to fd %d\n", req_exec_amf_componentregister->source.fd);
  1299. res_lib_amf_componentregister.header.magic = MESSAGE_MAGIC;
  1300. res_lib_amf_componentregister.header.size = sizeof (struct res_lib_amf_componentregister);
  1301. res_lib_amf_componentregister.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  1302. res_lib_amf_componentregister.error = error;
  1303. libais_send_response (req_exec_amf_componentregister->source.fd, &res_lib_amf_componentregister,
  1304. sizeof (struct res_lib_amf_componentregister));
  1305. }
  1306. /*
  1307. * If no error on registration, determine if we should enter new state
  1308. */
  1309. if (error == SA_OK) {
  1310. dsm (component);
  1311. }
  1312. return (0);
  1313. }
  1314. static int message_handler_req_exec_amf_componentunregister (int fd, void *message)
  1315. {
  1316. struct req_exec_amf_componentunregister *req_exec_amf_componentunregister = (struct req_exec_amf_componentunregister *)message;
  1317. struct res_lib_amf_componentunregister res_lib_amf_componentunregister;
  1318. struct saAmfComponent *component;
  1319. struct saAmfComponent *amfProxyComponent;
  1320. SaErrorT error;
  1321. log_printf (LOG_LEVEL_DEBUG, "Executive: ComponentUnregister for %s\n",
  1322. getSaNameT (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName));
  1323. component = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.compName);
  1324. amfProxyComponent = findComponent (&req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName);
  1325. /*
  1326. * Check for proxy and component not existing in system
  1327. */
  1328. error = SA_OK;
  1329. if (component == 0) {
  1330. error = SA_ERR_NOT_EXIST;
  1331. }
  1332. if (req_exec_amf_componentunregister->req_lib_amf_componentunregister.proxyCompName.length > 0) {
  1333. if (amfProxyComponent) {
  1334. if (amfProxyComponent->registered == 0) {
  1335. error = SA_ERR_NOT_EXIST;
  1336. }
  1337. } else {
  1338. error = SA_ERR_NOT_EXIST;
  1339. }
  1340. }
  1341. /*
  1342. * If there is a proxycompname, make sure it is the proxy
  1343. * of compName
  1344. */
  1345. if (error == SA_OK && amfProxyComponent) {
  1346. if (component->saAmfProxyComponent != amfProxyComponent) {
  1347. error = SA_ERR_BAD_OPERATION;
  1348. }
  1349. }
  1350. /*
  1351. * Finally unregister the component
  1352. */
  1353. if (error == SA_OK) {
  1354. component->registered = 0;
  1355. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1356. }
  1357. /*
  1358. * If this node originated the request to the cluster, respond back
  1359. * to the AMF library
  1360. */
  1361. if (req_exec_amf_componentunregister->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1362. log_printf (LOG_LEVEL_DEBUG, "sending component unregister response to fd %d\n",
  1363. req_exec_amf_componentunregister->source.fd);
  1364. res_lib_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  1365. res_lib_amf_componentunregister.header.size = sizeof (struct res_lib_amf_componentunregister);
  1366. res_lib_amf_componentunregister.header.id = MESSAGE_RES_AMF_COMPONENTUNREGISTER;
  1367. res_lib_amf_componentunregister.error = error;
  1368. libais_send_response (req_exec_amf_componentunregister->source.fd,
  1369. &res_lib_amf_componentunregister, sizeof (struct res_lib_amf_componentunregister));
  1370. }
  1371. return (0);
  1372. }
  1373. static int message_handler_req_exec_amf_errorreport (int fd, void *message)
  1374. {
  1375. struct req_exec_amf_errorreport *req_exec_amf_errorreport = (struct req_exec_amf_errorreport *)message;
  1376. struct res_lib_amf_errorreport res_lib_amf_errorreport;
  1377. struct saAmfComponent *component;
  1378. SaErrorT error = SA_ERR_BAD_OPERATION;
  1379. log_printf (LOG_LEVEL_DEBUG, "Executive: ErrorReport for %s\n",
  1380. getSaNameT (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent));
  1381. component = findComponent (&req_exec_amf_errorreport->req_lib_amf_errorreport.erroneousComponent);
  1382. if (component && component->registered) {
  1383. component->probableCause = req_exec_amf_errorreport->req_lib_amf_errorreport.errorDescriptor.probableCause;
  1384. /*
  1385. * One registered component left, so transition
  1386. * SU to failed operational state
  1387. */
  1388. dsmEnabledUnlockedTransitionDisabledUnlocked (component);
  1389. error = SA_OK;
  1390. }
  1391. /*
  1392. * If this node originated the request to the cluster, respond back
  1393. * to the AMF library
  1394. */
  1395. if (req_exec_amf_errorreport->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1396. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1397. req_exec_amf_errorreport->source.fd);
  1398. res_lib_amf_errorreport.header.magic = MESSAGE_MAGIC;
  1399. res_lib_amf_errorreport.header.size = sizeof (struct res_lib_amf_errorreport);
  1400. res_lib_amf_errorreport.header.id = MESSAGE_RES_AMF_ERRORREPORT;
  1401. res_lib_amf_errorreport.error = error;
  1402. libais_send_response (req_exec_amf_errorreport->source.fd,
  1403. &res_lib_amf_errorreport, sizeof (struct res_lib_amf_errorreport));
  1404. }
  1405. return (0);
  1406. }
  1407. static int message_handler_req_exec_amf_errorcancelall (int fd, void *message)
  1408. {
  1409. struct req_exec_amf_errorcancelall *req_exec_amf_errorcancelall = (struct req_exec_amf_errorcancelall *)message;
  1410. struct res_lib_amf_errorcancelall res_lib_amf_errorcancelall;
  1411. struct saAmfComponent *component;
  1412. SaErrorT error = SA_ERR_BAD_OPERATION;
  1413. log_printf (LOG_LEVEL_DEBUG, "Executive: ErrorCancelAll for %s\n",
  1414. getSaNameT (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName));
  1415. component = findComponent (&req_exec_amf_errorcancelall->req_lib_amf_errorcancelall.compName);
  1416. if (component && component->registered) {
  1417. /*
  1418. * Mark component in service if its a AMF service
  1419. * connected to this aisexec
  1420. */
  1421. if (component->probableCause) {
  1422. component->probableCause = 0;
  1423. component->disabledUnlockedState = AMF_DISABLED_UNLOCKED_REGISTEREDORERRORCANCEL;
  1424. dsm (component);
  1425. }
  1426. error = SA_OK;
  1427. }
  1428. /*
  1429. * If this node originated the request to the cluster, respond back
  1430. * to the AMF library
  1431. */
  1432. if (req_exec_amf_errorcancelall->source.in_addr.s_addr == this_ip.sin_addr.s_addr) {
  1433. log_printf (LOG_LEVEL_DEBUG, "sending error report response to fd %d\n",
  1434. req_exec_amf_errorcancelall->source.fd);
  1435. res_lib_amf_errorcancelall.header.magic = MESSAGE_MAGIC;
  1436. res_lib_amf_errorcancelall.header.size = sizeof (struct res_lib_amf_errorcancelall);
  1437. res_lib_amf_errorcancelall.header.id = MESSAGE_RES_AMF_ERRORCANCELALL;
  1438. res_lib_amf_errorcancelall.error = error;
  1439. libais_send_response (req_exec_amf_errorcancelall->source.fd,
  1440. &res_lib_amf_errorcancelall, sizeof (struct res_lib_amf_errorcancelall));
  1441. }
  1442. return (0);
  1443. }
  1444. /*
  1445. * If receiving this message from another cluster node, another cluster node
  1446. * has selected a readiness state for a component connected to _that_ cluster
  1447. * node. That cluster node API has verified the readiness state, so its time to let
  1448. * the rest of the cluster nodes know about the readiness state change.
  1449. */
  1450. static int message_handler_req_exec_amf_readinessstateset (int fd, void *message)
  1451. {
  1452. struct req_exec_amf_readinessstateset *req_exec_amf_readinessstateset = (struct req_exec_amf_readinessstateset *)message;
  1453. struct saAmfComponent *component;
  1454. component = findComponent (&req_exec_amf_readinessstateset->compName);
  1455. if (component) {
  1456. log_printf (LOG_LEVEL_DEBUG, "found component %s, setting current readiness state to %d\n",
  1457. getSaNameT (&component->name),
  1458. req_exec_amf_readinessstateset->readinessState);
  1459. component->currentReadinessState = req_exec_amf_readinessstateset->readinessState;
  1460. dsm (component);
  1461. }
  1462. return (0);
  1463. }
  1464. /*
  1465. * If receiving this message from another cluster node, another cluster node
  1466. * has selected a ha state for a component connected to _that_ cluster
  1467. * node. That cluster node API has verified the ha state, so its time to let
  1468. * the rest of the cluster nodes know about the HA state change.
  1469. */
  1470. static int message_handler_req_exec_amf_hastateset (int fd, void *message)
  1471. {
  1472. struct req_exec_amf_hastateset *req_exec_amf_hastateset = (struct req_exec_amf_hastateset *)message;
  1473. struct saAmfComponent *component;
  1474. component = findComponent (&req_exec_amf_hastateset->compName);
  1475. if (component) {
  1476. log_printf (LOG_LEVEL_DEBUG, "found component %s, setting current HA state to %d\n",
  1477. getSaNameT (&component->name),
  1478. req_exec_amf_hastateset->haState);
  1479. component->currentHAState = req_exec_amf_hastateset->haState;
  1480. dsm (component);
  1481. }
  1482. return (0);
  1483. }
  1484. static int message_handler_req_amf_init (int fd, void *message)
  1485. {
  1486. struct res_lib_init res_lib_init;
  1487. SaErrorT error = SA_ERR_SECURITY;
  1488. log_printf (LOG_LEVEL_DEBUG, "Got AMF request to initalize availability management framework service.\n");
  1489. if (connections[fd].authenticated) {
  1490. connections[fd].service = SOCKET_SERVICE_AMF;
  1491. error = SA_OK;
  1492. }
  1493. res_lib_init.header.magic = MESSAGE_MAGIC;
  1494. res_lib_init.header.size = sizeof (struct res_lib_init);
  1495. res_lib_init.header.id = MESSAGE_RES_INIT;
  1496. res_lib_init.error = error;
  1497. libais_send_response (fd, &res_lib_init, sizeof (res_lib_init));
  1498. if (connections[fd].authenticated) {
  1499. return (0);
  1500. }
  1501. return (-1);
  1502. }
  1503. static int message_handler_req_amf_activatepoll (int fd, void *message)
  1504. {
  1505. struct res_amf_activatepoll res_amf_activatepoll;
  1506. res_amf_activatepoll.header.magic = MESSAGE_MAGIC;
  1507. res_amf_activatepoll.header.size = sizeof (struct res_amf_activatepoll);
  1508. res_amf_activatepoll.header.id = MESSAGE_RES_AMF_ACTIVATEPOLL;
  1509. libais_send_response (fd, &res_amf_activatepoll, sizeof (struct res_amf_activatepoll));
  1510. return (0);
  1511. }
  1512. static int message_handler_req_amf_componentregister (int fd, void *message)
  1513. {
  1514. struct req_amf_componentregister *req_lib_amf_componentregister = (struct req_amf_componentregister *)message;
  1515. struct req_exec_amf_componentregister req_exec_amf_componentregister;
  1516. struct iovec iovecs[2];
  1517. int result;
  1518. req_exec_amf_componentregister.header.magic = MESSAGE_MAGIC;
  1519. req_exec_amf_componentregister.header.size = sizeof (struct req_exec_amf_componentregister);
  1520. req_exec_amf_componentregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTREGISTER;
  1521. req_exec_amf_componentregister.source.fd = fd;
  1522. req_exec_amf_componentregister.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1523. memcpy (&req_exec_amf_componentregister.req_lib_amf_componentregister,
  1524. req_lib_amf_componentregister,
  1525. sizeof (struct req_lib_amf_componentregister));
  1526. iovecs[0].iov_base = &req_exec_amf_componentregister;
  1527. iovecs[0].iov_len = sizeof (req_exec_amf_componentregister);
  1528. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1529. return (0);
  1530. }
  1531. static int message_handler_req_amf_componentunregister (int fd, void *message)
  1532. {
  1533. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  1534. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  1535. struct iovec iovecs[2];
  1536. int result;
  1537. struct saAmfComponent *component;
  1538. req_exec_amf_componentunregister.header.magic = MESSAGE_MAGIC;
  1539. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  1540. req_exec_amf_componentunregister.header.id = MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER;
  1541. req_exec_amf_componentunregister.source.fd = fd;
  1542. req_exec_amf_componentunregister.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1543. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  1544. req_lib_amf_componentunregister,
  1545. sizeof (struct req_lib_amf_componentunregister));
  1546. component = findComponent (&req_lib_amf_componentunregister->compName);
  1547. if (component && component->registered && component->local) {
  1548. component->probableCause = SA_AMF_NOT_RESPONDING;
  1549. }
  1550. iovecs[0].iov_base = &req_exec_amf_componentunregister;
  1551. iovecs[0].iov_len = sizeof (req_exec_amf_componentunregister);
  1552. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1553. return (0);
  1554. }
  1555. static int message_handler_req_amf_readinessstateget (int fd, void *message)
  1556. {
  1557. struct req_amf_readinessstateget *req_amf_readinessstateget = (struct req_amf_readinessstateget *)message;
  1558. struct res_amf_readinessstateget res_amf_readinessstateget;
  1559. struct saAmfComponent *component;
  1560. log_printf (LOG_LEVEL_DEBUG, "got request to return readiness state\n");
  1561. res_amf_readinessstateget.header.magic = MESSAGE_MAGIC;
  1562. res_amf_readinessstateget.header.id = MESSAGE_RES_AMF_READINESSSTATEGET;
  1563. res_amf_readinessstateget.header.size = sizeof (struct res_amf_readinessstateget);
  1564. res_amf_readinessstateget.error = SA_ERR_NOT_EXIST;
  1565. component = findComponent (&req_amf_readinessstateget->compName);
  1566. log_printf (LOG_LEVEL_DEBUG, "readinessstateget: found component %p\n", component);
  1567. if (component) {
  1568. memcpy (&res_amf_readinessstateget.readinessState,
  1569. &component->currentReadinessState, sizeof (SaAmfReadinessStateT));
  1570. res_amf_readinessstateget.error = SA_OK;
  1571. }
  1572. libais_send_response (fd, &res_amf_readinessstateget, sizeof (struct res_amf_readinessstateget));
  1573. return (0);
  1574. }
  1575. static int message_handler_req_amf_hastateget (int fd, void *message)
  1576. {
  1577. struct req_amf_hastateget *req_amf_hastateget = (struct req_amf_hastateget *)message;
  1578. struct res_amf_hastateget res_amf_hastateget;
  1579. struct saAmfComponent *component;
  1580. res_amf_hastateget.header.magic = MESSAGE_MAGIC;
  1581. res_amf_hastateget.header.id = MESSAGE_RES_AMF_HASTATEGET;
  1582. res_amf_hastateget.header.size = sizeof (struct res_amf_hastateget);
  1583. res_amf_hastateget.error = SA_ERR_NOT_EXIST;
  1584. component = findComponentInProtectionGroup (&req_amf_hastateget->csiName, &req_amf_hastateget->compName);
  1585. if (component) {
  1586. memcpy (&res_amf_hastateget.haState,
  1587. &component->currentHAState, sizeof (SaAmfHAStateT));
  1588. res_amf_hastateget.error = SA_OK;
  1589. }
  1590. libais_send_response (fd, &res_amf_hastateget, sizeof (struct res_amf_hastateget));
  1591. return (0);
  1592. }
  1593. static int message_handler_req_amf_protectiongrouptrackstart (int fd, void *message)
  1594. {
  1595. struct req_amf_protectiongrouptrackstart *req_amf_protectiongrouptrackstart = (struct req_amf_protectiongrouptrackstart *)message;
  1596. struct res_amf_protectiongrouptrackstart res_amf_protectiongrouptrackstart;
  1597. struct libamf_ci_trackentry *track = 0;
  1598. int i;
  1599. struct saAmfProtectionGroup *amfProtectionGroup;
  1600. amfProtectionGroup = findProtectionGroup (&req_amf_protectiongrouptrackstart->csiName);
  1601. if (amfProtectionGroup) {
  1602. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstart: Got valid track start on CSI: %s.\n", getSaNameT (&req_amf_protectiongrouptrackstart->csiName));
  1603. for (i = 0; i < connections[fd].ais_ci.u.libamf_ci.trackEntries; i++) {
  1604. if (connections[fd].ais_ci.u.libamf_ci.tracks[i].active == 0) {
  1605. track = &connections[fd].ais_ci.u.libamf_ci.tracks[i];
  1606. break;
  1607. }
  1608. }
  1609. if (track == 0) {
  1610. grow_amf_track_table (fd, 1);
  1611. track = &connections[fd].ais_ci.u.libamf_ci.tracks[i];
  1612. }
  1613. track->active = 1;
  1614. track->trackFlags = req_amf_protectiongrouptrackstart->trackFlags;
  1615. track->notificationBufferAddress = req_amf_protectiongrouptrackstart->notificationBufferAddress;
  1616. memcpy (&track->csiName,
  1617. &req_amf_protectiongrouptrackstart->csiName, sizeof (SaNameT));
  1618. /*
  1619. * If SA_TRACK_CURRENT is specified, write out all current connections
  1620. */
  1621. } else {
  1622. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  1623. }
  1624. res_amf_protectiongrouptrackstart.header.magic = MESSAGE_MAGIC;
  1625. res_amf_protectiongrouptrackstart.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTART;
  1626. res_amf_protectiongrouptrackstart.header.size = sizeof (struct res_amf_protectiongrouptrackstart);
  1627. res_amf_protectiongrouptrackstart.error = SA_ERR_NOT_EXIST;
  1628. if (amfProtectionGroup) {
  1629. res_amf_protectiongrouptrackstart.error = SA_OK;
  1630. }
  1631. libais_send_response (fd, &res_amf_protectiongrouptrackstart,
  1632. sizeof (struct res_amf_protectiongrouptrackstart));
  1633. if (amfProtectionGroup &&
  1634. req_amf_protectiongrouptrackstart->trackFlags & SA_TRACK_CURRENT) {
  1635. sendProtectionGroupNotification (fd,
  1636. track->notificationBufferAddress,
  1637. amfProtectionGroup,
  1638. 0,
  1639. 0,
  1640. track->trackFlags);
  1641. track->trackFlags &= ~SA_TRACK_CURRENT;
  1642. }
  1643. return (0);
  1644. }
  1645. static int message_handler_req_amf_protectiongrouptrackstop (int fd, void *message)
  1646. {
  1647. struct req_amf_protectiongrouptrackstop *req_amf_protectiongrouptrackstop = (struct req_amf_protectiongrouptrackstop *)message;
  1648. struct res_amf_protectiongrouptrackstop res_amf_protectiongrouptrackstop;
  1649. struct libamf_ci_trackentry *track = 0;
  1650. int i;
  1651. for (i = 0; i < connections[fd].ais_ci.u.libamf_ci.trackEntries; i++) {
  1652. if (SaNameTisNameT (&req_amf_protectiongrouptrackstop->csiName,
  1653. &connections[fd].ais_ci.u.libamf_ci.tracks[i].csiName)) {
  1654. track = &connections[fd].ais_ci.u.libamf_ci.tracks[i];
  1655. }
  1656. }
  1657. if (track) {
  1658. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_amf_protectiongrouptrackstop->csiName));
  1659. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  1660. }
  1661. res_amf_protectiongrouptrackstop.header.magic = MESSAGE_MAGIC;
  1662. res_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  1663. res_amf_protectiongrouptrackstop.header.size = sizeof (struct res_amf_protectiongrouptrackstop);
  1664. res_amf_protectiongrouptrackstop.error = SA_ERR_NOT_EXIST;
  1665. if (track) {
  1666. res_amf_protectiongrouptrackstop.error = SA_OK;
  1667. }
  1668. libais_send_response (fd, &res_amf_protectiongrouptrackstop,
  1669. sizeof (struct res_amf_protectiongrouptrackstop));
  1670. return (0);
  1671. }
  1672. static int message_handler_req_amf_errorreport (int fd, void *message)
  1673. {
  1674. struct req_lib_amf_errorreport *req_lib_amf_errorreport = (struct req_lib_amf_errorreport *)message;
  1675. struct req_exec_amf_errorreport req_exec_amf_errorreport;
  1676. struct iovec iovecs[2];
  1677. int result;
  1678. req_exec_amf_errorreport.header.magic = MESSAGE_MAGIC;
  1679. req_exec_amf_errorreport.header.size = sizeof (struct req_exec_amf_errorreport);
  1680. req_exec_amf_errorreport.header.id = MESSAGE_REQ_EXEC_AMF_ERRORREPORT;
  1681. req_exec_amf_errorreport.source.fd = fd;
  1682. req_exec_amf_errorreport.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1683. memcpy (&req_exec_amf_errorreport.req_lib_amf_errorreport,
  1684. req_lib_amf_errorreport,
  1685. sizeof (struct req_lib_amf_errorreport));
  1686. iovecs[0].iov_base = &req_exec_amf_errorreport;
  1687. iovecs[0].iov_len = sizeof (req_exec_amf_errorreport);
  1688. // iovecs[0].iov_len = sizeof (req_exec_amf_errorreport) - sizeof (req_lib_amf_errorreport);
  1689. // iovecs[1].iov_base = &req_lib_amf_errorreport;
  1690. // iovecs[1].iov_len = sizeof (req_lib_amf_errorreport);
  1691. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1692. return (0);
  1693. }
  1694. static int message_handler_req_amf_errorcancelall (int fd, void *message)
  1695. {
  1696. struct req_lib_amf_errorcancelall *req_lib_amf_errorcancelall = (struct req_lib_amf_errorcancelall *)message;
  1697. struct req_exec_amf_errorcancelall req_exec_amf_errorcancelall;
  1698. struct iovec iovecs[2];
  1699. int result;
  1700. req_exec_amf_errorcancelall.header.magic = MESSAGE_MAGIC;
  1701. req_exec_amf_errorcancelall.header.size = sizeof (struct req_exec_amf_errorcancelall);
  1702. req_exec_amf_errorcancelall.header.id = MESSAGE_REQ_EXEC_AMF_ERRORCANCELALL;
  1703. req_exec_amf_errorcancelall.source.fd = fd;
  1704. req_exec_amf_errorcancelall.source.in_addr.s_addr = this_ip.sin_addr.s_addr;
  1705. memcpy (&req_exec_amf_errorcancelall.req_lib_amf_errorcancelall,
  1706. req_lib_amf_errorcancelall,
  1707. sizeof (struct req_lib_amf_errorcancelall));
  1708. iovecs[0].iov_base = &req_exec_amf_errorcancelall;
  1709. iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall);
  1710. // iovecs[0].iov_len = sizeof (req_exec_amf_errorcancelall) - sizeof (req_lib_amf_errorcancelall);
  1711. // iovecs[1].iov_base = &req_lib_amf_errorcancelall;
  1712. // iovecs[1].iov_len = sizeof (req_lib_amf_errorcancelall);
  1713. result = gmi_mcast (&aisexec_groupname, iovecs, 1, GMI_PRIO_MED);
  1714. return (0);
  1715. }
  1716. static int message_handler_req_amf_stoppingcomplete (int fd, void *message)
  1717. {
  1718. struct req_amf_stoppingcomplete *req_amf_stoppingcomplete = (struct req_amf_stoppingcomplete *)message;
  1719. int connection;
  1720. log_printf (LOG_LEVEL_DEBUG, "handling stopping complete\n");
  1721. connection = req_amf_response_get_connection (req_amf_stoppingcomplete->invocation);
  1722. connections[connection].component->currentReadinessState = connections[connection].component->newReadinessState;
  1723. readinessStateSetCluster (connections[connection].component, SA_AMF_STOPPING);
  1724. sendProtectionGroupNotifications (connections[connection].component,
  1725. SA_AMF_PROTECTION_GROUP_STATE_CHANGE);
  1726. // This is part of dsm now
  1727. // readinessStateSetApi (connections[connection].component, SA_AMF_OUT_OF_SERVICE);
  1728. return (0);
  1729. }
  1730. void response_handler_healthcheckcallback (int connection,
  1731. struct req_amf_response *req_amf_response) {
  1732. if (req_amf_response->error == SA_OK) {
  1733. log_printf (LOG_LEVEL_DEBUG, "setting healthcheck ok\n");
  1734. connections[connection].component->healthcheck_outstanding = 0;
  1735. }
  1736. }
  1737. static int message_handler_req_amf_response (int fd, void *message)
  1738. {
  1739. struct req_amf_response *req_amf_response = (struct req_amf_response *)message;
  1740. int connection;
  1741. int interface;
  1742. connection = req_amf_response_get_connection (req_amf_response->invocation);
  1743. interface = req_amf_response_get_interface (req_amf_response->invocation);
  1744. log_printf (LOG_LEVEL_DEBUG, "handling response connection %d interface %x\n", connection, interface);
  1745. switch (interface) {
  1746. case MESSAGE_REQ_AMF_RESPONSE_SAAMFHEALTHCHECKCALLBACK:
  1747. response_handler_healthcheckcallback (connection, req_amf_response);
  1748. break;
  1749. case MESSAGE_REQ_AMF_RESPONSE_SAAMFREADINESSSTATESETCALLBACK:
  1750. response_handler_readinessstatesetcallback (connection, req_amf_response);
  1751. break;
  1752. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSISETCALLBACK:
  1753. response_handler_csisetcallback (connection, req_amf_response);
  1754. break;
  1755. case MESSAGE_REQ_AMF_RESPONSE_SAAMFCSIREMOVECALLBACK:
  1756. break;
  1757. default:
  1758. // TODO
  1759. log_printf (LOG_LEVEL_ERROR, "invalid invocation value %x\n", req_amf_response->invocation);
  1760. break;
  1761. }
  1762. return (0);
  1763. }
  1764. static int message_handler_req_amf_componentcapabilitymodelget (int fd, void *message)
  1765. {
  1766. struct req_amf_componentcapabilitymodelget *req_amf_componentcapabilitymodelget = (struct req_amf_componentcapabilitymodelget *)message;
  1767. struct res_amf_componentcapabilitymodelget res_amf_componentcapabilitymodelget;
  1768. struct saAmfComponent *component;
  1769. SaErrorT error = SA_OK;
  1770. log_printf (LOG_LEVEL_DEBUG, "componentcapabilitymodelget: Retrieve name %s.\n", getSaNameT (&req_amf_componentcapabilitymodelget->compName));
  1771. component = findComponent (&req_amf_componentcapabilitymodelget->compName);
  1772. if (component && component->registered) {
  1773. memcpy (&res_amf_componentcapabilitymodelget.componentCapabilityModel,
  1774. &component->componentCapabilityModel, sizeof (SaAmfComponentCapabilityModelT));
  1775. } else {
  1776. error = SA_ERR_NOT_EXIST;
  1777. }
  1778. res_amf_componentcapabilitymodelget.header.magic = MESSAGE_MAGIC;
  1779. res_amf_componentcapabilitymodelget.header.size = sizeof (struct res_amf_componentcapabilitymodelget);
  1780. res_amf_componentcapabilitymodelget.header.id = MESSAGE_RES_AMF_COMPONENTCAPABILITYMODELGET;
  1781. res_amf_componentcapabilitymodelget.error = error;
  1782. libais_send_response (fd, &res_amf_componentcapabilitymodelget, sizeof (struct res_amf_componentcapabilitymodelget));
  1783. return (0);
  1784. }