amfcomp.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263
  1. /** @file amfcomp.c
  2. *
  3. * Copyright (c) 2006 Ericsson AB.
  4. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  5. * Copyright (c) 2006 Sun Microsystems, Inc. Copyright (c) 2006
  6. *
  7. * All rights reserved.
  8. *
  9. * Author: Steven Dake (sdake@mvista.com)
  10. *
  11. * Author: Hans Feldt, Anders Eriksson, Lars Holm
  12. * - Introduced AMF B.02 information model
  13. * - Use DN in API and multicast messages
  14. * - (Re-)Introduction of event based multicast messages
  15. * - Refactoring of code into several AMF files
  16. * - Component/SU restart, SU failover
  17. * - Constructors/destructors
  18. * - Serializers/deserializers
  19. *
  20. * This software licensed under BSD license, the text of which follows:
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions are met:
  24. *
  25. * - Redistributions of source code must retain the above copyright notice,
  26. * this list of conditions and the following disclaimer.
  27. * - Redistributions in binary form must reproduce the above copyright notice,
  28. * this list of conditions and the following disclaimer in the documentation
  29. * and/or other materials provided with the distribution.
  30. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  31. * contributors may be used to endorse or promote products derived from this
  32. * software without specific prior written permission.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  35. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  36. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  37. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  38. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  39. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  40. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  41. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  42. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  44. * THE POSSIBILITY OF SUCH DAMAGE.
  45. *
  46. * AMF Component Class Implementation
  47. *
  48. * This file contains functions for handling AMF-components. It can be
  49. * viewed as the implementation of the AMF Component class (called comp)
  50. * as described in SAI-Overview-B.02.01. The SA Forum specification
  51. * SAI-AIS-AMF-B.02.01 has been used as specification of the behaviour
  52. * and is referred to as 'the spec' below.
  53. *
  54. * The functions in this file are responsible for handling the following
  55. * types of components:
  56. * - sa-aware components
  57. * (proxy or non-proxy)
  58. * - non-sa-aware components
  59. * (non-proxied non-pre-instantiable and
  60. * proxied pre-instantiable or not pre-instantiable)
  61. *
  62. * The functions of this file are also responsible for:
  63. * - handling all communication with the AMF API library supported by the
  64. * AMF main function, see below
  65. * - instantiating and terminating components upon request
  66. * - updating the ha-state of the CSI-assignment related to the component
  67. * - initiating an error report to the parent SU
  68. * - handling all run time attributes of the AMF Component; all cached
  69. * attributes are stored as variables and sent to the IMM service
  70. * upon the changes described in the specification.
  71. *
  72. * Incoming events from the AMF library is primarily handled by the AMF
  73. * main function which:
  74. * <1> transforms the incoming event to an event that is multicast
  75. * to all AMF service instances in the cluster
  76. * <2> the event received from multicast is tranformed to a function
  77. * call of the external interface of comp
  78. *
  79. * Outgoing events to the AMF library is handled by static functions called
  80. * lib_<api callback function name>_request which creates an invocation handle
  81. * unique to this call and stores any variables comp want to associate to the
  82. * call back so it is possible to pick them up when the component responses
  83. * through the API. Finally, a timer is started to supervise that a response
  84. * really is received.
  85. *
  86. * Comp initiates error reports to its parent SU in the cases described in
  87. * paragraph 3.3.2.2 in the spec. Comp delegates all actions to SU except
  88. * - it stores the received or pre-configured recommended recovery
  89. * action
  90. * - sets the operational state to DISABLED unless the
  91. * recommended recovery action was SA_AMF_COMP_RESTART. (In this case
  92. * SU or node may set operational state of the component later on
  93. * when it has been fully investigated that no escallation to a
  94. * more powerful recovery action shall be made.)
  95. *
  96. * Comp contains the following state machines:
  97. * - presence state machine (PRSM)
  98. * - operational state machine (OPSM)
  99. * - readiness state machine (RESM)
  100. * - ha state per component service instance (CSI)
  101. *
  102. * The behaviour of comp is mainly controlled by the presence state machine,
  103. * while the operational and readiness state machines are used only to report
  104. * information to its parent (service unit SU) and management (IMM). Comp does
  105. * not control the logic to assign a CSI to itself and neither to decide the
  106. * value of the ha-state but only to faciltate the communication of the CSI
  107. * set (or remove) order and to evaluate the response from the library.
  108. *
  109. * The presence state machine implements all the states described in the
  110. * specification.
  111. * The '-ING' states of PRSM are designed as composite states (UML terminology).
  112. * Being a composite state means that the state contains substates.
  113. * PRSM composite states are:
  114. * - TERMINATING (TERMINATE and CLEANUP)
  115. * - INSTANTIATING (INSTANTIATE, INSTANTIATEDELAY and CLEANUP)
  116. * - RESTARTING (TERMINATE, INSTANTIATE, INSTANTIATEDELAY and CLEANUP)
  117. *
  118. * The reason for introducing these composite states is to make it easier to
  119. * understand the implementation of the behaviour described in paragraphs
  120. * 4.1 - 4.6 in the spec. The comp PRSM implements all the logic described
  121. * except for node reboot, which is handled by the AMF Node class.
  122. * Also PRSM reports all changes of state to its parent SU.
  123. *
  124. */
  125. #include <sys/types.h>
  126. #include <unistd.h>
  127. #include <sys/wait.h>
  128. #include <stdio.h>
  129. #include <string.h>
  130. #include <stdlib.h>
  131. #include <errno.h>
  132. #include <assert.h>
  133. #include "../include/saAis.h"
  134. #include "../include/saAmf.h"
  135. #include "../include/ipc_gen.h"
  136. #include "../include/ipc_amf.h"
  137. #include "totempg.h"
  138. #include "timer.h"
  139. #include "ipc.h"
  140. #include "service.h"
  141. #include "util.h"
  142. #include "amf.h"
  143. #include "print.h"
  144. #include "main.h"
  145. enum clc_command_run_operation_type {
  146. CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE = 1,
  147. CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE = 2,
  148. CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP = 3
  149. };
  150. struct clc_command_run_data {
  151. struct amf_comp *comp;
  152. enum clc_command_run_operation_type type;
  153. void (*completion_callback) (void *context);
  154. };
  155. struct clc_interface {
  156. int (*instantiate) (struct amf_comp *comp);
  157. int (*terminate) (struct amf_comp *comp);
  158. int (*cleanup) (struct amf_comp *comp);
  159. };
  160. struct csi_remove_callback_data {
  161. struct amf_csi *csi;
  162. };
  163. struct component_terminate_callback_data {
  164. struct amf_comp *comp;
  165. };
  166. static void comp_presence_state_set (
  167. struct amf_comp *comp,
  168. SaAmfPresenceStateT presence_state);
  169. static int clc_cli_instantiate (struct amf_comp *comp);
  170. static int clc_instantiate_callback (struct amf_comp *comp);
  171. static int clc_csi_set_callback (struct amf_comp *comp);
  172. static int clc_cli_terminate (struct amf_comp *comp);
  173. static int lib_comp_terminate_request (struct amf_comp *comp);
  174. static int clc_csi_remove_callback (struct amf_comp *comp);
  175. static int clc_cli_cleanup (struct amf_comp *comp);
  176. static int clc_cli_cleanup_local (struct amf_comp *comp);
  177. static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active);
  178. static void lib_healthcheck_request (struct amf_healthcheck *healthcheck);
  179. static void timer_function_healthcheck_tmo (void *_healthcheck);
  180. static void lib_csi_set_request (
  181. struct amf_comp *comp,
  182. struct amf_csi_assignment *csi_assignment);
  183. /*
  184. * Life cycle functions
  185. */
  186. static struct clc_interface clc_interface_sa_aware = {
  187. clc_cli_instantiate,
  188. lib_comp_terminate_request,
  189. clc_cli_cleanup
  190. };
  191. static struct clc_interface clc_interface_proxied_pre = {
  192. clc_instantiate_callback,
  193. lib_comp_terminate_request,
  194. clc_cli_cleanup
  195. };
  196. static struct clc_interface clc_interface_proxied_non_pre = {
  197. clc_csi_set_callback,
  198. clc_csi_remove_callback,
  199. clc_cli_cleanup_local
  200. };
  201. static struct clc_interface clc_interface_non_proxied_non_saware = {
  202. clc_cli_instantiate,
  203. clc_cli_terminate,
  204. clc_cli_cleanup_local
  205. };
  206. static struct clc_interface *clc_interfaces[4] = {
  207. &clc_interface_sa_aware,
  208. &clc_interface_proxied_pre,
  209. &clc_interface_proxied_non_pre,
  210. &clc_interface_non_proxied_non_saware
  211. };
  212. struct invocation {
  213. void *data;
  214. int interface;
  215. int active;
  216. };
  217. static struct invocation *invocation_entries = 0;
  218. static int invocation_entries_size = 0;
  219. static int is_not_instantiating_or_instantiated_or_restarting (amf_comp_t *comp)
  220. {
  221. return (!(comp->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATING ||
  222. comp->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATED ||
  223. comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING));
  224. }
  225. static int invocation_create (
  226. int interface,
  227. void *data)
  228. {
  229. struct invocation *invocation_addr = 0;
  230. struct invocation *invocation_temp;
  231. int i;
  232. int loc = 0;
  233. for (i = 0; i < invocation_entries_size; i++) {
  234. if (invocation_entries[i].active == 0) {
  235. invocation_addr = &invocation_entries[i];
  236. loc = i;
  237. break;
  238. }
  239. }
  240. if (invocation_addr == 0) {
  241. invocation_temp = (struct invocation *)realloc (invocation_entries,
  242. (invocation_entries_size + 1) * sizeof (struct invocation));
  243. if (invocation_temp == NULL) {
  244. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  245. }
  246. invocation_entries = invocation_temp;
  247. invocation_addr = &invocation_entries[invocation_entries_size];
  248. loc = invocation_entries_size;
  249. invocation_entries_size += 1;
  250. }
  251. invocation_addr->interface = interface;
  252. invocation_addr->data = data;
  253. invocation_addr->active = 1;
  254. return (loc);
  255. }
  256. static int invocation_get_and_destroy (
  257. SaUint64T invocation, unsigned int *interface, void **data)
  258. {
  259. if (invocation > invocation_entries_size) {
  260. return (-1);
  261. }
  262. if (invocation_entries[invocation].active == 0) {
  263. return (-1);
  264. }
  265. *interface = invocation_entries[invocation].interface;
  266. *data = invocation_entries[invocation].data;
  267. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  268. return (0);
  269. }
  270. static void invocation_destroy_by_data (void *data)
  271. {
  272. int i;
  273. for (i = 0; i < invocation_entries_size; i++) {
  274. if (invocation_entries[i].data == data) {
  275. memset (&invocation_entries[i], 0,
  276. sizeof (struct invocation));
  277. break;
  278. }
  279. }
  280. }
  281. /**
  282. * Set suspected error flag and report to SU.
  283. *
  284. * @param comp
  285. * @param recommended_recovery
  286. */
  287. static void report_error_suspected (
  288. struct amf_comp *comp,
  289. SaAmfRecommendedRecoveryT recommended_recovery)
  290. {
  291. comp->error_suspected = 1;
  292. amf_su_comp_error_suspected (comp->su, comp, recommended_recovery);
  293. }
  294. #ifndef xprintf
  295. #define xprintf(...)
  296. #endif
  297. static void *clc_command_run (void *context)
  298. {
  299. struct clc_command_run_data *clc_command_run_data =
  300. (struct clc_command_run_data *)context;
  301. pid_t pid;
  302. int res;
  303. char **argv = NULL;
  304. char **envp = NULL;
  305. int status;
  306. char path[PATH_MAX];
  307. char *cmd = 0;
  308. char *comp_argv = 0;
  309. char comp_name[SA_MAX_NAME_LENGTH + 24];
  310. int i;
  311. int argv_size;
  312. int envp_size;
  313. ENTER_VOID();
  314. pid = fork();
  315. if (pid == -1) {
  316. fprintf (stderr, "Couldn't fork process %s\n", strerror (errno));
  317. return (0);
  318. }
  319. if (pid) {
  320. xprintf ("waiting for pid %d to finish\n", pid);
  321. waitpid (pid, &status, 0);
  322. if (WIFEXITED (status) != 0 && WEXITSTATUS(status) != 0) {
  323. fprintf (stderr, "Error: CLC_CLI (%d) failed with exit status:"
  324. " %d - %s\n", pid, WEXITSTATUS(status),
  325. strerror (WEXITSTATUS(status)));
  326. /*
  327. * Healthcheck timout will expire laterfore the component
  328. * and this will lead to Intantiation failed for the component.
  329. */
  330. }
  331. if (WIFSIGNALED (status) != 0) {
  332. fprintf (stderr, "Error: CLC_CLI (%d) failed with exit status:"
  333. " %d\n", pid, WTERMSIG(status));
  334. /*
  335. * TODO: remove this and handle properly later...
  336. */
  337. /*
  338. * Healthcheck timout will expire laterfore the component
  339. * and this will lead to Intantiation failed for the component.
  340. */
  341. }
  342. xprintf ("process (%d) finished with %x\n", pid, status);
  343. if (clc_command_run_data->completion_callback) {
  344. clc_command_run_data->completion_callback (context);
  345. }
  346. pthread_exit(0);
  347. }
  348. switch (clc_command_run_data->type) {
  349. case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE:
  350. cmd = clc_command_run_data->comp->saAmfCompInstantiateCmd;
  351. comp_argv = clc_command_run_data->comp->saAmfCompInstantiateCmdArgv;
  352. break;
  353. case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE:
  354. cmd = clc_command_run_data->comp->saAmfCompTerminateCmd;
  355. comp_argv = clc_command_run_data->comp->saAmfCompTerminateCmdArgv;
  356. break;
  357. case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP:
  358. cmd = clc_command_run_data->comp->saAmfCompCleanupCmd;
  359. comp_argv = clc_command_run_data->comp->saAmfCompCleanupCmdArgv;
  360. break;
  361. default:
  362. assert (0 != 1);
  363. break;
  364. }
  365. /* If command is not an absolute path, search for paths in parent objects */
  366. if (cmd[0] != '/') {
  367. if (clc_command_run_data->comp->clccli_path != NULL) {
  368. sprintf (path, "%s/%s",
  369. clc_command_run_data->comp->clccli_path, cmd);
  370. } else if (clc_command_run_data->comp->su->clccli_path != NULL) {
  371. sprintf (path, "%s/%s",
  372. clc_command_run_data->comp->su->clccli_path, cmd);
  373. } else if (clc_command_run_data->comp->su->sg->clccli_path != NULL) {
  374. sprintf (path, "%s/%s",
  375. clc_command_run_data->comp->su->sg->clccli_path, cmd);
  376. } else if (clc_command_run_data->comp->su->sg->application->clccli_path != NULL) {
  377. sprintf (path, "%s/%s",
  378. clc_command_run_data->comp->su->sg->application->clccli_path, cmd);
  379. }
  380. cmd = path;
  381. }
  382. argv_size = 2;
  383. argv = amf_malloc (sizeof (char*) * argv_size);
  384. argv[0] = cmd;
  385. {
  386. /* make a proper argv array */
  387. i = 1;
  388. char *ptrptr;
  389. char *arg = strtok_r(comp_argv, " ", &ptrptr);
  390. while (arg) {
  391. argv_size++;
  392. argv = realloc (argv, sizeof (char*) * argv_size);
  393. if (argv == NULL) {
  394. fprintf (stderr, "out-of-memory");
  395. exit (-1);
  396. }
  397. argv[i] = arg;
  398. arg = strtok_r(NULL, " ", &ptrptr);
  399. i++;
  400. }
  401. }
  402. argv[i] = NULL;
  403. i = snprintf (comp_name, SA_MAX_NAME_LENGTH,
  404. "SA_AMF_COMPONENT_NAME=safComp=%s,safSu=%s,safSg=%s,safApp=%s",
  405. clc_command_run_data->comp->name.value,
  406. clc_command_run_data->comp->su->name.value,
  407. clc_command_run_data->comp->su->sg->name.value,
  408. clc_command_run_data->comp->su->sg->application->name.value);
  409. assert (i <= sizeof (comp_name));
  410. /* two is for component name and NULL termination */
  411. envp_size = 2;
  412. envp = amf_malloc (sizeof (char*) * envp_size);
  413. envp[0] = comp_name;
  414. for (i = 1; clc_command_run_data->comp->saAmfCompCmdEnv &&
  415. clc_command_run_data->comp->saAmfCompCmdEnv[i - 1]; i++) {
  416. envp_size++;
  417. envp = realloc (envp, sizeof (char*) * envp_size);
  418. if (envp == NULL) {
  419. fprintf (stderr, "out-of-memory");
  420. exit (-1);
  421. }
  422. envp[i] = clc_command_run_data->comp->saAmfCompCmdEnv[i - 1];
  423. }
  424. envp[i] = NULL;
  425. xprintf ("running command '%s' with environment (%d):\n", cmd, envp_size);
  426. for (i = 0; envp[i] != NULL; i++) {
  427. xprintf (" %s\n", envp[i]);
  428. }
  429. xprintf (" and argv (%d):\n", argv_size);
  430. for (i = 0; argv[i] != NULL; i++) {
  431. xprintf (" %s\n", argv[i]);
  432. }
  433. res = execve (cmd, argv, envp);
  434. if (res == -1) {
  435. fprintf (stderr, "Couldn't exec program %s (%s)\n",
  436. cmd, strerror (errno));
  437. }
  438. exit (res); /* abnormal exit of forked process */
  439. return (0);
  440. }
  441. static void amf_comp_instantiate_tmo (void *component)
  442. {
  443. SaNameT compName;
  444. amf_comp_dn_make (component, &compName);
  445. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_COMPONENT_INSTANTIATE_TMO,
  446. &compName, sizeof (SaNameT));
  447. }
  448. static void start_component_instantiate_timer (struct amf_comp *component)
  449. {
  450. ENTER("%s",component->name.value);
  451. poll_timer_add (aisexec_poll_handle,
  452. component->saAmfCompInstantiateTimeout,
  453. component,
  454. amf_comp_instantiate_tmo,
  455. &component->instantiate_timeout_handle);
  456. }
  457. /*
  458. * Instantiate possible operations
  459. */
  460. static int clc_cli_instantiate (struct amf_comp *comp)
  461. {
  462. int res;
  463. pthread_t thread;
  464. pthread_attr_t thread_attr; /* thread attribute */
  465. struct clc_command_run_data *clc_command_run_data;
  466. ENTER("comp '%s'\n", getSaNameT (&comp->name));
  467. clc_command_run_data = amf_malloc (sizeof (struct clc_command_run_data));
  468. clc_command_run_data->comp = comp;
  469. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE;
  470. clc_command_run_data->completion_callback = NULL;
  471. pthread_attr_init (&thread_attr);
  472. pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
  473. res = pthread_create (&thread, &thread_attr, clc_command_run,
  474. (void *)clc_command_run_data);
  475. if (res != 0) {
  476. log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res);
  477. }
  478. start_component_instantiate_timer (comp);
  479. // clc_command_run_data->completion_callback (clc_command_run_data);
  480. // TODO error code from pthread_create
  481. return (res);
  482. }
  483. static int clc_instantiate_callback (struct amf_comp *comp)
  484. {
  485. ENTER("comp %s\n", getSaNameT (&comp->name));
  486. return (0);
  487. }
  488. static int clc_csi_set_callback (struct amf_comp *comp)
  489. {
  490. ENTER("comp %s\n", getSaNameT (&comp->name));
  491. return (0);
  492. }
  493. /*
  494. * Terminate possible operations
  495. */
  496. static int clc_cli_terminate (struct amf_comp *comp)
  497. {
  498. ENTER("comp %s\n", getSaNameT (&comp->name));
  499. return (0);
  500. }
  501. /**
  502. * Request component to terminate itself
  503. * @param comp
  504. *
  505. * @return int
  506. */
  507. static int lib_comp_terminate_request (struct amf_comp *comp)
  508. {
  509. struct res_lib_amf_componentterminatecallback res_lib;
  510. struct component_terminate_callback_data *component_terminate_callback_data;
  511. ENTER("comp %s\n", getSaNameT (&comp->name));
  512. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  513. res_lib.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  514. res_lib.header.error = SA_AIS_OK;
  515. memcpy (&res_lib.compName, &comp->name, sizeof (SaNameT));
  516. component_terminate_callback_data =
  517. amf_malloc (sizeof (struct component_terminate_callback_data));
  518. component_terminate_callback_data->comp = comp;
  519. res_lib.invocation =
  520. invocation_create (
  521. AMF_RESPONSE_COMPONENTTERMINATECALLBACK,
  522. component_terminate_callback_data);
  523. openais_conn_send_response (
  524. openais_conn_partner_get (comp->conn),
  525. &res_lib,
  526. sizeof (struct res_lib_amf_componentterminatecallback));
  527. return (0);
  528. }
  529. static int clc_csi_remove_callback (struct amf_comp *comp)
  530. {
  531. dprintf ("clc_tcsi_remove_callback\n");
  532. return (0);
  533. }
  534. /*
  535. * Clean up completed
  536. */
  537. static void mcast_cleanup_completion_event (void *context)
  538. {
  539. struct clc_command_run_data *clc_command_run_data =
  540. (struct clc_command_run_data *)context;
  541. struct req_exec_amf_clc_cleanup_completed req;
  542. struct iovec iovec;
  543. req.header.size = sizeof (struct req_exec_amf_clc_cleanup_completed);
  544. req.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  545. MESSAGE_REQ_EXEC_AMF_CLC_CLEANUP_COMPLETED);
  546. amf_comp_dn_make (clc_command_run_data->comp, &req.compName);
  547. iovec.iov_base = (char *)&req;
  548. iovec.iov_len = sizeof (req);
  549. assert (totempg_groups_mcast_joined (openais_group_handle,
  550. &iovec, 1, TOTEMPG_AGREED) == 0);
  551. }
  552. /*
  553. * Cleanup possible operations
  554. */
  555. static int clc_cli_cleanup (struct amf_comp *comp)
  556. {
  557. int res;
  558. pthread_t thread;
  559. pthread_attr_t thread_attr; /* thread attribute */
  560. struct clc_command_run_data *clc_command_run_data;
  561. dprintf ("clc_cli_cleanup\n");
  562. clc_command_run_data = amf_malloc (sizeof (struct clc_command_run_data));
  563. clc_command_run_data->comp = comp;
  564. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP;
  565. clc_command_run_data->completion_callback = mcast_cleanup_completion_event;
  566. pthread_attr_init (&thread_attr);
  567. pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
  568. res = pthread_create (&thread, &thread_attr, clc_command_run,
  569. (void *)clc_command_run_data);
  570. if (res != 0) {
  571. log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res);
  572. }
  573. // TODO error code from pthread_create
  574. return (res);
  575. }
  576. static int clc_cli_cleanup_local (struct amf_comp *comp)
  577. {
  578. dprintf ("clc_cli_cleanup_local\n");
  579. return (0);
  580. }
  581. #if 0
  582. static int clc_terminate (struct amf_comp *comp)
  583. {
  584. int res;
  585. dprintf ("clc terminate for comp %s\n", getSaNameT (&comp->name));
  586. assert (0);
  587. operational_state_comp_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  588. comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATING);
  589. res = clc_interfaces[comp->comptype]->terminate (comp);
  590. return (0);
  591. }
  592. #endif
  593. char *amf_comp_dn_make (struct amf_comp *comp, SaNameT *name)
  594. {
  595. int i = snprintf ((char*) name->value, SA_MAX_NAME_LENGTH,
  596. "safComp=%s,safSu=%s,safSg=%s,safApp=%s",
  597. comp->name.value, comp->su->name.value,
  598. comp->su->sg->name.value, comp->su->sg->application->name.value);
  599. assert (i <= SA_MAX_NAME_LENGTH);
  600. name->length = i;
  601. return (char *)name->value;
  602. }
  603. struct amf_healthcheck *amf_comp_find_healthcheck (
  604. struct amf_comp *comp, SaAmfHealthcheckKeyT *key)
  605. {
  606. struct amf_healthcheck *healthcheck;
  607. struct amf_healthcheck *ret_healthcheck = 0;
  608. if (key == NULL) {
  609. return NULL;
  610. }
  611. for (healthcheck = comp->healthcheck_head;
  612. healthcheck != NULL;
  613. healthcheck = healthcheck->next) {
  614. if (key->keyLen == healthcheck->safHealthcheckKey.keyLen &&
  615. memcmp (key, &healthcheck->safHealthcheckKey,key->keyLen) == 0) {
  616. ret_healthcheck = healthcheck;
  617. break;
  618. }
  619. }
  620. return (ret_healthcheck);
  621. }
  622. /**
  623. * Constructor for component objects. Adds component last in
  624. * the list owned by the specified SU. Always returns a
  625. * valid comp object, out-of-memory problems are handled
  626. * here. Default values are initialized.
  627. * @param su
  628. * @param name
  629. *
  630. * @return struct amf_comp*
  631. */
  632. struct amf_comp *amf_comp_new(struct amf_su *su, char *name)
  633. {
  634. struct amf_comp *tail = su->comp_head;
  635. struct amf_comp *comp = amf_calloc (1, sizeof (struct amf_comp));
  636. while (tail != NULL) {
  637. if (tail->next == NULL) {
  638. break;
  639. }
  640. tail = tail->next;
  641. }
  642. if (tail == NULL) {
  643. su->comp_head = comp;
  644. } else {
  645. tail->next = comp;
  646. }
  647. comp->su = su;
  648. /* setup default values from spec. */
  649. comp->saAmfCompNumMaxInstantiateWithoutDelay = 2;
  650. comp->saAmfCompNumMaxAmStartAttempt = 2;
  651. comp->saAmfCompNumMaxAmStopAttempt = 2;
  652. comp->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED;
  653. comp->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  654. comp->error_suspected = 0;
  655. setSaNameT (&comp->name, name);
  656. return comp;
  657. }
  658. void amf_comp_delete (struct amf_comp *comp)
  659. {
  660. int i;
  661. struct amf_healthcheck *healthcheck;
  662. for (healthcheck = comp->healthcheck_head; healthcheck != NULL;) {
  663. struct amf_healthcheck *tmp = healthcheck;
  664. healthcheck = healthcheck->next;
  665. free (tmp);
  666. }
  667. for (i = 0; comp->saAmfCompCsTypes[i] != NULL; i++) {
  668. free (comp->saAmfCompCsTypes[i]);
  669. }
  670. for (i = 0; comp->saAmfCompCmdEnv[i] != NULL; i++) {
  671. free (comp->saAmfCompCmdEnv[i]);
  672. }
  673. free (comp->saAmfCompInstantiateCmd);
  674. free (comp->saAmfCompInstantiateCmdArgv);
  675. free (comp->saAmfCompTerminateCmd);
  676. free (comp->saAmfCompTerminateCmdArgv);
  677. free (comp->saAmfCompCleanupCmd);
  678. free (comp->saAmfCompCleanupCmdArgv);
  679. free (comp->saAmfCompAmStartCmd);
  680. free (comp->saAmfCompAmStartCmdArgv);
  681. free (comp->saAmfCompAmStopCmd);
  682. free (comp->saAmfCompAmStopCmdArgv);
  683. free (comp->clccli_path);
  684. free (comp);
  685. }
  686. struct amf_comp *amf_comp_find (struct amf_cluster *cluster, SaNameT *name)
  687. {
  688. struct amf_application *app;
  689. struct amf_sg *sg;
  690. struct amf_su *su;
  691. struct amf_comp *comp = NULL;
  692. char *app_name;
  693. char *sg_name;
  694. char *su_name;
  695. char *comp_name;
  696. char *ptrptr;
  697. char *buf;
  698. assert (cluster != NULL && name != NULL);
  699. /* malloc new buffer since strtok_r writes to its first argument */
  700. buf = amf_malloc (name->length + 1);
  701. memcpy (buf, name->value,name ->length + 1);
  702. comp_name = strtok_r(buf, ",", &ptrptr);
  703. su_name = strtok_r(NULL, ",", &ptrptr);
  704. sg_name = strtok_r(NULL, ",", &ptrptr);
  705. app_name = strtok_r(NULL, ",", &ptrptr);
  706. if (comp_name == NULL || su_name == NULL ||
  707. sg_name == NULL || app_name == NULL) {
  708. goto end;
  709. }
  710. comp_name += 8;
  711. su_name += 6;
  712. sg_name += 6;
  713. app_name += 7;
  714. app = amf_application_find (cluster, app_name);
  715. if (app == NULL) {
  716. goto end;
  717. }
  718. sg = amf_sg_find (app, sg_name);
  719. if (sg == NULL) {
  720. goto end;
  721. }
  722. for (su = sg->su_head; su != NULL; su = su->next) {
  723. if (strncmp (su_name, (char*)su->name.value, su->name.length) == 0) {
  724. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  725. if (comp->name.length == strlen(comp_name) &&
  726. strncmp (comp_name, (char*)comp->name.value,
  727. comp->name.length) == 0) {
  728. goto end;
  729. }
  730. }
  731. }
  732. }
  733. end:
  734. free (buf);
  735. return comp;
  736. }
  737. void amf_comp_healthcheck_deactivate (struct amf_comp *comp)
  738. {
  739. struct amf_healthcheck *healthcheck;
  740. if (!amf_su_is_local (comp->su))
  741. return;
  742. ENTER ("'%s'\n", getSaNameT (&comp->name));
  743. for (healthcheck = comp->healthcheck_head;
  744. healthcheck != NULL;
  745. healthcheck = healthcheck->next) {
  746. if (healthcheck->active) {
  747. healthcheck_deactivate (healthcheck);
  748. }
  749. }
  750. }
  751. static void comp_ha_state_set ( struct amf_comp *comp,
  752. struct amf_csi_assignment *csi_assignment,
  753. SaAmfHAStateT ha_state)
  754. {
  755. /* set confirmed HA state */
  756. csi_assignment->saAmfCSICompHAState = ha_state;
  757. TRACE1 ("Setting comp '%s', SU '%s' CSI '%s', HA state: %s\n",
  758. comp->name.value, comp->su->name.value,
  759. csi_assignment->csi->name.value,
  760. amf_ha_state (csi_assignment->saAmfCSICompHAState));
  761. amf_si_comp_set_ha_state_done (csi_assignment->csi->si, csi_assignment);
  762. }
  763. static void comp_presence_state_set (struct amf_comp *comp,
  764. SaAmfPresenceStateT presence_state)
  765. {
  766. comp->saAmfCompPresenceState = presence_state;
  767. TRACE1 ("Setting comp '%s', SU '%s' presence state: %s\n",
  768. comp->name.value, comp->su->name.value,
  769. amf_presence_state (comp->saAmfCompPresenceState));
  770. amf_su_comp_state_changed (
  771. comp->su, comp, SA_AMF_PRESENCE_STATE, presence_state);
  772. }
  773. struct amf_csi_assignment *amf_comp_get_next_csi_assignment (
  774. struct amf_comp *component,
  775. const struct amf_csi_assignment *csi_assignment)
  776. {
  777. struct amf_si *si;
  778. struct amf_csi *csi;
  779. struct amf_csi_assignment *tmp_csi_assignment;
  780. SaNameT dn;
  781. amf_comp_dn_make (component, &dn);
  782. if (csi_assignment == NULL) {
  783. si = component->su->sg->application->si_head;
  784. csi = si->csi_head;
  785. tmp_csi_assignment = csi->assigned_csis;
  786. } else {
  787. tmp_csi_assignment = csi_assignment->next;
  788. if (tmp_csi_assignment == NULL) {
  789. csi = csi_assignment->csi->next;
  790. if (csi == NULL) {
  791. si = csi_assignment->csi->si->next;
  792. if (si == NULL) {
  793. return NULL;
  794. } else {
  795. csi = si->csi_head;
  796. tmp_csi_assignment = csi->assigned_csis;
  797. }
  798. } else {
  799. si = csi->si;
  800. tmp_csi_assignment = csi->assigned_csis;
  801. }
  802. } else {
  803. csi = tmp_csi_assignment->csi;
  804. si = csi->si;
  805. }
  806. }
  807. for (; si != NULL; si = si->next) {
  808. if (tmp_csi_assignment == NULL && csi == NULL && si != NULL) {
  809. csi = si->csi_head;
  810. tmp_csi_assignment = csi->assigned_csis;
  811. }
  812. for (; csi != NULL; csi = csi->next) {
  813. if (tmp_csi_assignment == NULL && csi != NULL) {
  814. tmp_csi_assignment = csi->assigned_csis;
  815. }
  816. for (; tmp_csi_assignment != NULL;
  817. tmp_csi_assignment = tmp_csi_assignment->next) {
  818. if (name_match (&tmp_csi_assignment->name, &dn)) {
  819. return tmp_csi_assignment;
  820. }
  821. }
  822. }
  823. }
  824. return NULL;
  825. }
  826. void amf_comp_foreach_csi_assignment (
  827. struct amf_comp *component,
  828. void (*foreach_fn) (struct amf_comp *component,
  829. struct amf_csi_assignment *csi_assignment))
  830. {
  831. struct amf_csi_assignment *csi_assignment;
  832. assert (foreach_fn != NULL);
  833. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  834. while (csi_assignment != NULL) {
  835. foreach_fn (component, csi_assignment);
  836. csi_assignment = amf_comp_get_next_csi_assignment (
  837. component, csi_assignment);
  838. }
  839. }
  840. static struct amf_csi_assignment *csi_assignment_find_in (
  841. struct amf_comp *component, SaNameT *csi_name)
  842. {
  843. struct amf_csi_assignment *csi_assignment;
  844. SaNameT dn;
  845. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  846. while (csi_assignment != NULL) {
  847. amf_csi_dn_make (csi_assignment->csi, &dn);
  848. if (name_match (csi_name, &dn)) {
  849. return csi_assignment;
  850. }
  851. csi_assignment = amf_comp_get_next_csi_assignment (
  852. component, csi_assignment);
  853. }
  854. return NULL;
  855. }
  856. static void healthcheck_deactivate (
  857. struct amf_healthcheck *healthcheck_active)
  858. {
  859. dprintf ("deactivating healthcheck for component %s\n",
  860. getSaNameT (&healthcheck_active->comp->name));
  861. poll_timer_delete (aisexec_poll_handle,
  862. healthcheck_active->timer_handle_period);
  863. poll_timer_delete (aisexec_poll_handle,
  864. healthcheck_active->timer_handle_duration);
  865. invocation_destroy_by_data ((void *)healthcheck_active);
  866. healthcheck_active->active = 0;
  867. }
  868. /**
  869. * This function is called by the timer subsystem when AMF should request
  870. * a new healthcheck from a component.
  871. * @param data
  872. */
  873. static void timer_function_healthcheck_next_fn (void *_healthcheck)
  874. {
  875. struct amf_healthcheck *healthcheck = _healthcheck;
  876. /* send healthcheck request to component */
  877. lib_healthcheck_request (healthcheck);
  878. /* start duration timer for response */
  879. poll_timer_add (aisexec_poll_handle,
  880. healthcheck->saAmfHealthcheckMaxDuration,
  881. (void *)healthcheck,
  882. timer_function_healthcheck_tmo,
  883. &healthcheck->timer_handle_duration);
  884. }
  885. /**
  886. * Multicast a healthcheck timeout event.
  887. * @param healthcheck
  888. */
  889. static void mcast_healthcheck_tmo_event (
  890. struct amf_healthcheck *healthcheck)
  891. {
  892. struct req_exec_amf_healthcheck_tmo req_exec;
  893. struct iovec iovec;
  894. if (healthcheck->active == 0) {
  895. log_printf (LOG_ERR, "Healthcheck timeout: ignored key = %s, "
  896. "due to wrong state = %d, comp = %s",
  897. healthcheck->safHealthcheckKey.key,
  898. healthcheck->comp->saAmfCompPresenceState,
  899. healthcheck->comp->name.value);
  900. goto out;
  901. }
  902. req_exec.header.size = sizeof (struct req_exec_amf_healthcheck_tmo);
  903. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  904. MESSAGE_REQ_EXEC_AMF_HEALTHCHECK_TMO);
  905. amf_comp_dn_make (healthcheck->comp, &req_exec.compName);
  906. memcpy (&req_exec.safHealthcheckKey,
  907. &healthcheck->safHealthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  908. iovec.iov_base = (char *)&req_exec;
  909. iovec.iov_len = sizeof (req_exec);
  910. assert (totempg_groups_mcast_joined (openais_group_handle,
  911. &iovec, 1, TOTEMPG_AGREED) == 0);
  912. out:
  913. return;
  914. }
  915. /**
  916. * This function is called by the timer subsystem when a component has not
  917. * performed a healthcheck on time.
  918. * The event is multicasted to the cluster.
  919. * @param data
  920. */
  921. static void timer_function_healthcheck_tmo (
  922. void *_healthcheck)
  923. {
  924. struct amf_healthcheck *healthcheck = (struct amf_healthcheck *)_healthcheck;
  925. TRACE2 ("timeout occured on healthcheck for component %s.\n",
  926. getSaNameT (&healthcheck->comp->name));
  927. mcast_healthcheck_tmo_event (healthcheck);
  928. }
  929. static void lib_healthcheck_request (struct amf_healthcheck *healthcheck)
  930. {
  931. struct res_lib_amf_healthcheckcallback res_lib;
  932. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  933. res_lib.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  934. res_lib.header.error = SA_AIS_OK;
  935. res_lib.invocation =
  936. invocation_create (AMF_RESPONSE_HEALTHCHECKCALLBACK, healthcheck);
  937. amf_comp_dn_make (healthcheck->comp, &res_lib.compName);
  938. memcpy (&res_lib.key, &healthcheck->safHealthcheckKey,
  939. sizeof (SaAmfHealthcheckKeyT));
  940. TRACE7 ("sending healthcheck request to component %s",
  941. res_lib.compName.value);
  942. openais_conn_send_response (
  943. openais_conn_partner_get (healthcheck->comp->conn),
  944. &res_lib, sizeof (struct res_lib_amf_healthcheckcallback));
  945. }
  946. static void lib_csi_set_request (
  947. struct amf_comp *comp,
  948. struct amf_csi_assignment *csi_assignment)
  949. {
  950. struct res_lib_amf_csisetcallback* res_lib;
  951. void* p;
  952. struct amf_csi_attribute *attribute;
  953. size_t char_length_of_csi_attrs=0;
  954. size_t num_of_csi_attrs=0;
  955. int i;
  956. struct amf_csi *csi;
  957. char* csi_attribute_buf;
  958. unsigned int byte_offset;
  959. if (!amf_su_is_local (comp->su))
  960. return;
  961. csi = csi_assignment->csi;
  962. ENTER ("Assigning CSI '%s' state %s to comp '%s'\n",
  963. getSaNameT (&csi->name),
  964. amf_ha_state (csi_assignment->requested_ha_state),
  965. comp->name.value);
  966. for (attribute = csi->attributes_head;
  967. attribute != NULL;
  968. attribute = attribute->next) {
  969. for (i = 0; attribute->value[i] != NULL; i++) {
  970. num_of_csi_attrs++;
  971. char_length_of_csi_attrs += strlen(attribute->name);
  972. char_length_of_csi_attrs += strlen(attribute->value[i]);
  973. char_length_of_csi_attrs += 2;
  974. }
  975. }
  976. p = amf_malloc(sizeof(struct res_lib_amf_csisetcallback) +
  977. char_length_of_csi_attrs);
  978. res_lib = (struct res_lib_amf_csisetcallback*)p;
  979. /* Address of the buffer containing the Csi name value pair */
  980. csi_attribute_buf = res_lib->csi_attr_buf;
  981. /* Byteoffset start at the zero byte */
  982. byte_offset = 0;
  983. for (attribute = csi->attributes_head;
  984. attribute != NULL;
  985. attribute = attribute->next) {
  986. for (i = 0; attribute->value[i] != NULL; i++) {
  987. strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->name);
  988. byte_offset += strlen(attribute->name) + 1;
  989. strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->value[i]);
  990. byte_offset += strlen(attribute->value[i]) + 1;
  991. }
  992. }
  993. res_lib->number = num_of_csi_attrs;
  994. res_lib->csiFlags = SA_AMF_CSI_ADD_ONE;
  995. switch (csi_assignment->requested_ha_state) {
  996. case SA_AMF_HA_ACTIVE: {
  997. res_lib->csiStateDescriptor.activeDescriptor.activeCompName.length = 0;
  998. res_lib->csiStateDescriptor.activeDescriptor.transitionDescriptor =
  999. SA_AMF_CSI_NEW_ASSIGN;
  1000. break;
  1001. }
  1002. case SA_AMF_HA_STANDBY: {
  1003. res_lib->csiStateDescriptor.standbyDescriptor.activeCompName.length = 0;
  1004. res_lib->csiStateDescriptor.standbyDescriptor.standbyRank = 1;
  1005. break;
  1006. }
  1007. case SA_AMF_HA_QUIESCED: {
  1008. /*TODO*/
  1009. break;
  1010. }
  1011. case SA_AMF_HA_QUIESCING: {
  1012. /*TODO*/
  1013. break;
  1014. }
  1015. default: {
  1016. assert(SA_AMF_HA_ACTIVE||SA_AMF_HA_STANDBY||SA_AMF_HA_QUIESCING||SA_AMF_HA_QUIESCED);
  1017. break;
  1018. }
  1019. }
  1020. res_lib->header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  1021. res_lib->header.size =
  1022. sizeof (struct res_lib_amf_csisetcallback) +
  1023. char_length_of_csi_attrs;
  1024. res_lib->header.error = SA_AIS_OK;
  1025. amf_comp_dn_make (comp, &res_lib->compName);
  1026. amf_csi_dn_make (csi, &res_lib->csiName);
  1027. res_lib->haState = csi_assignment->requested_ha_state;
  1028. res_lib->invocation =
  1029. invocation_create (AMF_RESPONSE_CSISETCALLBACK, csi_assignment);
  1030. openais_conn_send_response (
  1031. openais_conn_partner_get (comp->conn), res_lib, res_lib->header.size);
  1032. free(p);
  1033. }
  1034. static void stop_component_instantiate_timer (struct amf_comp *component)
  1035. {
  1036. ENTER("%s",component->name.value);
  1037. if (component->instantiate_timeout_handle) {
  1038. dprintf ("Stop component instantiate timer");
  1039. poll_timer_delete (aisexec_poll_handle,
  1040. component->instantiate_timeout_handle);
  1041. component->instantiate_timeout_handle = 0;
  1042. }
  1043. }
  1044. SaAisErrorT amf_comp_register (struct amf_comp *comp)
  1045. {
  1046. TRACE2("Exec comp register '%s'", comp->name.value);
  1047. stop_component_instantiate_timer (comp);
  1048. switch (comp->saAmfCompPresenceState) {
  1049. case SA_AMF_PRESENCE_RESTARTING:
  1050. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATED);
  1051. break;
  1052. case SA_AMF_PRESENCE_INSTANTIATING:
  1053. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_ENABLED);
  1054. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATED);
  1055. break;
  1056. case SA_AMF_PRESENCE_INSTANTIATION_FAILED:
  1057. /* ignore due to instantitate timeout a while ago */
  1058. break;
  1059. default:
  1060. assert (0);
  1061. break;
  1062. }
  1063. return SA_AIS_OK;
  1064. }
  1065. void amf_comp_error_report (struct amf_comp *comp, SaAmfRecommendedRecoveryT recommendedRecovery)
  1066. {
  1067. struct res_lib_amf_componenterrorreport res_lib;
  1068. TRACE2("Exec comp error report '%s'", comp->name.value);
  1069. if (amf_su_is_local (comp->su)) {
  1070. res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  1071. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  1072. res_lib.header.error = SA_AIS_OK;
  1073. openais_conn_send_response (comp->conn, &res_lib, sizeof (res_lib));
  1074. }
  1075. /* report to SU and let it handle the problem */
  1076. report_error_suspected (comp, recommendedRecovery);
  1077. }
  1078. /**
  1079. * Healthcheck timeout event handler
  1080. * @param comp
  1081. * @param healthcheck
  1082. */
  1083. void amf_comp_healthcheck_tmo (
  1084. struct amf_comp *comp, struct amf_healthcheck *healthcheck)
  1085. {
  1086. TRACE2("Exec healthcheck tmo for '%s'", comp->name.value);
  1087. /* report to SU and let it handle the problem */
  1088. report_error_suspected (comp, healthcheck->recommendedRecovery);
  1089. }
  1090. static void clear_ha_state (
  1091. struct amf_comp *comp, struct amf_csi_assignment *csi_assignment)
  1092. {
  1093. ENTER ("");
  1094. csi_assignment->saAmfCSICompHAState = 0;
  1095. }
  1096. /**
  1097. * Event method to be called when a cleanup completed event is received
  1098. * @param comp
  1099. */
  1100. void amf_comp_cleanup_completed (struct amf_comp *comp)
  1101. {
  1102. TRACE2("Exec CLC cleanup completed for '%s'", comp->name.value);
  1103. /* Set all CSI's confirmed HA state to unknown */
  1104. amf_comp_foreach_csi_assignment (comp, clear_ha_state);
  1105. /* clear error suspected flag, component is terminated now */
  1106. comp->error_suspected = 0;
  1107. if (comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING) {
  1108. amf_comp_instantiate (comp);
  1109. } else {
  1110. comp_presence_state_set (comp, SA_AMF_PRESENCE_UNINSTANTIATED);
  1111. }
  1112. }
  1113. /**
  1114. * Handle the request from a component to start a healthcheck
  1115. *
  1116. * @param comp
  1117. * @param healthcheckKey
  1118. * @param invocationType
  1119. * @param recommendedRecovery
  1120. *
  1121. * @return SaAisErrorT - return value to component
  1122. */
  1123. SaAisErrorT amf_comp_healthcheck_start (
  1124. struct amf_comp *comp,
  1125. SaAmfHealthcheckKeyT *healthcheckKey,
  1126. SaAmfHealthcheckInvocationT invocationType,
  1127. SaAmfRecommendedRecoveryT recommendedRecovery)
  1128. {
  1129. struct amf_healthcheck *healthcheck;
  1130. SaAisErrorT error = SA_AIS_OK;
  1131. if (is_not_instantiating_or_instantiated_or_restarting (comp)) {
  1132. log_printf (LOG_ERR, "Healthcheckstart: ignored key = %s, "
  1133. "due to wrong state = %d, comp = %s",
  1134. healthcheckKey->key, comp->saAmfCompPresenceState, comp->name.value);
  1135. error = SA_AIS_OK;
  1136. goto error_exit;
  1137. }
  1138. healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey);
  1139. if (healthcheck == 0) {
  1140. log_printf (LOG_ERR, "Healthcheckstart: Healthcheck '%s' not found",
  1141. healthcheckKey->key);
  1142. error = SA_AIS_ERR_NOT_EXIST;
  1143. goto error_exit;
  1144. }
  1145. dprintf ("Healthcheckstart: '%s', key '%s'",
  1146. comp->name.value, healthcheckKey->key);
  1147. /*
  1148. * Determine if this healthcheck is already active
  1149. */
  1150. if (healthcheck->active) {
  1151. error = SA_AIS_ERR_EXIST;
  1152. goto error_exit;
  1153. }
  1154. /*
  1155. * Initialise
  1156. */
  1157. healthcheck->invocationType = invocationType;
  1158. healthcheck->recommendedRecovery = recommendedRecovery;
  1159. healthcheck->timer_handle_duration = 0;
  1160. healthcheck->timer_handle_period = 0;
  1161. healthcheck->active = 1;
  1162. if (invocationType == SA_AMF_HEALTHCHECK_AMF_INVOKED) {
  1163. /* start timer to execute first healthcheck request */
  1164. poll_timer_add (aisexec_poll_handle,
  1165. healthcheck->saAmfHealthcheckPeriod,
  1166. (void *)healthcheck,
  1167. timer_function_healthcheck_next_fn,
  1168. &healthcheck->timer_handle_period);
  1169. } else if (invocationType == SA_AMF_HEALTHCHECK_COMPONENT_INVOKED) {
  1170. /* start supervision timer */
  1171. poll_timer_add (aisexec_poll_handle,
  1172. healthcheck->saAmfHealthcheckPeriod,
  1173. (void *)healthcheck,
  1174. timer_function_healthcheck_tmo,
  1175. &healthcheck->timer_handle_period);
  1176. } else {
  1177. error = SA_AIS_ERR_INVALID_PARAM;
  1178. }
  1179. error_exit:
  1180. return error;
  1181. }
  1182. /**
  1183. * Stop all or a specifed healthcheck
  1184. * @param comp
  1185. * @param healthcheckKey - NULL if all
  1186. *
  1187. * @return SaAisErrorT
  1188. */
  1189. SaAisErrorT amf_comp_healthcheck_stop (
  1190. struct amf_comp *comp,
  1191. SaAmfHealthcheckKeyT *healthcheckKey)
  1192. {
  1193. struct amf_healthcheck *healthcheck;
  1194. SaAisErrorT error = SA_AIS_OK;
  1195. dprintf ("Healthcheckstop: '%s'", comp->name.value);
  1196. if (!amf_su_is_local (comp->su)) {
  1197. return SA_AIS_OK;
  1198. }
  1199. if (healthcheckKey == NULL) {
  1200. for (healthcheck = comp->healthcheck_head;
  1201. healthcheck != NULL;
  1202. healthcheck = healthcheck->next) {
  1203. healthcheck_deactivate (healthcheck);
  1204. }
  1205. } else {
  1206. healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey);
  1207. if (healthcheck == NULL) {
  1208. log_printf (LOG_ERR, "Healthcheckstop: Healthcheck '%s' not found",
  1209. healthcheckKey->key);
  1210. error = SA_AIS_ERR_NOT_EXIST;
  1211. } else {
  1212. healthcheck_deactivate (healthcheck);
  1213. }
  1214. }
  1215. return error;
  1216. }
  1217. /**
  1218. * Instantiate a component
  1219. * @param comp
  1220. */
  1221. void amf_comp_instantiate (struct amf_comp *comp)
  1222. {
  1223. ENTER ("'%s' SU '%s'", getSaNameT (&comp->name),
  1224. getSaNameT (&comp->su->name));
  1225. switch (comp->saAmfCompPresenceState) {
  1226. case SA_AMF_PRESENCE_RESTARTING:
  1227. /* fall through */
  1228. case SA_AMF_PRESENCE_UNINSTANTIATED:
  1229. if (amf_su_is_local (comp->su)) {
  1230. TRACE1("Send instantiate event for comp '%s' from host %s",
  1231. comp->name.value, comp->su->saAmfSUHostedByNode.value);
  1232. SaNameT compName;
  1233. amf_comp_dn_make (comp, &compName);
  1234. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_COMPONENT_INSTANTIATE,
  1235. &compName, sizeof (SaNameT));
  1236. }
  1237. break;
  1238. default:
  1239. dprintf("Instantiate ignored in Component presence state %d",
  1240. comp->saAmfCompPresenceState);
  1241. break;
  1242. }
  1243. return 0;
  1244. }
  1245. void amf_comp_instantiate_tmo_event (struct amf_comp *comp)
  1246. {
  1247. ENTER ("Comp instantiate timeout after %d ms '%s' '%s'",
  1248. comp->saAmfCompInstantiateTimeout, comp->su->name.value,
  1249. comp->name.value);
  1250. switch (comp->saAmfCompPresenceState) {
  1251. case SA_AMF_PRESENCE_RESTARTING:
  1252. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  1253. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATION_FAILED);
  1254. break;
  1255. case SA_AMF_PRESENCE_INSTANTIATING:
  1256. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  1257. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATION_FAILED);
  1258. break;
  1259. case SA_AMF_PRESENCE_INSTANTIATED:
  1260. assert (comp->instantiate_timeout_handle == 0);
  1261. break;
  1262. default:
  1263. dprintf("Presence state = %d", comp->saAmfCompPresenceState);
  1264. assert (0);
  1265. break;
  1266. }
  1267. }
  1268. void amf_comp_instantiate_event (struct amf_comp *component)
  1269. {
  1270. int res;
  1271. ENTER ("");
  1272. switch (component->saAmfCompPresenceState) {
  1273. case SA_AMF_PRESENCE_INSTANTIATING:
  1274. case SA_AMF_PRESENCE_INSTANTIATED:
  1275. case SA_AMF_PRESENCE_TERMINATING:
  1276. case SA_AMF_PRESENCE_INSTANTIATION_FAILED:
  1277. case SA_AMF_PRESENCE_TERMINATION_FAILED:
  1278. dprintf("Instantiate ignored in Component presence state %d",
  1279. component->saAmfCompPresenceState);
  1280. break;
  1281. case SA_AMF_PRESENCE_UNINSTANTIATED:
  1282. comp_presence_state_set (component, SA_AMF_PRESENCE_INSTANTIATING);
  1283. amf_su_comp_state_changed(component->su,
  1284. component,SA_AMF_PRESENCE_STATE,SA_AMF_PRESENCE_INSTANTIATING);
  1285. if (amf_su_is_local (component->su)) {
  1286. res = clc_interfaces[component->comptype]->instantiate (
  1287. component);
  1288. }
  1289. break;
  1290. case SA_AMF_PRESENCE_RESTARTING:
  1291. if (amf_su_is_local (component->su)) {
  1292. res = clc_interfaces[component->comptype]->instantiate (
  1293. component);
  1294. }
  1295. break;
  1296. default:
  1297. dprintf("Component presence state %d",
  1298. component->saAmfCompPresenceState);
  1299. assert (0);
  1300. break;
  1301. }
  1302. }
  1303. void amf_comp_readiness_state_set (struct amf_comp *comp,
  1304. SaAmfReadinessStateT state)
  1305. {
  1306. TRACE1 ("Setting comp '%s' readiness state: %s\n",
  1307. comp->name.value, amf_readiness_state (state));
  1308. }
  1309. /**
  1310. * Handle a component response (received from the lib) of an earlier AMF request.
  1311. * This function should be invoked when the lib request is received.
  1312. * @param invocation [in] associates the response with the request (callback)
  1313. * @param error [in] response from the component of the associated callback
  1314. * @param retval [out] contains return value to component when needed
  1315. *
  1316. * @return ==0 respond to component, do not multicast
  1317. * @return >0 do not respond to component, multicast response
  1318. */
  1319. int amf_comp_response_1 (
  1320. SaInvocationT invocation, SaAisErrorT error, SaAisErrorT *retval,
  1321. SaUint32T *interface, SaNameT *dn)
  1322. {
  1323. int res;
  1324. void *data;
  1325. res = invocation_get_and_destroy (invocation, interface, &data);
  1326. if (res == -1) {
  1327. log_printf (LOG_ERR, "Lib response: invocation not found\n");
  1328. *retval = SA_AIS_ERR_INVALID_PARAM;
  1329. return 0;
  1330. }
  1331. switch (*interface) {
  1332. case AMF_RESPONSE_HEALTHCHECKCALLBACK: {
  1333. struct amf_healthcheck *healthcheck = data;
  1334. SaNameT name;
  1335. TRACE7 ("Healthcheck response from '%s': %d",
  1336. amf_comp_dn_make (healthcheck->comp, &name), error);
  1337. if (is_not_instantiating_or_instantiated_or_restarting(
  1338. healthcheck->comp)) {
  1339. log_printf (LOG_ERR, "HealthcheckResponse: ignored for key = %s, "
  1340. "due to wrong state = %d comp = %s",
  1341. healthcheck->safHealthcheckKey.key,
  1342. healthcheck->comp->saAmfCompPresenceState,
  1343. healthcheck->comp->name.value);
  1344. *retval = SA_AIS_OK;
  1345. return 0; /* do not multicast event */
  1346. }
  1347. if (healthcheck->invocationType == SA_AMF_HEALTHCHECK_AMF_INVOKED) {
  1348. /* the response was on time, delete supervision timer */
  1349. poll_timer_delete (aisexec_poll_handle,
  1350. healthcheck->timer_handle_duration);
  1351. healthcheck->timer_handle_duration = 0;
  1352. /* start timer to execute next healthcheck request */
  1353. poll_timer_add (aisexec_poll_handle,
  1354. healthcheck->saAmfHealthcheckPeriod,
  1355. (void *)healthcheck,
  1356. timer_function_healthcheck_next_fn,
  1357. &healthcheck->timer_handle_period);
  1358. *retval = SA_AIS_OK;
  1359. } else {
  1360. *retval = SA_AIS_ERR_INVALID_PARAM;
  1361. }
  1362. return 0; /* do not multicast event */
  1363. break;
  1364. }
  1365. case AMF_RESPONSE_CSISETCALLBACK: /* fall-through */
  1366. case AMF_RESPONSE_CSIREMOVECALLBACK:
  1367. amf_csi_assignment_dn_make (data, dn);
  1368. return 1; /* multicast event */
  1369. break;
  1370. #if 0
  1371. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: {
  1372. struct component_terminate_callback_data *component_terminate_callback_data;
  1373. component_terminate_callback_data = data;
  1374. dprintf ("Lib component terminate callback response, error: %d", error);
  1375. amf_comp_healthcheck_deactivate (component_terminate_callback_data->comp);
  1376. escalation_policy_restart (component_terminate_callback_data->comp);
  1377. return 1;
  1378. break;
  1379. }
  1380. #endif
  1381. default:
  1382. assert (0);
  1383. break;
  1384. }
  1385. /* XXX we fall here in case NDEBUG is set */
  1386. *retval = -1;
  1387. return 0;
  1388. }
  1389. /**
  1390. * Handle a component response (received from EVS) of an earlier AMF request.
  1391. * This function should be invoked when the multicast request is received.
  1392. * @param invocation [in] associates the response with the request (callback)
  1393. * @param error [in] response from the component of the associated callback
  1394. * @param retval [out] contains return value to component when needed
  1395. *
  1396. * @return component to which the response should be sent
  1397. */
  1398. struct amf_comp *amf_comp_response_2 (
  1399. SaUint32T interface, SaNameT *dn, SaAisErrorT error, SaAisErrorT *retval)
  1400. {
  1401. struct amf_csi_assignment *csi_assignment;
  1402. struct amf_comp *comp = NULL;
  1403. assert (retval != NULL);
  1404. *retval = SA_AIS_OK;
  1405. switch (interface) {
  1406. case AMF_RESPONSE_CSISETCALLBACK: {
  1407. ENTER("'%s'", dn->value);
  1408. csi_assignment = amf_csi_assignment_find (amf_cluster, dn);
  1409. assert (csi_assignment != NULL);
  1410. comp = csi_assignment->comp;
  1411. dprintf ("CSI '%s' set callback response from '%s', error: %d",
  1412. csi_assignment->csi->name.value,
  1413. csi_assignment->comp->name.value, error);
  1414. comp = csi_assignment->comp;
  1415. if (error == SA_AIS_OK) {
  1416. comp_ha_state_set (
  1417. comp, csi_assignment, csi_assignment->requested_ha_state);
  1418. } else if (error == SA_AIS_ERR_FAILED_OPERATION) {
  1419. amf_si_comp_set_ha_state_failed (csi_assignment->csi->si,
  1420. csi_assignment);
  1421. } else {
  1422. *retval = SA_AIS_ERR_INVALID_PARAM;
  1423. }
  1424. break;
  1425. }
  1426. case AMF_RESPONSE_CSIREMOVECALLBACK: {
  1427. ENTER("'%s'", dn->value);
  1428. csi_assignment = amf_csi_assignment_find (amf_cluster, dn);
  1429. assert (csi_assignment != NULL);
  1430. dprintf ("Lib csi '%s' remove callback response from '%s', error: %d",
  1431. csi_assignment->csi->name.value,
  1432. csi_assignment->comp->name.value, error);
  1433. comp = csi_assignment->comp;
  1434. if (error == SA_AIS_OK || error == SA_AIS_ERR_FAILED_OPERATION) {
  1435. amf_si_comp_csi_removed (csi_assignment->csi->si,
  1436. csi_assignment, error);
  1437. } else {
  1438. *retval = SA_AIS_ERR_INVALID_PARAM;
  1439. }
  1440. break;
  1441. }
  1442. #if 0
  1443. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: {
  1444. struct component_terminate_callback_data *callback_data = data;
  1445. dprintf ("Lib comp '%s' terminate callback response, error: %d",
  1446. callback_data->comp->name.value, error);
  1447. comp_presence_state_set (callback_data->comp,
  1448. SA_AMF_PRESENCE_UNINSTANTIATED);
  1449. break;
  1450. }
  1451. #endif
  1452. default:
  1453. assert (0);
  1454. break;
  1455. }
  1456. return comp;
  1457. }
  1458. /**
  1459. * Request a component to assume a particular HA state
  1460. * @param comp
  1461. * @param csi_assignment
  1462. * @param requested_ha_state
  1463. */
  1464. void amf_comp_hastate_set (
  1465. struct amf_comp *component,
  1466. struct amf_csi_assignment *csi_assignment)
  1467. {
  1468. ENTER ("'%s'", csi_assignment->csi->name.value);
  1469. assert (component != NULL && csi_assignment != NULL);
  1470. if (!component->error_suspected) {
  1471. lib_csi_set_request(component, csi_assignment);
  1472. } else {
  1473. if (csi_assignment->requested_ha_state == SA_AMF_HA_QUIESCED) {
  1474. csi_assignment->saAmfCSICompHAState = csi_assignment->requested_ha_state;
  1475. } else {
  1476. dprintf ("csi_assignment->requested_ha_state = %d",
  1477. component->error_suspected);
  1478. assert (0);
  1479. }
  1480. }
  1481. LEAVE("");
  1482. }
  1483. /**
  1484. * Request termination of a component
  1485. * @param comp
  1486. */
  1487. void amf_comp_terminate (struct amf_comp *comp)
  1488. {
  1489. dprintf ("comp terminate '%s'\n", getSaNameT (&comp->name));
  1490. comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATING);
  1491. if (amf_su_is_local (comp->su)) {
  1492. amf_comp_healthcheck_stop (comp, NULL);
  1493. if (comp->error_suspected) {
  1494. clc_interfaces[comp->comptype]->cleanup (comp);
  1495. } else {
  1496. clc_interfaces[comp->comptype]->terminate (comp);
  1497. }
  1498. }
  1499. }
  1500. /**
  1501. * Request restart of a component
  1502. * @param comp
  1503. */
  1504. void amf_comp_restart (struct amf_comp *comp)
  1505. {
  1506. dprintf ("comp restart '%s'\n", getSaNameT (&comp->name));
  1507. comp_presence_state_set (comp, SA_AMF_PRESENCE_RESTARTING);
  1508. comp->saAmfCompRestartCount += 1;
  1509. if (amf_su_is_local (comp->su)) {
  1510. amf_comp_healthcheck_stop (comp, NULL);
  1511. clc_interfaces[comp->comptype]->cleanup (comp);
  1512. }
  1513. }
  1514. /**
  1515. * Request to return the HA state for a components CSI
  1516. * @param comp
  1517. * @param csi_name
  1518. * @param ha_state
  1519. *
  1520. * @return SaAisErrorT
  1521. */
  1522. SaAisErrorT amf_comp_hastate_get (
  1523. struct amf_comp *comp, SaNameT *csi_name, SaAmfHAStateT *ha_state)
  1524. {
  1525. struct amf_csi_assignment *assignment;
  1526. assert (comp != NULL && csi_name != NULL && ha_state != NULL);
  1527. dprintf ("comp ha state get from comp '%s' CSI '%s'\n",
  1528. getSaNameT (&comp->name), csi_name->value);
  1529. assignment = csi_assignment_find_in (comp, csi_name);
  1530. if (assignment != NULL) {
  1531. *ha_state = assignment->saAmfCSICompHAState;
  1532. return SA_AIS_OK;
  1533. }
  1534. return SA_AIS_ERR_INVALID_PARAM;
  1535. }
  1536. /**
  1537. * Response from a component informs AMF that it has performed a healthcheck
  1538. * @param comp
  1539. * @param healthcheckKey
  1540. * @param healthcheckResult
  1541. *
  1542. * @return SaAisErrorT
  1543. */
  1544. SaAisErrorT amf_comp_healthcheck_confirm (
  1545. struct amf_comp *comp,
  1546. SaAmfHealthcheckKeyT *healthcheckKey,
  1547. SaAisErrorT healthcheckResult)
  1548. {
  1549. struct amf_healthcheck *healthcheck;
  1550. SaAisErrorT error = SA_AIS_OK;
  1551. healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey);
  1552. if (is_not_instantiating_or_instantiated_or_restarting(comp)) {
  1553. log_printf (LOG_ERR, "HealthcheckConfirm: ignored for key = %s, "
  1554. "due to wrong state = %d, comp = %s",
  1555. healthcheckKey->key, comp->saAmfCompPresenceState, comp->name.value);
  1556. error = SA_AIS_OK;
  1557. goto out;
  1558. }
  1559. if (healthcheck == NULL) {
  1560. log_printf (LOG_ERR, "Healthcheckstop: Healthcheck '%s' not found",
  1561. healthcheckKey->key);
  1562. error = SA_AIS_ERR_NOT_EXIST;
  1563. } else if (healthcheck->active) {
  1564. if (healthcheckResult == SA_AIS_OK) {
  1565. /* the response was on time, restart the supervision timer */
  1566. poll_timer_delete (aisexec_poll_handle,
  1567. healthcheck->timer_handle_period);
  1568. poll_timer_add (aisexec_poll_handle,
  1569. healthcheck->saAmfHealthcheckPeriod,
  1570. (void *)healthcheck,
  1571. timer_function_healthcheck_tmo,
  1572. &healthcheck->timer_handle_period);
  1573. } else if (healthcheckResult == SA_AIS_ERR_FAILED_OPERATION) {
  1574. /* send to cluster */
  1575. mcast_healthcheck_tmo_event (healthcheck);
  1576. } else {
  1577. error = SA_AIS_ERR_INVALID_PARAM;
  1578. }
  1579. } else {
  1580. error = SA_AIS_ERR_INVALID_PARAM;
  1581. }
  1582. out:
  1583. return error;
  1584. }
  1585. void amf_comp_init (void)
  1586. {
  1587. log_init ("AMF");
  1588. }
  1589. void amf_comp_operational_state_set (struct amf_comp *comp,
  1590. SaAmfOperationalStateT oper_state)
  1591. {
  1592. comp->saAmfCompOperState = oper_state;
  1593. TRACE1 ("Setting comp '%s', SU '%s' operational state: %s\n",
  1594. comp->name.value, comp->su->name.value,
  1595. amf_op_state (comp->saAmfCompOperState));
  1596. amf_su_comp_state_changed (
  1597. comp->su, comp, SA_AMF_OP_STATE, oper_state);
  1598. }
  1599. int amf_comp_get_saAmfCompNumCurrActiveCsi(struct amf_comp *component)
  1600. {
  1601. int cnt = 0;
  1602. struct amf_csi_assignment *csi_assignment;
  1603. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1604. while (csi_assignment != NULL) {
  1605. if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_ACTIVE) {
  1606. cnt++;
  1607. }
  1608. csi_assignment = amf_comp_get_next_csi_assignment (
  1609. component, csi_assignment);
  1610. }
  1611. return cnt;
  1612. }
  1613. int amf_comp_get_saAmfCompNumCurrStandbyCsi(struct amf_comp *component)
  1614. {
  1615. int cnt = 0;
  1616. struct amf_csi_assignment *csi_assignment;
  1617. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1618. while (csi_assignment != NULL) {
  1619. if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_STANDBY) {
  1620. cnt++;
  1621. }
  1622. csi_assignment = amf_comp_get_next_csi_assignment (
  1623. component, csi_assignment);
  1624. }
  1625. return cnt;
  1626. }
  1627. SaAmfReadinessStateT amf_comp_get_saAmfCompReadinessState (
  1628. struct amf_comp *component)
  1629. {
  1630. if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
  1631. return amf_su_get_saAmfSUReadinessState (component->su);
  1632. } else if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_DISABLED) {
  1633. return SA_AMF_READINESS_OUT_OF_SERVICE;
  1634. }
  1635. assert (0);
  1636. /* XXX we fall here in case NDEBUG is set */
  1637. return -1;
  1638. }
  1639. /**
  1640. * Component is informed that the node where the 'real'
  1641. * component process is executing has unexpectadly left the
  1642. * node. If there is a pending interaction between AMF
  1643. * (component) and the 'real' component process, then component
  1644. * will indicate to its subordinate objects the interaction
  1645. * failed. Pending presence state changes is indicated by
  1646. * reporting the new state is uninstantiated while pending csi
  1647. * operations are indicated by 'operation failed'.
  1648. * @param comp
  1649. *
  1650. * @return void
  1651. */
  1652. void amf_comp_node_left (struct amf_comp *component)
  1653. {
  1654. int change_pending = 0;
  1655. struct amf_csi_assignment *csi_assignment;
  1656. ENTER("saAmfCompPresenceState = %d", component->saAmfCompPresenceState);
  1657. component->error_suspected = 0;
  1658. if (component->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATING ||
  1659. component->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING ||
  1660. component->saAmfCompPresenceState == SA_AMF_PRESENCE_TERMINATING) {
  1661. change_pending = 1;
  1662. }
  1663. component->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  1664. if (amf_su_presence_state_all_comps_in_su_are_set (component->su,
  1665. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  1666. component->su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  1667. }
  1668. if (change_pending) {
  1669. change_pending = 0;
  1670. amf_su_comp_state_changed ( component->su,
  1671. component,
  1672. SA_AMF_PRESENCE_STATE,
  1673. SA_AMF_PRESENCE_UNINSTANTIATED);
  1674. }
  1675. if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
  1676. change_pending = 1;
  1677. }
  1678. component->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED;
  1679. if (change_pending) {
  1680. change_pending =0;
  1681. amf_su_comp_state_changed (component->su,
  1682. component,
  1683. SA_AMF_OP_STATE,
  1684. SA_AMF_OPERATIONAL_DISABLED);
  1685. }
  1686. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1687. while (csi_assignment != NULL) {
  1688. if (csi_assignment->requested_ha_state !=
  1689. csi_assignment->saAmfCSICompHAState) {
  1690. amf_si_comp_set_ha_state_failed (
  1691. csi_assignment->csi->si,csi_assignment);
  1692. }
  1693. csi_assignment = amf_comp_get_next_csi_assignment (
  1694. component, csi_assignment);
  1695. }
  1696. }
  1697. /**
  1698. * Serialize a component including variable length arrays and
  1699. * strings to a buffer returned. Buffer is to be freed by
  1700. * caller.
  1701. * @param component
  1702. * @param len
  1703. *
  1704. * @return void*
  1705. */
  1706. void *amf_comp_serialize (struct amf_comp *component, int *len)
  1707. {
  1708. char *buf = NULL;
  1709. int i, offset = 0, size = 0;
  1710. TRACE8 ("%s", component->name.value);
  1711. buf = amf_serialize_SaNameT (buf, &size, &offset, &component->name);
  1712. /* count cstypes and write to buf */
  1713. for (i = 0; component->saAmfCompCsTypes &&
  1714. component->saAmfCompCsTypes[i] != NULL; i++);
  1715. buf = amf_serialize_SaUint32T (buf, &size, &offset, i);
  1716. for (i = 0; component->saAmfCompCsTypes &&
  1717. component->saAmfCompCsTypes[i] != NULL; i++) {
  1718. buf = amf_serialize_SaNameT (
  1719. buf, &size, &offset, component->saAmfCompCsTypes[i]);
  1720. }
  1721. buf = amf_serialize_SaUint32T (
  1722. buf, &size, &offset, component->saAmfCompCategory);
  1723. buf = amf_serialize_SaUint32T (
  1724. buf, &size, &offset, component->saAmfCompCapability);
  1725. buf = amf_serialize_SaUint32T (
  1726. buf, &size, &offset, component->saAmfCompNumMaxActiveCsi);
  1727. buf = amf_serialize_SaUint32T (
  1728. buf, &size, &offset, component->saAmfCompNumMaxStandbyCsi);
  1729. /* count environment vars and write to buf */
  1730. for (i = 0; component->saAmfCompCmdEnv &&
  1731. component->saAmfCompCmdEnv[i] != NULL; i++);
  1732. buf = amf_serialize_SaUint32T (buf, &size, &offset, i);
  1733. for (i = 0; component->saAmfCompCmdEnv &&
  1734. component->saAmfCompCmdEnv[i] != NULL; i++) {
  1735. buf = amf_serialize_SaStringT (
  1736. buf, &size, &offset, component->saAmfCompCmdEnv[i]);
  1737. }
  1738. buf = amf_serialize_SaUint32T (
  1739. buf, &size, &offset, component->saAmfCompDefaultClcCliTimeout);
  1740. buf = amf_serialize_SaUint32T (
  1741. buf, &size, &offset, component->saAmfCompDefaultCallbackTimeOut);
  1742. buf = amf_serialize_SaStringT (
  1743. buf, &size, &offset, component->saAmfCompInstantiateCmd);
  1744. buf = amf_serialize_SaStringT (
  1745. buf, &size, &offset, component->saAmfCompInstantiateCmdArgv);
  1746. buf = amf_serialize_SaUint32T (
  1747. buf, &size, &offset, component->saAmfCompInstantiateTimeout);
  1748. buf = amf_serialize_SaUint32T (
  1749. buf, &size, &offset, component->saAmfCompInstantiationLevel);
  1750. buf = amf_serialize_SaUint32T (
  1751. buf, &size, &offset, component->saAmfCompNumMaxInstantiateWithoutDelay);
  1752. buf = amf_serialize_SaUint32T (
  1753. buf, &size, &offset, component->saAmfCompNumMaxInstantiateWithDelay);
  1754. buf = amf_serialize_SaUint32T (
  1755. buf, &size, &offset, component->saAmfCompDelayBetweenInstantiateAttempts);
  1756. buf = amf_serialize_SaStringT (
  1757. buf, &size, &offset, component->saAmfCompTerminateCmd);
  1758. buf = amf_serialize_SaUint32T (
  1759. buf, &size, &offset, component->saAmfCompTerminateTimeout);
  1760. buf = amf_serialize_SaStringT (
  1761. buf, &size, &offset, component->saAmfCompTerminateCmdArgv);
  1762. buf = amf_serialize_SaStringT (
  1763. buf, &size, &offset, component->saAmfCompCleanupCmd);
  1764. buf = amf_serialize_SaUint32T (
  1765. buf, &size, &offset, component->saAmfCompCleanupTimeout);
  1766. buf = amf_serialize_SaStringT (
  1767. buf, &size, &offset, component->saAmfCompCleanupCmdArgv);
  1768. buf = amf_serialize_SaStringT (
  1769. buf, &size, &offset, component->saAmfCompAmStartCmd);
  1770. buf = amf_serialize_SaUint32T (
  1771. buf, &size, &offset, component->saAmfCompAmStartTimeout);
  1772. buf = amf_serialize_SaStringT (
  1773. buf, &size, &offset, component->saAmfCompAmStartCmdArgv);
  1774. buf = amf_serialize_SaUint32T (
  1775. buf, &size, &offset, component->saAmfCompNumMaxAmStartAttempt);
  1776. buf = amf_serialize_SaStringT (
  1777. buf, &size, &offset, component->saAmfCompAmStopCmd);
  1778. buf = amf_serialize_SaUint32T (
  1779. buf, &size, &offset, component->saAmfCompAmStopTimeout);
  1780. buf = amf_serialize_SaStringT (
  1781. buf, &size, &offset, component->saAmfCompAmStopCmdArgv);
  1782. buf = amf_serialize_SaUint32T (
  1783. buf, &size, &offset, component->saAmfCompNumMaxAmStopAttempt);
  1784. buf = amf_serialize_SaUint32T (
  1785. buf, &size, &offset, component->saAmfCompTerminateCallbackTimeout);
  1786. buf = amf_serialize_SaUint32T (
  1787. buf, &size, &offset, component->saAmfCompCSISetCallbackTimeout);
  1788. buf = amf_serialize_SaUint32T (
  1789. buf, &size, &offset, component->saAmfCompQuiescingCompleteTimeout);
  1790. buf = amf_serialize_SaUint32T (
  1791. buf, &size, &offset, component->saAmfCompCSIRmvCallbackTimeout);
  1792. buf = amf_serialize_SaUint32T (
  1793. buf, &size, &offset, component->saAmfCompRecoveryOnError);
  1794. buf = amf_serialize_SaUint32T (
  1795. buf, &size, &offset, component->saAmfCompDisableRestart);
  1796. buf = amf_serialize_SaNameT (
  1797. buf, &size, &offset, &component->saAmfCompProxyCsi);
  1798. buf = amf_serialize_SaUint32T (
  1799. buf, &size, &offset, component->saAmfCompOperState);
  1800. buf = amf_serialize_SaUint32T (
  1801. buf, &size, &offset, component->saAmfCompPresenceState);
  1802. buf = amf_serialize_SaUint32T (
  1803. buf, &size, &offset, component->saAmfCompRestartCount);
  1804. buf = amf_serialize_SaNameT (
  1805. buf, &size, &offset, &component->saAmfCompCurrProxyName);
  1806. buf = amf_serialize_SaStringT (
  1807. buf, &size, &offset, component->clccli_path);
  1808. buf = amf_serialize_SaUint32T (
  1809. buf, &size, &offset, component->comptype);
  1810. buf = amf_serialize_SaUint32T (
  1811. buf, &size, &offset, component->error_suspected);
  1812. *len = offset;
  1813. return buf;
  1814. }
  1815. /**
  1816. * Deserialize a buffer into a AMF component object.
  1817. * @param su
  1818. * @param buf
  1819. * @param size
  1820. *
  1821. * @return struct amf_comp*
  1822. */
  1823. struct amf_comp *amf_comp_deserialize (struct amf_su *su, char *buf)
  1824. {
  1825. char *tmp = buf;
  1826. int i;
  1827. SaUint32T cnt;
  1828. struct amf_comp *component = amf_comp_new (su, "");
  1829. tmp = amf_deserialize_SaNameT (tmp, &component->name);
  1830. tmp = amf_deserialize_SaUint32T (tmp, &cnt);
  1831. component->saAmfCompCsTypes = amf_malloc ((cnt + 1) * sizeof (SaNameT*));
  1832. for (i = 0; i < cnt; i++) {
  1833. component->saAmfCompCsTypes[i] = amf_malloc (sizeof (SaNameT));
  1834. tmp = amf_deserialize_SaNameT (tmp, component->saAmfCompCsTypes[i]);
  1835. }
  1836. component->saAmfCompCsTypes[i] = NULL;
  1837. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompCategory);
  1838. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompCapability);
  1839. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompNumMaxActiveCsi);
  1840. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompNumMaxStandbyCsi);
  1841. tmp = amf_deserialize_SaUint32T (tmp, &cnt);
  1842. component->saAmfCompCmdEnv = amf_malloc ((cnt + 1) * sizeof (SaStringT*));
  1843. for (i = 0; i < cnt; i++) {
  1844. tmp = amf_deserialize_SaStringT (tmp, &component->saAmfCompCmdEnv[i]);
  1845. }
  1846. component->saAmfCompCmdEnv[i] = NULL;
  1847. tmp = amf_deserialize_SaUint32T (
  1848. tmp, &component->saAmfCompDefaultClcCliTimeout);
  1849. tmp = amf_deserialize_SaUint32T (
  1850. tmp, &component->saAmfCompDefaultCallbackTimeOut);
  1851. tmp = amf_deserialize_SaStringT (
  1852. tmp, &component->saAmfCompInstantiateCmd);
  1853. tmp = amf_deserialize_SaStringT (
  1854. tmp, &component->saAmfCompInstantiateCmdArgv);
  1855. tmp = amf_deserialize_SaUint32T (
  1856. tmp, &component->saAmfCompInstantiateTimeout);
  1857. tmp = amf_deserialize_SaUint32T (
  1858. tmp, &component->saAmfCompInstantiationLevel);
  1859. tmp = amf_deserialize_SaUint32T (
  1860. tmp, &component->saAmfCompNumMaxInstantiateWithoutDelay);
  1861. tmp = amf_deserialize_SaUint32T (
  1862. tmp, &component->saAmfCompNumMaxInstantiateWithDelay);
  1863. tmp = amf_deserialize_SaUint32T (
  1864. tmp, &component->saAmfCompDelayBetweenInstantiateAttempts);
  1865. tmp = amf_deserialize_SaStringT (
  1866. tmp, &component->saAmfCompTerminateCmd);
  1867. tmp = amf_deserialize_SaUint32T (
  1868. tmp, &component->saAmfCompTerminateTimeout);
  1869. tmp = amf_deserialize_SaStringT (
  1870. tmp, &component->saAmfCompTerminateCmdArgv);
  1871. tmp = amf_deserialize_SaStringT (
  1872. tmp, &component->saAmfCompCleanupCmd);
  1873. tmp = amf_deserialize_SaUint32T (
  1874. tmp, &component->saAmfCompCleanupTimeout);
  1875. tmp = amf_deserialize_SaStringT (
  1876. tmp, &component->saAmfCompCleanupCmdArgv);
  1877. tmp = amf_deserialize_SaStringT (
  1878. tmp, &component->saAmfCompAmStartCmd);
  1879. tmp = amf_deserialize_SaUint32T (
  1880. tmp, &component->saAmfCompAmStartTimeout);
  1881. tmp = amf_deserialize_SaStringT (
  1882. tmp, &component->saAmfCompAmStartCmdArgv);
  1883. tmp = amf_deserialize_SaUint32T (
  1884. tmp, &component->saAmfCompNumMaxAmStartAttempt);
  1885. tmp = amf_deserialize_SaStringT (
  1886. tmp, &component->saAmfCompAmStopCmd);
  1887. tmp = amf_deserialize_SaUint32T (
  1888. tmp, &component->saAmfCompAmStopTimeout);
  1889. tmp = amf_deserialize_SaStringT (
  1890. tmp, &component->saAmfCompAmStopCmdArgv);
  1891. tmp = amf_deserialize_SaUint32T (
  1892. tmp, &component->saAmfCompNumMaxAmStopAttempt);
  1893. tmp = amf_deserialize_SaUint32T (
  1894. tmp, &component->saAmfCompTerminateCallbackTimeout);
  1895. tmp = amf_deserialize_SaUint32T (
  1896. tmp, &component->saAmfCompCSISetCallbackTimeout);
  1897. tmp = amf_deserialize_SaUint32T (
  1898. tmp, &component->saAmfCompQuiescingCompleteTimeout);
  1899. tmp = amf_deserialize_SaUint32T (
  1900. tmp, &component->saAmfCompCSIRmvCallbackTimeout);
  1901. tmp = amf_deserialize_SaUint32T (
  1902. tmp, &component->saAmfCompRecoveryOnError);
  1903. tmp = amf_deserialize_SaUint32T (
  1904. tmp, &component->saAmfCompDisableRestart);
  1905. tmp = amf_deserialize_SaNameT (
  1906. tmp, &component->saAmfCompProxyCsi);
  1907. tmp = amf_deserialize_SaUint32T (
  1908. tmp, &component->saAmfCompOperState);
  1909. tmp = amf_deserialize_SaUint32T (
  1910. tmp, &component->saAmfCompPresenceState);
  1911. tmp = amf_deserialize_SaUint32T (
  1912. tmp, &component->saAmfCompRestartCount);
  1913. tmp = amf_deserialize_SaNameT (
  1914. tmp, &component->saAmfCompCurrProxyName);
  1915. tmp = amf_deserialize_SaStringT (
  1916. tmp, &component->clccli_path);
  1917. tmp = amf_deserialize_SaUint32T (
  1918. tmp, &component->comptype);
  1919. tmp = amf_deserialize_SaUint32T (
  1920. tmp, &component->error_suspected);
  1921. return component;
  1922. }
  1923. void *amf_healthcheck_serialize (struct amf_healthcheck *healthcheck, int *len)
  1924. {
  1925. char *buf = NULL;
  1926. int offset = 0, size = 0;
  1927. TRACE8 ("%s", healthcheck->safHealthcheckKey.key);
  1928. buf = amf_serialize_opaque (buf, &size, &offset,
  1929. &healthcheck->safHealthcheckKey.key, SA_AMF_HEALTHCHECK_KEY_MAX);
  1930. buf = amf_serialize_SaUint16T (buf, &size, &offset,
  1931. healthcheck->safHealthcheckKey.keyLen);
  1932. buf = amf_serialize_SaUint32T (buf, &size, &offset,
  1933. healthcheck->saAmfHealthcheckMaxDuration);
  1934. buf = amf_serialize_SaUint32T (buf, &size, &offset,
  1935. healthcheck->saAmfHealthcheckPeriod);
  1936. *len = offset;
  1937. return buf;
  1938. }
  1939. struct amf_healthcheck *amf_healthcheck_deserialize (
  1940. struct amf_comp *comp, char *buf)
  1941. {
  1942. char *tmp = buf;
  1943. int cnt;
  1944. amf_healthcheck_t *healthcheck = amf_healthcheck_new (comp);
  1945. tmp = amf_deserialize_opaque (tmp, &healthcheck->safHealthcheckKey.key, &cnt);
  1946. tmp = amf_deserialize_SaUint16T (tmp,
  1947. &healthcheck->safHealthcheckKey.keyLen);
  1948. tmp = amf_deserialize_SaUint32T (tmp,
  1949. &healthcheck->saAmfHealthcheckMaxDuration);
  1950. tmp = amf_deserialize_SaUint32T (tmp,
  1951. &healthcheck->saAmfHealthcheckPeriod);
  1952. return healthcheck;
  1953. }
  1954. amf_healthcheck_t *amf_healthcheck_new (struct amf_comp *comp)
  1955. {
  1956. amf_healthcheck_t *healthcheck = amf_calloc (1, sizeof (amf_healthcheck_t));
  1957. healthcheck->comp = comp;
  1958. healthcheck->next = comp->healthcheck_head;
  1959. comp->healthcheck_head = healthcheck;
  1960. return healthcheck;
  1961. }
  1962. void amf_comp_csi_remove (amf_comp_t *component,
  1963. amf_csi_assignment_t *csi_assignment)
  1964. {
  1965. struct res_lib_amf_csiremovecallback res_lib;
  1966. ENTER("");
  1967. res_lib.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  1968. res_lib.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  1969. res_lib.header.error = SA_AIS_OK;
  1970. res_lib.invocation =
  1971. invocation_create (AMF_RESPONSE_CSIREMOVECALLBACK, csi_assignment);
  1972. amf_comp_dn_make (component, &res_lib.compName);
  1973. amf_csi_dn_make (csi_assignment->csi, &res_lib.csiName);
  1974. res_lib.csiFlags = SA_AMF_CSI_TARGET_ONE;
  1975. TRACE7 ("sending CSI remove request to component %s",
  1976. res_lib.compName.value);
  1977. openais_conn_send_response (
  1978. openais_conn_partner_get (component->conn),
  1979. &res_lib, sizeof (struct res_lib_amf_csiremovecallback));
  1980. }