amfcomp.c 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491
  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. int exit_code;
  155. };
  156. struct clc_interface {
  157. int (*instantiate) (struct amf_comp *comp);
  158. int (*terminate) (struct amf_comp *comp);
  159. int (*cleanup) (struct amf_comp *comp);
  160. };
  161. struct csi_remove_callback_data {
  162. struct amf_csi *csi;
  163. };
  164. struct component_terminate_callback_data {
  165. struct amf_comp *comp;
  166. };
  167. static void comp_presence_state_set (
  168. struct amf_comp *comp,
  169. SaAmfPresenceStateT presence_state);
  170. static int clc_cli_instantiate (struct amf_comp *comp);
  171. static int clc_instantiate_callback (struct amf_comp *comp);
  172. static int clc_csi_set_callback (struct amf_comp *comp);
  173. static int clc_cli_terminate (struct amf_comp *comp);
  174. static int lib_comp_terminate_request (struct amf_comp *comp);
  175. static int clc_csi_remove_callback (struct amf_comp *comp);
  176. static int clc_cli_cleanup (struct amf_comp *comp);
  177. static int clc_cli_cleanup_local (struct amf_comp *comp);
  178. static void healthcheck_deactivate (struct amf_healthcheck *healthcheck_active);
  179. static void lib_healthcheck_request (struct amf_healthcheck *healthcheck);
  180. static void timer_function_healthcheck_tmo (void *_healthcheck);
  181. static void lib_csi_set_request (
  182. struct amf_comp *comp,
  183. struct amf_csi_assignment *csi_assignment);
  184. static void comp_recover_action (amf_comp_t *comp,
  185. SaAmfRecommendedRecoveryT recommendedRecovery);
  186. /*
  187. * Life cycle functions
  188. */
  189. static struct clc_interface clc_interface_sa_aware = {
  190. clc_cli_instantiate,
  191. lib_comp_terminate_request,
  192. clc_cli_cleanup
  193. };
  194. static struct clc_interface clc_interface_proxied_pre = {
  195. clc_instantiate_callback,
  196. lib_comp_terminate_request,
  197. clc_cli_cleanup
  198. };
  199. static struct clc_interface clc_interface_proxied_non_pre = {
  200. clc_csi_set_callback,
  201. clc_csi_remove_callback,
  202. clc_cli_cleanup_local
  203. };
  204. static struct clc_interface clc_interface_non_proxied_non_saware = {
  205. clc_cli_instantiate,
  206. clc_cli_terminate,
  207. clc_cli_cleanup_local
  208. };
  209. static struct clc_interface *clc_interfaces[4] = {
  210. &clc_interface_sa_aware,
  211. &clc_interface_proxied_pre,
  212. &clc_interface_proxied_non_pre,
  213. &clc_interface_non_proxied_non_saware
  214. };
  215. struct invocation {
  216. void *data;
  217. int interface;
  218. int active;
  219. };
  220. static struct invocation *invocation_entries = 0;
  221. static int invocation_entries_size = 0;
  222. static int is_not_instantiating_or_instantiated_or_restarting (amf_comp_t *comp)
  223. {
  224. return (!(comp->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATING ||
  225. comp->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATED ||
  226. comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING));
  227. }
  228. static int invocation_create (
  229. int interface,
  230. void *data)
  231. {
  232. struct invocation *invocation_addr = 0;
  233. struct invocation *invocation_temp;
  234. int i;
  235. int loc = 0;
  236. for (i = 0; i < invocation_entries_size; i++) {
  237. if (invocation_entries[i].active == 0) {
  238. invocation_addr = &invocation_entries[i];
  239. loc = i;
  240. break;
  241. }
  242. }
  243. if (invocation_addr == 0) {
  244. invocation_temp = (struct invocation *)realloc (invocation_entries,
  245. (invocation_entries_size + 1) * sizeof (struct invocation));
  246. if (invocation_temp == NULL) {
  247. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  248. }
  249. invocation_entries = invocation_temp;
  250. invocation_addr = &invocation_entries[invocation_entries_size];
  251. loc = invocation_entries_size;
  252. invocation_entries_size += 1;
  253. }
  254. invocation_addr->interface = interface;
  255. invocation_addr->data = data;
  256. invocation_addr->active = 1;
  257. return (loc);
  258. }
  259. static int invocation_get_and_destroy (
  260. SaUint64T invocation, unsigned int *interface, void **data)
  261. {
  262. if (invocation > invocation_entries_size) {
  263. return (-1);
  264. }
  265. if (invocation_entries[invocation].active == 0) {
  266. return (-1);
  267. }
  268. *interface = invocation_entries[invocation].interface;
  269. *data = invocation_entries[invocation].data;
  270. memset (&invocation_entries[invocation], 0, sizeof (struct invocation));
  271. return (0);
  272. }
  273. static void invocation_destroy_by_data (void *data)
  274. {
  275. int i;
  276. for (i = 0; i < invocation_entries_size; i++) {
  277. if (invocation_entries[i].data == data) {
  278. memset (&invocation_entries[i], 0,
  279. sizeof (struct invocation));
  280. break;
  281. }
  282. }
  283. }
  284. /**
  285. * Set suspected error flag and report to SU.
  286. *
  287. * @param comp
  288. * @param recommended_recovery
  289. */
  290. static void report_error_suspected (
  291. struct amf_comp *comp,
  292. SaAmfRecommendedRecoveryT recommended_recovery)
  293. {
  294. ENTER ("%s, recommended_recovery = %d",
  295. comp->name.value, recommended_recovery);
  296. amf_comp_error_suspected_set (comp);
  297. comp_recover_action (comp, recommended_recovery);
  298. }
  299. #ifndef xprintf
  300. #define xprintf(...)
  301. #endif
  302. static void *clc_command_run (void *context)
  303. {
  304. struct clc_command_run_data *clc_command_run_data =
  305. (struct clc_command_run_data *)context;
  306. clc_command_run_data->exit_code = 0;
  307. pid_t pid;
  308. int res;
  309. char **argv = NULL;
  310. char **envp = NULL;
  311. int status;
  312. char path[PATH_MAX];
  313. char *cmd = 0;
  314. char *comp_argv = 0;
  315. char comp_name[SA_MAX_NAME_LENGTH + 24];
  316. int i;
  317. int argv_size;
  318. int envp_size;
  319. ENTER_VOID();
  320. pid = fork();
  321. if (pid == -1) {
  322. fprintf (stderr, "Couldn't fork process %s\n", strerror (errno));
  323. return (0);
  324. }
  325. if (pid) {
  326. xprintf ("waiting for pid %d to finish\n", pid);
  327. waitpid (pid, &status, 0);
  328. if (WIFEXITED (status) != 0 && WEXITSTATUS(status) != 0) {
  329. fprintf (stderr, "Error: CLC_CLI (%d) failed with exit status:"
  330. " %d - %s\n", pid, WEXITSTATUS(status),
  331. strerror (WEXITSTATUS(status)));
  332. /*
  333. * Store the exit code from the script in the return data.
  334. */
  335. clc_command_run_data->exit_code = WEXITSTATUS(status);
  336. }
  337. if (WIFSIGNALED (status) != 0) {
  338. fprintf (stderr, "Error: CLC_CLI (%d) failed with exit status:"
  339. " %d\n", pid, WTERMSIG(status));
  340. /*
  341. * TODO: remove this and handle properly later...
  342. */
  343. /*
  344. * Healthcheck timout will expire laterfore the component
  345. * and this will lead to Intantiation failed for the component.
  346. */
  347. }
  348. xprintf ("process (%d) finished with %x\n", pid, status);
  349. if (clc_command_run_data->completion_callback) {
  350. clc_command_run_data->completion_callback (context);
  351. }
  352. pthread_exit(0);
  353. }
  354. switch (clc_command_run_data->type) {
  355. case CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE:
  356. cmd = clc_command_run_data->comp->saAmfCompInstantiateCmd;
  357. comp_argv = clc_command_run_data->comp->saAmfCompInstantiateCmdArgv;
  358. break;
  359. case CLC_COMMAND_RUN_OPERATION_TYPE_TERMINATE:
  360. cmd = clc_command_run_data->comp->saAmfCompTerminateCmd;
  361. comp_argv = clc_command_run_data->comp->saAmfCompTerminateCmdArgv;
  362. break;
  363. case CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP:
  364. cmd = clc_command_run_data->comp->saAmfCompCleanupCmd;
  365. comp_argv = clc_command_run_data->comp->saAmfCompCleanupCmdArgv;
  366. break;
  367. default:
  368. assert (0 != 1);
  369. break;
  370. }
  371. /* If command is not an absolute path, search for paths in parent objects */
  372. if (cmd[0] != '/') {
  373. if (clc_command_run_data->comp->clccli_path != NULL) {
  374. sprintf (path, "%s/%s",
  375. clc_command_run_data->comp->clccli_path, cmd);
  376. } else if (clc_command_run_data->comp->su->clccli_path != NULL) {
  377. sprintf (path, "%s/%s",
  378. clc_command_run_data->comp->su->clccli_path, cmd);
  379. } else if (clc_command_run_data->comp->su->sg->clccli_path != NULL) {
  380. sprintf (path, "%s/%s",
  381. clc_command_run_data->comp->su->sg->clccli_path, cmd);
  382. } else if (clc_command_run_data->comp->su->sg->application->clccli_path != NULL) {
  383. sprintf (path, "%s/%s",
  384. clc_command_run_data->comp->su->sg->application->clccli_path, cmd);
  385. }
  386. cmd = path;
  387. }
  388. argv_size = 2;
  389. argv = amf_malloc (sizeof (char*) * argv_size);
  390. argv[0] = cmd;
  391. {
  392. /* make a proper argv array */
  393. i = 1;
  394. char *ptrptr;
  395. char *arg = strtok_r(comp_argv, " ", &ptrptr);
  396. while (arg) {
  397. argv_size++;
  398. argv = realloc (argv, sizeof (char*) * argv_size);
  399. if (argv == NULL) {
  400. fprintf (stderr, "out-of-memory");
  401. exit (-1);
  402. }
  403. argv[i] = arg;
  404. arg = strtok_r(NULL, " ", &ptrptr);
  405. i++;
  406. }
  407. }
  408. argv[i] = NULL;
  409. i = snprintf (comp_name, SA_MAX_NAME_LENGTH,
  410. "SA_AMF_COMPONENT_NAME=safComp=%s,safSu=%s,safSg=%s,safApp=%s",
  411. clc_command_run_data->comp->name.value,
  412. clc_command_run_data->comp->su->name.value,
  413. clc_command_run_data->comp->su->sg->name.value,
  414. clc_command_run_data->comp->su->sg->application->name.value);
  415. assert (i <= sizeof (comp_name));
  416. /* two is for component name and NULL termination */
  417. envp_size = 2;
  418. envp = amf_malloc (sizeof (char*) * envp_size);
  419. envp[0] = comp_name;
  420. for (i = 1; clc_command_run_data->comp->saAmfCompCmdEnv &&
  421. clc_command_run_data->comp->saAmfCompCmdEnv[i - 1]; i++) {
  422. envp_size++;
  423. envp = realloc (envp, sizeof (char*) * envp_size);
  424. if (envp == NULL) {
  425. fprintf (stderr, "out-of-memory");
  426. exit (-1);
  427. }
  428. envp[i] = clc_command_run_data->comp->saAmfCompCmdEnv[i - 1];
  429. }
  430. envp[i] = NULL;
  431. xprintf ("running command '%s' with environment (%d):\n", cmd, envp_size);
  432. for (i = 0; envp[i] != NULL; i++) {
  433. xprintf (" %s\n", envp[i]);
  434. }
  435. xprintf (" and argv (%d):\n", argv_size);
  436. for (i = 0; argv[i] != NULL; i++) {
  437. xprintf (" %s\n", argv[i]);
  438. }
  439. res = execve (cmd, argv, envp);
  440. if (res == -1) {
  441. fprintf (stderr, "Couldn't exec program %s (%s)\n",
  442. cmd, strerror (errno));
  443. }
  444. exit (res); /* abnormal exit of forked process */
  445. return (0);
  446. }
  447. static void amf_comp_instantiate_tmo (void *component)
  448. {
  449. SaNameT compName;
  450. amf_comp_dn_make (component, &compName);
  451. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_COMPONENT_INSTANTIATE_TMO,
  452. &compName, sizeof (SaNameT));
  453. }
  454. static void amf_comp_cleanup_tmo (void *component)
  455. {
  456. SaNameT compName;
  457. amf_comp_dn_make (component, &compName);
  458. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_COMPONENT_CLEANUP_TMO,
  459. &compName, sizeof (SaNameT));
  460. }
  461. static void start_component_instantiate_timer (struct amf_comp *component)
  462. {
  463. ENTER("%s",component->name.value);
  464. if (component->instantiate_timeout_handle == 0) {
  465. poll_timer_add (aisexec_poll_handle,
  466. component->saAmfCompInstantiateTimeout,
  467. component,
  468. amf_comp_instantiate_tmo,
  469. &component->instantiate_timeout_handle);
  470. }
  471. }
  472. static void start_component_cleanup_timer (struct amf_comp *component)
  473. {
  474. ENTER("%s",component->name.value);
  475. if (component->cleanup_timeout_handle == 0) {
  476. poll_timer_add (aisexec_poll_handle,
  477. component->saAmfCompCleanupTimeout,
  478. component,
  479. amf_comp_cleanup_tmo,
  480. &component->cleanup_timeout_handle);
  481. }
  482. }
  483. void stop_component_cleanup_timer (struct amf_comp *component)
  484. {
  485. ENTER("%s",component->name.value);
  486. if (component->cleanup_timeout_handle != 0) {
  487. poll_timer_delete (aisexec_poll_handle,
  488. component->cleanup_timeout_handle);
  489. component->cleanup_timeout_handle = 0;
  490. }
  491. }
  492. /*
  493. * Instantiate possible operations
  494. */
  495. static int clc_cli_instantiate (struct amf_comp *comp)
  496. {
  497. int res;
  498. pthread_t thread;
  499. pthread_attr_t thread_attr; /* thread attribute */
  500. struct clc_command_run_data *clc_command_run_data;
  501. ENTER("comp '%s'\n", getSaNameT (&comp->name));
  502. clc_command_run_data = amf_malloc (sizeof (struct clc_command_run_data));
  503. clc_command_run_data->comp = comp;
  504. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_INSTANTIATE;
  505. clc_command_run_data->completion_callback = NULL;
  506. pthread_attr_init (&thread_attr);
  507. pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
  508. res = pthread_create (&thread, &thread_attr, clc_command_run,
  509. (void *)clc_command_run_data);
  510. if (res != 0) {
  511. log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res);
  512. }
  513. start_component_instantiate_timer (comp);
  514. return (res);
  515. }
  516. static int clc_instantiate_callback (struct amf_comp *comp)
  517. {
  518. ENTER("comp %s\n", getSaNameT (&comp->name));
  519. return (0);
  520. }
  521. static int clc_csi_set_callback (struct amf_comp *comp)
  522. {
  523. ENTER("comp %s\n", getSaNameT (&comp->name));
  524. return (0);
  525. }
  526. /*
  527. * Terminate possible operations
  528. */
  529. static int clc_cli_terminate (struct amf_comp *comp)
  530. {
  531. ENTER("comp %s\n", getSaNameT (&comp->name));
  532. return (0);
  533. }
  534. /**
  535. * Request component to terminate itself
  536. * @param comp
  537. *
  538. * @return int
  539. */
  540. static int lib_comp_terminate_request (struct amf_comp *comp)
  541. {
  542. struct res_lib_amf_componentterminatecallback res_lib;
  543. struct component_terminate_callback_data *component_terminate_callback_data;
  544. ENTER("comp %s\n", getSaNameT (&comp->name));
  545. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTTERMINATECALLBACK;
  546. res_lib.header.size = sizeof (struct res_lib_amf_componentterminatecallback);
  547. res_lib.header.error = SA_AIS_OK;
  548. memcpy (&res_lib.compName, &comp->name, sizeof (SaNameT));
  549. component_terminate_callback_data =
  550. amf_malloc (sizeof (struct component_terminate_callback_data));
  551. component_terminate_callback_data->comp = comp;
  552. res_lib.invocation =
  553. invocation_create (
  554. AMF_RESPONSE_COMPONENTTERMINATECALLBACK,
  555. component_terminate_callback_data);
  556. openais_conn_send_response (
  557. openais_conn_partner_get (comp->conn),
  558. &res_lib,
  559. sizeof (struct res_lib_amf_componentterminatecallback));
  560. return (0);
  561. }
  562. static int clc_csi_remove_callback (struct amf_comp *comp)
  563. {
  564. dprintf ("clc_tcsi_remove_callback\n");
  565. return (0);
  566. }
  567. /*
  568. * Clean up completed
  569. */
  570. static void mcast_cleanup_completion_event (void *context)
  571. {
  572. struct clc_command_run_data *clc_command_run_data =
  573. (struct clc_command_run_data *)context;
  574. struct req_exec_amf_clc_cleanup_completed req;
  575. struct iovec iovec;
  576. req.header.size = sizeof (struct req_exec_amf_clc_cleanup_completed);
  577. req.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  578. MESSAGE_REQ_EXEC_AMF_CLC_CLEANUP_COMPLETED);
  579. amf_comp_dn_make (clc_command_run_data->comp, &req.compName);
  580. iovec.iov_base = (char *)&req;
  581. iovec.iov_len = sizeof (req);
  582. /*
  583. * Exit code from the invoked cleanup script.
  584. */
  585. req.cleanup_exit_code = clc_command_run_data->exit_code;
  586. assert (totempg_groups_mcast_joined (openais_group_handle,
  587. &iovec, 1, TOTEMPG_AGREED) == 0);
  588. }
  589. /*
  590. * Cleanup possible operations
  591. */
  592. static int clc_cli_cleanup (struct amf_comp *comp)
  593. {
  594. int res;
  595. pthread_t thread;
  596. pthread_attr_t thread_attr; /* thread attribute */
  597. struct clc_command_run_data *clc_command_run_data;
  598. dprintf ("clc_cli_cleanup\n");
  599. clc_command_run_data = amf_malloc (sizeof (struct clc_command_run_data));
  600. clc_command_run_data->comp = comp;
  601. clc_command_run_data->type = CLC_COMMAND_RUN_OPERATION_TYPE_CLEANUP;
  602. clc_command_run_data->completion_callback = mcast_cleanup_completion_event;
  603. start_component_cleanup_timer (comp);
  604. pthread_attr_init (&thread_attr);
  605. pthread_attr_setdetachstate (&thread_attr, PTHREAD_CREATE_DETACHED);
  606. res = pthread_create (&thread, &thread_attr, clc_command_run,
  607. (void *)clc_command_run_data);
  608. if (res != 0) {
  609. log_printf (LOG_LEVEL_ERROR, "pthread_create failed: %d", res);
  610. }
  611. // TODO error code from pthread_create
  612. return (res);
  613. }
  614. static int clc_cli_cleanup_local (struct amf_comp *comp)
  615. {
  616. dprintf ("clc_cli_cleanup_local\n");
  617. return (0);
  618. }
  619. #if 0
  620. static int clc_terminate (struct amf_comp *comp)
  621. {
  622. int res;
  623. dprintf ("clc terminate for comp %s\n", getSaNameT (&comp->name));
  624. assert (0);
  625. comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATING);
  626. operational_state_comp_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  627. res = clc_interfaces[comp->comptype]->terminate (comp);
  628. return (0);
  629. }
  630. #endif
  631. char *amf_comp_dn_make (struct amf_comp *comp, SaNameT *name)
  632. {
  633. int i = snprintf ((char*) name->value, SA_MAX_NAME_LENGTH,
  634. "safComp=%s,safSu=%s,safSg=%s,safApp=%s",
  635. comp->name.value, comp->su->name.value,
  636. comp->su->sg->name.value, comp->su->sg->application->name.value);
  637. assert (i <= SA_MAX_NAME_LENGTH);
  638. name->length = i;
  639. return (char *)name->value;
  640. }
  641. struct amf_healthcheck *amf_comp_find_healthcheck (
  642. struct amf_comp *comp, SaAmfHealthcheckKeyT *key)
  643. {
  644. struct amf_healthcheck *healthcheck;
  645. struct amf_healthcheck *ret_healthcheck = 0;
  646. if (key == NULL) {
  647. return NULL;
  648. }
  649. for (healthcheck = comp->healthcheck_head;
  650. healthcheck != NULL;
  651. healthcheck = healthcheck->next) {
  652. if (key->keyLen == healthcheck->safHealthcheckKey.keyLen &&
  653. memcmp (key, &healthcheck->safHealthcheckKey,key->keyLen) == 0) {
  654. ret_healthcheck = healthcheck;
  655. break;
  656. }
  657. }
  658. return (ret_healthcheck);
  659. }
  660. /**
  661. * Constructor for component objects. Adds component last in
  662. * the list owned by the specified SU. Always returns a
  663. * valid comp object, out-of-memory problems are handled
  664. * here. Default values are initialized.
  665. * @param su
  666. * @param name
  667. *
  668. * @return struct amf_comp*
  669. */
  670. struct amf_comp *amf_comp_new(struct amf_su *su, char *name)
  671. {
  672. struct amf_comp *tail = su->comp_head;
  673. struct amf_comp *comp = amf_calloc (1, sizeof (struct amf_comp));
  674. while (tail != NULL) {
  675. if (tail->next == NULL) {
  676. break;
  677. }
  678. tail = tail->next;
  679. }
  680. if (tail == NULL) {
  681. su->comp_head = comp;
  682. } else {
  683. tail->next = comp;
  684. }
  685. comp->su = su;
  686. /* setup default values from spec. */
  687. comp->saAmfCompNumMaxInstantiateWithoutDelay = 2;
  688. comp->saAmfCompNumMaxAmStartAttempt = 2;
  689. comp->saAmfCompNumMaxAmStopAttempt = 2;
  690. comp->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED;
  691. comp->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  692. amf_comp_error_suspected_clear (comp);
  693. setSaNameT (&comp->name, name);
  694. comp->instantiate_timeout_handle = 0;
  695. comp->cleanup_timeout_handle = 0;
  696. return comp;
  697. }
  698. void amf_comp_delete (struct amf_comp *comp)
  699. {
  700. int i;
  701. struct amf_healthcheck *healthcheck;
  702. for (healthcheck = comp->healthcheck_head; healthcheck != NULL;) {
  703. struct amf_healthcheck *tmp = healthcheck;
  704. healthcheck = healthcheck->next;
  705. free (tmp);
  706. }
  707. for (i = 0; comp->saAmfCompCsTypes[i] != NULL; i++) {
  708. free (comp->saAmfCompCsTypes[i]);
  709. }
  710. for (i = 0; comp->saAmfCompCmdEnv[i] != NULL; i++) {
  711. free (comp->saAmfCompCmdEnv[i]);
  712. }
  713. free (comp->saAmfCompInstantiateCmd);
  714. free (comp->saAmfCompInstantiateCmdArgv);
  715. free (comp->saAmfCompTerminateCmd);
  716. free (comp->saAmfCompTerminateCmdArgv);
  717. free (comp->saAmfCompCleanupCmd);
  718. free (comp->saAmfCompCleanupCmdArgv);
  719. free (comp->saAmfCompAmStartCmd);
  720. free (comp->saAmfCompAmStartCmdArgv);
  721. free (comp->saAmfCompAmStopCmd);
  722. free (comp->saAmfCompAmStopCmdArgv);
  723. free (comp->clccli_path);
  724. free (comp);
  725. }
  726. struct amf_comp *amf_comp_find_from_conn_info (void *conn)
  727. {
  728. struct amf_application *app;
  729. struct amf_sg *sg;
  730. struct amf_su *su;
  731. struct amf_comp *comp = NULL;
  732. for (app = amf_cluster->application_head; app != NULL; app = app->next) {
  733. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  734. for (su = sg->su_head; su != NULL; su = su->next) {
  735. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  736. if (comp->conn == conn) {
  737. goto end;
  738. }
  739. }
  740. }
  741. }
  742. }
  743. end:
  744. return comp;
  745. }
  746. struct amf_comp *amf_comp_find (struct amf_cluster *cluster, SaNameT *name)
  747. {
  748. struct amf_application *app;
  749. struct amf_sg *sg;
  750. struct amf_su *su;
  751. struct amf_comp *comp = NULL;
  752. char *app_name;
  753. char *sg_name;
  754. char *su_name;
  755. char *comp_name;
  756. char *ptrptr;
  757. char *buf;
  758. assert (cluster != NULL && name != NULL);
  759. /* malloc new buffer since strtok_r writes to its first argument */
  760. buf = amf_malloc (name->length + 1);
  761. memcpy (buf, name->value,name ->length + 1);
  762. comp_name = strtok_r(buf, ",", &ptrptr);
  763. su_name = strtok_r(NULL, ",", &ptrptr);
  764. sg_name = strtok_r(NULL, ",", &ptrptr);
  765. app_name = strtok_r(NULL, ",", &ptrptr);
  766. if (comp_name == NULL || su_name == NULL ||
  767. sg_name == NULL || app_name == NULL) {
  768. goto end;
  769. }
  770. comp_name += 8;
  771. su_name += 6;
  772. sg_name += 6;
  773. app_name += 7;
  774. app = amf_application_find (cluster, app_name);
  775. if (app == NULL) {
  776. goto end;
  777. }
  778. sg = amf_sg_find (app, sg_name);
  779. if (sg == NULL) {
  780. goto end;
  781. }
  782. for (su = sg->su_head; su != NULL; su = su->next) {
  783. if (strncmp (su_name, (char*)su->name.value, su->name.length) == 0) {
  784. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  785. if (comp->name.length == strlen(comp_name) &&
  786. strncmp (comp_name, (char*)comp->name.value,
  787. comp->name.length) == 0) {
  788. goto end;
  789. }
  790. }
  791. }
  792. }
  793. end:
  794. free (buf);
  795. return comp;
  796. }
  797. void amf_comp_healthcheck_deactivate (struct amf_comp *comp)
  798. {
  799. struct amf_healthcheck *healthcheck;
  800. if (!amf_su_is_local (comp->su))
  801. return;
  802. ENTER ("'%s'\n", getSaNameT (&comp->name));
  803. for (healthcheck = comp->healthcheck_head;
  804. healthcheck != NULL;
  805. healthcheck = healthcheck->next) {
  806. if (healthcheck->active) {
  807. healthcheck_deactivate (healthcheck);
  808. }
  809. }
  810. }
  811. static void comp_ha_state_set ( struct amf_comp *comp,
  812. struct amf_csi_assignment *csi_assignment,
  813. SaAmfHAStateT ha_state)
  814. {
  815. /* set confirmed HA state */
  816. csi_assignment->saAmfCSICompHAState = ha_state;
  817. TRACE1 ("Setting comp '%s', SU '%s' CSI '%s', HA state: %s\n",
  818. comp->name.value, comp->su->name.value,
  819. csi_assignment->csi->name.value,
  820. amf_ha_state (csi_assignment->saAmfCSICompHAState));
  821. amf_si_comp_set_ha_state_done (csi_assignment->csi->si, csi_assignment);
  822. }
  823. static void comp_presence_state_set (struct amf_comp *comp,
  824. SaAmfPresenceStateT presence_state)
  825. {
  826. comp->saAmfCompPresenceState = presence_state;
  827. TRACE1 ("Setting comp '%s', SU '%s' presence state: %s\n",
  828. comp->name.value, comp->su->name.value,
  829. amf_presence_state (comp->saAmfCompPresenceState));
  830. amf_su_comp_state_changed (
  831. comp->su, comp, SA_AMF_PRESENCE_STATE, presence_state);
  832. }
  833. struct amf_csi_assignment *amf_comp_get_next_csi_assignment (
  834. struct amf_comp *component,
  835. const struct amf_csi_assignment *csi_assignment)
  836. {
  837. struct amf_si *si;
  838. struct amf_csi *csi;
  839. struct amf_csi_assignment *tmp_csi_assignment;
  840. SaNameT dn;
  841. amf_comp_dn_make (component, &dn);
  842. if (csi_assignment == NULL) {
  843. si = component->su->sg->application->si_head;
  844. csi = si->csi_head;
  845. tmp_csi_assignment = csi->assigned_csis;
  846. } else {
  847. tmp_csi_assignment = csi_assignment->next;
  848. if (tmp_csi_assignment == NULL) {
  849. csi = csi_assignment->csi->next;
  850. if (csi == NULL) {
  851. si = csi_assignment->csi->si->next;
  852. if (si == NULL) {
  853. return NULL;
  854. } else {
  855. csi = si->csi_head;
  856. tmp_csi_assignment = csi->assigned_csis;
  857. }
  858. } else {
  859. si = csi->si;
  860. tmp_csi_assignment = csi->assigned_csis;
  861. }
  862. } else {
  863. csi = tmp_csi_assignment->csi;
  864. si = csi->si;
  865. }
  866. }
  867. for (; si != NULL; si = si->next) {
  868. if (tmp_csi_assignment == NULL && csi == NULL && si != NULL) {
  869. csi = si->csi_head;
  870. tmp_csi_assignment = csi->assigned_csis;
  871. }
  872. for (; csi != NULL; csi = csi->next) {
  873. if (tmp_csi_assignment == NULL && csi != NULL) {
  874. tmp_csi_assignment = csi->assigned_csis;
  875. }
  876. for (; tmp_csi_assignment != NULL;
  877. tmp_csi_assignment = tmp_csi_assignment->next) {
  878. if (name_match (&tmp_csi_assignment->name, &dn)) {
  879. return tmp_csi_assignment;
  880. }
  881. }
  882. }
  883. }
  884. return NULL;
  885. }
  886. void amf_comp_foreach_csi_assignment (
  887. struct amf_comp *component,
  888. void (*foreach_fn) (struct amf_comp *component,
  889. struct amf_csi_assignment *csi_assignment))
  890. {
  891. struct amf_csi_assignment *csi_assignment;
  892. assert (foreach_fn != NULL);
  893. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  894. while (csi_assignment != NULL) {
  895. foreach_fn (component, csi_assignment);
  896. csi_assignment = amf_comp_get_next_csi_assignment (
  897. component, csi_assignment);
  898. }
  899. }
  900. static struct amf_csi_assignment *csi_assignment_find_in (
  901. struct amf_comp *component, SaNameT *csi_name)
  902. {
  903. struct amf_csi_assignment *csi_assignment;
  904. SaNameT dn;
  905. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  906. while (csi_assignment != NULL) {
  907. amf_csi_dn_make (csi_assignment->csi, &dn);
  908. if (name_match (csi_name, &dn)) {
  909. return csi_assignment;
  910. }
  911. csi_assignment = amf_comp_get_next_csi_assignment (
  912. component, csi_assignment);
  913. }
  914. return NULL;
  915. }
  916. static void healthcheck_deactivate (
  917. struct amf_healthcheck *healthcheck_active)
  918. {
  919. dprintf ("deactivating healthcheck for component %s\n",
  920. getSaNameT (&healthcheck_active->comp->name));
  921. poll_timer_delete (aisexec_poll_handle,
  922. healthcheck_active->timer_handle_period);
  923. poll_timer_delete (aisexec_poll_handle,
  924. healthcheck_active->timer_handle_duration);
  925. invocation_destroy_by_data ((void *)healthcheck_active);
  926. healthcheck_active->active = 0;
  927. }
  928. /**
  929. * This function is called by the timer subsystem when AMF should request
  930. * a new healthcheck from a component.
  931. * @param data
  932. */
  933. static void timer_function_healthcheck_next_fn (void *_healthcheck)
  934. {
  935. struct amf_healthcheck *healthcheck = _healthcheck;
  936. /* send healthcheck request to component */
  937. lib_healthcheck_request (healthcheck);
  938. /* start duration timer for response */
  939. poll_timer_add (aisexec_poll_handle,
  940. healthcheck->saAmfHealthcheckMaxDuration,
  941. (void *)healthcheck,
  942. timer_function_healthcheck_tmo,
  943. &healthcheck->timer_handle_duration);
  944. }
  945. /**
  946. * Multicast a healthcheck timeout event.
  947. * @param healthcheck
  948. */
  949. static void mcast_healthcheck_tmo_event (
  950. struct amf_healthcheck *healthcheck)
  951. {
  952. struct req_exec_amf_healthcheck_tmo req_exec;
  953. struct iovec iovec;
  954. if (healthcheck->active == 0) {
  955. log_printf (LOG_ERR, "Healthcheck timeout: ignored key = %s, "
  956. "due to wrong state = %d, comp = %s",
  957. healthcheck->safHealthcheckKey.key,
  958. healthcheck->comp->saAmfCompPresenceState,
  959. healthcheck->comp->name.value);
  960. goto out;
  961. }
  962. req_exec.header.size = sizeof (struct req_exec_amf_healthcheck_tmo);
  963. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  964. MESSAGE_REQ_EXEC_AMF_HEALTHCHECK_TMO);
  965. amf_comp_dn_make (healthcheck->comp, &req_exec.compName);
  966. memcpy (&req_exec.safHealthcheckKey,
  967. &healthcheck->safHealthcheckKey, sizeof (SaAmfHealthcheckKeyT));
  968. req_exec.recommendedRecovery = healthcheck->recommendedRecovery;
  969. iovec.iov_base = (char *)&req_exec;
  970. iovec.iov_len = sizeof (req_exec);
  971. assert (totempg_groups_mcast_joined (openais_group_handle,
  972. &iovec, 1, TOTEMPG_AGREED) == 0);
  973. out:
  974. return;
  975. }
  976. /**
  977. * This function is called by the timer subsystem when a component has not
  978. * performed a healthcheck on time.
  979. * The event is multicasted to the cluster.
  980. * @param data
  981. */
  982. static void timer_function_healthcheck_tmo (
  983. void *_healthcheck)
  984. {
  985. struct amf_healthcheck *healthcheck = (struct amf_healthcheck *)_healthcheck;
  986. TRACE2 ("timeout occured on healthcheck for component %s.\n",
  987. getSaNameT (&healthcheck->comp->name));
  988. mcast_healthcheck_tmo_event (healthcheck);
  989. }
  990. static void lib_healthcheck_request (struct amf_healthcheck *healthcheck)
  991. {
  992. struct res_lib_amf_healthcheckcallback res_lib;
  993. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKCALLBACK;
  994. res_lib.header.size = sizeof (struct res_lib_amf_healthcheckcallback);
  995. res_lib.header.error = SA_AIS_OK;
  996. res_lib.invocation =
  997. invocation_create (AMF_RESPONSE_HEALTHCHECKCALLBACK, healthcheck);
  998. amf_comp_dn_make (healthcheck->comp, &res_lib.compName);
  999. memcpy (&res_lib.key, &healthcheck->safHealthcheckKey,
  1000. sizeof (SaAmfHealthcheckKeyT));
  1001. TRACE7 ("sending healthcheck request to component %s",
  1002. res_lib.compName.value);
  1003. openais_conn_send_response (
  1004. openais_conn_partner_get (healthcheck->comp->conn),
  1005. &res_lib, sizeof (struct res_lib_amf_healthcheckcallback));
  1006. }
  1007. static void lib_csi_set_request (
  1008. struct amf_comp *comp,
  1009. struct amf_csi_assignment *csi_assignment)
  1010. {
  1011. struct res_lib_amf_csisetcallback* res_lib;
  1012. void* p;
  1013. struct amf_csi_attribute *attribute;
  1014. size_t char_length_of_csi_attrs=0;
  1015. size_t num_of_csi_attrs=0;
  1016. int i;
  1017. struct amf_csi *csi;
  1018. char* csi_attribute_buf;
  1019. unsigned int byte_offset;
  1020. if (!amf_su_is_local (comp->su))
  1021. return;
  1022. csi = csi_assignment->csi;
  1023. ENTER ("Assigning CSI '%s' state %s to comp '%s'\n",
  1024. getSaNameT (&csi->name),
  1025. amf_ha_state (csi_assignment->requested_ha_state),
  1026. comp->name.value);
  1027. for (attribute = csi->attributes_head;
  1028. attribute != NULL;
  1029. attribute = attribute->next) {
  1030. for (i = 0; attribute->value[i] != NULL; i++) {
  1031. num_of_csi_attrs++;
  1032. char_length_of_csi_attrs += strlen(attribute->name);
  1033. char_length_of_csi_attrs += strlen(attribute->value[i]);
  1034. char_length_of_csi_attrs += 2;
  1035. }
  1036. }
  1037. p = amf_malloc(sizeof(struct res_lib_amf_csisetcallback) +
  1038. char_length_of_csi_attrs);
  1039. res_lib = (struct res_lib_amf_csisetcallback*)p;
  1040. /* Address of the buffer containing the Csi name value pair */
  1041. csi_attribute_buf = res_lib->csi_attr_buf;
  1042. /* Byteoffset start at the zero byte */
  1043. byte_offset = 0;
  1044. for (attribute = csi->attributes_head;
  1045. attribute != NULL;
  1046. attribute = attribute->next) {
  1047. for (i = 0; attribute->value[i] != NULL; i++) {
  1048. strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->name);
  1049. byte_offset += strlen(attribute->name) + 1;
  1050. strcpy(&csi_attribute_buf[byte_offset], (char*)attribute->value[i]);
  1051. byte_offset += strlen(attribute->value[i]) + 1;
  1052. }
  1053. }
  1054. res_lib->number = num_of_csi_attrs;
  1055. res_lib->csiFlags = SA_AMF_CSI_ADD_ONE;
  1056. switch (csi_assignment->requested_ha_state) {
  1057. case SA_AMF_HA_ACTIVE: {
  1058. res_lib->csiStateDescriptor.activeDescriptor.activeCompName.length = 0;
  1059. res_lib->csiStateDescriptor.activeDescriptor.transitionDescriptor =
  1060. SA_AMF_CSI_NEW_ASSIGN;
  1061. break;
  1062. }
  1063. case SA_AMF_HA_STANDBY: {
  1064. res_lib->csiStateDescriptor.standbyDescriptor.activeCompName.length = 0;
  1065. res_lib->csiStateDescriptor.standbyDescriptor.standbyRank = 1;
  1066. break;
  1067. }
  1068. case SA_AMF_HA_QUIESCED: {
  1069. /*TODO*/
  1070. break;
  1071. }
  1072. case SA_AMF_HA_QUIESCING: {
  1073. /*TODO*/
  1074. break;
  1075. }
  1076. default: {
  1077. assert(SA_AMF_HA_ACTIVE||SA_AMF_HA_STANDBY||SA_AMF_HA_QUIESCING||SA_AMF_HA_QUIESCED);
  1078. break;
  1079. }
  1080. }
  1081. res_lib->header.id = MESSAGE_RES_AMF_CSISETCALLBACK;
  1082. res_lib->header.size =
  1083. sizeof (struct res_lib_amf_csisetcallback) +
  1084. char_length_of_csi_attrs;
  1085. res_lib->header.error = SA_AIS_OK;
  1086. amf_comp_dn_make (comp, &res_lib->compName);
  1087. amf_csi_dn_make (csi, &res_lib->csiName);
  1088. res_lib->haState = csi_assignment->requested_ha_state;
  1089. res_lib->invocation =
  1090. invocation_create (AMF_RESPONSE_CSISETCALLBACK, csi_assignment);
  1091. openais_conn_send_response (
  1092. openais_conn_partner_get (comp->conn), res_lib, res_lib->header.size);
  1093. free(p);
  1094. }
  1095. static void stop_component_instantiate_timer (struct amf_comp *component)
  1096. {
  1097. ENTER("%s",component->name.value);
  1098. if (component->instantiate_timeout_handle) {
  1099. dprintf ("Stop component instantiate timer");
  1100. poll_timer_delete (aisexec_poll_handle,
  1101. component->instantiate_timeout_handle);
  1102. component->instantiate_timeout_handle = 0;
  1103. }
  1104. }
  1105. SaAisErrorT amf_comp_register (struct amf_comp *comp)
  1106. {
  1107. TRACE2("Exec comp register '%s'", comp->name.value);
  1108. stop_component_instantiate_timer (comp);
  1109. switch (comp->saAmfCompPresenceState) {
  1110. case SA_AMF_PRESENCE_RESTARTING:
  1111. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATED);
  1112. break;
  1113. case SA_AMF_PRESENCE_INSTANTIATING:
  1114. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_ENABLED);
  1115. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATED);
  1116. break;
  1117. case SA_AMF_PRESENCE_INSTANTIATION_FAILED:
  1118. /* ignore due to instantitate timeout a while ago */
  1119. break;
  1120. default:
  1121. log_printf(LOG_LEVEL_ERROR,"comp->saAmfCompPresenceState = %d",
  1122. comp->saAmfCompPresenceState);
  1123. assert (0);
  1124. break;
  1125. }
  1126. return SA_AIS_OK;
  1127. }
  1128. void amf_comp_error_report (struct amf_comp *comp, amf_comp_t* reporting_comp,
  1129. SaAmfRecommendedRecoveryT recommendedRecovery)
  1130. {
  1131. struct res_lib_amf_componenterrorreport res_lib;
  1132. TRACE2("Exec comp error report on comp'%s' from %s", comp->name.value,
  1133. reporting_comp->name.value );
  1134. if (amf_su_is_local (reporting_comp->su)) {
  1135. res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  1136. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  1137. res_lib.header.error = SA_AIS_OK;
  1138. openais_conn_send_response (reporting_comp->conn, &res_lib, sizeof (res_lib));
  1139. }
  1140. /* Report to SU and let it handle the problem */
  1141. report_error_suspected (comp, recommendedRecovery);
  1142. }
  1143. /**
  1144. * Healthcheck timeout event handler
  1145. * @param comp
  1146. * @param healthcheck
  1147. */
  1148. void amf_comp_healthcheck_tmo (
  1149. struct amf_comp *comp, SaAmfRecommendedRecoveryT recommendedRecovery)
  1150. {
  1151. TRACE2("Exec healthcheck tmo for '%s'", comp->name.value);
  1152. /* report to SU and let it handle the problem */
  1153. report_error_suspected (comp, recommendedRecovery);
  1154. }
  1155. static void clear_ha_state (
  1156. struct amf_comp *comp, struct amf_csi_assignment *csi_assignment)
  1157. {
  1158. ENTER ("");
  1159. csi_assignment->saAmfCSICompHAState = 0;
  1160. }
  1161. static void comp_recover_action (amf_comp_t *comp,
  1162. SaAmfRecommendedRecoveryT recommendedRecovery)
  1163. {
  1164. ENTER ("%s %d %d", comp->name.value,recommendedRecovery,
  1165. comp->saAmfCompRecoveryOnError);
  1166. amf_node_t *node = amf_node_find (&comp->su->saAmfSUHostedByNode);
  1167. switch (recommendedRecovery) {
  1168. case SA_AMF_NO_RECOMMENDATION: {
  1169. /*
  1170. * If the recommendation was SA_AMF_NO_RECOMMENDATION,
  1171. * then use the configured recovery action for the component
  1172. */
  1173. switch (comp->saAmfCompRecoveryOnError) {
  1174. case SA_AMF_NO_RECOMMENDATION:
  1175. if (comp->saAmfCompDisableRestart) {
  1176. /* Comp or SU failover */
  1177. amf_node_comp_failover_req (node, comp);
  1178. } else {
  1179. /* Component restart */
  1180. amf_su_comp_error_suspected (comp->su, comp,
  1181. recommendedRecovery);
  1182. }
  1183. case SA_AMF_COMPONENT_RESTART:
  1184. if (comp->saAmfCompDisableRestart) {
  1185. /* Comp or SU failover */
  1186. amf_node_comp_failover_req (node, comp);
  1187. } else {
  1188. /* Component restart */
  1189. amf_su_comp_error_suspected (comp->su, comp,
  1190. recommendedRecovery);
  1191. }
  1192. break;
  1193. case SA_AMF_COMPONENT_FAILOVER:
  1194. /* SU failover */
  1195. amf_node_comp_failover_req (node, comp);
  1196. break;
  1197. case SA_AMF_NODE_SWITCHOVER:
  1198. break;
  1199. case SA_AMF_NODE_FAILOVER: {
  1200. /* Node failover */
  1201. amf_node_t *node = amf_node_find (
  1202. &comp->su->saAmfSUHostedByNode);
  1203. amf_node_failover(node);
  1204. }
  1205. break;
  1206. case SA_AMF_NODE_FAILFAST:
  1207. break;
  1208. case SA_AMF_CLUSTER_RESET:
  1209. break;
  1210. case SA_AMF_APPLICATION_RESTART:
  1211. default:
  1212. dprintf("recommendedRecovery=%d",recommendedRecovery);
  1213. assert (0);
  1214. break;
  1215. }
  1216. break;
  1217. }
  1218. case SA_AMF_COMPONENT_RESTART:
  1219. if (comp->saAmfCompDisableRestart == SA_TRUE) {
  1220. amf_node_comp_failover_req (node, comp);
  1221. } else {
  1222. amf_su_comp_error_suspected (comp->su, comp, recommendedRecovery);
  1223. }
  1224. break;
  1225. case SA_AMF_COMPONENT_FAILOVER:
  1226. amf_node_comp_failover_req (node, comp);
  1227. break;
  1228. case SA_AMF_NODE_SWITCHOVER:
  1229. break;
  1230. case SA_AMF_NODE_FAILOVER:
  1231. /* Node failover */
  1232. amf_node_failover (amf_node_find (&comp->su->saAmfSUHostedByNode));
  1233. break;
  1234. case SA_AMF_NODE_FAILFAST:
  1235. break;
  1236. case SA_AMF_CLUSTER_RESET:
  1237. break;
  1238. case SA_AMF_APPLICATION_RESTART:
  1239. default:
  1240. assert (0);
  1241. break;
  1242. }
  1243. }
  1244. /**
  1245. * Event method to be called when a cleanup completed event is received
  1246. * with failure.
  1247. * @param comp
  1248. */
  1249. void amf_comp_cleanup_failed_completed (amf_comp_t *comp)
  1250. {
  1251. ENTER ("'%s'", comp->name.value);
  1252. stop_component_cleanup_timer (comp);
  1253. amf_comp_error_suspected_clear (comp);
  1254. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  1255. comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATION_FAILED);
  1256. }
  1257. /**
  1258. * Event method to be called when a cleanup completed event is received
  1259. * @param comp
  1260. */
  1261. void amf_comp_cleanup_completed (struct amf_comp *comp)
  1262. {
  1263. TRACE2("Exec CLC cleanup completed for '%s'", comp->name.value);
  1264. stop_component_cleanup_timer (comp);
  1265. /* Set all CSI's confirmed HA state to unknown */
  1266. amf_comp_foreach_csi_assignment (comp, clear_ha_state);
  1267. amf_comp_error_suspected_clear (comp);
  1268. if (comp->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING) {
  1269. amf_comp_instantiate (comp);
  1270. } else {
  1271. comp_presence_state_set (comp, SA_AMF_PRESENCE_UNINSTANTIATED);
  1272. }
  1273. }
  1274. /**
  1275. * Handle the request from a component to start a healthcheck
  1276. *
  1277. * @param comp
  1278. * @param healthcheckKey
  1279. * @param invocationType
  1280. * @param recommendedRecovery
  1281. *
  1282. * @return SaAisErrorT - return value to component
  1283. */
  1284. SaAisErrorT amf_comp_healthcheck_start (
  1285. struct amf_comp *comp,
  1286. SaAmfHealthcheckKeyT *healthcheckKey,
  1287. SaAmfHealthcheckInvocationT invocationType,
  1288. SaAmfRecommendedRecoveryT recommendedRecovery)
  1289. {
  1290. struct amf_healthcheck *healthcheck;
  1291. SaAisErrorT error = SA_AIS_OK;
  1292. if (is_not_instantiating_or_instantiated_or_restarting (comp)) {
  1293. log_printf (LOG_ERR, "Healthcheckstart: ignored key = %s, "
  1294. "due to wrong state = %d, comp = %s",
  1295. healthcheckKey->key, comp->saAmfCompPresenceState, comp->name.value);
  1296. error = SA_AIS_OK;
  1297. goto error_exit;
  1298. }
  1299. healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey);
  1300. if (healthcheck == 0) {
  1301. log_printf (LOG_ERR, "Healthcheckstart: Healthcheck '%s' not found",
  1302. healthcheckKey->key);
  1303. error = SA_AIS_ERR_NOT_EXIST;
  1304. goto error_exit;
  1305. }
  1306. dprintf ("Healthcheckstart: '%s', key '%s'",
  1307. comp->name.value, healthcheckKey->key);
  1308. /*
  1309. * Determine if this healthcheck is already active
  1310. */
  1311. if (healthcheck->active) {
  1312. error = SA_AIS_ERR_EXIST;
  1313. goto error_exit;
  1314. }
  1315. /*
  1316. * Initialise
  1317. */
  1318. healthcheck->invocationType = invocationType;
  1319. healthcheck->recommendedRecovery = recommendedRecovery;
  1320. healthcheck->timer_handle_duration = 0;
  1321. healthcheck->timer_handle_period = 0;
  1322. healthcheck->active = 1;
  1323. if (invocationType == SA_AMF_HEALTHCHECK_AMF_INVOKED) {
  1324. /* start timer to execute first healthcheck request */
  1325. poll_timer_add (aisexec_poll_handle,
  1326. healthcheck->saAmfHealthcheckPeriod,
  1327. (void *)healthcheck,
  1328. timer_function_healthcheck_next_fn,
  1329. &healthcheck->timer_handle_period);
  1330. } else if (invocationType == SA_AMF_HEALTHCHECK_COMPONENT_INVOKED) {
  1331. /* start supervision timer */
  1332. poll_timer_add (aisexec_poll_handle,
  1333. healthcheck->saAmfHealthcheckPeriod,
  1334. (void *)healthcheck,
  1335. timer_function_healthcheck_tmo,
  1336. &healthcheck->timer_handle_period);
  1337. } else {
  1338. error = SA_AIS_ERR_INVALID_PARAM;
  1339. }
  1340. error_exit:
  1341. return error;
  1342. }
  1343. /**
  1344. * Stop all or a specifed healthcheck
  1345. * @param comp
  1346. * @param healthcheckKey - NULL if all
  1347. *
  1348. * @return SaAisErrorT
  1349. */
  1350. SaAisErrorT amf_comp_healthcheck_stop (
  1351. struct amf_comp *comp,
  1352. SaAmfHealthcheckKeyT *healthcheckKey)
  1353. {
  1354. struct amf_healthcheck *healthcheck;
  1355. SaAisErrorT error = SA_AIS_OK;
  1356. dprintf ("Healthcheckstop: '%s'", comp->name.value);
  1357. if (!amf_su_is_local (comp->su)) {
  1358. return SA_AIS_OK;
  1359. }
  1360. if (healthcheckKey == NULL) {
  1361. for (healthcheck = comp->healthcheck_head;
  1362. healthcheck != NULL;
  1363. healthcheck = healthcheck->next) {
  1364. healthcheck_deactivate (healthcheck);
  1365. }
  1366. } else {
  1367. healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey);
  1368. if (healthcheck == NULL) {
  1369. log_printf (LOG_ERR, "Healthcheckstop: Healthcheck '%s' not found",
  1370. healthcheckKey->key);
  1371. error = SA_AIS_ERR_NOT_EXIST;
  1372. } else {
  1373. healthcheck_deactivate (healthcheck);
  1374. }
  1375. }
  1376. return error;
  1377. }
  1378. /**
  1379. * Instantiate a component
  1380. * @param comp
  1381. */
  1382. void amf_comp_instantiate (struct amf_comp *comp)
  1383. {
  1384. ENTER ("'%s' SU '%s'", getSaNameT (&comp->name),
  1385. getSaNameT (&comp->su->name));
  1386. switch (comp->saAmfCompPresenceState) {
  1387. case SA_AMF_PRESENCE_RESTARTING:
  1388. /* fall through */
  1389. case SA_AMF_PRESENCE_UNINSTANTIATED:
  1390. if (amf_su_is_local (comp->su)) {
  1391. TRACE1("Send instantiate event for comp '%s' from host %s",
  1392. comp->name.value, comp->su->saAmfSUHostedByNode.value);
  1393. SaNameT compName;
  1394. amf_comp_dn_make (comp, &compName);
  1395. amf_msg_mcast (MESSAGE_REQ_EXEC_AMF_COMPONENT_INSTANTIATE,
  1396. &compName, sizeof (SaNameT));
  1397. }
  1398. break;
  1399. default:
  1400. dprintf("Instantiate ignored in Component presence state %d",
  1401. comp->saAmfCompPresenceState);
  1402. break;
  1403. }
  1404. }
  1405. void amf_comp_cleanup_tmo_event (struct amf_comp *comp)
  1406. {
  1407. ENTER ("Comp cleanup timeout after %d ms '%s' '%s'",
  1408. comp->saAmfCompCleanupTimeout, comp->su->name.value,
  1409. comp->name.value);
  1410. amf_comp_error_suspected_clear(comp);
  1411. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  1412. comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATION_FAILED);
  1413. }
  1414. void amf_comp_instantiate_tmo_event (struct amf_comp *comp)
  1415. {
  1416. ENTER ("Comp instantiate timeout after %d ms '%s' '%s'",
  1417. comp->saAmfCompInstantiateTimeout, comp->su->name.value,
  1418. comp->name.value);
  1419. switch (comp->saAmfCompPresenceState) {
  1420. case SA_AMF_PRESENCE_RESTARTING:
  1421. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  1422. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATION_FAILED);
  1423. break;
  1424. case SA_AMF_PRESENCE_INSTANTIATING:
  1425. amf_comp_operational_state_set (comp, SA_AMF_OPERATIONAL_DISABLED);
  1426. comp_presence_state_set (comp, SA_AMF_PRESENCE_INSTANTIATION_FAILED);
  1427. break;
  1428. case SA_AMF_PRESENCE_INSTANTIATED:
  1429. assert (comp->instantiate_timeout_handle == 0);
  1430. break;
  1431. default:
  1432. dprintf("Presence state = %d", comp->saAmfCompPresenceState);
  1433. assert (0);
  1434. break;
  1435. }
  1436. }
  1437. void amf_comp_instantiate_event (struct amf_comp *component)
  1438. {
  1439. int res;
  1440. ENTER ("");
  1441. switch (component->saAmfCompPresenceState) {
  1442. case SA_AMF_PRESENCE_INSTANTIATING:
  1443. case SA_AMF_PRESENCE_INSTANTIATED:
  1444. case SA_AMF_PRESENCE_TERMINATING:
  1445. case SA_AMF_PRESENCE_INSTANTIATION_FAILED:
  1446. case SA_AMF_PRESENCE_TERMINATION_FAILED:
  1447. dprintf("Instantiate ignored in Component presence state %d",
  1448. component->saAmfCompPresenceState);
  1449. break;
  1450. case SA_AMF_PRESENCE_UNINSTANTIATED:
  1451. comp_presence_state_set (component, SA_AMF_PRESENCE_INSTANTIATING);
  1452. amf_su_comp_state_changed(component->su,
  1453. component,SA_AMF_PRESENCE_STATE,SA_AMF_PRESENCE_INSTANTIATING);
  1454. if (amf_su_is_local (component->su)) {
  1455. res = clc_interfaces[component->comptype]->instantiate (
  1456. component);
  1457. }
  1458. break;
  1459. case SA_AMF_PRESENCE_RESTARTING:
  1460. if (amf_su_is_local (component->su)) {
  1461. res = clc_interfaces[component->comptype]->instantiate (
  1462. component);
  1463. }
  1464. break;
  1465. default:
  1466. dprintf("Component presence state %d",
  1467. component->saAmfCompPresenceState);
  1468. assert (0);
  1469. break;
  1470. }
  1471. }
  1472. void amf_comp_readiness_state_set (struct amf_comp *comp,
  1473. SaAmfReadinessStateT state)
  1474. {
  1475. TRACE1 ("Setting comp '%s' readiness state: %s\n",
  1476. comp->name.value, amf_readiness_state (state));
  1477. }
  1478. /**
  1479. * Handle a component response (received from the lib) of an earlier AMF request.
  1480. * This function should be invoked when the lib request is received.
  1481. * @param invocation [in] associates the response with the request (callback)
  1482. * @param error [in] response from the component of the associated callback
  1483. * @param retval [out] contains return value to component when needed
  1484. *
  1485. * @return ==0 respond to component, do not multicast
  1486. * @return >0 do not respond to component, multicast response
  1487. */
  1488. int amf_comp_response_1 (
  1489. SaInvocationT invocation, SaAisErrorT error, SaAisErrorT *retval,
  1490. SaUint32T *interface, SaNameT *dn, SaAmfHealthcheckKeyT *healtcheck_key,
  1491. SaAmfRecommendedRecoveryT *recommendedRecovery)
  1492. {
  1493. int res;
  1494. void *data;
  1495. res = invocation_get_and_destroy (invocation, interface, &data);
  1496. if (res == -1) {
  1497. log_printf (LOG_ERR, "Lib response: invocation not found\n");
  1498. *retval = SA_AIS_ERR_INVALID_PARAM;
  1499. return 0;
  1500. }
  1501. switch (*interface) {
  1502. case AMF_RESPONSE_HEALTHCHECKCALLBACK: {
  1503. struct amf_healthcheck *healthcheck = data;
  1504. amf_comp_dn_make (healthcheck->comp, dn);
  1505. TRACE7 ("Healthcheck response from '%s': %d",dn->value, error);
  1506. /*
  1507. * Healthcheck with erroneous response
  1508. * and no recovery action is in progress.
  1509. */
  1510. memcpy(healtcheck_key, &healthcheck->safHealthcheckKey,
  1511. sizeof (SaAmfHealthcheckKeyT));
  1512. *recommendedRecovery = healthcheck->recommendedRecovery;
  1513. if (error != SA_AIS_OK &&
  1514. !amf_comp_is_error_suspected (healthcheck->comp)) {
  1515. return 1;
  1516. }
  1517. if (is_not_instantiating_or_instantiated_or_restarting(
  1518. healthcheck->comp)) {
  1519. log_printf (LOG_ERR, "HealthcheckResponse: ignored for key = %s, "
  1520. "due to wrong state = %d comp = %s",
  1521. healthcheck->safHealthcheckKey.key,
  1522. healthcheck->comp->saAmfCompPresenceState,
  1523. healthcheck->comp->name.value);
  1524. *retval = SA_AIS_OK;
  1525. return 0; /* do not multicast event */
  1526. }
  1527. if (healthcheck->invocationType == SA_AMF_HEALTHCHECK_AMF_INVOKED) {
  1528. /* the response was on time, delete supervision timer */
  1529. poll_timer_delete (aisexec_poll_handle,
  1530. healthcheck->timer_handle_duration);
  1531. healthcheck->timer_handle_duration = 0;
  1532. /* start timer to execute next healthcheck request */
  1533. poll_timer_add (aisexec_poll_handle,
  1534. healthcheck->saAmfHealthcheckPeriod,
  1535. (void *)healthcheck,
  1536. timer_function_healthcheck_next_fn,
  1537. &healthcheck->timer_handle_period);
  1538. *retval = SA_AIS_OK;
  1539. } else {
  1540. *retval = SA_AIS_ERR_INVALID_PARAM;
  1541. }
  1542. return 0; /* do not multicast event */
  1543. break;
  1544. }
  1545. case AMF_RESPONSE_CSISETCALLBACK: /* fall-through */
  1546. case AMF_RESPONSE_CSIREMOVECALLBACK:
  1547. amf_csi_assignment_dn_make (data, dn);
  1548. return 1; /* multicast event */
  1549. break;
  1550. #if 0
  1551. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: {
  1552. struct component_terminate_callback_data *component_terminate_callback_data;
  1553. component_terminate_callback_data = data;
  1554. dprintf ("Lib component terminate callback response, error: %d", error);
  1555. amf_comp_healthcheck_deactivate (component_terminate_callback_data->comp);
  1556. escalation_policy_restart (component_terminate_callback_data->comp);
  1557. return 1;
  1558. break;
  1559. }
  1560. #endif
  1561. default:
  1562. assert (0);
  1563. break;
  1564. }
  1565. /* XXX we fall here in case NDEBUG is set */
  1566. *retval = -1;
  1567. return 0;
  1568. }
  1569. /**
  1570. * Handle a component response (received from EVS) of an earlier AMF request.
  1571. * This function should be invoked when the multicast request is received.
  1572. * @param invocation [in] associates the response with the request (callback)
  1573. * @param error [in] response from the component of the associated callback
  1574. * @param retval [out] contains return value to component when needed
  1575. *
  1576. * @return component to which the response should be sent
  1577. */
  1578. struct amf_comp *amf_comp_response_2 (SaUint32T interface, SaNameT *dn,
  1579. SaAmfHealthcheckKeyT *healthcheck_key, SaAisErrorT error,
  1580. SaAisErrorT *retval, SaAmfRecommendedRecoveryT recommendedRecovery)
  1581. {
  1582. struct amf_csi_assignment *csi_assignment;
  1583. struct amf_comp *comp = NULL;
  1584. assert (retval != NULL);
  1585. *retval = SA_AIS_OK;
  1586. switch (interface) {
  1587. case AMF_RESPONSE_CSISETCALLBACK: {
  1588. ENTER("'%s'", dn->value);
  1589. csi_assignment = amf_csi_assignment_find (amf_cluster, dn);
  1590. assert (csi_assignment != NULL);
  1591. comp = csi_assignment->comp;
  1592. dprintf ("CSI '%s' set callback response from '%s', error: %d",
  1593. csi_assignment->csi->name.value,
  1594. csi_assignment->comp->name.value, error);
  1595. comp = csi_assignment->comp;
  1596. if (error == SA_AIS_OK) {
  1597. comp_ha_state_set (
  1598. comp, csi_assignment, csi_assignment->requested_ha_state);
  1599. } else if (error == SA_AIS_ERR_FAILED_OPERATION) {
  1600. amf_si_comp_set_ha_state_failed (csi_assignment->csi->si,
  1601. csi_assignment);
  1602. } else {
  1603. *retval = SA_AIS_ERR_INVALID_PARAM;
  1604. }
  1605. break;
  1606. }
  1607. case AMF_RESPONSE_CSIREMOVECALLBACK: {
  1608. ENTER("'%s'", dn->value);
  1609. csi_assignment = amf_csi_assignment_find (amf_cluster, dn);
  1610. assert (csi_assignment != NULL);
  1611. dprintf ("Lib csi '%s' remove callback response from '%s', error: %d",
  1612. csi_assignment->csi->name.value,
  1613. csi_assignment->comp->name.value, error);
  1614. comp = csi_assignment->comp;
  1615. if (error == SA_AIS_OK || error == SA_AIS_ERR_FAILED_OPERATION) {
  1616. amf_si_comp_csi_removed (csi_assignment->csi->si,
  1617. csi_assignment, error);
  1618. } else {
  1619. *retval = SA_AIS_ERR_INVALID_PARAM;
  1620. }
  1621. break;
  1622. }
  1623. case AMF_RESPONSE_HEALTHCHECKCALLBACK: {
  1624. dprintf("AMF_RESPONSE_HEALTHCHECKCALLBACK for %s", dn->value);
  1625. comp = amf_comp_find (amf_cluster, dn);
  1626. assert (comp);
  1627. amf_healthcheck_t *healthcheck = amf_comp_find_healthcheck (
  1628. comp, healthcheck_key);
  1629. assert (comp);
  1630. healthcheck->recommendedRecovery = recommendedRecovery;
  1631. comp_recover_action (comp, healthcheck->recommendedRecovery);
  1632. break;
  1633. }
  1634. #if 0
  1635. case AMF_RESPONSE_COMPONENTTERMINATECALLBACK: {
  1636. struct component_terminate_callback_data *callback_data = data;
  1637. dprintf ("Lib comp '%s' terminate callback response, error: %d",
  1638. callback_data->comp->name.value, error);
  1639. comp_presence_state_set (callback_data->comp,
  1640. SA_AMF_PRESENCE_UNINSTANTIATED);
  1641. break;
  1642. }
  1643. #endif
  1644. default:
  1645. assert (0);
  1646. break;
  1647. }
  1648. return comp;
  1649. }
  1650. /**
  1651. * Request a component to assume a particular HA state
  1652. * @param comp
  1653. * @param csi_assignment
  1654. * @param requested_ha_state
  1655. */
  1656. void amf_comp_hastate_set (
  1657. struct amf_comp *component,
  1658. struct amf_csi_assignment *csi_assignment)
  1659. {
  1660. ENTER ("'%s'", csi_assignment->csi->name.value);
  1661. assert (component != NULL && csi_assignment != NULL);
  1662. if (!amf_comp_is_error_suspected (component)) {
  1663. lib_csi_set_request(component, csi_assignment);
  1664. } else {
  1665. if (csi_assignment->requested_ha_state == SA_AMF_HA_QUIESCED) {
  1666. csi_assignment->saAmfCSICompHAState = csi_assignment->requested_ha_state;
  1667. } else {
  1668. dprintf ("csi_assignment->requested_ha_state = %d",
  1669. component->error_suspected);
  1670. assert (0);
  1671. }
  1672. }
  1673. LEAVE("");
  1674. }
  1675. /**
  1676. * Request termination of a component
  1677. * @param comp
  1678. */
  1679. void amf_comp_terminate (struct amf_comp *comp)
  1680. {
  1681. dprintf ("comp terminate '%s'\n", getSaNameT (&comp->name));
  1682. comp_presence_state_set (comp, SA_AMF_PRESENCE_TERMINATING);
  1683. if (amf_su_is_local (comp->su)) {
  1684. amf_comp_healthcheck_stop (comp, NULL);
  1685. if (amf_comp_is_error_suspected(comp)) {
  1686. clc_interfaces[comp->comptype]->cleanup (comp);
  1687. } else {
  1688. clc_interfaces[comp->comptype]->terminate (comp);
  1689. }
  1690. }
  1691. }
  1692. /**
  1693. * Request restart of a component
  1694. * @param comp
  1695. */
  1696. void amf_comp_restart (struct amf_comp *comp)
  1697. {
  1698. dprintf ("comp restart '%s'\n", getSaNameT (&comp->name));
  1699. comp_presence_state_set (comp, SA_AMF_PRESENCE_RESTARTING);
  1700. comp->saAmfCompRestartCount += 1;
  1701. if (amf_su_is_local (comp->su)) {
  1702. amf_comp_healthcheck_stop (comp, NULL);
  1703. clc_interfaces[comp->comptype]->cleanup (comp);
  1704. }
  1705. }
  1706. /**
  1707. * Request to return the HA state for a components CSI
  1708. * @param comp
  1709. * @param csi_name
  1710. * @param ha_state
  1711. *
  1712. * @return SaAisErrorT
  1713. */
  1714. SaAisErrorT amf_comp_hastate_get (
  1715. struct amf_comp *comp, SaNameT *csi_name, SaAmfHAStateT *ha_state)
  1716. {
  1717. struct amf_csi_assignment *assignment;
  1718. assert (comp != NULL && csi_name != NULL && ha_state != NULL);
  1719. dprintf ("comp ha state get from comp '%s' CSI '%s'\n",
  1720. getSaNameT (&comp->name), csi_name->value);
  1721. assignment = csi_assignment_find_in (comp, csi_name);
  1722. if (assignment != NULL) {
  1723. *ha_state = assignment->saAmfCSICompHAState;
  1724. return SA_AIS_OK;
  1725. }
  1726. return SA_AIS_ERR_INVALID_PARAM;
  1727. }
  1728. /**
  1729. * Response from a component informs AMF that it has performed a healthcheck
  1730. * @param comp
  1731. * @param healthcheckKey
  1732. * @param healthcheckResult
  1733. *
  1734. * @return SaAisErrorT
  1735. */
  1736. SaAisErrorT amf_comp_healthcheck_confirm (
  1737. struct amf_comp *comp,
  1738. SaAmfHealthcheckKeyT *healthcheckKey,
  1739. SaAisErrorT healthcheckResult)
  1740. {
  1741. struct amf_healthcheck *healthcheck;
  1742. SaAisErrorT error = SA_AIS_OK;
  1743. healthcheck = amf_comp_find_healthcheck (comp, healthcheckKey);
  1744. if (is_not_instantiating_or_instantiated_or_restarting(comp)) {
  1745. log_printf (LOG_ERR, "HealthcheckConfirm: ignored for key = %s, "
  1746. "due to wrong state = %d, comp = %s",
  1747. healthcheckKey->key, comp->saAmfCompPresenceState, comp->name.value);
  1748. error = SA_AIS_OK;
  1749. goto out;
  1750. }
  1751. if (healthcheck == NULL) {
  1752. log_printf (LOG_ERR, "Healthcheckstop: Healthcheck '%s' not found",
  1753. healthcheckKey->key);
  1754. error = SA_AIS_ERR_NOT_EXIST;
  1755. } else if (healthcheck->active) {
  1756. if (healthcheckResult == SA_AIS_OK) {
  1757. /* the response was on time, restart the supervision timer */
  1758. poll_timer_delete (aisexec_poll_handle,
  1759. healthcheck->timer_handle_period);
  1760. poll_timer_add (aisexec_poll_handle,
  1761. healthcheck->saAmfHealthcheckPeriod,
  1762. (void *)healthcheck,
  1763. timer_function_healthcheck_tmo,
  1764. &healthcheck->timer_handle_period);
  1765. } else if (healthcheckResult == SA_AIS_ERR_FAILED_OPERATION) {
  1766. /* send to cluster */
  1767. if (!comp->error_suspected) {
  1768. poll_timer_delete (aisexec_poll_handle,
  1769. healthcheck->timer_handle_period);
  1770. mcast_healthcheck_tmo_event (healthcheck);
  1771. }
  1772. } else {
  1773. error = SA_AIS_ERR_INVALID_PARAM;
  1774. }
  1775. } else {
  1776. error = SA_AIS_ERR_INVALID_PARAM;
  1777. }
  1778. out:
  1779. return error;
  1780. }
  1781. void amf_comp_init (void)
  1782. {
  1783. log_init ("AMF");
  1784. }
  1785. void amf_comp_operational_state_set (struct amf_comp *comp,
  1786. SaAmfOperationalStateT oper_state)
  1787. {
  1788. comp->saAmfCompOperState = oper_state;
  1789. TRACE1 ("Setting comp '%s', SU '%s' operational state: %s\n",
  1790. comp->name.value, comp->su->name.value,
  1791. amf_op_state (comp->saAmfCompOperState));
  1792. amf_su_comp_state_changed (
  1793. comp->su, comp, SA_AMF_OP_STATE, oper_state);
  1794. }
  1795. int amf_comp_get_saAmfCompNumCurrActiveCsi(struct amf_comp *component)
  1796. {
  1797. int cnt = 0;
  1798. struct amf_csi_assignment *csi_assignment;
  1799. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1800. while (csi_assignment != NULL) {
  1801. if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_ACTIVE) {
  1802. cnt++;
  1803. }
  1804. csi_assignment = amf_comp_get_next_csi_assignment (
  1805. component, csi_assignment);
  1806. }
  1807. return cnt;
  1808. }
  1809. int amf_comp_get_saAmfCompNumCurrStandbyCsi(struct amf_comp *component)
  1810. {
  1811. int cnt = 0;
  1812. struct amf_csi_assignment *csi_assignment;
  1813. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1814. while (csi_assignment != NULL) {
  1815. if (csi_assignment->saAmfCSICompHAState == SA_AMF_HA_STANDBY) {
  1816. cnt++;
  1817. }
  1818. csi_assignment = amf_comp_get_next_csi_assignment (
  1819. component, csi_assignment);
  1820. }
  1821. return cnt;
  1822. }
  1823. SaAmfReadinessStateT amf_comp_get_saAmfCompReadinessState (
  1824. struct amf_comp *component)
  1825. {
  1826. if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
  1827. return amf_su_get_saAmfSUReadinessState (component->su);
  1828. } else if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_DISABLED) {
  1829. return SA_AMF_READINESS_OUT_OF_SERVICE;
  1830. }
  1831. assert (0);
  1832. /* XXX we fall here in case NDEBUG is set */
  1833. return -1;
  1834. }
  1835. /**
  1836. * Component is informed that the node where the 'real'
  1837. * component process is executing has unexpectadly left the
  1838. * node. If there is a pending interaction between AMF
  1839. * (component) and the 'real' component process, then component
  1840. * will indicate to its subordinate objects the interaction
  1841. * failed. Pending presence state changes is indicated by
  1842. * reporting the new state is uninstantiated while pending csi
  1843. * operations are indicated by 'operation failed'.
  1844. * @param comp
  1845. *
  1846. * @return void
  1847. */
  1848. void amf_comp_node_left (struct amf_comp *component)
  1849. {
  1850. int change_pending = 0;
  1851. struct amf_csi_assignment *csi_assignment;
  1852. ENTER("saAmfCompPresenceState = %d", component->saAmfCompPresenceState);
  1853. amf_comp_error_suspected_clear (component);
  1854. if (component->saAmfCompPresenceState == SA_AMF_PRESENCE_INSTANTIATING ||
  1855. component->saAmfCompPresenceState == SA_AMF_PRESENCE_RESTARTING ||
  1856. component->saAmfCompPresenceState == SA_AMF_PRESENCE_TERMINATING) {
  1857. change_pending = 1;
  1858. }
  1859. component->saAmfCompPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  1860. if (amf_su_are_all_comps_in_su (component->su,
  1861. SA_AMF_PRESENCE_UNINSTANTIATED)) {
  1862. component->su->saAmfSUPresenceState = SA_AMF_PRESENCE_UNINSTANTIATED;
  1863. }
  1864. if (change_pending) {
  1865. change_pending = 0;
  1866. amf_su_comp_state_changed ( component->su,
  1867. component,
  1868. SA_AMF_PRESENCE_STATE,
  1869. SA_AMF_PRESENCE_UNINSTANTIATED);
  1870. }
  1871. if (component->saAmfCompOperState == SA_AMF_OPERATIONAL_ENABLED) {
  1872. change_pending = 1;
  1873. }
  1874. component->saAmfCompOperState = SA_AMF_OPERATIONAL_DISABLED;
  1875. if (change_pending) {
  1876. change_pending =0;
  1877. amf_su_comp_state_changed (component->su,
  1878. component,
  1879. SA_AMF_OP_STATE,
  1880. SA_AMF_OPERATIONAL_DISABLED);
  1881. }
  1882. csi_assignment = amf_comp_get_next_csi_assignment (component, NULL);
  1883. while (csi_assignment != NULL) {
  1884. if (csi_assignment->requested_ha_state !=
  1885. csi_assignment->saAmfCSICompHAState) {
  1886. amf_si_comp_set_ha_state_failed (
  1887. csi_assignment->csi->si,csi_assignment);
  1888. }
  1889. csi_assignment = amf_comp_get_next_csi_assignment (
  1890. component, csi_assignment);
  1891. }
  1892. }
  1893. /**
  1894. * Serialize a component including variable length arrays and
  1895. * strings to a buffer returned. Buffer is to be freed by
  1896. * caller.
  1897. * @param component
  1898. * @param len
  1899. *
  1900. * @return void*
  1901. */
  1902. void *amf_comp_serialize (struct amf_comp *component, int *len)
  1903. {
  1904. char *buf = NULL;
  1905. int i, offset = 0, size = 0;
  1906. TRACE8 ("%s", component->name.value);
  1907. buf = amf_serialize_SaNameT (buf, &size, &offset, &component->name);
  1908. /* count cstypes and write to buf */
  1909. for (i = 0; component->saAmfCompCsTypes &&
  1910. component->saAmfCompCsTypes[i] != NULL; i++);
  1911. buf = amf_serialize_SaUint32T (buf, &size, &offset, i);
  1912. for (i = 0; component->saAmfCompCsTypes &&
  1913. component->saAmfCompCsTypes[i] != NULL; i++) {
  1914. buf = amf_serialize_SaNameT (
  1915. buf, &size, &offset, component->saAmfCompCsTypes[i]);
  1916. }
  1917. buf = amf_serialize_SaUint32T (
  1918. buf, &size, &offset, component->saAmfCompCategory);
  1919. buf = amf_serialize_SaUint32T (
  1920. buf, &size, &offset, component->saAmfCompCapability);
  1921. buf = amf_serialize_SaUint32T (
  1922. buf, &size, &offset, component->saAmfCompNumMaxActiveCsi);
  1923. buf = amf_serialize_SaUint32T (
  1924. buf, &size, &offset, component->saAmfCompNumMaxStandbyCsi);
  1925. /* count environment vars and write to buf */
  1926. for (i = 0; component->saAmfCompCmdEnv &&
  1927. component->saAmfCompCmdEnv[i] != NULL; i++);
  1928. buf = amf_serialize_SaUint32T (buf, &size, &offset, i);
  1929. for (i = 0; component->saAmfCompCmdEnv &&
  1930. component->saAmfCompCmdEnv[i] != NULL; i++) {
  1931. buf = amf_serialize_SaStringT (
  1932. buf, &size, &offset, component->saAmfCompCmdEnv[i]);
  1933. }
  1934. buf = amf_serialize_SaUint32T (
  1935. buf, &size, &offset, component->saAmfCompDefaultClcCliTimeout);
  1936. buf = amf_serialize_SaUint32T (
  1937. buf, &size, &offset, component->saAmfCompDefaultCallbackTimeOut);
  1938. buf = amf_serialize_SaStringT (
  1939. buf, &size, &offset, component->saAmfCompInstantiateCmd);
  1940. buf = amf_serialize_SaStringT (
  1941. buf, &size, &offset, component->saAmfCompInstantiateCmdArgv);
  1942. buf = amf_serialize_SaUint32T (
  1943. buf, &size, &offset, component->saAmfCompInstantiateTimeout);
  1944. buf = amf_serialize_SaUint32T (
  1945. buf, &size, &offset, component->saAmfCompInstantiationLevel);
  1946. buf = amf_serialize_SaUint32T (
  1947. buf, &size, &offset, component->saAmfCompNumMaxInstantiateWithoutDelay);
  1948. buf = amf_serialize_SaUint32T (
  1949. buf, &size, &offset, component->saAmfCompNumMaxInstantiateWithDelay);
  1950. buf = amf_serialize_SaUint32T (
  1951. buf, &size, &offset, component->saAmfCompDelayBetweenInstantiateAttempts);
  1952. buf = amf_serialize_SaStringT (
  1953. buf, &size, &offset, component->saAmfCompTerminateCmd);
  1954. buf = amf_serialize_SaUint32T (
  1955. buf, &size, &offset, component->saAmfCompTerminateTimeout);
  1956. buf = amf_serialize_SaStringT (
  1957. buf, &size, &offset, component->saAmfCompTerminateCmdArgv);
  1958. buf = amf_serialize_SaStringT (
  1959. buf, &size, &offset, component->saAmfCompCleanupCmd);
  1960. buf = amf_serialize_SaUint32T (
  1961. buf, &size, &offset, component->saAmfCompCleanupTimeout);
  1962. buf = amf_serialize_SaStringT (
  1963. buf, &size, &offset, component->saAmfCompCleanupCmdArgv);
  1964. buf = amf_serialize_SaStringT (
  1965. buf, &size, &offset, component->saAmfCompAmStartCmd);
  1966. buf = amf_serialize_SaUint32T (
  1967. buf, &size, &offset, component->saAmfCompAmStartTimeout);
  1968. buf = amf_serialize_SaStringT (
  1969. buf, &size, &offset, component->saAmfCompAmStartCmdArgv);
  1970. buf = amf_serialize_SaUint32T (
  1971. buf, &size, &offset, component->saAmfCompNumMaxAmStartAttempt);
  1972. buf = amf_serialize_SaStringT (
  1973. buf, &size, &offset, component->saAmfCompAmStopCmd);
  1974. buf = amf_serialize_SaUint32T (
  1975. buf, &size, &offset, component->saAmfCompAmStopTimeout);
  1976. buf = amf_serialize_SaStringT (
  1977. buf, &size, &offset, component->saAmfCompAmStopCmdArgv);
  1978. buf = amf_serialize_SaUint32T (
  1979. buf, &size, &offset, component->saAmfCompNumMaxAmStopAttempt);
  1980. buf = amf_serialize_SaUint32T (
  1981. buf, &size, &offset, component->saAmfCompTerminateCallbackTimeout);
  1982. buf = amf_serialize_SaUint32T (
  1983. buf, &size, &offset, component->saAmfCompCSISetCallbackTimeout);
  1984. buf = amf_serialize_SaUint32T (
  1985. buf, &size, &offset, component->saAmfCompQuiescingCompleteTimeout);
  1986. buf = amf_serialize_SaUint32T (
  1987. buf, &size, &offset, component->saAmfCompCSIRmvCallbackTimeout);
  1988. buf = amf_serialize_SaUint32T (
  1989. buf, &size, &offset, component->saAmfCompRecoveryOnError);
  1990. buf = amf_serialize_SaUint32T (
  1991. buf, &size, &offset, component->saAmfCompDisableRestart);
  1992. buf = amf_serialize_SaNameT (
  1993. buf, &size, &offset, &component->saAmfCompProxyCsi);
  1994. buf = amf_serialize_SaUint32T (
  1995. buf, &size, &offset, component->saAmfCompOperState);
  1996. buf = amf_serialize_SaUint32T (
  1997. buf, &size, &offset, component->saAmfCompPresenceState);
  1998. buf = amf_serialize_SaUint32T (
  1999. buf, &size, &offset, component->saAmfCompRestartCount);
  2000. buf = amf_serialize_SaNameT (
  2001. buf, &size, &offset, &component->saAmfCompCurrProxyName);
  2002. buf = amf_serialize_SaStringT (
  2003. buf, &size, &offset, component->clccli_path);
  2004. buf = amf_serialize_SaUint32T (
  2005. buf, &size, &offset, component->comptype);
  2006. buf = amf_serialize_SaUint32T (
  2007. buf, &size, &offset, component->error_suspected);
  2008. *len = offset;
  2009. return buf;
  2010. }
  2011. /**
  2012. * Deserialize a buffer into a AMF component object.
  2013. * @param su
  2014. * @param buf
  2015. * @param size
  2016. *
  2017. * @return struct amf_comp*
  2018. */
  2019. struct amf_comp *amf_comp_deserialize (struct amf_su *su, char *buf)
  2020. {
  2021. char *tmp = buf;
  2022. int i;
  2023. SaUint32T cnt;
  2024. struct amf_comp *component = amf_comp_new (su, "");
  2025. tmp = amf_deserialize_SaNameT (tmp, &component->name);
  2026. tmp = amf_deserialize_SaUint32T (tmp, &cnt);
  2027. component->saAmfCompCsTypes = amf_malloc ((cnt + 1) * sizeof (SaNameT*));
  2028. for (i = 0; i < cnt; i++) {
  2029. component->saAmfCompCsTypes[i] = amf_malloc (sizeof (SaNameT));
  2030. tmp = amf_deserialize_SaNameT (tmp, component->saAmfCompCsTypes[i]);
  2031. }
  2032. component->saAmfCompCsTypes[i] = NULL;
  2033. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompCategory);
  2034. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompCapability);
  2035. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompNumMaxActiveCsi);
  2036. tmp = amf_deserialize_SaUint32T (tmp, &component->saAmfCompNumMaxStandbyCsi);
  2037. tmp = amf_deserialize_SaUint32T (tmp, &cnt);
  2038. component->saAmfCompCmdEnv = amf_malloc ((cnt + 1) * sizeof (SaStringT*));
  2039. for (i = 0; i < cnt; i++) {
  2040. tmp = amf_deserialize_SaStringT (tmp, &component->saAmfCompCmdEnv[i]);
  2041. }
  2042. component->saAmfCompCmdEnv[i] = NULL;
  2043. tmp = amf_deserialize_SaUint32T (
  2044. tmp, &component->saAmfCompDefaultClcCliTimeout);
  2045. tmp = amf_deserialize_SaUint32T (
  2046. tmp, &component->saAmfCompDefaultCallbackTimeOut);
  2047. tmp = amf_deserialize_SaStringT (
  2048. tmp, &component->saAmfCompInstantiateCmd);
  2049. tmp = amf_deserialize_SaStringT (
  2050. tmp, &component->saAmfCompInstantiateCmdArgv);
  2051. tmp = amf_deserialize_SaUint32T (
  2052. tmp, &component->saAmfCompInstantiateTimeout);
  2053. tmp = amf_deserialize_SaUint32T (
  2054. tmp, &component->saAmfCompInstantiationLevel);
  2055. tmp = amf_deserialize_SaUint32T (
  2056. tmp, &component->saAmfCompNumMaxInstantiateWithoutDelay);
  2057. tmp = amf_deserialize_SaUint32T (
  2058. tmp, &component->saAmfCompNumMaxInstantiateWithDelay);
  2059. tmp = amf_deserialize_SaUint32T (
  2060. tmp, &component->saAmfCompDelayBetweenInstantiateAttempts);
  2061. tmp = amf_deserialize_SaStringT (
  2062. tmp, &component->saAmfCompTerminateCmd);
  2063. tmp = amf_deserialize_SaUint32T (
  2064. tmp, &component->saAmfCompTerminateTimeout);
  2065. tmp = amf_deserialize_SaStringT (
  2066. tmp, &component->saAmfCompTerminateCmdArgv);
  2067. tmp = amf_deserialize_SaStringT (
  2068. tmp, &component->saAmfCompCleanupCmd);
  2069. tmp = amf_deserialize_SaUint32T (
  2070. tmp, &component->saAmfCompCleanupTimeout);
  2071. tmp = amf_deserialize_SaStringT (
  2072. tmp, &component->saAmfCompCleanupCmdArgv);
  2073. tmp = amf_deserialize_SaStringT (
  2074. tmp, &component->saAmfCompAmStartCmd);
  2075. tmp = amf_deserialize_SaUint32T (
  2076. tmp, &component->saAmfCompAmStartTimeout);
  2077. tmp = amf_deserialize_SaStringT (
  2078. tmp, &component->saAmfCompAmStartCmdArgv);
  2079. tmp = amf_deserialize_SaUint32T (
  2080. tmp, &component->saAmfCompNumMaxAmStartAttempt);
  2081. tmp = amf_deserialize_SaStringT (
  2082. tmp, &component->saAmfCompAmStopCmd);
  2083. tmp = amf_deserialize_SaUint32T (
  2084. tmp, &component->saAmfCompAmStopTimeout);
  2085. tmp = amf_deserialize_SaStringT (
  2086. tmp, &component->saAmfCompAmStopCmdArgv);
  2087. tmp = amf_deserialize_SaUint32T (
  2088. tmp, &component->saAmfCompNumMaxAmStopAttempt);
  2089. tmp = amf_deserialize_SaUint32T (
  2090. tmp, &component->saAmfCompTerminateCallbackTimeout);
  2091. tmp = amf_deserialize_SaUint32T (
  2092. tmp, &component->saAmfCompCSISetCallbackTimeout);
  2093. tmp = amf_deserialize_SaUint32T (
  2094. tmp, &component->saAmfCompQuiescingCompleteTimeout);
  2095. tmp = amf_deserialize_SaUint32T (
  2096. tmp, &component->saAmfCompCSIRmvCallbackTimeout);
  2097. tmp = amf_deserialize_SaUint32T (
  2098. tmp, &component->saAmfCompRecoveryOnError);
  2099. tmp = amf_deserialize_SaUint32T (
  2100. tmp, &component->saAmfCompDisableRestart);
  2101. tmp = amf_deserialize_SaNameT (
  2102. tmp, &component->saAmfCompProxyCsi);
  2103. tmp = amf_deserialize_SaUint32T (
  2104. tmp, &component->saAmfCompOperState);
  2105. tmp = amf_deserialize_SaUint32T (
  2106. tmp, &component->saAmfCompPresenceState);
  2107. tmp = amf_deserialize_SaUint32T (
  2108. tmp, &component->saAmfCompRestartCount);
  2109. tmp = amf_deserialize_SaNameT (
  2110. tmp, &component->saAmfCompCurrProxyName);
  2111. tmp = amf_deserialize_SaStringT (
  2112. tmp, &component->clccli_path);
  2113. tmp = amf_deserialize_SaUint32T (
  2114. tmp, &component->comptype);
  2115. tmp = amf_deserialize_SaUint32T (
  2116. tmp, &component->error_suspected);
  2117. return component;
  2118. }
  2119. void *amf_healthcheck_serialize (struct amf_healthcheck *healthcheck, int *len)
  2120. {
  2121. char *buf = NULL;
  2122. int offset = 0, size = 0;
  2123. TRACE8 ("%s", healthcheck->safHealthcheckKey.key);
  2124. buf = amf_serialize_opaque (buf, &size, &offset,
  2125. &healthcheck->safHealthcheckKey.key, SA_AMF_HEALTHCHECK_KEY_MAX);
  2126. buf = amf_serialize_SaUint16T (buf, &size, &offset,
  2127. healthcheck->safHealthcheckKey.keyLen);
  2128. buf = amf_serialize_SaUint32T (buf, &size, &offset,
  2129. healthcheck->saAmfHealthcheckMaxDuration);
  2130. buf = amf_serialize_SaUint32T (buf, &size, &offset,
  2131. healthcheck->saAmfHealthcheckPeriod);
  2132. *len = offset;
  2133. return buf;
  2134. }
  2135. struct amf_healthcheck *amf_healthcheck_deserialize (
  2136. struct amf_comp *comp, char *buf)
  2137. {
  2138. char *tmp = buf;
  2139. int cnt;
  2140. amf_healthcheck_t *healthcheck = amf_healthcheck_new (comp);
  2141. tmp = amf_deserialize_opaque (tmp, &healthcheck->safHealthcheckKey.key, &cnt);
  2142. tmp = amf_deserialize_SaUint16T (tmp,
  2143. &healthcheck->safHealthcheckKey.keyLen);
  2144. tmp = amf_deserialize_SaUint32T (tmp,
  2145. &healthcheck->saAmfHealthcheckMaxDuration);
  2146. tmp = amf_deserialize_SaUint32T (tmp,
  2147. &healthcheck->saAmfHealthcheckPeriod);
  2148. return healthcheck;
  2149. }
  2150. amf_healthcheck_t *amf_healthcheck_new (struct amf_comp *comp)
  2151. {
  2152. amf_healthcheck_t *healthcheck = amf_calloc (1, sizeof (amf_healthcheck_t));
  2153. healthcheck->comp = comp;
  2154. healthcheck->next = comp->healthcheck_head;
  2155. comp->healthcheck_head = healthcheck;
  2156. return healthcheck;
  2157. }
  2158. void amf_comp_csi_remove (amf_comp_t *component,
  2159. amf_csi_assignment_t *csi_assignment)
  2160. {
  2161. struct res_lib_amf_csiremovecallback res_lib;
  2162. ENTER("");
  2163. res_lib.header.id = MESSAGE_RES_AMF_CSIREMOVECALLBACK;
  2164. res_lib.header.size = sizeof (struct res_lib_amf_csiremovecallback);
  2165. res_lib.header.error = SA_AIS_OK;
  2166. res_lib.invocation =
  2167. invocation_create (AMF_RESPONSE_CSIREMOVECALLBACK, csi_assignment);
  2168. amf_comp_dn_make (component, &res_lib.compName);
  2169. amf_csi_dn_make (csi_assignment->csi, &res_lib.csiName);
  2170. res_lib.csiFlags = SA_AMF_CSI_TARGET_ONE;
  2171. TRACE7 ("sending CSI remove request to component %s",
  2172. res_lib.compName.value);
  2173. openais_conn_send_response (
  2174. openais_conn_partner_get (component->conn),
  2175. &res_lib, sizeof (struct res_lib_amf_csiremovecallback));
  2176. }
  2177. void amf_comp_error_suspected_clear (amf_comp_t *comp)
  2178. {
  2179. comp->error_suspected = 0;
  2180. }
  2181. void amf_comp_error_suspected_set (amf_comp_t *comp)
  2182. {
  2183. comp->error_suspected = 1;
  2184. }
  2185. int amf_comp_is_error_suspected (amf_comp_t *comp)
  2186. {
  2187. return comp->error_suspected ? 1 : 0;
  2188. }