amfcomp.c 67 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261
  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. }
  1244. void amf_comp_instantiate_tmo_event (struct amf_comp *comp)
  1245. {
  1246. ENTER ("Comp instantiate timeout after %d ms '%s' '%s'",
  1247. comp->saAmfCompInstantiateTimeout, comp->su->name.value,
  1248. comp->name.value);
  1249. switch (comp->saAmfCompPresenceState) {
  1250. case SA_AMF_PRESENCE_RESTARTING:
  1251. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  1252. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATION_FAILED);
  1253. break;
  1254. case SA_AMF_PRESENCE_INSTANTIATING:
  1255. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  1256. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATION_FAILED);
  1257. break;
  1258. case SA_AMF_PRESENCE_INSTANTIATED:
  1259. assert (comp->instantiate_timeout_handle == 0);
  1260. break;
  1261. default:
  1262. dprintf("Presence state = %d", comp->saAmfCompPresenceState);
  1263. assert (0);
  1264. break;
  1265. }
  1266. }
  1267. void amf_comp_instantiate_event (struct amf_comp *component)
  1268. {
  1269. int res;
  1270. ENTER ("");
  1271. switch (component->saAmfCompPresenceState) {
  1272. case SA_AMF_PRESENCE_INSTANTIATING:
  1273. case SA_AMF_PRESENCE_INSTANTIATED:
  1274. case SA_AMF_PRESENCE_TERMINATING:
  1275. case SA_AMF_PRESENCE_INSTANTIATION_FAILED:
  1276. case SA_AMF_PRESENCE_TERMINATION_FAILED:
  1277. dprintf("Instantiate ignored in Component presence state %d",
  1278. component->saAmfCompPresenceState);
  1279. break;
  1280. case SA_AMF_PRESENCE_UNINSTANTIATED:
  1281. comp_presence_state_set (component, SA_AMF_PRESENCE_INSTANTIATING);
  1282. amf_su_comp_state_changed(component->su,
  1283. component,SA_AMF_PRESENCE_STATE,SA_AMF_PRESENCE_INSTANTIATING);
  1284. if (amf_su_is_local (component->su)) {
  1285. res = clc_interfaces[component->comptype]->instantiate (
  1286. component);
  1287. }
  1288. break;
  1289. case SA_AMF_PRESENCE_RESTARTING:
  1290. if (amf_su_is_local (component->su)) {
  1291. res = clc_interfaces[component->comptype]->instantiate (
  1292. component);
  1293. }
  1294. break;
  1295. default:
  1296. dprintf("Component presence state %d",
  1297. component->saAmfCompPresenceState);
  1298. assert (0);
  1299. break;
  1300. }
  1301. }
  1302. void amf_comp_readiness_state_set (struct amf_comp *comp,
  1303. SaAmfReadinessStateT state)
  1304. {
  1305. TRACE1 ("Setting comp '%s' readiness state: %s\n",
  1306. comp->name.value, amf_readiness_state (state));
  1307. }
  1308. /**
  1309. * Handle a component response (received from the lib) of an earlier AMF request.
  1310. * This function should be invoked when the lib request is received.
  1311. * @param invocation [in] associates the response with the request (callback)
  1312. * @param error [in] response from the component of the associated callback
  1313. * @param retval [out] contains return value to component when needed
  1314. *
  1315. * @return ==0 respond to component, do not multicast
  1316. * @return >0 do not respond to component, multicast response
  1317. */
  1318. int amf_comp_response_1 (
  1319. SaInvocationT invocation, SaAisErrorT error, SaAisErrorT *retval,
  1320. SaUint32T *interface, SaNameT *dn)
  1321. {
  1322. int res;
  1323. void *data;
  1324. res = invocation_get_and_destroy (invocation, interface, &data);
  1325. if (res == -1) {
  1326. log_printf (LOG_ERR, "Lib response: invocation not found\n");
  1327. *retval = SA_AIS_ERR_INVALID_PARAM;
  1328. return 0;
  1329. }
  1330. switch (*interface) {
  1331. case AMF_RESPONSE_HEALTHCHECKCALLBACK: {
  1332. struct amf_healthcheck *healthcheck = data;
  1333. SaNameT name;
  1334. TRACE7 ("Healthcheck response from '%s': %d",
  1335. amf_comp_dn_make (healthcheck->comp, &name), error);
  1336. if (is_not_instantiating_or_instantiated_or_restarting(
  1337. healthcheck->comp)) {
  1338. log_printf (LOG_ERR, "HealthcheckResponse: ignored for key = %s, "
  1339. "due to wrong state = %d comp = %s",
  1340. healthcheck->safHealthcheckKey.key,
  1341. healthcheck->comp->saAmfCompPresenceState,
  1342. healthcheck->comp->name.value);
  1343. *retval = SA_AIS_OK;
  1344. return 0; /* do not multicast event */
  1345. }
  1346. if (healthcheck->invocationType == SA_AMF_HEALTHCHECK_AMF_INVOKED) {
  1347. /* the response was on time, delete supervision timer */
  1348. poll_timer_delete (aisexec_poll_handle,
  1349. healthcheck->timer_handle_duration);
  1350. healthcheck->timer_handle_duration = 0;
  1351. /* start timer to execute next healthcheck request */
  1352. poll_timer_add (aisexec_poll_handle,
  1353. healthcheck->saAmfHealthcheckPeriod,
  1354. (void *)healthcheck,
  1355. timer_function_healthcheck_next_fn,
  1356. &healthcheck->timer_handle_period);
  1357. *retval = SA_AIS_OK;
  1358. } else {
  1359. *retval = SA_AIS_ERR_INVALID_PARAM;
  1360. }
  1361. return 0; /* do not multicast event */
  1362. break;
  1363. }
  1364. case AMF_RESPONSE_CSISETCALLBACK: /* fall-through */
  1365. case AMF_RESPONSE_CSIREMOVECALLBACK:
  1366. amf_csi_assignment_dn_make (data, dn);
  1367. return 1; /* multicast event */
  1368. break;
  1369. #if 0
  1370. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: {
  1371. struct component_terminate_callback_data *component_terminate_callback_data;
  1372. component_terminate_callback_data = data;
  1373. dprintf ("Lib component terminate callback response, error: %d", error);
  1374. amf_comp_healthcheck_deactivate (component_terminate_callback_data->comp);
  1375. escalation_policy_restart (component_terminate_callback_data->comp);
  1376. return 1;
  1377. break;
  1378. }
  1379. #endif
  1380. default:
  1381. assert (0);
  1382. break;
  1383. }
  1384. /* XXX we fall here in case NDEBUG is set */
  1385. *retval = -1;
  1386. return 0;
  1387. }
  1388. /**
  1389. * Handle a component response (received from EVS) of an earlier AMF request.
  1390. * This function should be invoked when the multicast request is received.
  1391. * @param invocation [in] associates the response with the request (callback)
  1392. * @param error [in] response from the component of the associated callback
  1393. * @param retval [out] contains return value to component when needed
  1394. *
  1395. * @return component to which the response should be sent
  1396. */
  1397. struct amf_comp *amf_comp_response_2 (
  1398. SaUint32T interface, SaNameT *dn, SaAisErrorT error, SaAisErrorT *retval)
  1399. {
  1400. struct amf_csi_assignment *csi_assignment;
  1401. struct amf_comp *comp = NULL;
  1402. assert (retval != NULL);
  1403. *retval = SA_AIS_OK;
  1404. switch (interface) {
  1405. case AMF_RESPONSE_CSISETCALLBACK: {
  1406. ENTER("'%s'", dn->value);
  1407. csi_assignment = amf_csi_assignment_find (amf_cluster, dn);
  1408. assert (csi_assignment != NULL);
  1409. comp = csi_assignment->comp;
  1410. dprintf ("CSI '%s' set callback response from '%s', error: %d",
  1411. csi_assignment->csi->name.value,
  1412. csi_assignment->comp->name.value, error);
  1413. comp = csi_assignment->comp;
  1414. if (error == SA_AIS_OK) {
  1415. comp_ha_state_set (
  1416. comp, csi_assignment, csi_assignment->requested_ha_state);
  1417. } else if (error == SA_AIS_ERR_FAILED_OPERATION) {
  1418. amf_si_comp_set_ha_state_failed (csi_assignment->csi->si,
  1419. csi_assignment);
  1420. } else {
  1421. *retval = SA_AIS_ERR_INVALID_PARAM;
  1422. }
  1423. break;
  1424. }
  1425. case AMF_RESPONSE_CSIREMOVECALLBACK: {
  1426. ENTER("'%s'", dn->value);
  1427. csi_assignment = amf_csi_assignment_find (amf_cluster, dn);
  1428. assert (csi_assignment != NULL);
  1429. dprintf ("Lib csi '%s' remove callback response from '%s', error: %d",
  1430. csi_assignment->csi->name.value,
  1431. csi_assignment->comp->name.value, error);
  1432. comp = csi_assignment->comp;
  1433. if (error == SA_AIS_OK || error == SA_AIS_ERR_FAILED_OPERATION) {
  1434. amf_si_comp_csi_removed (csi_assignment->csi->si,
  1435. csi_assignment, error);
  1436. } else {
  1437. *retval = SA_AIS_ERR_INVALID_PARAM;
  1438. }
  1439. break;
  1440. }
  1441. #if 0
  1442. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: {
  1443. struct component_terminate_callback_data *callback_data = data;
  1444. dprintf ("Lib comp '%s' terminate callback response, error: %d",
  1445. callback_data->comp->name.value, error);
  1446. comp_presence_state_set (callback_data->comp,
  1447. SA_AMF_PRESENCE_UNINSTANTIATED);
  1448. break;
  1449. }
  1450. #endif
  1451. default:
  1452. assert (0);
  1453. break;
  1454. }
  1455. return comp;
  1456. }
  1457. /**
  1458. * Request a component to assume a particular HA state
  1459. * @param comp
  1460. * @param csi_assignment
  1461. * @param requested_ha_state
  1462. */
  1463. void amf_comp_hastate_set (
  1464. struct amf_comp *component,
  1465. struct amf_csi_assignment *csi_assignment)
  1466. {
  1467. ENTER ("'%s'", csi_assignment->csi->name.value);
  1468. assert (component != NULL && csi_assignment != NULL);
  1469. if (!component->error_suspected) {
  1470. lib_csi_set_request(component, csi_assignment);
  1471. } else {
  1472. if (csi_assignment->requested_ha_state == SA_AMF_HA_QUIESCED) {
  1473. csi_assignment->saAmfCSICompHAState = csi_assignment->requested_ha_state;
  1474. } else {
  1475. dprintf ("csi_assignment->requested_ha_state = %d",
  1476. component->error_suspected);
  1477. assert (0);
  1478. }
  1479. }
  1480. LEAVE("");
  1481. }
  1482. /**
  1483. * Request termination of a component
  1484. * @param comp
  1485. */
  1486. void amf_comp_terminate (struct amf_comp *comp)
  1487. {
  1488. dprintf ("comp terminate '%s'\n", getSaNameT (&comp->name));
  1489. comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATING);
  1490. if (amf_su_is_local (comp->su)) {
  1491. amf_comp_healthcheck_stop (comp, NULL);
  1492. if (comp->error_suspected) {
  1493. clc_interfaces[comp->comptype]->cleanup (comp);
  1494. } else {
  1495. clc_interfaces[comp->comptype]->terminate (comp);
  1496. }
  1497. }
  1498. }
  1499. /**
  1500. * Request restart of a component
  1501. * @param comp
  1502. */
  1503. void amf_comp_restart (struct amf_comp *comp)
  1504. {
  1505. dprintf ("comp restart '%s'\n", getSaNameT (&comp->name));
  1506. comp_presence_state_set (comp, SA_AMF_PRESENCE_RESTARTING);
  1507. comp->saAmfCompRestartCount += 1;
  1508. if (amf_su_is_local (comp->su)) {
  1509. amf_comp_healthcheck_stop (comp, NULL);
  1510. clc_interfaces[comp->comptype]->cleanup (comp);
  1511. }
  1512. }
  1513. /**
  1514. * Request to return the HA state for a components CSI
  1515. * @param comp
  1516. * @param csi_name
  1517. * @param ha_state
  1518. *
  1519. * @return SaAisErrorT
  1520. */
  1521. SaAisErrorT amf_comp_hastate_get (
  1522. struct amf_comp *comp, SaNameT *csi_name, SaAmfHAStateT *ha_state)
  1523. {
  1524. struct amf_csi_assignment *assignment;
  1525. assert (comp != NULL && csi_name != NULL && ha_state != NULL);
  1526. dprintf ("comp ha state get from comp '%s' CSI '%s'\n",
  1527. getSaNameT (&comp->name), csi_name->value);
  1528. assignment = csi_assignment_find_in (comp, csi_name);
  1529. if (assignment != NULL) {
  1530. *ha_state = assignment->saAmfCSICompHAState;
  1531. return SA_AIS_OK;
  1532. }
  1533. return SA_AIS_ERR_INVALID_PARAM;
  1534. }
  1535. /**
  1536. * Response from a component informs AMF that it has performed a healthcheck
  1537. * @param comp
  1538. * @param healthcheckKey
  1539. * @param healthcheckResult
  1540. *
  1541. * @return SaAisErrorT
  1542. */
  1543. SaAisErrorT amf_comp_healthcheck_confirm (
  1544. struct amf_comp *comp,
  1545. SaAmfHealthcheckKeyT *healthcheckKey,
  1546. SaAisErrorT healthcheckResult)
  1547. {
  1548. struct amf_healthcheck *healthcheck;
  1549. SaAisErrorT error = SA_AIS_OK;
  1550. healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey);
  1551. if (is_not_instantiating_or_instantiated_or_restarting(comp)) {
  1552. log_printf (LOG_ERR, "HealthcheckConfirm: ignored for key = %s, "
  1553. "due to wrong state = %d, comp = %s",
  1554. healthcheckKey->key, comp->saAmfCompPresenceState, comp->name.value);
  1555. error = SA_AIS_OK;
  1556. goto out;
  1557. }
  1558. if (healthcheck == NULL) {
  1559. log_printf (LOG_ERR, "Healthcheckstop: Healthcheck '%s' not found",
  1560. healthcheckKey->key);
  1561. error = SA_AIS_ERR_NOT_EXIST;
  1562. } else if (healthcheck->active) {
  1563. if (healthcheckResult == SA_AIS_OK) {
  1564. /* the response was on time, restart the supervision timer */
  1565. poll_timer_delete (aisexec_poll_handle,
  1566. healthcheck->timer_handle_period);
  1567. poll_timer_add (aisexec_poll_handle,
  1568. healthcheck->saAmfHealthcheckPeriod,
  1569. (void *)healthcheck,
  1570. timer_function_healthcheck_tmo,
  1571. &healthcheck->timer_handle_period);
  1572. } else if (healthcheckResult == SA_AIS_ERR_FAILED_OPERATION) {
  1573. /* send to cluster */
  1574. mcast_healthcheck_tmo_event (healthcheck);
  1575. } else {
  1576. error = SA_AIS_ERR_INVALID_PARAM;
  1577. }
  1578. } else {
  1579. error = SA_AIS_ERR_INVALID_PARAM;
  1580. }
  1581. out:
  1582. return error;
  1583. }
  1584. void amf_comp_init (void)
  1585. {
  1586. log_init ("AMF");
  1587. }
  1588. void amf_comp_operational_state_set (struct amf_comp *comp,
  1589. SaAmfOperationalStateT oper_state)
  1590. {
  1591. comp->saAmfCompOperState = oper_state;
  1592. TRACE1 ("Setting comp '%s', SU '%s' operational state: %s\n",
  1593. comp->name.value, comp->su->name.value,
  1594. amf_op_state (comp->saAmfCompOperState));
  1595. amf_su_comp_state_changed (
  1596. comp->su, comp, SA_AMF_OP_STATE, oper_state);
  1597. }
  1598. int amf_comp_get_saAmfCompNumCurrActiveCsi(struct amf_comp *component)
  1599. {
  1600. int cnt = 0;
  1601. struct amf_csi_assignment *csi_assignment;
  1602. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1603. while (csi_assignment != NULL) {
  1604. if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_ACTIVE) {
  1605. cnt++;
  1606. }
  1607. csi_assignment = amf_comp_get_next_csi_assignment (
  1608. component, csi_assignment);
  1609. }
  1610. return cnt;
  1611. }
  1612. int amf_comp_get_saAmfCompNumCurrStandbyCsi(struct amf_comp *component)
  1613. {
  1614. int cnt = 0;
  1615. struct amf_csi_assignment *csi_assignment;
  1616. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1617. while (csi_assignment != NULL) {
  1618. if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_STANDBY) {
  1619. cnt++;
  1620. }
  1621. csi_assignment = amf_comp_get_next_csi_assignment (
  1622. component, csi_assignment);
  1623. }
  1624. return cnt;
  1625. }
  1626. SaAmfReadinessStateT amf_comp_get_saAmfCompReadinessState (
  1627. struct amf_comp *component)
  1628. {
  1629. if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
  1630. return amf_su_get_saAmfSUReadinessState (component->su);
  1631. } else if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_DISABLED) {
  1632. return SA_AMF_READINESS_OUT_OF_SERVICE;
  1633. }
  1634. assert (0);
  1635. /* XXX we fall here in case NDEBUG is set */
  1636. return -1;
  1637. }
  1638. /**
  1639. * Component is informed that the node where the 'real'
  1640. * component process is executing has unexpectadly left the
  1641. * node. If there is a pending interaction between AMF
  1642. * (component) and the 'real' component process, then component
  1643. * will indicate to its subordinate objects the interaction
  1644. * failed. Pending presence state changes is indicated by
  1645. * reporting the new state is uninstantiated while pending csi
  1646. * operations are indicated by 'operation failed'.
  1647. * @param comp
  1648. *
  1649. * @return void
  1650. */
  1651. void amf_comp_node_left (struct amf_comp *component)
  1652. {
  1653. int change_pending = 0;
  1654. struct amf_csi_assignment *csi_assignment;
  1655. ENTER("saAmfCompPresenceState = %d", component->saAmfCompPresenceState);
  1656. component->error_suspected = 0;
  1657. if (component->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATING ||
  1658. component->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING ||
  1659. component->saAmfCompPresenceState == SA_AMF_PRESENCE_TERMINATING) {
  1660. change_pending = 1;
  1661. }
  1662. component->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  1663. if (amf_su_presence_state_all_comps_in_su_are_set (component->su,
  1664. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  1665. component->su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  1666. }
  1667. if (change_pending) {
  1668. change_pending = 0;
  1669. amf_su_comp_state_changed ( component->su,
  1670. component,
  1671. SA_AMF_PRESENCE_STATE,
  1672. SA_AMF_PRESENCE_UNINSTANTIATED);
  1673. }
  1674. if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
  1675. change_pending = 1;
  1676. }
  1677. component->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED;
  1678. if (change_pending) {
  1679. change_pending =0;
  1680. amf_su_comp_state_changed (component->su,
  1681. component,
  1682. SA_AMF_OP_STATE,
  1683. SA_AMF_OPERATIONAL_DISABLED);
  1684. }
  1685. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1686. while (csi_assignment != NULL) {
  1687. if (csi_assignment->requested_ha_state !=
  1688. csi_assignment->saAmfCSICompHAState) {
  1689. amf_si_comp_set_ha_state_failed (
  1690. csi_assignment->csi->si,csi_assignment);
  1691. }
  1692. csi_assignment = amf_comp_get_next_csi_assignment (
  1693. component, csi_assignment);
  1694. }
  1695. }
  1696. /**
  1697. * Serialize a component including variable length arrays and
  1698. * strings to a buffer returned. Buffer is to be freed by
  1699. * caller.
  1700. * @param component
  1701. * @param len
  1702. *
  1703. * @return void*
  1704. */
  1705. void *amf_comp_serialize (struct amf_comp *component, int *len)
  1706. {
  1707. char *buf = NULL;
  1708. int i, offset = 0, size = 0;
  1709. TRACE8 ("%s", component->name.value);
  1710. buf = amf_serialize_SaNameT (buf, &size, &offset, &component->name);
  1711. /* count cstypes and write to buf */
  1712. for (i = 0; component->saAmfCompCsTypes &&
  1713. component->saAmfCompCsTypes[i] != NULL; i++);
  1714. buf = amf_serialize_SaUint32T (buf, &size, &offset, i);
  1715. for (i = 0; component->saAmfCompCsTypes &&
  1716. component->saAmfCompCsTypes[i] != NULL; i++) {
  1717. buf = amf_serialize_SaNameT (
  1718. buf, &size, &offset, component->saAmfCompCsTypes[i]);
  1719. }
  1720. buf = amf_serialize_SaUint32T (
  1721. buf, &size, &offset, component->saAmfCompCategory);
  1722. buf = amf_serialize_SaUint32T (
  1723. buf, &size, &offset, component->saAmfCompCapability);
  1724. buf = amf_serialize_SaUint32T (
  1725. buf, &size, &offset, component->saAmfCompNumMaxActiveCsi);
  1726. buf = amf_serialize_SaUint32T (
  1727. buf, &size, &offset, component->saAmfCompNumMaxStandbyCsi);
  1728. /* count environment vars and write to buf */
  1729. for (i = 0; component->saAmfCompCmdEnv &&
  1730. component->saAmfCompCmdEnv[i] != NULL; i++);
  1731. buf = amf_serialize_SaUint32T (buf, &size, &offset, i);
  1732. for (i = 0; component->saAmfCompCmdEnv &&
  1733. component->saAmfCompCmdEnv[i] != NULL; i++) {
  1734. buf = amf_serialize_SaStringT (
  1735. buf, &size, &offset, component->saAmfCompCmdEnv[i]);
  1736. }
  1737. buf = amf_serialize_SaUint32T (
  1738. buf, &size, &offset, component->saAmfCompDefaultClcCliTimeout);
  1739. buf = amf_serialize_SaUint32T (
  1740. buf, &size, &offset, component->saAmfCompDefaultCallbackTimeOut);
  1741. buf = amf_serialize_SaStringT (
  1742. buf, &size, &offset, component->saAmfCompInstantiateCmd);
  1743. buf = amf_serialize_SaStringT (
  1744. buf, &size, &offset, component->saAmfCompInstantiateCmdArgv);
  1745. buf = amf_serialize_SaUint32T (
  1746. buf, &size, &offset, component->saAmfCompInstantiateTimeout);
  1747. buf = amf_serialize_SaUint32T (
  1748. buf, &size, &offset, component->saAmfCompInstantiationLevel);
  1749. buf = amf_serialize_SaUint32T (
  1750. buf, &size, &offset, component->saAmfCompNumMaxInstantiateWithoutDelay);
  1751. buf = amf_serialize_SaUint32T (
  1752. buf, &size, &offset, component->saAmfCompNumMaxInstantiateWithDelay);
  1753. buf = amf_serialize_SaUint32T (
  1754. buf, &size, &offset, component->saAmfCompDelayBetweenInstantiateAttempts);
  1755. buf = amf_serialize_SaStringT (
  1756. buf, &size, &offset, component->saAmfCompTerminateCmd);
  1757. buf = amf_serialize_SaUint32T (
  1758. buf, &size, &offset, component->saAmfCompTerminateTimeout);
  1759. buf = amf_serialize_SaStringT (
  1760. buf, &size, &offset, component->saAmfCompTerminateCmdArgv);
  1761. buf = amf_serialize_SaStringT (
  1762. buf, &size, &offset, component->saAmfCompCleanupCmd);
  1763. buf = amf_serialize_SaUint32T (
  1764. buf, &size, &offset, component->saAmfCompCleanupTimeout);
  1765. buf = amf_serialize_SaStringT (
  1766. buf, &size, &offset, component->saAmfCompCleanupCmdArgv);
  1767. buf = amf_serialize_SaStringT (
  1768. buf, &size, &offset, component->saAmfCompAmStartCmd);
  1769. buf = amf_serialize_SaUint32T (
  1770. buf, &size, &offset, component->saAmfCompAmStartTimeout);
  1771. buf = amf_serialize_SaStringT (
  1772. buf, &size, &offset, component->saAmfCompAmStartCmdArgv);
  1773. buf = amf_serialize_SaUint32T (
  1774. buf, &size, &offset, component->saAmfCompNumMaxAmStartAttempt);
  1775. buf = amf_serialize_SaStringT (
  1776. buf, &size, &offset, component->saAmfCompAmStopCmd);
  1777. buf = amf_serialize_SaUint32T (
  1778. buf, &size, &offset, component->saAmfCompAmStopTimeout);
  1779. buf = amf_serialize_SaStringT (
  1780. buf, &size, &offset, component->saAmfCompAmStopCmdArgv);
  1781. buf = amf_serialize_SaUint32T (
  1782. buf, &size, &offset, component->saAmfCompNumMaxAmStopAttempt);
  1783. buf = amf_serialize_SaUint32T (
  1784. buf, &size, &offset, component->saAmfCompTerminateCallbackTimeout);
  1785. buf = amf_serialize_SaUint32T (
  1786. buf, &size, &offset, component->saAmfCompCSISetCallbackTimeout);
  1787. buf = amf_serialize_SaUint32T (
  1788. buf, &size, &offset, component->saAmfCompQuiescingCompleteTimeout);
  1789. buf = amf_serialize_SaUint32T (
  1790. buf, &size, &offset, component->saAmfCompCSIRmvCallbackTimeout);
  1791. buf = amf_serialize_SaUint32T (
  1792. buf, &size, &offset, component->saAmfCompRecoveryOnError);
  1793. buf = amf_serialize_SaUint32T (
  1794. buf, &size, &offset, component->saAmfCompDisableRestart);
  1795. buf = amf_serialize_SaNameT (
  1796. buf, &size, &offset, &component->saAmfCompProxyCsi);
  1797. buf = amf_serialize_SaUint32T (
  1798. buf, &size, &offset, component->saAmfCompOperState);
  1799. buf = amf_serialize_SaUint32T (
  1800. buf, &size, &offset, component->saAmfCompPresenceState);
  1801. buf = amf_serialize_SaUint32T (
  1802. buf, &size, &offset, component->saAmfCompRestartCount);
  1803. buf = amf_serialize_SaNameT (
  1804. buf, &size, &offset, &component->saAmfCompCurrProxyName);
  1805. buf = amf_serialize_SaStringT (
  1806. buf, &size, &offset, component->clccli_path);
  1807. buf = amf_serialize_SaUint32T (
  1808. buf, &size, &offset, component->comptype);
  1809. buf = amf_serialize_SaUint32T (
  1810. buf, &size, &offset, component->error_suspected);
  1811. *len = offset;
  1812. return buf;
  1813. }
  1814. /**
  1815. * Deserialize a buffer into a AMF component object.
  1816. * @param su
  1817. * @param buf
  1818. * @param size
  1819. *
  1820. * @return struct amf_comp*
  1821. */
  1822. struct amf_comp *amf_comp_deserialize (struct amf_su *su, char *buf)
  1823. {
  1824. char *tmp = buf;
  1825. int i;
  1826. SaUint32T cnt;
  1827. struct amf_comp *component = amf_comp_new (su, "");
  1828. tmp = amf_deserialize_SaNameT (tmp, &component->name);
  1829. tmp = amf_deserialize_SaUint32T (tmp, &cnt);
  1830. component->saAmfCompCsTypes = amf_malloc ((cnt + 1) * sizeof (SaNameT*));
  1831. for (i = 0; i < cnt; i++) {
  1832. component->saAmfCompCsTypes[i] = amf_malloc (sizeof (SaNameT));
  1833. tmp = amf_deserialize_SaNameT (tmp, component->saAmfCompCsTypes[i]);
  1834. }
  1835. component->saAmfCompCsTypes[i] = NULL;
  1836. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompCategory);
  1837. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompCapability);
  1838. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompNumMaxActiveCsi);
  1839. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompNumMaxStandbyCsi);
  1840. tmp = amf_deserialize_SaUint32T (tmp, &cnt);
  1841. component->saAmfCompCmdEnv = amf_malloc ((cnt + 1) * sizeof (SaStringT*));
  1842. for (i = 0; i < cnt; i++) {
  1843. tmp = amf_deserialize_SaStringT (tmp, &component->saAmfCompCmdEnv[i]);
  1844. }
  1845. component->saAmfCompCmdEnv[i] = NULL;
  1846. tmp = amf_deserialize_SaUint32T (
  1847. tmp, &component->saAmfCompDefaultClcCliTimeout);
  1848. tmp = amf_deserialize_SaUint32T (
  1849. tmp, &component->saAmfCompDefaultCallbackTimeOut);
  1850. tmp = amf_deserialize_SaStringT (
  1851. tmp, &component->saAmfCompInstantiateCmd);
  1852. tmp = amf_deserialize_SaStringT (
  1853. tmp, &component->saAmfCompInstantiateCmdArgv);
  1854. tmp = amf_deserialize_SaUint32T (
  1855. tmp, &component->saAmfCompInstantiateTimeout);
  1856. tmp = amf_deserialize_SaUint32T (
  1857. tmp, &component->saAmfCompInstantiationLevel);
  1858. tmp = amf_deserialize_SaUint32T (
  1859. tmp, &component->saAmfCompNumMaxInstantiateWithoutDelay);
  1860. tmp = amf_deserialize_SaUint32T (
  1861. tmp, &component->saAmfCompNumMaxInstantiateWithDelay);
  1862. tmp = amf_deserialize_SaUint32T (
  1863. tmp, &component->saAmfCompDelayBetweenInstantiateAttempts);
  1864. tmp = amf_deserialize_SaStringT (
  1865. tmp, &component->saAmfCompTerminateCmd);
  1866. tmp = amf_deserialize_SaUint32T (
  1867. tmp, &component->saAmfCompTerminateTimeout);
  1868. tmp = amf_deserialize_SaStringT (
  1869. tmp, &component->saAmfCompTerminateCmdArgv);
  1870. tmp = amf_deserialize_SaStringT (
  1871. tmp, &component->saAmfCompCleanupCmd);
  1872. tmp = amf_deserialize_SaUint32T (
  1873. tmp, &component->saAmfCompCleanupTimeout);
  1874. tmp = amf_deserialize_SaStringT (
  1875. tmp, &component->saAmfCompCleanupCmdArgv);
  1876. tmp = amf_deserialize_SaStringT (
  1877. tmp, &component->saAmfCompAmStartCmd);
  1878. tmp = amf_deserialize_SaUint32T (
  1879. tmp, &component->saAmfCompAmStartTimeout);
  1880. tmp = amf_deserialize_SaStringT (
  1881. tmp, &component->saAmfCompAmStartCmdArgv);
  1882. tmp = amf_deserialize_SaUint32T (
  1883. tmp, &component->saAmfCompNumMaxAmStartAttempt);
  1884. tmp = amf_deserialize_SaStringT (
  1885. tmp, &component->saAmfCompAmStopCmd);
  1886. tmp = amf_deserialize_SaUint32T (
  1887. tmp, &component->saAmfCompAmStopTimeout);
  1888. tmp = amf_deserialize_SaStringT (
  1889. tmp, &component->saAmfCompAmStopCmdArgv);
  1890. tmp = amf_deserialize_SaUint32T (
  1891. tmp, &component->saAmfCompNumMaxAmStopAttempt);
  1892. tmp = amf_deserialize_SaUint32T (
  1893. tmp, &component->saAmfCompTerminateCallbackTimeout);
  1894. tmp = amf_deserialize_SaUint32T (
  1895. tmp, &component->saAmfCompCSISetCallbackTimeout);
  1896. tmp = amf_deserialize_SaUint32T (
  1897. tmp, &component->saAmfCompQuiescingCompleteTimeout);
  1898. tmp = amf_deserialize_SaUint32T (
  1899. tmp, &component->saAmfCompCSIRmvCallbackTimeout);
  1900. tmp = amf_deserialize_SaUint32T (
  1901. tmp, &component->saAmfCompRecoveryOnError);
  1902. tmp = amf_deserialize_SaUint32T (
  1903. tmp, &component->saAmfCompDisableRestart);
  1904. tmp = amf_deserialize_SaNameT (
  1905. tmp, &component->saAmfCompProxyCsi);
  1906. tmp = amf_deserialize_SaUint32T (
  1907. tmp, &component->saAmfCompOperState);
  1908. tmp = amf_deserialize_SaUint32T (
  1909. tmp, &component->saAmfCompPresenceState);
  1910. tmp = amf_deserialize_SaUint32T (
  1911. tmp, &component->saAmfCompRestartCount);
  1912. tmp = amf_deserialize_SaNameT (
  1913. tmp, &component->saAmfCompCurrProxyName);
  1914. tmp = amf_deserialize_SaStringT (
  1915. tmp, &component->clccli_path);
  1916. tmp = amf_deserialize_SaUint32T (
  1917. tmp, &component->comptype);
  1918. tmp = amf_deserialize_SaUint32T (
  1919. tmp, &component->error_suspected);
  1920. return component;
  1921. }
  1922. void *amf_healthcheck_serialize (struct amf_healthcheck *healthcheck, int *len)
  1923. {
  1924. char *buf = NULL;
  1925. int offset = 0, size = 0;
  1926. TRACE8 ("%s", healthcheck->safHealthcheckKey.key);
  1927. buf = amf_serialize_opaque (buf, &size, &offset,
  1928. &healthcheck->safHealthcheckKey.key, SA_AMF_HEALTHCHECK_KEY_MAX);
  1929. buf = amf_serialize_SaUint16T (buf, &size, &offset,
  1930. healthcheck->safHealthcheckKey.keyLen);
  1931. buf = amf_serialize_SaUint32T (buf, &size, &offset,
  1932. healthcheck->saAmfHealthcheckMaxDuration);
  1933. buf = amf_serialize_SaUint32T (buf, &size, &offset,
  1934. healthcheck->saAmfHealthcheckPeriod);
  1935. *len = offset;
  1936. return buf;
  1937. }
  1938. struct amf_healthcheck *amf_healthcheck_deserialize (
  1939. struct amf_comp *comp, char *buf)
  1940. {
  1941. char *tmp = buf;
  1942. int cnt;
  1943. amf_healthcheck_t *healthcheck = amf_healthcheck_new (comp);
  1944. tmp = amf_deserialize_opaque (tmp, &healthcheck->safHealthcheckKey.key, &cnt);
  1945. tmp = amf_deserialize_SaUint16T (tmp,
  1946. &healthcheck->safHealthcheckKey.keyLen);
  1947. tmp = amf_deserialize_SaUint32T (tmp,
  1948. &healthcheck->saAmfHealthcheckMaxDuration);
  1949. tmp = amf_deserialize_SaUint32T (tmp,
  1950. &healthcheck->saAmfHealthcheckPeriod);
  1951. return healthcheck;
  1952. }
  1953. amf_healthcheck_t *amf_healthcheck_new (struct amf_comp *comp)
  1954. {
  1955. amf_healthcheck_t *healthcheck = amf_calloc (1, sizeof (amf_healthcheck_t));
  1956. healthcheck->comp = comp;
  1957. healthcheck->next = comp->healthcheck_head;
  1958. comp->healthcheck_head = healthcheck;
  1959. return healthcheck;
  1960. }
  1961. void amf_comp_csi_remove (amf_comp_t *component,
  1962. amf_csi_assignment_t *csi_assignment)
  1963. {
  1964. struct res_lib_amf_csiremovecallback res_lib;
  1965. ENTER("");
  1966. res_lib.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  1967. res_lib.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  1968. res_lib.header.error = SA_AIS_OK;
  1969. res_lib.invocation =
  1970. invocation_create (AMF_RESPONSE_CSIREMOVECALLBACK, csi_assignment);
  1971. amf_comp_dn_make (component, &res_lib.compName);
  1972. amf_csi_dn_make (csi_assignment->csi, &res_lib.csiName);
  1973. res_lib.csiFlags = SA_AMF_CSI_TARGET_ONE;
  1974. TRACE7 ("sending CSI remove request to component %s",
  1975. res_lib.compName.value);
  1976. openais_conn_send_response (
  1977. openais_conn_partner_get (component->conn),
  1978. &res_lib, sizeof (struct res_lib_amf_csiremovecallback));
  1979. }