amfutil.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441
  1. /** @file exec/amfutil.c
  2. *
  3. * Copyright (c) 2002-2005 MontaVista Software, Inc.
  4. * Author: Steven Dake (sdake@mvista.com)
  5. *
  6. * Copyright (c) 2006 Ericsson AB.
  7. * Author: Hans Feldt
  8. * Description:
  9. * - Reworked to match AMF B.02 information model Description:
  10. * - Refactoring of code into several AMF files
  11. * - Serializers/deserializers
  12. *
  13. * All rights reserved.
  14. *
  15. * This software licensed under BSD license, the text of which follows:
  16. *
  17. * Redistribution and use in source and binary forms, with or without
  18. * modification, are permitted provided that the following conditions are met:
  19. *
  20. * - Redistributions of source code must retain the above copyright notice,
  21. * this list of conditions and the following disclaimer.
  22. * - Redistributions in binary form must reproduce the above copyright notice,
  23. * this list of conditions and the following disclaimer in the documentation
  24. * and/or other materials provided with the distribution.
  25. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  26. * contributors may be used to endorse or promote products derived from this
  27. * software without specific prior written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  30. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  31. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  32. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  33. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  34. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  35. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  36. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  37. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  38. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  39. * THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. * AMF utility functions
  42. *
  43. * This file contains functions that provide different services used by other
  44. * AMF files. For example parsing the configuration file, printing state etc.
  45. *
  46. */
  47. #include <stdio.h>
  48. #include <string.h>
  49. #include <stdlib.h>
  50. #include <errno.h>
  51. #include <sys/types.h>
  52. #include <regex.h>
  53. #include "../include/saAis.h"
  54. #include "../include/saAmf.h"
  55. #include "../include/ipc_amf.h"
  56. #include "../include/list.h"
  57. #include "util.h"
  58. #include "amf.h"
  59. #include "totem.h"
  60. #include "print.h"
  61. #include "aispoll.h"
  62. #include "main.h"
  63. #include "service.h"
  64. #ifndef OPENAIS_CLUSTER_STARTUP_TIMEOUT
  65. #define OPENAIS_CLUSTER_STARTUP_TIMEOUT 5000
  66. #endif
  67. struct req_exec_amf_msg {
  68. mar_req_header_t header;
  69. };
  70. static const char *presence_state_text[] = {
  71. "UNKNOWN",
  72. "UNINSTANTIATED",
  73. "INSTANTIATING",
  74. "INSTANTIATED",
  75. "TERMINATING",
  76. "RESTARTING",
  77. "INSTANTIATION_FAILED",
  78. "TERMINATION_FAILED"
  79. };
  80. static const char *oper_state_text[] = {
  81. "UNKNOWN",
  82. "ENABLED",
  83. "DISABLED"
  84. };
  85. static const char *admin_state_text[] = {
  86. "UNKNOWN",
  87. "UNLOCKED",
  88. "LOCKED",
  89. "LOCKED-INSTANTIATION",
  90. "SHUTTING-DOWN"
  91. };
  92. static const char *readiness_state_text[] = {
  93. "UNKNOWN",
  94. "OUT-OF-SERVICE",
  95. "IN-SERVICE",
  96. };
  97. static const char *ha_state_text[] = {
  98. "UNKNOWN",
  99. "ACTIVE",
  100. "STANDBY",
  101. "QUIESCED",
  102. "QUIESCING",
  103. };
  104. static const char *assignment_state_text[] = {
  105. "UNKNOWN",
  106. "UNASSIGNED",
  107. "FULLY-ASSIGNED",
  108. "PARTIALLY-ASSIGNED"
  109. };
  110. static int init_category (struct amf_comp *comp, char *loc)
  111. {
  112. if (strcmp (loc, "sa_aware") == 0) {
  113. comp->saAmfCompCategory = SA_AMF_COMP_SA_AWARE;
  114. } else if (strcmp (loc, "proxy") == 0) {
  115. comp->saAmfCompCategory = SA_AMF_COMP_PROXY;
  116. } else if (strcmp (loc, "proxied") == 0) {
  117. comp->saAmfCompCategory = SA_AMF_COMP_PROXIED;
  118. } else if (strcmp (loc, "local") == 0) {
  119. comp->saAmfCompCategory = SA_AMF_COMP_LOCAL;
  120. } else {
  121. return -1;
  122. }
  123. return 0;
  124. }
  125. static int init_capability (struct amf_comp *comp, char *loc)
  126. {
  127. if (strcmp (loc, "x_active_and_y_standby") == 0) {
  128. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE_AND_Y_STANDBY;
  129. } else if (strcmp (loc, "x_active_or_y_standby") == 0) {
  130. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE_OR_Y_STANDBY;
  131. } else if (strcmp (loc, "one_active_or_y_standby") == 0) {
  132. comp->saAmfCompCapability = SA_AMF_COMP_ONE_ACTIVE_OR_Y_STANDBY;
  133. } else if (strcmp (loc, "one_active_or_one_standby") == 0) {
  134. comp->saAmfCompCapability = SA_AMF_COMP_ONE_ACTIVE_OR_ONE_STANDBY;
  135. } else if (strcmp (loc, "x_active") == 0) {
  136. comp->saAmfCompCapability = SA_AMF_COMP_X_ACTIVE;
  137. } else if (strcmp (loc, "1_active") == 0) {
  138. comp->saAmfCompCapability = SA_AMF_COMP_1_ACTIVE;
  139. } else if (strcmp (loc, "non_preinstantiable") == 0) {
  140. comp->saAmfCompCapability = SA_AMF_COMP_NON_PRE_INSTANTIABLE;
  141. } else {
  142. return -1;
  143. }
  144. return 0;
  145. }
  146. static int init_recovery_on_error (struct amf_comp *comp, char *loc)
  147. {
  148. if (strcmp (loc, "component_restart") == 0) {
  149. comp->saAmfCompRecoveryOnError = SA_AMF_COMPONENT_RESTART;
  150. } else if (strcmp (loc, "component_failover") == 0) {
  151. comp->saAmfCompRecoveryOnError = SA_AMF_COMPONENT_FAILOVER;
  152. } else if (strcmp (loc, "node_switchover") == 0) {
  153. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_SWITCHOVER;
  154. } else if (strcmp (loc, "node_failover") == 0) {
  155. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_FAILOVER;
  156. } else if (strcmp (loc, "node_failfast") == 0) {
  157. comp->saAmfCompRecoveryOnError = SA_AMF_NODE_FAILFAST;
  158. } else if (strcmp (loc, "application_restart") == 0) {
  159. comp->saAmfCompRecoveryOnError = SA_AMF_APPLICATION_RESTART;
  160. } else if (strcmp (loc, "cluster_reset") == 0) {
  161. comp->saAmfCompRecoveryOnError = SA_AMF_CLUSTER_RESET;
  162. } else if (strcmp (loc, "no_recomondation") == 0) {
  163. comp->saAmfCompRecoveryOnError = SA_AMF_NO_RECOMMENDATION;
  164. } else {
  165. return -1;
  166. }
  167. return 0;
  168. }
  169. static void post_init_comp(struct amf_comp *comp)
  170. {
  171. if (comp->saAmfCompInstantiateTimeout == 0) {
  172. comp->saAmfCompInstantiateTimeout = comp->saAmfCompDefaultClcCliTimeout;
  173. }
  174. if (comp->saAmfCompTerminateTimeout == 0) {
  175. comp->saAmfCompTerminateTimeout = comp->saAmfCompDefaultClcCliTimeout;
  176. }
  177. if (comp->saAmfCompCleanupTimeout == 0) {
  178. comp->saAmfCompCleanupTimeout = comp->saAmfCompDefaultClcCliTimeout;
  179. }
  180. if (comp->saAmfCompAmStartTimeout == 0) {
  181. comp->saAmfCompAmStartTimeout = comp->saAmfCompDefaultClcCliTimeout;
  182. }
  183. if (comp->saAmfCompAmStopTimeout == 0) {
  184. comp->saAmfCompAmStopTimeout = comp->saAmfCompDefaultClcCliTimeout;
  185. }
  186. if (comp->saAmfCompTerminateCallbackTimeout == 0) {
  187. comp->saAmfCompTerminateCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  188. }
  189. if (comp->saAmfCompCSISetCallbackTimeout == 0) {
  190. comp->saAmfCompCSISetCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  191. }
  192. if (comp->saAmfCompCSIRmvCallbackTimeout == 0) {
  193. comp->saAmfCompCSIRmvCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  194. }
  195. }
  196. static char *trim_str(char *str)
  197. {
  198. char *s = str + strlen (str) - 1;
  199. while (*s == '\t' || *s == ' ' || *s == '{') {
  200. *s = '\0';
  201. s--;
  202. }
  203. return str;
  204. }
  205. static char *rm_beginning_ws(char *str)
  206. {
  207. char *s = str + strlen (str) - 1;
  208. while (*s == '\t' || *s == ' ') {
  209. *s = '\0';
  210. s--;
  211. }
  212. s = str;
  213. while (*s == '\t' || *s == ' ') {
  214. s++;
  215. }
  216. return s;
  217. }
  218. struct amf_cluster *amf_config_read (char **error_string)
  219. {
  220. char buf[1024];
  221. char *line;
  222. FILE *fp;
  223. char *filename;
  224. amf_object_type_t current_parse = AMF_NONE;
  225. int line_number = 0;
  226. char *loc;
  227. int i;
  228. struct amf_cluster *cluster;
  229. struct amf_application *app = 0;
  230. struct amf_node *node = 0;
  231. struct amf_sg *sg = 0;
  232. struct amf_su *su = 0;
  233. struct amf_comp *comp = 0;
  234. struct amf_si *si = 0;
  235. struct amf_si_ranked_su *si_ranked_su = 0;
  236. struct amf_si_dependency *si_dependency = 0;
  237. struct amf_healthcheck *healthcheck = 0;
  238. struct amf_csi *csi = 0;
  239. struct amf_csi_attribute *attribute = 0;
  240. SaStringT env_var;
  241. int su_cnt = 0;
  242. int sg_cnt = 0;
  243. int comp_env_var_cnt = 0;
  244. int comp_cs_type_cnt = 0;
  245. int csi_attr_cnt = 0;
  246. int csi_dependencies_cnt = 0;
  247. char *error_reason = NULL;
  248. char *value;
  249. filename = getenv ("OPENAIS_AMF_CONFIG_FILE");
  250. if (!filename) {
  251. filename = "/etc/ais/amf.conf";
  252. }
  253. fp = fopen (filename, "r");
  254. if (fp == 0) {
  255. sprintf (buf, "Can't read %s file reason = (%s).\n",
  256. filename, strerror (errno));
  257. *error_string = buf;
  258. return NULL;
  259. }
  260. cluster = amf_cluster_new ();
  261. assert (cluster != NULL);
  262. while (fgets (buf, 255, fp)) {
  263. line_number += 1;
  264. line = buf;
  265. line[strlen(line) - 1] = '\0';
  266. /*
  267. * Clear out comments and empty lines
  268. */
  269. if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') {
  270. continue;
  271. }
  272. /*
  273. * Clear out white space and tabs
  274. */
  275. for (i = strlen (line) - 1; i > -1; i--) {
  276. if (line[i] == '\t' || line[i] == ' ') {
  277. line[i] = '\0';
  278. } else {
  279. break;
  280. }
  281. }
  282. /* Trim whitespace from beginning of string */
  283. line = rm_beginning_ws(line);
  284. error_reason = line;
  285. error_reason = NULL;
  286. switch (current_parse) {
  287. case AMF_NONE:
  288. if ((loc = strstr_rs (line, "safAmfCluster=")) != 0) {
  289. setSaNameT (&cluster->name, trim_str (loc));
  290. current_parse = AMF_CLUSTER;
  291. } else {
  292. goto parse_error;
  293. }
  294. break;
  295. case AMF_CLUSTER:
  296. if ((loc = strstr_rs (line, "saAmfClusterClmCluster=")) != 0) {
  297. setSaNameT (&cluster->saAmfClusterClmCluster, loc);
  298. } else if ((loc = strstr_rs (line, "saAmfClusterStartupTimeout=")) != 0) {
  299. cluster->saAmfClusterStartupTimeout = atol(loc);
  300. } else if ((loc = strstr_rs (line, "safAmfNode=")) != 0) {
  301. node = amf_node_new (cluster, trim_str (loc));
  302. cluster->node_head = node;
  303. current_parse = AMF_NODE;
  304. } else if ((loc = strstr_rs (line, "safApp=")) != 0) {
  305. app = amf_application_new (cluster);
  306. setSaNameT (&app->name, trim_str (loc));
  307. current_parse = AMF_APPLICATION;
  308. sg_cnt = 0;
  309. } else if (strstr_rs (line, "}")) {
  310. if (cluster->saAmfClusterStartupTimeout == -1) {
  311. error_reason = "saAmfClusterStartupTimeout missing";
  312. goto parse_error;
  313. }
  314. /* spec: set to default value if zero */
  315. if (cluster->saAmfClusterStartupTimeout == 0) {
  316. cluster->saAmfClusterStartupTimeout = OPENAIS_CLUSTER_STARTUP_TIMEOUT;
  317. }
  318. current_parse = AMF_NONE;
  319. } else {
  320. goto parse_error;
  321. }
  322. break;
  323. case AMF_NODE:
  324. if ((loc = strstr_rs (line, "saAmfNodeSuFailOverProb=")) != 0) {
  325. node->saAmfNodeSuFailOverProb = atol(loc);
  326. } else if ((loc = strstr_rs (line, "saAmfNodeSuFailoverMax=")) != 0) {
  327. node->saAmfNodeSuFailoverMax = atol(loc);
  328. } else if ((loc = strstr_rs (line, "saAmfNodeClmNode=")) != 0) {
  329. setSaNameT (&node->saAmfNodeClmNode, trim_str (loc));
  330. } else if ((loc = strstr_rs (line, "saAmfNodeAutoRepair=")) != 0) {
  331. if (strcmp (loc, "true") == 0) {
  332. node->saAmfNodeAutoRepair = SA_TRUE;
  333. } else if (strcmp (loc, "false") == 0) {
  334. node->saAmfNodeAutoRepair = SA_FALSE;
  335. } else {
  336. goto parse_error;
  337. }
  338. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnTerminationFailure=")) != 0) {
  339. if (strcmp (loc, "true") == 0) {
  340. node->saAmfNodeRebootOnTerminationFailure = SA_TRUE;
  341. } else if (strcmp (loc, "false") == 0) {
  342. node->saAmfNodeRebootOnTerminationFailure = SA_FALSE;
  343. } else {
  344. goto parse_error;
  345. }
  346. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnInstantiationFailure=")) != 0) {
  347. if (strcmp (loc, "true") == 0) {
  348. node->saAmfNodeRebootOnInstantiationFailure = SA_TRUE;
  349. } else if (strcmp (loc, "false") == 0) {
  350. node->saAmfNodeRebootOnInstantiationFailure = SA_FALSE;
  351. } else {
  352. goto parse_error;
  353. }
  354. } else if (strstr_rs (line, "}")) {
  355. if (node->saAmfNodeSuFailOverProb == -1) {
  356. error_reason = "saAmfNodeSuFailOverProb missing";
  357. goto parse_error;
  358. }
  359. if (node->saAmfNodeSuFailoverMax == ~0) {
  360. error_reason = "saAmfNodeSuFailoverMax missing";
  361. goto parse_error;
  362. }
  363. if (node->saAmfNodeClmNode.length == 0) {
  364. error_reason = "saAmfNodeClmNode missing";
  365. goto parse_error;
  366. }
  367. current_parse = AMF_CLUSTER;
  368. } else {
  369. goto parse_error;
  370. }
  371. break;
  372. case AMF_APPLICATION:
  373. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  374. app->clccli_path = amf_malloc (strlen (loc) + 1);
  375. strcpy (app->clccli_path, loc);
  376. } else if ((loc = strstr_rs (line, "safSg=")) != 0) {
  377. sg = amf_sg_new (app, trim_str (loc));
  378. sg_cnt++;
  379. sg->recovery_scope.comp = NULL;
  380. sg->recovery_scope.event_type = 0;
  381. sg->recovery_scope.node = NULL;
  382. sg->recovery_scope.sis = NULL;
  383. sg->recovery_scope.sus = NULL;
  384. current_parse = AMF_SG;
  385. su_cnt = 0;
  386. } else if ((loc = strstr_rs (line, "safSi=")) != 0) {
  387. si = amf_si_new (app, trim_str (loc));
  388. current_parse = AMF_SI;
  389. } else if ((loc = strstr_rs (line, "safCSType=")) != 0) {
  390. current_parse = AMF_CS_TYPE;
  391. } else if (strstr_rs (line, "}")) {
  392. if (sg_cnt == 1) {
  393. for (si = app->si_head; si != NULL; si = si->next) {
  394. memcpy (&si->saAmfSIProtectedbySG, &sg->name,
  395. sizeof (SaNameT));
  396. }
  397. } else {
  398. for (si = app->si_head; si != NULL; si = si->next) {
  399. if (si->saAmfSIProtectedbySG.length == 0) {
  400. error_reason = "saAmfSIProtectedbySG not set in SI"
  401. ", needed when several SGs are specified.";
  402. goto parse_error;
  403. }
  404. }
  405. }
  406. current_parse = AMF_CLUSTER;
  407. } else {
  408. goto parse_error;
  409. }
  410. break;
  411. case AMF_SG:
  412. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  413. sg->clccli_path = amf_malloc (strlen (loc) + 1);
  414. strcpy (sg->clccli_path, loc);
  415. } else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) {
  416. if (strcmp (loc, "2n") == 0) {
  417. sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL;
  418. } else if (strcmp (loc, "nplusm") == 0) {
  419. sg->saAmfSGRedundancyModel = SA_AMF_NPM_REDUNDANCY_MODEL;
  420. } else if (strcmp (loc, "nway") == 0) {
  421. error_reason = "nway redundancy model not supported";
  422. goto parse_error;
  423. } else if (strcmp (loc, "nwayactive") == 0) {
  424. error_reason = "nway active redundancy model not supported";
  425. goto parse_error;
  426. } else if (strcmp (loc, "noredundancy") == 0) {
  427. sg->saAmfSGRedundancyModel = SA_AMF_NO_REDUNDANCY_MODEL;
  428. } else {
  429. goto parse_error;
  430. }
  431. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefActiveSUs=")) != 0) {
  432. sg->saAmfSGNumPrefActiveSUs = atoi (loc);
  433. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefStandbySUs=")) != 0) {
  434. sg->saAmfSGNumPrefStandbySUs = atoi (loc);
  435. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefInserviceSUs=")) != 0) {
  436. sg->saAmfSGNumPrefInserviceSUs = atoi (loc);
  437. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefAssignedSUs=")) != 0) {
  438. sg->saAmfSGNumPrefAssignedSUs = atoi (loc);
  439. } else if ((loc = strstr_rs (line, "saAmfSGMaxActiveSIsperSUs=")) != 0) {
  440. sg->saAmfSGMaxActiveSIsperSUs = atoi (loc);
  441. } else if ((loc = strstr_rs (line, "saAmfSGMaxStandbySIsperSUs=")) != 0) {
  442. sg->saAmfSGMaxStandbySIsperSUs = atoi (loc);
  443. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartProb=")) != 0) {
  444. sg->saAmfSGCompRestartProb = atoi (loc);
  445. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartMax=")) != 0) {
  446. sg->saAmfSGCompRestartMax = atoi (loc);
  447. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartProb=")) != 0) {
  448. sg->saAmfSGSuRestartProb = atoi (loc);
  449. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartMax=")) != 0) {
  450. sg->saAmfSGSuRestartMax = atoi (loc);
  451. } else if ((loc = strstr_rs (line, "saAmfSGAutoAdjustProb=")) != 0) {
  452. sg->saAmfSGAutoAdjustProb = atoi (loc);
  453. } else if ((loc = strstr_rs (line, "saAmfSGAutoRepair=")) != 0) {
  454. sg->saAmfSGAutoRepair = atoi (loc);
  455. } else if ((loc = strstr_rs (line, "safSu=")) != 0) {
  456. su = amf_su_new (sg, trim_str (loc));
  457. su_cnt++;
  458. current_parse = AMF_SU;
  459. } else if (strstr_rs (line, "}")) {
  460. if (sg->saAmfSGRedundancyModel == 0) {
  461. error_reason = "saAmfSGRedundancyModel missing";
  462. goto parse_error;
  463. }
  464. if (sg->saAmfSGCompRestartProb == -1) {
  465. error_reason = "saAmfSGCompRestartProb missing";
  466. goto parse_error;
  467. }
  468. if (sg->saAmfSGCompRestartMax == ~0) {
  469. error_reason = "saAmfSGCompRestartMax missing";
  470. goto parse_error;
  471. }
  472. if (sg->saAmfSGSuRestartProb == -1) {
  473. error_reason = "saAmfSGSuRestartProb missing";
  474. goto parse_error;
  475. }
  476. if (sg->saAmfSGSuRestartMax == ~0) {
  477. error_reason = "saAmfSGSuRestartMax missing";
  478. goto parse_error;
  479. }
  480. if (sg->saAmfSGAutoAdjustProb == -1) {
  481. error_reason = "saAmfSGAutoAdjustProb missing";
  482. goto parse_error;
  483. }
  484. if (sg->saAmfSGAutoRepair > 1) {
  485. error_reason = "saAmfSGAutoRepair erroneous";
  486. goto parse_error;
  487. }
  488. if (sg->saAmfSGNumPrefInserviceSUs == ~0) {
  489. sg->saAmfSGNumPrefInserviceSUs = su_cnt;
  490. }
  491. if (sg->saAmfSGNumPrefAssignedSUs == ~0) {
  492. sg->saAmfSGNumPrefAssignedSUs =
  493. sg->saAmfSGNumPrefInserviceSUs;
  494. }
  495. current_parse = AMF_APPLICATION;
  496. } else {
  497. goto parse_error;
  498. }
  499. break;
  500. case AMF_SU:
  501. if ((loc = strstr_rs (line, "saAmfSUNumComponents=")) != 0) {
  502. su->saAmfSUNumComponents = atoi (loc);
  503. } else if ((loc = strstr_rs (line, "saAmfSUIsExternal=")) != 0) {
  504. su->saAmfSUIsExternal = atoi (loc);
  505. } else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) {
  506. su->saAmfSUFailover = atoi (loc);
  507. } else if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  508. su->clccli_path = amf_malloc (strlen (loc) + 1);
  509. strcpy (su->clccli_path, loc);
  510. } else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) {
  511. setSaNameT (&su->saAmfSUHostedByNode, loc);
  512. } else if ((loc = strstr_rs (line, "safComp=")) != 0) {
  513. comp = amf_comp_new (su, trim_str (loc));
  514. comp_env_var_cnt = 0;
  515. comp_cs_type_cnt = 0;
  516. current_parse = AMF_COMP;
  517. } else if (strstr_rs (line, "}")) {
  518. if (su->saAmfSUNumComponents == 0) {
  519. error_reason = "saAmfSUNumComponents missing";
  520. goto parse_error;
  521. }
  522. if (su->saAmfSUIsExternal > 1) {
  523. error_reason = "saAmfSUIsExternal erroneous";
  524. goto parse_error;
  525. }
  526. if (su->saAmfSUFailover > 1) {
  527. error_reason = "saAmfSUFailover erroneous";
  528. goto parse_error;
  529. }
  530. if (strcmp ((char*)su->saAmfSUHostedByNode.value, "") == 0) {
  531. error_reason = "saAmfSUHostedByNode missing";
  532. goto parse_error;
  533. }
  534. current_parse = AMF_SG;
  535. } else {
  536. goto parse_error;
  537. }
  538. break;
  539. case AMF_COMP:
  540. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  541. comp->clccli_path = amf_malloc (strlen (loc) + 1);
  542. strcpy (comp->clccli_path, loc);
  543. } else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) {
  544. current_parse = AMF_COMP_CS_TYPE;
  545. } else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) {
  546. if (init_category(comp, loc) != 0) {
  547. error_reason = "unknown category";
  548. goto parse_error;
  549. }
  550. } else if ((loc = strstr_rs (line, "saAmfCompCapability=")) != 0) {
  551. if (init_capability(comp, loc) != 0) {
  552. error_reason = "unknown capability model";
  553. goto parse_error;
  554. }
  555. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxActiveCsi=")) != 0) {
  556. comp->saAmfCompNumMaxActiveCsi = atol (loc);
  557. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxStandbyCsi=")) != 0) {
  558. comp->saAmfCompNumMaxStandbyCsi = atol (loc);
  559. } else if ((loc = strstr_rs (line, "saAmfCompCmdEnv{")) != 0) {
  560. current_parse = AMF_COMP_ENV_VAR;
  561. } else if ((loc = strstr_rs(line, "saAmfCompDefaultClcCliTimeout=")) != 0) {
  562. comp->saAmfCompDefaultClcCliTimeout = atol (loc);
  563. } else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) {
  564. comp->saAmfCompDefaultCallbackTimeOut = atol (loc);
  565. } else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) {
  566. comp->saAmfCompInstantiateCmdArgv = amf_malloc (strlen(loc) + 1);
  567. strcpy (comp->saAmfCompInstantiateCmdArgv, loc);
  568. } else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) {
  569. comp->saAmfCompInstantiateCmd = amf_malloc (strlen(loc) + 1);
  570. strcpy (comp->saAmfCompInstantiateCmd, loc);
  571. } else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) {
  572. comp->saAmfCompInstantiateTimeout = atol (loc);
  573. } else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) {
  574. comp->saAmfCompInstantiationLevel = atol (loc);
  575. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithoutDelay=")) != 0) {
  576. comp->saAmfCompNumMaxInstantiateWithoutDelay = atol (loc);
  577. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithDelay=")) != 0) {
  578. comp->saAmfCompNumMaxInstantiateWithDelay = atol (loc);
  579. } else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) {
  580. comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc);
  581. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) {
  582. comp->saAmfCompTerminateCmdArgv = amf_malloc (strlen(loc) + 1);
  583. strcpy (comp->saAmfCompTerminateCmdArgv, loc);
  584. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) {
  585. comp->saAmfCompTerminateCmd = amf_malloc (strlen(loc) + 1);
  586. strcpy (comp->saAmfCompTerminateCmd, loc);
  587. } else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) {
  588. comp->saAmfCompTerminateTimeout = atol (loc);
  589. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) {
  590. comp->saAmfCompCleanupCmdArgv = amf_malloc (strlen(loc) + 1);
  591. strcpy (comp->saAmfCompCleanupCmdArgv, loc);
  592. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) {
  593. comp->saAmfCompCleanupCmd = amf_malloc (strlen(loc) + 1);
  594. strcpy (comp->saAmfCompCleanupCmd, loc);
  595. } else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) {
  596. comp->saAmfCompCleanupTimeout = atol (loc);
  597. } else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) {
  598. comp->saAmfCompTerminateCallbackTimeout = atol (loc);
  599. } else if ((loc = strstr_rs(line, "saAmfCompCSISetCallbackTimeout=")) != 0) {
  600. comp->saAmfCompCSISetCallbackTimeout = atol (loc);
  601. } else if ((loc = strstr_rs(line, "saAmfCompQuiescingCompleteTimeout=")) != 0) {
  602. comp->saAmfCompQuiescingCompleteTimeout = atol (loc);
  603. } else if ((loc = strstr_rs(line, "saAmfCompCSIRmvCallbackTimeout=")) != 0) {
  604. comp->saAmfCompCSIRmvCallbackTimeout = atol (loc);
  605. } else if ((loc = strstr_rs (line, "saAmfCompRecoveryOnError=")) != 0) {
  606. if (init_recovery_on_error (comp, loc) != 0) {
  607. error_reason = "bad value";
  608. goto parse_error;
  609. }
  610. } else if ((loc = strstr_rs (line, "saAmfCompDisableRestart=")) != 0) {
  611. if (strcmp (loc, "false") == 0) {
  612. comp->saAmfCompDisableRestart = SA_FALSE;
  613. } else if (strcmp (loc, "true") == 0) {
  614. comp->saAmfCompDisableRestart = SA_TRUE;
  615. } else {
  616. error_reason = "bad value";
  617. goto parse_error;
  618. }
  619. } else if ((loc = strstr_rs (line, "saAmfCompProxyCsi=")) != 0) {
  620. setSaNameT (&comp->saAmfCompProxyCsi, loc);
  621. } else if ((loc = strstr_rs (line, "safHealthcheckKey=")) != 0) {
  622. healthcheck = calloc (1, sizeof (struct amf_healthcheck));
  623. healthcheck->next = comp->healthcheck_head;
  624. comp->healthcheck_head = healthcheck;
  625. healthcheck->comp = comp;
  626. strcpy ((char *)healthcheck->safHealthcheckKey.key, trim_str (loc));
  627. healthcheck->safHealthcheckKey.keyLen = strlen (loc);
  628. current_parse = AMF_HEALTHCHECK;
  629. } else if (strstr_rs (line, "}")) {
  630. if (comp->saAmfCompCategory == 0) {
  631. error_reason = "category missing";
  632. goto parse_error;
  633. }
  634. if (comp->saAmfCompCapability == 0) {
  635. error_reason = "capability model missing";
  636. goto parse_error;
  637. }
  638. if (comp->saAmfCompCategory == SA_AMF_COMP_SA_AWARE) {
  639. comp->comptype = clc_component_sa_aware;
  640. } else if (comp->saAmfCompCategory == SA_AMF_COMP_PROXY) {
  641. if (comp->saAmfCompCapability == SA_AMF_COMP_NON_PRE_INSTANTIABLE) {
  642. comp->comptype = clc_component_proxied_non_pre;
  643. } else {
  644. comp->comptype = clc_component_proxied_pre;
  645. }
  646. } else if (comp->saAmfCompCategory == SA_AMF_COMP_LOCAL) {
  647. comp->comptype = clc_component_non_proxied_non_sa_aware;
  648. }
  649. if (comp->saAmfCompNumMaxActiveCsi == 0) {
  650. error_reason = "saAmfCompNumMaxActiveCsi missing";
  651. goto parse_error;
  652. }
  653. if (comp->saAmfCompNumMaxStandbyCsi == 0) {
  654. error_reason = "saAmfCompNumMaxStandbyCsi missing";
  655. goto parse_error;
  656. }
  657. if (comp->saAmfCompDefaultClcCliTimeout == 0) {
  658. error_reason = "saAmfCompDefaultClcCliTimeout missing or erroneous";
  659. goto parse_error;
  660. }
  661. if (comp->saAmfCompDefaultCallbackTimeOut == 0) {
  662. error_reason = "saAmfCompDefaultCallbackTimeOut missing or erroneous";
  663. goto parse_error;
  664. }
  665. if (comp->saAmfCompRecoveryOnError == 0) {
  666. error_reason = "saAmfCompRecoveryOnError missing";
  667. goto parse_error;
  668. }
  669. post_init_comp (comp);
  670. current_parse = AMF_SU;
  671. } else {
  672. error_reason = line;
  673. goto parse_error;
  674. }
  675. break;
  676. case AMF_COMP_CS_TYPE:
  677. if (strstr_rs (line, "}")) {
  678. current_parse = AMF_COMP;
  679. } else {
  680. comp_cs_type_cnt++;
  681. comp->saAmfCompCsTypes = realloc (comp->saAmfCompCsTypes,
  682. (comp_cs_type_cnt + 1) * sizeof(SaNameT));
  683. comp->saAmfCompCsTypes[comp_cs_type_cnt] = NULL;
  684. comp->saAmfCompCsTypes[comp_cs_type_cnt - 1] = amf_malloc (sizeof(SaNameT));
  685. setSaNameT (comp->saAmfCompCsTypes[comp_cs_type_cnt - 1], line);
  686. }
  687. break;
  688. case AMF_COMP_ENV_VAR:
  689. if (strstr_rs (line, "}")) {
  690. current_parse = AMF_COMP;
  691. } else if ((loc = strchr (line, '=')) != 0) {
  692. comp_env_var_cnt++;
  693. comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv,
  694. (comp_env_var_cnt + 1) * sizeof(SaStringT));
  695. comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL;
  696. env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = amf_malloc (strlen (line) + 1);
  697. strcpy (env_var, line);
  698. } else {
  699. goto parse_error;
  700. }
  701. break;
  702. case AMF_HEALTHCHECK:
  703. if ((loc = strstr_rs (line, "saAmfHealthcheckPeriod=")) != 0) {
  704. healthcheck->saAmfHealthcheckPeriod = atoi (loc);
  705. } else if ((loc = strstr_rs (line, "saAmfHealthcheckMaxDuration=")) != 0) {
  706. healthcheck->saAmfHealthcheckMaxDuration = atoi (loc);
  707. } else if (strstr_rs (line, "}")) {
  708. current_parse = AMF_COMP;
  709. } else {
  710. goto parse_error;
  711. }
  712. break;
  713. case AMF_SI:
  714. if ((loc = strstr_rs (line, "safRankedSu=")) != 0) {
  715. si_ranked_su = calloc (1, sizeof(struct amf_si_ranked_su));
  716. si_ranked_su->si_next = si->ranked_sus;
  717. si->ranked_sus = si_ranked_su;
  718. si_ranked_su->si = si;
  719. setSaNameT (&si_ranked_su->name, trim_str (loc));
  720. current_parse = AMF_SI_RANKED_SU;
  721. } else if ((loc = strstr_rs (line, "safDepend=")) != 0) {
  722. si_dependency = calloc (1, sizeof(struct amf_si_dependency));
  723. si_dependency->next = si->depends_on;
  724. si->depends_on = si_dependency;
  725. setSaNameT (&si_dependency->name, trim_str (loc));
  726. current_parse = AMF_SI_DEPENDENCY;
  727. } else if ((loc = strstr_rs (line, "safCsi=")) != 0) {
  728. csi = calloc (1, sizeof(struct amf_csi));
  729. csi->next = si->csi_head;
  730. si->csi_head = csi;
  731. csi->si = si;
  732. setSaNameT (&csi->name, trim_str (loc));
  733. current_parse = AMF_CSI;
  734. } else if ((loc = strstr_rs (line, "saAmfSIProtectedbySG=")) != 0) {
  735. setSaNameT (&si->saAmfSIProtectedbySG, loc);
  736. } else if ((loc = strstr_rs (line, "saAmfSIRank=")) != 0) {
  737. si->saAmfSIRank = atoi (loc);
  738. } else if ((loc = strstr_rs (line, "saAmfSINumCSIs=")) != 0) {
  739. si->saAmfSINumCSIs = atoi (loc);
  740. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  741. si->saAmfSIPrefActiveAssignments = atoi (loc);
  742. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  743. si->saAmfSIPrefStandbyAssignments = atoi (loc);
  744. } else if (strstr_rs (line, "}")) {
  745. if (si->saAmfSINumCSIs == 0) {
  746. error_reason = "saAmfSINumCSIs missing";
  747. goto parse_error;
  748. }
  749. current_parse = AMF_APPLICATION;
  750. } else {
  751. goto parse_error;
  752. }
  753. break;
  754. case AMF_SI_RANKED_SU:
  755. if ((loc = strstr_rs (line, "saAmfRank=")) != 0) {
  756. si_ranked_su->saAmfRank = atoi (loc);
  757. } else if (strstr_rs (line, "}")) {
  758. current_parse = AMF_SI;
  759. } else {
  760. goto parse_error;
  761. }
  762. break;
  763. case AMF_SI_DEPENDENCY:
  764. if ((loc = strstr_rs (line, "saAmfToleranceTime=")) != 0) {
  765. si_dependency->saAmfToleranceTime = atoi (loc);
  766. } else if (strstr_rs (line, "}")) {
  767. current_parse = AMF_SI;
  768. } else {
  769. goto parse_error;
  770. }
  771. break;
  772. case AMF_CSI:
  773. if ((loc = strstr_rs (line, "saAmfCSTypeName=")) != 0) {
  774. setSaNameT (&csi->saAmfCSTypeName, loc);
  775. } else if ((loc = strstr_rs (line, "safCSIAttr=")) != 0) {
  776. attribute = calloc (1, sizeof(struct amf_csi_attribute));
  777. attribute->next = csi->attributes_head;
  778. csi->attributes_head = attribute;
  779. attribute->name = amf_malloc (strlen (loc) + 1);
  780. strcpy (attribute->name, trim_str (loc));
  781. csi_attr_cnt = 1;
  782. current_parse = AMF_CSI_ATTRIBUTE;
  783. } else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) {
  784. csi_dependencies_cnt = 0;
  785. current_parse = AMF_CSI_DEPENDENCIES;
  786. } else if (strstr_rs (line, "}")) {
  787. if (strcmp(getSaNameT(&csi->saAmfCSTypeName), "") == 0) {
  788. error_reason = "saAmfCSTypeName missing";
  789. goto parse_error;
  790. }
  791. current_parse = AMF_SI;
  792. } else {
  793. goto parse_error;
  794. }
  795. break;
  796. case AMF_CSI_DEPENDENCIES:
  797. if (strstr_rs (line, "}")) {
  798. current_parse = AMF_CSI;
  799. } else if ((loc = strstr_rs (line, "saAmfCSIDependency=")) != 0) {
  800. csi_dependencies_cnt++;
  801. csi->saAmfCSIDependencies = realloc (csi->saAmfCSIDependencies,
  802. (csi_dependencies_cnt + 1) * sizeof(SaNameT));
  803. csi->saAmfCSIDependencies[csi_dependencies_cnt] = NULL;
  804. csi->saAmfCSIDependencies[csi_dependencies_cnt - 1] =
  805. amf_malloc (sizeof(SaNameT));
  806. setSaNameT (
  807. csi->saAmfCSIDependencies[csi_dependencies_cnt - 1], loc);
  808. } else {
  809. goto parse_error;
  810. }
  811. break;
  812. case AMF_CSI_ATTRIBUTE:
  813. if ((loc = strstr_rs (line, "}")) != 0) {
  814. current_parse = AMF_CSI;
  815. } else {
  816. value = rm_beginning_ws (line);
  817. attribute->value = realloc (attribute->value,
  818. sizeof (SaStringT) * (csi_attr_cnt + 1));
  819. attribute->value[csi_attr_cnt - 1] =
  820. amf_malloc (strlen (value) + 1);
  821. strcpy (attribute->value[csi_attr_cnt - 1], value);
  822. attribute->value[csi_attr_cnt] = NULL;
  823. csi_attr_cnt++;
  824. }
  825. break;
  826. case AMF_CS_TYPE:
  827. if ((loc = strstr_rs (line, "}")) != 0) {
  828. current_parse = AMF_APPLICATION;
  829. }
  830. break;
  831. default:
  832. error_reason = "Invalid state\n";
  833. goto parse_error;
  834. break;
  835. }
  836. }
  837. fclose (fp);
  838. return cluster;
  839. parse_error:
  840. sprintf (buf, "parse error at %s: %d: %s\n",
  841. filename, line_number, error_reason);
  842. *error_string = buf;
  843. fclose (fp);
  844. return NULL;
  845. }
  846. static void print_csi_assignment (struct amf_comp *comp,
  847. struct amf_csi_assignment *csi_assignment)
  848. {
  849. log_printf (LOG_INFO, " safCSI=%s\n", csi_assignment->csi->name.value);
  850. log_printf (LOG_INFO, " HA state: %s\n",
  851. ha_state_text[csi_assignment->saAmfCSICompHAState]);
  852. }
  853. static void print_si_assignment (struct amf_su *su,
  854. struct amf_si_assignment *si_assignment)
  855. {
  856. log_printf (LOG_INFO, " safSi=%s\n", si_assignment->si->name.value);
  857. log_printf (LOG_INFO, " HA state: %s\n",
  858. ha_state_text[si_assignment->saAmfSISUHAState]);
  859. }
  860. void amf_runtime_attributes_print (struct amf_cluster *cluster)
  861. {
  862. struct amf_node *node;
  863. struct amf_application *app;
  864. struct amf_sg *sg;
  865. struct amf_su *su;
  866. struct amf_comp *comp;
  867. struct amf_si *si;
  868. struct amf_csi *csi;
  869. log_printf (LOG_INFO, "AMF runtime attributes:");
  870. log_printf (LOG_INFO, "===================================================");
  871. log_printf (LOG_INFO, "safCluster=%s", getSaNameT(&cluster->name));
  872. log_printf (LOG_INFO, " admin state: %s\n",
  873. admin_state_text[cluster->saAmfClusterAdminState]);
  874. log_printf (LOG_INFO, " state: %u\n", cluster->acsm_state);
  875. for (node = cluster->node_head; node != NULL; node = node->next) {
  876. log_printf (LOG_INFO, " safNode=%s\n", getSaNameT (&node->name));
  877. log_printf (LOG_INFO, " CLM Node: %s\n", getSaNameT (&node->saAmfNodeClmNode));
  878. log_printf (LOG_INFO, " node ID: %u\n", node->nodeid);
  879. log_printf (LOG_INFO, " admin state: %s\n",
  880. admin_state_text[node->saAmfNodeAdminState]);
  881. log_printf (LOG_INFO, " oper state: %s\n",
  882. oper_state_text[node->saAmfNodeOperState]);
  883. log_printf (LOG_INFO, " acsm state: %u\n", node->acsm_state);
  884. }
  885. for (app = cluster->application_head; app != NULL; app = app->next) {
  886. log_printf (LOG_INFO, " safApp=%s\n", getSaNameT(&app->name));
  887. log_printf (LOG_INFO, " admin state: %s\n",
  888. admin_state_text[app->saAmfApplicationAdminState]);
  889. log_printf (LOG_INFO, " num_sg: %d\n", app->saAmfApplicationCurrNumSG);
  890. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  891. log_printf (LOG_INFO, " safSg=%s\n", getSaNameT(&sg->name));
  892. log_printf (LOG_INFO, " avail_state: %u\n",
  893. sg->avail_state);
  894. log_printf (LOG_INFO, " admin state: %s\n",
  895. admin_state_text[sg->saAmfSGAdminState]);
  896. log_printf (LOG_INFO, " assigned SUs %d\n",
  897. sg->saAmfSGNumCurrAssignedSUs);
  898. log_printf (LOG_INFO, " non inst. spare SUs %d\n",
  899. sg->saAmfSGNumCurrNonInstantiatedSpareSUs);
  900. log_printf (LOG_INFO, " inst. spare SUs %d\n",
  901. sg->saAmfSGNumCurrInstantiatedSpareSUs);
  902. for (su = sg->su_head; su != NULL; su = su->next) {
  903. log_printf (LOG_INFO, " safSU=%s\n", getSaNameT(&su->name));
  904. log_printf (LOG_INFO, " oper state: %s\n",
  905. oper_state_text[su->saAmfSUOperState]);
  906. log_printf (LOG_INFO, " admin state: %s\n",
  907. admin_state_text[su->saAmfSUAdminState]);
  908. log_printf (LOG_INFO, " readiness state: %s\n",
  909. readiness_state_text[amf_su_get_saAmfSUReadinessState (su)]);
  910. log_printf (LOG_INFO, " presence state: %s\n",
  911. presence_state_text[su->saAmfSUPresenceState]);
  912. log_printf (LOG_INFO, " hosted by node %s\n",
  913. su->saAmfSUHostedByNode.value);
  914. log_printf (LOG_INFO, " num active SIs %d\n",
  915. amf_su_get_saAmfSUNumCurrActiveSIs (su));
  916. log_printf (LOG_INFO, " num standby SIs %d\n",
  917. amf_su_get_saAmfSUNumCurrStandbySIs (su));
  918. log_printf (LOG_INFO, " restart count %d\n",
  919. su->saAmfSURestartCount);
  920. log_printf (LOG_INFO, " restart control state %d\n",
  921. su->restart_control_state);
  922. log_printf (LOG_INFO, " SU failover cnt %d\n", su->su_failover_cnt);
  923. log_printf (LOG_INFO, " assigned SIs:");
  924. amf_su_foreach_si_assignment (su, print_si_assignment);
  925. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  926. log_printf (LOG_INFO, " safComp=%s\n", getSaNameT(&comp->name));
  927. log_printf (LOG_INFO, " oper state: %s\n",
  928. oper_state_text[comp->saAmfCompOperState]);
  929. log_printf (LOG_INFO, " readiness state: %s\n",
  930. readiness_state_text[amf_comp_get_saAmfCompReadinessState (comp)]);
  931. log_printf (LOG_INFO, " presence state: %s\n",
  932. presence_state_text[comp->saAmfCompPresenceState]);
  933. log_printf (LOG_INFO, " num active CSIs %d\n",
  934. amf_comp_get_saAmfCompNumCurrActiveCsi (comp));
  935. log_printf (LOG_INFO, " num standby CSIs %d\n",
  936. amf_comp_get_saAmfCompNumCurrStandbyCsi (comp));
  937. log_printf (LOG_INFO, " restart count %d\n",
  938. comp->saAmfCompRestartCount);
  939. log_printf (LOG_INFO, " assigned CSIs:");
  940. amf_comp_foreach_csi_assignment (
  941. comp, print_csi_assignment);
  942. }
  943. }
  944. }
  945. for (si = app->si_head; si != NULL; si = si->next) {
  946. log_printf (LOG_INFO, " safSi=%s\n", getSaNameT(&si->name));
  947. log_printf (LOG_INFO, " admin state: %s\n",
  948. admin_state_text[si->saAmfSIAdminState]);
  949. log_printf (LOG_INFO, " assignm. state: %s\n",
  950. assignment_state_text[
  951. amf_si_get_saAmfSIAssignmentState (si)]);
  952. log_printf (LOG_INFO, " active assignments: %d\n",
  953. amf_si_get_saAmfSINumCurrActiveAssignments (si));
  954. log_printf (LOG_INFO, " standby assignments: %d\n",
  955. amf_si_get_saAmfSINumCurrStandbyAssignments (si));
  956. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  957. log_printf (LOG_INFO, " safCsi=%s\n", getSaNameT(&csi->name));
  958. }
  959. }
  960. }
  961. log_printf (LOG_INFO, "===================================================");
  962. }
  963. /* to be removed... */
  964. int amf_enabled (struct objdb_iface_ver0 *objdb)
  965. {
  966. unsigned int object_service_handle;
  967. char *value;
  968. int enabled = 0;
  969. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  970. if (objdb->object_find (
  971. OBJECT_PARENT_HANDLE,
  972. "amf",
  973. strlen ("amf"),
  974. &object_service_handle) == 0) {
  975. value = NULL;
  976. if (!objdb->object_key_get (object_service_handle,
  977. "mode",
  978. strlen ("mode"),
  979. (void *)&value,
  980. NULL) && value) {
  981. if (strcmp (value, "enabled") == 0) {
  982. enabled = 1;
  983. } else
  984. if (strcmp (value, "disabled") == 0) {
  985. enabled = 0;
  986. }
  987. }
  988. }
  989. return enabled;
  990. }
  991. const char *amf_admin_state (int state)
  992. {
  993. return admin_state_text[state];
  994. }
  995. const char *amf_op_state (int state)
  996. {
  997. return oper_state_text[state];
  998. }
  999. const char *amf_presence_state (int state)
  1000. {
  1001. return presence_state_text[state];
  1002. }
  1003. const char *amf_ha_state (int state)
  1004. {
  1005. return ha_state_text[state];
  1006. }
  1007. const char *amf_readiness_state (int state)
  1008. {
  1009. return readiness_state_text[state];
  1010. }
  1011. const char *amf_assignment_state (int state)
  1012. {
  1013. return assignment_state_text[state];
  1014. }
  1015. #define ALIGN_ADDR(addr) ((addr) + (4 - ((unsigned long)(addr) % 4)))
  1016. char *amf_serialize_SaNameT (char *buf, int *size, int *offset, SaNameT *name)
  1017. {
  1018. char *tmp = buf;
  1019. if ((*size - *offset ) < sizeof (SaNameT)) {
  1020. *size += sizeof (SaNameT);
  1021. tmp = realloc (buf, *size);
  1022. if (tmp == NULL) {
  1023. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1024. }
  1025. }
  1026. memcpy (&tmp[*offset], name, sizeof (SaNameT));
  1027. (*offset) += sizeof (SaNameT);
  1028. return tmp;
  1029. }
  1030. char *amf_serialize_SaStringT (char *buf, int *size, int *offset, SaStringT str)
  1031. {
  1032. unsigned int len;
  1033. if (str != NULL) {
  1034. len = strlen ((char*)str);
  1035. } else {
  1036. len = 0;
  1037. }
  1038. return amf_serialize_opaque (buf, size, offset, str, len);
  1039. }
  1040. char *amf_serialize_SaUint16T (char *buf, int *size, int *offset, SaUint16T num)
  1041. {
  1042. char *tmp = buf;
  1043. if ((*size - *offset ) < sizeof (SaUint16T)) {
  1044. *size += sizeof (SaUint16T);
  1045. tmp = realloc (buf, *size);
  1046. if (tmp == NULL) {
  1047. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1048. }
  1049. }
  1050. *((SaUint16T *)&tmp[*offset]) = num;
  1051. (*offset) += sizeof (SaUint16T);
  1052. return tmp;
  1053. }
  1054. char *amf_serialize_SaUint32T (char *buf, int *size, int *offset, SaUint32T num)
  1055. {
  1056. char *tmp = buf;
  1057. if ((*size - *offset ) < sizeof (SaUint32T)) {
  1058. *size += sizeof (SaUint32T);
  1059. tmp = realloc (buf, *size);
  1060. if (tmp == NULL) {
  1061. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1062. }
  1063. }
  1064. *((SaUint32T *)&tmp[*offset]) = num;
  1065. (*offset) += sizeof (SaUint32T);
  1066. return tmp;
  1067. }
  1068. char *amf_serialize_opaque (
  1069. char *buf, int *size, int *offset, void *src, int cnt)
  1070. {
  1071. unsigned int required_size;
  1072. char *tmp = buf;
  1073. required_size = cnt + sizeof (SaUint32T);
  1074. if ((*size - *offset ) < required_size) {
  1075. *size += required_size;
  1076. tmp = realloc (buf, *size);
  1077. if (tmp == NULL) {
  1078. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1079. }
  1080. }
  1081. *((SaUint32T *)&tmp[*offset]) = cnt;
  1082. (*offset) += sizeof (SaUint32T);
  1083. memcpy (&tmp[*offset], src, cnt);
  1084. (*offset) += cnt;
  1085. return tmp;
  1086. }
  1087. char *amf_deserialize_SaNameT (char *buf, SaNameT *name)
  1088. {
  1089. memcpy (name, buf, sizeof (SaNameT));
  1090. return (buf + sizeof (SaNameT));
  1091. }
  1092. char *amf_deserialize_SaStringT (char *buf, SaStringT *str)
  1093. {
  1094. int len;
  1095. char *tmp, *tmp_str;
  1096. len = *((SaUint32T *)buf);
  1097. tmp = buf + sizeof (SaUint32T);
  1098. if (len > 0) {
  1099. tmp_str = amf_malloc (len + 1);
  1100. memcpy (tmp_str, tmp, len);
  1101. tmp_str[len] = '\0';
  1102. *str = tmp_str;
  1103. } else {
  1104. *str = NULL;
  1105. }
  1106. tmp += len;
  1107. return tmp;
  1108. }
  1109. char *amf_deserialize_SaUint16T (char *buf, SaUint16T *num)
  1110. {
  1111. *num = *((SaUint16T *)buf);
  1112. return buf + sizeof (SaUint16T);
  1113. }
  1114. char *amf_deserialize_SaUint32T (char *buf, SaUint32T *num)
  1115. {
  1116. *num = *((SaUint32T *)buf);
  1117. return buf + sizeof (SaUint32T);
  1118. }
  1119. char *amf_deserialize_opaque (char *buf, void *dst, int *cnt)
  1120. {
  1121. *cnt = *((SaUint32T *)buf);
  1122. memcpy (dst, buf + sizeof (SaUint32T), *cnt);
  1123. return buf + *cnt + sizeof (SaUint32T);
  1124. }
  1125. void *_amf_malloc (size_t size, char *file, unsigned int line)
  1126. {
  1127. void *tmp = malloc (size);
  1128. if (tmp == NULL) {
  1129. log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line);
  1130. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1131. }
  1132. return tmp;
  1133. }
  1134. void *_amf_calloc (size_t nmemb, size_t size, char *file, unsigned int line)
  1135. {
  1136. void *tmp = calloc (nmemb, size);
  1137. if (tmp == NULL) {
  1138. log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line);
  1139. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1140. }
  1141. return tmp;
  1142. }
  1143. void *_amf_realloc (void* ptr, size_t size, char *file, unsigned int line)
  1144. {
  1145. void *tmp = realloc (ptr, size);
  1146. if (tmp == NULL) {
  1147. log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line);
  1148. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1149. }
  1150. return tmp;
  1151. }
  1152. int sa_amf_grep_one_sub_match(const char *string, char *pattern,
  1153. SaNameT *matches_arr)
  1154. {
  1155. int status;
  1156. regex_t re;
  1157. size_t nmatch = 2;
  1158. regmatch_t pmatch[nmatch];
  1159. int i;
  1160. ENTER("'%s %s'",string, pattern);
  1161. if (regcomp(&re, pattern, REG_EXTENDED) != 0) {
  1162. status = 0;
  1163. goto out;
  1164. }
  1165. status = regexec(&re, string, nmatch, pmatch, 0);
  1166. if (status != 0) {
  1167. regfree(&re);
  1168. status = 0;
  1169. goto out;
  1170. } else {
  1171. for (i = 0; i < nmatch; i++) {
  1172. int sub_string_len;
  1173. sub_string_len = pmatch[i].rm_eo - pmatch[i].rm_so;
  1174. if (i==1) {
  1175. memcpy(matches_arr[i].value, string + pmatch[i].rm_so,
  1176. sub_string_len);
  1177. matches_arr[i].value[sub_string_len] = '\0';
  1178. }
  1179. }
  1180. status = 1;
  1181. regfree(&re);
  1182. }
  1183. out:
  1184. return status;
  1185. }
  1186. int sa_amf_grep(const char *string, char *pattern, size_t nmatch,
  1187. SaNameT *matches_arr)
  1188. {
  1189. int status;
  1190. regex_t re;
  1191. regmatch_t pmatch[nmatch];
  1192. int i;
  1193. ENTER("'%s %s'",string, pattern);
  1194. if (regcomp(&re, pattern, REG_EXTENDED) != 0) {
  1195. status = 0;
  1196. goto out;
  1197. }
  1198. status = regexec(&re, string, nmatch, pmatch, 0);
  1199. if (status != 0) {
  1200. regfree(&re);
  1201. status = 0;
  1202. goto out;
  1203. } else {
  1204. for (i = 0; i < nmatch; i++) {
  1205. int sub_string_len;
  1206. sub_string_len = pmatch[i].rm_eo - pmatch[i].rm_so;
  1207. memcpy(matches_arr[i].value, string + pmatch[i].rm_so,
  1208. sub_string_len);
  1209. matches_arr[i].value[sub_string_len] = '\0';
  1210. matches_arr[i].length = sub_string_len;
  1211. }
  1212. status = 1;
  1213. regfree(&re);
  1214. }
  1215. out:
  1216. return status;
  1217. }
  1218. /**
  1219. * Multicast a message to the cluster. Errors are treated as
  1220. * fatal and will exit the program.
  1221. * @param msg_id
  1222. * @param buf
  1223. * @param len
  1224. *
  1225. * @return int
  1226. */
  1227. int amf_msg_mcast (int msg_id, void *buf, size_t len)
  1228. {
  1229. struct req_exec_amf_msg msg;
  1230. struct iovec iov[2];
  1231. int iov_cnt;
  1232. int res;
  1233. // ENTER ("%u, %p, %u", msg_id, buf, len);
  1234. msg.header.size = sizeof (msg);
  1235. msg.header.id = SERVICE_ID_MAKE (AMF_SERVICE, msg_id);
  1236. iov[0].iov_base = &msg;
  1237. iov[0].iov_len = sizeof (msg);
  1238. if (buf == NULL) {
  1239. msg.header.size = sizeof (msg);
  1240. iov_cnt = 1;
  1241. } else {
  1242. msg.header.size = sizeof (msg) + len;
  1243. iov[1].iov_base = buf;
  1244. iov[1].iov_len = len;
  1245. iov_cnt = 2;
  1246. }
  1247. res = totempg_groups_mcast_joined (
  1248. openais_group_handle, iov, iov_cnt, TOTEMPG_AGREED);
  1249. if (res != 0) {
  1250. dprintf("Unable to send %d bytes\n", msg.header.size);
  1251. openais_exit_error (AIS_DONE_FATAL_ERR);
  1252. }
  1253. return res;
  1254. }
  1255. void amf_util_init (void)
  1256. {
  1257. log_init ("AMF");
  1258. }
  1259. void amf_fifo_put (int entry_type, amf_fifo_t **root, int size_of_data,
  1260. void *data)
  1261. {
  1262. amf_fifo_t *fifo;
  1263. amf_fifo_t **new_item = root;
  1264. /* Insert newest entry at the end of the single linked list */
  1265. for (fifo = *root; fifo != NULL; fifo = fifo->next) {
  1266. if (fifo->next == NULL) {
  1267. new_item = &fifo->next;
  1268. }
  1269. }
  1270. *new_item = amf_malloc (size_of_data + sizeof (amf_fifo_t));
  1271. fifo = *new_item;
  1272. /* Set data of this entry*/
  1273. fifo->entry_type = entry_type;
  1274. fifo->next = NULL;
  1275. fifo->size_of_data = size_of_data;
  1276. memcpy (fifo->data, data, size_of_data);
  1277. }
  1278. int amf_fifo_get (amf_fifo_t **root, void *data)
  1279. {
  1280. amf_fifo_t *fifo;
  1281. int result = 0;
  1282. fifo = *root;
  1283. if (fifo != NULL) {
  1284. /* Unlink oldest entry*/
  1285. *root = fifo->next;
  1286. memcpy (data, fifo->data, fifo->size_of_data);
  1287. free (fifo);
  1288. result = 1;
  1289. }
  1290. return result;
  1291. }
  1292. /**
  1293. *
  1294. * Use timer to call function f (void *data) after that current
  1295. * execution in this thread has been re-assumed because of a
  1296. * time-out. Time-out time is 0 msec so f will be called as soon
  1297. * as possible. *
  1298. *
  1299. * @param async_func
  1300. * @param func_param
  1301. */
  1302. void amf_call_function_asynchronous (async_func_t async_func, void *func_param)
  1303. {
  1304. static poll_timer_handle async_func_timer_handle;
  1305. poll_timer_add (aisexec_poll_handle, 0, func_param, async_func,
  1306. &async_func_timer_handle);
  1307. }