amfutil.c 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  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. "INSTANTION_FAILED",
  78. "TERMINIATION-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 {
  163. return -1;
  164. }
  165. return 0;
  166. }
  167. static void post_init_comp(struct amf_comp *comp)
  168. {
  169. if (comp->saAmfCompInstantiateTimeout == 0) {
  170. comp->saAmfCompInstantiateTimeout = comp->saAmfCompDefaultClcCliTimeout;
  171. }
  172. if (comp->saAmfCompTerminateTimeout == 0) {
  173. comp->saAmfCompTerminateTimeout = comp->saAmfCompDefaultClcCliTimeout;
  174. }
  175. if (comp->saAmfCompCleanupTimeout == 0) {
  176. comp->saAmfCompCleanupTimeout = comp->saAmfCompDefaultClcCliTimeout;
  177. }
  178. if (comp->saAmfCompAmStartTimeout == 0) {
  179. comp->saAmfCompAmStartTimeout = comp->saAmfCompDefaultClcCliTimeout;
  180. }
  181. if (comp->saAmfCompAmStopTimeout == 0) {
  182. comp->saAmfCompAmStopTimeout = comp->saAmfCompDefaultClcCliTimeout;
  183. }
  184. if (comp->saAmfCompTerminateCallbackTimeout == 0) {
  185. comp->saAmfCompTerminateCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  186. }
  187. if (comp->saAmfCompCSISetCallbackTimeout == 0) {
  188. comp->saAmfCompCSISetCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  189. }
  190. if (comp->saAmfCompCSIRmvCallbackTimeout == 0) {
  191. comp->saAmfCompCSIRmvCallbackTimeout = comp->saAmfCompDefaultCallbackTimeOut;
  192. }
  193. }
  194. static char *trim_str(char *str)
  195. {
  196. char *s = str + strlen (str) - 1;
  197. while (*s == '\t' || *s == ' ' || *s == '{') {
  198. *s = '\0';
  199. s--;
  200. }
  201. return str;
  202. }
  203. static char *rm_beginning_ws(char *str)
  204. {
  205. char *s = str + strlen (str) - 1;
  206. while (*s == '\t' || *s == ' ') {
  207. *s = '\0';
  208. s--;
  209. }
  210. s = str;
  211. while (*s == '\t' || *s == ' ') {
  212. s++;
  213. }
  214. return s;
  215. }
  216. struct amf_cluster *amf_config_read (char **error_string)
  217. {
  218. char buf[1024];
  219. char *line;
  220. FILE *fp;
  221. char *filename;
  222. amf_object_type_t current_parse = AMF_NONE;
  223. int line_number = 0;
  224. char *loc;
  225. int i;
  226. struct amf_cluster *cluster;
  227. struct amf_application *app = 0;
  228. struct amf_node *node = 0;
  229. struct amf_sg *sg = 0;
  230. struct amf_su *su = 0;
  231. struct amf_comp *comp = 0;
  232. struct amf_si *si = 0;
  233. struct amf_si_ranked_su *si_ranked_su = 0;
  234. struct amf_si_dependency *si_dependency = 0;
  235. struct amf_healthcheck *healthcheck = 0;
  236. struct amf_csi *csi = 0;
  237. struct amf_csi_attribute *attribute = 0;
  238. SaStringT env_var;
  239. int su_cnt = 0;
  240. int sg_cnt = 0;
  241. int comp_env_var_cnt = 0;
  242. int comp_cs_type_cnt = 0;
  243. int csi_attr_cnt = 0;
  244. int csi_dependencies_cnt = 0;
  245. char *error_reason = NULL;
  246. char *value;
  247. filename = getenv ("OPENAIS_AMF_CONFIG_FILE");
  248. if (!filename) {
  249. filename = "/etc/ais/amf.conf";
  250. }
  251. fp = fopen (filename, "r");
  252. if (fp == 0) {
  253. sprintf (buf, "Can't read %s file reason = (%s).\n",
  254. filename, strerror (errno));
  255. *error_string = buf;
  256. return NULL;
  257. }
  258. cluster = amf_cluster_new ();
  259. assert (cluster != NULL);
  260. while (fgets (buf, 255, fp)) {
  261. line_number += 1;
  262. line = buf;
  263. line[strlen(line) - 1] = '\0';
  264. /*
  265. * Clear out comments and empty lines
  266. */
  267. if (line[0] == '#' || line[0] == '\0' || line[0] == '\n') {
  268. continue;
  269. }
  270. /*
  271. * Clear out white space and tabs
  272. */
  273. for (i = strlen (line) - 1; i > -1; i--) {
  274. if (line[i] == '\t' || line[i] == ' ') {
  275. line[i] = '\0';
  276. } else {
  277. break;
  278. }
  279. }
  280. /* Trim whitespace from beginning of string */
  281. line = rm_beginning_ws(line);
  282. error_reason = line;
  283. error_reason = NULL;
  284. switch (current_parse) {
  285. case AMF_NONE:
  286. if ((loc = strstr_rs (line, "safAmfCluster=")) != 0) {
  287. setSaNameT (&cluster->name, trim_str (loc));
  288. current_parse = AMF_CLUSTER;
  289. } else {
  290. goto parse_error;
  291. }
  292. break;
  293. case AMF_CLUSTER:
  294. if ((loc = strstr_rs (line, "saAmfClusterClmCluster=")) != 0) {
  295. setSaNameT (&cluster->saAmfClusterClmCluster, loc);
  296. } else if ((loc = strstr_rs (line, "saAmfClusterStartupTimeout=")) != 0) {
  297. cluster->saAmfClusterStartupTimeout = atol(loc);
  298. } else if ((loc = strstr_rs (line, "safAmfNode=")) != 0) {
  299. node = amf_node_new (cluster, trim_str (loc));
  300. cluster->node_head = node;
  301. current_parse = AMF_NODE;
  302. } else if ((loc = strstr_rs (line, "safApp=")) != 0) {
  303. app = calloc (1, sizeof (struct amf_application));
  304. app->next = cluster->application_head;
  305. cluster->application_head = app;
  306. app->cluster = cluster;
  307. app->saAmfApplicationAdminState = SA_AMF_ADMIN_UNLOCKED;
  308. setSaNameT (&app->name, trim_str (loc));
  309. current_parse = AMF_APPLICATION;
  310. sg_cnt = 0;
  311. } else if (strstr_rs (line, "}")) {
  312. if (cluster->saAmfClusterStartupTimeout == -1) {
  313. error_reason = "saAmfClusterStartupTimeout missing";
  314. goto parse_error;
  315. }
  316. /* spec: set to default value if zero */
  317. if (cluster->saAmfClusterStartupTimeout == 0) {
  318. cluster->saAmfClusterStartupTimeout = OPENAIS_CLUSTER_STARTUP_TIMEOUT;
  319. }
  320. current_parse = AMF_NONE;
  321. } else {
  322. goto parse_error;
  323. }
  324. break;
  325. case AMF_NODE:
  326. if ((loc = strstr_rs (line, "saAmfNodeSuFailOverProb=")) != 0) {
  327. node->saAmfNodeSuFailOverProb = atol(loc);
  328. } else if ((loc = strstr_rs (line, "saAmfNodeSuFailoverMax=")) != 0) {
  329. node->saAmfNodeSuFailoverMax = atol(loc);
  330. } else if ((loc = strstr_rs (line, "saAmfNodeClmNode=")) != 0) {
  331. setSaNameT (&node->saAmfNodeClmNode, trim_str (loc));
  332. } else if ((loc = strstr_rs (line, "saAmfNodeAutoRepair=")) != 0) {
  333. if (strcmp (loc, "true") == 0) {
  334. node->saAmfNodeAutoRepair = SA_TRUE;
  335. } else if (strcmp (loc, "false") == 0) {
  336. node->saAmfNodeAutoRepair = SA_FALSE;
  337. } else {
  338. goto parse_error;
  339. }
  340. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnTerminationFailure=")) != 0) {
  341. if (strcmp (loc, "true") == 0) {
  342. node->saAmfNodeRebootOnTerminationFailure = SA_TRUE;
  343. } else if (strcmp (loc, "false") == 0) {
  344. node->saAmfNodeRebootOnTerminationFailure = SA_FALSE;
  345. } else {
  346. goto parse_error;
  347. }
  348. } else if ((loc = strstr_rs (line, "saAmfNodeRebootOnInstantiationFailure=")) != 0) {
  349. if (strcmp (loc, "true") == 0) {
  350. node->saAmfNodeRebootOnInstantiationFailure = SA_TRUE;
  351. } else if (strcmp (loc, "false") == 0) {
  352. node->saAmfNodeRebootOnInstantiationFailure = SA_FALSE;
  353. } else {
  354. goto parse_error;
  355. }
  356. } else if (strstr_rs (line, "}")) {
  357. if (node->saAmfNodeSuFailOverProb == -1) {
  358. error_reason = "saAmfNodeSuFailOverProb missing";
  359. goto parse_error;
  360. }
  361. if (node->saAmfNodeSuFailoverMax == ~0) {
  362. error_reason = "saAmfNodeSuFailoverMax missing";
  363. goto parse_error;
  364. }
  365. if (node->saAmfNodeClmNode.length == 0) {
  366. error_reason = "saAmfNodeClmNode missing";
  367. goto parse_error;
  368. }
  369. current_parse = AMF_CLUSTER;
  370. } else {
  371. goto parse_error;
  372. }
  373. break;
  374. case AMF_APPLICATION:
  375. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  376. app->clccli_path = amf_malloc (strlen (loc) + 1);
  377. strcpy (app->clccli_path, loc);
  378. } else if ((loc = strstr_rs (line, "safSg=")) != 0) {
  379. sg = amf_sg_new (app, trim_str (loc));
  380. sg_cnt++;
  381. sg->recovery_scope.comp = NULL;
  382. sg->recovery_scope.recovery_type = 0;
  383. sg->recovery_scope.sis = NULL;
  384. sg->recovery_scope.sus = NULL;
  385. current_parse = AMF_SG;
  386. su_cnt = 0;
  387. } else if ((loc = strstr_rs (line, "safSi=")) != 0) {
  388. si = amf_si_new (app, trim_str (loc));
  389. current_parse = AMF_SI;
  390. } else if ((loc = strstr_rs (line, "safCSType=")) != 0) {
  391. current_parse = AMF_CS_TYPE;
  392. } else if (strstr_rs (line, "}")) {
  393. if (sg_cnt == 1) {
  394. for (si = app->si_head; si != NULL; si = si->next) {
  395. memcpy (&si->saAmfSIProtectedbySG, &sg->name,
  396. sizeof (SaNameT));
  397. }
  398. } else {
  399. for (si = app->si_head; si != NULL; si = si->next) {
  400. if (si->saAmfSIProtectedbySG.length == 0) {
  401. error_reason = "saAmfSIProtectedbySG not set in SI"
  402. ", needed when several SGs are specified.";
  403. goto parse_error;
  404. }
  405. }
  406. }
  407. current_parse = AMF_CLUSTER;
  408. } else {
  409. goto parse_error;
  410. }
  411. break;
  412. case AMF_SG:
  413. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  414. sg->clccli_path = amf_malloc (strlen (loc) + 1);
  415. strcpy (sg->clccli_path, loc);
  416. } else if ((loc = strstr_rs (line, "saAmfSGRedundancyModel=")) != 0) {
  417. if (strcmp (loc, "2n") == 0) {
  418. sg->saAmfSGRedundancyModel = SA_AMF_2N_REDUNDANCY_MODEL;
  419. } else if (strcmp (loc, "nplusm") == 0) {
  420. sg->saAmfSGRedundancyModel = SA_AMF_NPM_REDUNDANCY_MODEL;
  421. } else if (strcmp (loc, "nway") == 0) {
  422. error_reason = "nway redundancy model not supported";
  423. goto parse_error;
  424. } else if (strcmp (loc, "nwayactive") == 0) {
  425. error_reason = "nway active redundancy model not supported";
  426. goto parse_error;
  427. } else if (strcmp (loc, "noredundancy") == 0) {
  428. sg->saAmfSGRedundancyModel = SA_AMF_NO_REDUNDANCY_MODEL;
  429. } else {
  430. goto parse_error;
  431. }
  432. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefActiveSUs=")) != 0) {
  433. sg->saAmfSGNumPrefActiveSUs = atoi (loc);
  434. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefStandbySUs=")) != 0) {
  435. sg->saAmfSGNumPrefStandbySUs = atoi (loc);
  436. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefInserviceSUs=")) != 0) {
  437. sg->saAmfSGNumPrefInserviceSUs = atoi (loc);
  438. } else if ((loc = strstr_rs (line, "saAmfSGNumPrefAssignedSUs=")) != 0) {
  439. sg->saAmfSGNumPrefAssignedSUs = atoi (loc);
  440. } else if ((loc = strstr_rs (line, "saAmfSGMaxActiveSIsperSUs=")) != 0) {
  441. sg->saAmfSGMaxActiveSIsperSUs = atoi (loc);
  442. } else if ((loc = strstr_rs (line, "saAmfSGMaxStandbySIsperSUs=")) != 0) {
  443. sg->saAmfSGMaxStandbySIsperSUs = atoi (loc);
  444. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartProb=")) != 0) {
  445. sg->saAmfSGCompRestartProb = atoi (loc);
  446. } else if ((loc = strstr_rs (line, "saAmfSGCompRestartMax=")) != 0) {
  447. sg->saAmfSGCompRestartMax = atoi (loc);
  448. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartProb=")) != 0) {
  449. sg->saAmfSGSuRestartProb = atoi (loc);
  450. } else if ((loc = strstr_rs (line, "saAmfSGSuRestartMax=")) != 0) {
  451. sg->saAmfSGSuRestartMax = atoi (loc);
  452. } else if ((loc = strstr_rs (line, "saAmfSGAutoAdjustProb=")) != 0) {
  453. sg->saAmfSGAutoAdjustProb = atoi (loc);
  454. } else if ((loc = strstr_rs (line, "saAmfSGAutoRepair=")) != 0) {
  455. sg->saAmfSGAutoRepair = atoi (loc);
  456. } else if ((loc = strstr_rs (line, "safSu=")) != 0) {
  457. su = amf_su_new (sg, trim_str (loc));
  458. su_cnt++;
  459. current_parse = AMF_SU;
  460. } else if (strstr_rs (line, "}")) {
  461. if (sg->saAmfSGRedundancyModel == 0) {
  462. error_reason = "saAmfSGRedundancyModel missing";
  463. goto parse_error;
  464. }
  465. if (sg->saAmfSGCompRestartProb == -1) {
  466. error_reason = "saAmfSGCompRestartProb missing";
  467. goto parse_error;
  468. }
  469. if (sg->saAmfSGCompRestartMax == ~0) {
  470. error_reason = "saAmfSGCompRestartMax missing";
  471. goto parse_error;
  472. }
  473. if (sg->saAmfSGSuRestartProb == -1) {
  474. error_reason = "saAmfSGSuRestartProb missing";
  475. goto parse_error;
  476. }
  477. if (sg->saAmfSGSuRestartMax == ~0) {
  478. error_reason = "saAmfSGSuRestartMax missing";
  479. goto parse_error;
  480. }
  481. if (sg->saAmfSGAutoAdjustProb == -1) {
  482. error_reason = "saAmfSGAutoAdjustProb missing";
  483. goto parse_error;
  484. }
  485. if (sg->saAmfSGAutoRepair > 1) {
  486. error_reason = "saAmfSGAutoRepair erroneous";
  487. goto parse_error;
  488. }
  489. if (sg->saAmfSGNumPrefInserviceSUs == ~0) {
  490. sg->saAmfSGNumPrefInserviceSUs = su_cnt;
  491. }
  492. if (sg->saAmfSGNumPrefAssignedSUs == ~0) {
  493. sg->saAmfSGNumPrefAssignedSUs =
  494. sg->saAmfSGNumPrefInserviceSUs;
  495. }
  496. current_parse = AMF_APPLICATION;
  497. } else {
  498. goto parse_error;
  499. }
  500. break;
  501. case AMF_SU:
  502. if ((loc = strstr_rs (line, "saAmfSUNumComponents=")) != 0) {
  503. su->saAmfSUNumComponents = atoi (loc);
  504. } else if ((loc = strstr_rs (line, "saAmfSUIsExternal=")) != 0) {
  505. su->saAmfSUIsExternal = atoi (loc);
  506. } else if ((loc = strstr_rs (line, "saAmfSUFailover=")) != 0) {
  507. su->saAmfSUFailover = atoi (loc);
  508. } else if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  509. su->clccli_path = amf_malloc (strlen (loc) + 1);
  510. strcpy (su->clccli_path, loc);
  511. } else if ((loc = strstr_rs (line, "saAmfSUHostedByNode=")) != 0) {
  512. setSaNameT (&su->saAmfSUHostedByNode, loc);
  513. } else if ((loc = strstr_rs (line, "safComp=")) != 0) {
  514. comp = amf_comp_new (su, trim_str (loc));
  515. comp_env_var_cnt = 0;
  516. comp_cs_type_cnt = 0;
  517. current_parse = AMF_COMP;
  518. } else if (strstr_rs (line, "}")) {
  519. if (su->saAmfSUNumComponents == 0) {
  520. error_reason = "saAmfSUNumComponents missing";
  521. goto parse_error;
  522. }
  523. if (su->saAmfSUIsExternal > 1) {
  524. error_reason = "saAmfSUIsExternal erroneous";
  525. goto parse_error;
  526. }
  527. if (su->saAmfSUFailover > 1) {
  528. error_reason = "saAmfSUFailover erroneous";
  529. goto parse_error;
  530. }
  531. if (strcmp ((char*)su->saAmfSUHostedByNode.value, "") == 0) {
  532. error_reason = "saAmfSUHostedByNode missing";
  533. goto parse_error;
  534. }
  535. current_parse = AMF_SG;
  536. } else {
  537. goto parse_error;
  538. }
  539. break;
  540. case AMF_COMP:
  541. if ((loc = strstr_rs (line, "clccli_path=")) != 0) {
  542. comp->clccli_path = amf_malloc (strlen (loc) + 1);
  543. strcpy (comp->clccli_path, loc);
  544. } else if ((loc = strstr_rs (line, "saAmfCompCsTypes{")) != 0) {
  545. current_parse = AMF_COMP_CS_TYPE;
  546. } else if ((loc = strstr_rs(line, "saAmfCompCategory=")) != 0) {
  547. if (init_category(comp, loc) != 0) {
  548. error_reason = "unknown category";
  549. goto parse_error;
  550. }
  551. } else if ((loc = strstr_rs (line, "saAmfCompCapability=")) != 0) {
  552. if (init_capability(comp, loc) != 0) {
  553. error_reason = "unknown capability model";
  554. goto parse_error;
  555. }
  556. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxActiveCsi=")) != 0) {
  557. comp->saAmfCompNumMaxActiveCsi = atol (loc);
  558. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxStandbyCsi=")) != 0) {
  559. comp->saAmfCompNumMaxStandbyCsi = atol (loc);
  560. } else if ((loc = strstr_rs (line, "saAmfCompCmdEnv{")) != 0) {
  561. current_parse = AMF_COMP_ENV_VAR;
  562. } else if ((loc = strstr_rs(line, "saAmfCompDefaultClcCliTimeout=")) != 0) {
  563. comp->saAmfCompDefaultClcCliTimeout = atol (loc);
  564. } else if ((loc = strstr_rs(line, "saAmfCompDefaultCallbackTimeOut=")) != 0) {
  565. comp->saAmfCompDefaultCallbackTimeOut = atol (loc);
  566. } else if ((loc = strstr_rs (line, "saAmfCompInstantiateCmdArgv=")) != 0) {
  567. comp->saAmfCompInstantiateCmdArgv = amf_malloc (strlen(loc) + 1);
  568. strcpy (comp->saAmfCompInstantiateCmdArgv, loc);
  569. } else if ((loc = strstr_rs ( line, "saAmfCompInstantiateCmd=")) != 0) {
  570. comp->saAmfCompInstantiateCmd = amf_malloc (strlen(loc) + 1);
  571. strcpy (comp->saAmfCompInstantiateCmd, loc);
  572. } else if ((loc = strstr_rs(line, "saAmfCompInstantiateTimeout=")) != 0) {
  573. comp->saAmfCompInstantiateTimeout = atol (loc);
  574. } else if ((loc = strstr_rs(line, "saAmfCompInstantiationLevel=")) != 0) {
  575. comp->saAmfCompInstantiationLevel = atol (loc);
  576. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithoutDelay=")) != 0) {
  577. comp->saAmfCompNumMaxInstantiateWithoutDelay = atol (loc);
  578. } else if ((loc = strstr_rs(line, "saAmfCompNumMaxInstantiateWithDelay=")) != 0) {
  579. comp->saAmfCompNumMaxInstantiateWithDelay = atol (loc);
  580. } else if ((loc = strstr_rs(line, "saAmfCompDelayBetweenInstantiateAttempts=")) != 0) {
  581. comp->saAmfCompDelayBetweenInstantiateAttempts = atol (loc);
  582. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmdArgv=")) != 0) {
  583. comp->saAmfCompTerminateCmdArgv = amf_malloc (strlen(loc) + 1);
  584. strcpy (comp->saAmfCompTerminateCmdArgv, loc);
  585. } else if ((loc = strstr_rs (line, "saAmfCompTerminateCmd=")) != 0) {
  586. comp->saAmfCompTerminateCmd = amf_malloc (strlen(loc) + 1);
  587. strcpy (comp->saAmfCompTerminateCmd, loc);
  588. } else if ((loc = strstr_rs(line, "saAmfCompTerminateTimeout=")) != 0) {
  589. comp->saAmfCompTerminateTimeout = atol (loc);
  590. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmdArgv=")) != 0) {
  591. comp->saAmfCompCleanupCmdArgv = amf_malloc (strlen(loc) + 1);
  592. strcpy (comp->saAmfCompCleanupCmdArgv, loc);
  593. } else if ((loc = strstr_rs (line, "saAmfCompCleanupCmd=")) != 0) {
  594. comp->saAmfCompCleanupCmd = amf_malloc (strlen(loc) + 1);
  595. strcpy (comp->saAmfCompCleanupCmd, loc);
  596. } else if ((loc = strstr_rs(line, "saAmfCompCleanupTimeout=")) != 0) {
  597. comp->saAmfCompCleanupTimeout = atol (loc);
  598. } else if ((loc = strstr_rs(line, "saAmfCompTerminateCallbackTimeout=")) != 0) {
  599. comp->saAmfCompTerminateCallbackTimeout = atol (loc);
  600. } else if ((loc = strstr_rs(line, "saAmfCompCSISetCallbackTimeout=")) != 0) {
  601. comp->saAmfCompCSISetCallbackTimeout = atol (loc);
  602. } else if ((loc = strstr_rs(line, "saAmfCompQuiescingCompleteTimeout=")) != 0) {
  603. comp->saAmfCompQuiescingCompleteTimeout = atol (loc);
  604. } else if ((loc = strstr_rs(line, "saAmfCompCSIRmvCallbackTimeout=")) != 0) {
  605. comp->saAmfCompCSIRmvCallbackTimeout = atol (loc);
  606. } else if ((loc = strstr_rs (line, "saAmfCompRecoveryOnError=")) != 0) {
  607. if (init_recovery_on_error (comp, loc) != 0) {
  608. error_reason = "bad value";
  609. goto parse_error;
  610. }
  611. } else if ((loc = strstr_rs (line, "saAmfCompDisableRestart")) != 0) {
  612. if (strcmp (loc, "false") == 0) {
  613. comp->saAmfCompDisableRestart = SA_FALSE;
  614. } else if (strcmp (loc, "true") == 0) {
  615. comp->saAmfCompDisableRestart = SA_TRUE;
  616. } else {
  617. error_reason = "bad value";
  618. goto parse_error;
  619. }
  620. } else if ((loc = strstr_rs (line, "saAmfCompProxyCsi=")) != 0) {
  621. setSaNameT (&comp->saAmfCompProxyCsi, loc);
  622. } else if ((loc = strstr_rs (line, "safHealthcheckKey=")) != 0) {
  623. healthcheck = calloc (1, sizeof (struct amf_healthcheck));
  624. healthcheck->next = comp->healthcheck_head;
  625. comp->healthcheck_head = healthcheck;
  626. healthcheck->comp = comp;
  627. strcpy ((char *)healthcheck->safHealthcheckKey.key, trim_str (loc));
  628. healthcheck->safHealthcheckKey.keyLen = strlen (loc);
  629. current_parse = AMF_HEALTHCHECK;
  630. } else if (strstr_rs (line, "}")) {
  631. if (comp->saAmfCompCategory == 0) {
  632. error_reason = "category missing";
  633. goto parse_error;
  634. }
  635. if (comp->saAmfCompCapability == 0) {
  636. error_reason = "capability model missing";
  637. goto parse_error;
  638. }
  639. if (comp->saAmfCompCategory == SA_AMF_COMP_SA_AWARE) {
  640. comp->comptype = clc_component_sa_aware;
  641. } else if (comp->saAmfCompCategory == SA_AMF_COMP_PROXY) {
  642. if (comp->saAmfCompCapability == SA_AMF_COMP_NON_PRE_INSTANTIABLE) {
  643. comp->comptype = clc_component_proxied_non_pre;
  644. } else {
  645. comp->comptype = clc_component_proxied_pre;
  646. }
  647. } else if (comp->saAmfCompCategory == SA_AMF_COMP_LOCAL) {
  648. comp->comptype = clc_component_non_proxied_non_sa_aware;
  649. }
  650. if (comp->saAmfCompNumMaxActiveCsi == 0) {
  651. error_reason = "saAmfCompNumMaxActiveCsi missing";
  652. goto parse_error;
  653. }
  654. if (comp->saAmfCompNumMaxStandbyCsi == 0) {
  655. error_reason = "saAmfCompNumMaxStandbyCsi missing";
  656. goto parse_error;
  657. }
  658. if (comp->saAmfCompDefaultClcCliTimeout == 0) {
  659. error_reason = "saAmfCompDefaultClcCliTimeout missing or erroneous";
  660. goto parse_error;
  661. }
  662. if (comp->saAmfCompDefaultCallbackTimeOut == 0) {
  663. error_reason = "saAmfCompDefaultCallbackTimeOut missing or erroneous";
  664. goto parse_error;
  665. }
  666. if (comp->saAmfCompRecoveryOnError == 0) {
  667. error_reason = "saAmfCompRecoveryOnError missing";
  668. goto parse_error;
  669. }
  670. post_init_comp (comp);
  671. current_parse = AMF_SU;
  672. } else {
  673. error_reason = line;
  674. goto parse_error;
  675. }
  676. break;
  677. case AMF_COMP_CS_TYPE:
  678. if (strstr_rs (line, "}")) {
  679. current_parse = AMF_COMP;
  680. } else {
  681. comp_cs_type_cnt++;
  682. comp->saAmfCompCsTypes = realloc (comp->saAmfCompCsTypes,
  683. (comp_cs_type_cnt + 1) * sizeof(SaNameT));
  684. comp->saAmfCompCsTypes[comp_cs_type_cnt] = NULL;
  685. comp->saAmfCompCsTypes[comp_cs_type_cnt - 1] = amf_malloc (sizeof(SaNameT));
  686. setSaNameT (comp->saAmfCompCsTypes[comp_cs_type_cnt - 1], line);
  687. }
  688. break;
  689. case AMF_COMP_ENV_VAR:
  690. if (strstr_rs (line, "}")) {
  691. current_parse = AMF_COMP;
  692. } else if ((loc = strchr (line, '=')) != 0) {
  693. comp_env_var_cnt++;
  694. comp->saAmfCompCmdEnv = realloc (comp->saAmfCompCmdEnv,
  695. (comp_env_var_cnt + 1) * sizeof(SaStringT));
  696. comp->saAmfCompCmdEnv[comp_env_var_cnt] = NULL;
  697. env_var = comp->saAmfCompCmdEnv[comp_env_var_cnt - 1] = amf_malloc (strlen (line) + 1);
  698. strcpy (env_var, line);
  699. } else {
  700. goto parse_error;
  701. }
  702. break;
  703. case AMF_HEALTHCHECK:
  704. if ((loc = strstr_rs (line, "saAmfHealthcheckPeriod=")) != 0) {
  705. healthcheck->saAmfHealthcheckPeriod = atoi (loc);
  706. } else if ((loc = strstr_rs (line, "saAmfHealthcheckMaxDuration=")) != 0) {
  707. healthcheck->saAmfHealthcheckMaxDuration = atoi (loc);
  708. } else if (strstr_rs (line, "}")) {
  709. current_parse = AMF_COMP;
  710. } else {
  711. goto parse_error;
  712. }
  713. break;
  714. case AMF_SI:
  715. if ((loc = strstr_rs (line, "safRankedSu=")) != 0) {
  716. si_ranked_su = calloc (1, sizeof(struct amf_si_ranked_su));
  717. si_ranked_su->si_next = si->ranked_sus;
  718. si->ranked_sus = si_ranked_su;
  719. si_ranked_su->si = si;
  720. setSaNameT (&si_ranked_su->name, trim_str (loc));
  721. current_parse = AMF_SI_RANKED_SU;
  722. } else if ((loc = strstr_rs (line, "safDepend=")) != 0) {
  723. si_dependency = calloc (1, sizeof(struct amf_si_dependency));
  724. si_dependency->next = si->depends_on;
  725. si->depends_on = si_dependency;
  726. setSaNameT (&si_dependency->name, trim_str (loc));
  727. current_parse = AMF_SI_DEPENDENCY;
  728. } else if ((loc = strstr_rs (line, "safCsi=")) != 0) {
  729. csi = calloc (1, sizeof(struct amf_csi));
  730. csi->next = si->csi_head;
  731. si->csi_head = csi;
  732. csi->si = si;
  733. setSaNameT (&csi->name, trim_str (loc));
  734. current_parse = AMF_CSI;
  735. } else if ((loc = strstr_rs (line, "saAmfSIProtectedbySG=")) != 0) {
  736. setSaNameT (&si->saAmfSIProtectedbySG, loc);
  737. } else if ((loc = strstr_rs (line, "saAmfSIRank=")) != 0) {
  738. si->saAmfSIRank = atoi (loc);
  739. } else if ((loc = strstr_rs (line, "saAmfSINumCSIs=")) != 0) {
  740. si->saAmfSINumCSIs = atoi (loc);
  741. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  742. si->saAmfSIPrefActiveAssignments = atoi (loc);
  743. } else if ((loc = strstr_rs (line, "saAmfSIPrefActiveAssignments=")) != 0) {
  744. si->saAmfSIPrefStandbyAssignments = atoi (loc);
  745. } else if (strstr_rs (line, "}")) {
  746. if (si->saAmfSINumCSIs == 0) {
  747. error_reason = "saAmfSINumCSIs missing";
  748. goto parse_error;
  749. }
  750. current_parse = AMF_APPLICATION;
  751. } else {
  752. goto parse_error;
  753. }
  754. break;
  755. case AMF_SI_RANKED_SU:
  756. if ((loc = strstr_rs (line, "saAmfRank=")) != 0) {
  757. si_ranked_su->saAmfRank = atoi (loc);
  758. } else if (strstr_rs (line, "}")) {
  759. current_parse = AMF_SI;
  760. } else {
  761. goto parse_error;
  762. }
  763. break;
  764. case AMF_SI_DEPENDENCY:
  765. if ((loc = strstr_rs (line, "saAmfToleranceTime=")) != 0) {
  766. si_dependency->saAmfToleranceTime = atoi (loc);
  767. } else if (strstr_rs (line, "}")) {
  768. current_parse = AMF_SI;
  769. } else {
  770. goto parse_error;
  771. }
  772. break;
  773. case AMF_CSI:
  774. if ((loc = strstr_rs (line, "saAmfCSTypeName=")) != 0) {
  775. setSaNameT (&csi->saAmfCSTypeName, loc);
  776. } else if ((loc = strstr_rs (line, "safCSIAttr=")) != 0) {
  777. attribute = calloc (1, sizeof(struct amf_csi_attribute));
  778. attribute->next = csi->attributes_head;
  779. csi->attributes_head = attribute;
  780. attribute->name = amf_malloc (strlen (loc) + 1);
  781. strcpy (attribute->name, trim_str (loc));
  782. csi_attr_cnt = 1;
  783. current_parse = AMF_CSI_ATTRIBUTE;
  784. } else if ((loc = strstr_rs (line, "saAmfCsiDependencies{")) != 0) {
  785. csi_dependencies_cnt = 0;
  786. current_parse = AMF_CSI_DEPENDENCIES;
  787. } else if (strstr_rs (line, "}")) {
  788. if (strcmp(getSaNameT(&csi->saAmfCSTypeName), "") == 0) {
  789. error_reason = "saAmfCSTypeName missing";
  790. goto parse_error;
  791. }
  792. current_parse = AMF_SI;
  793. } else {
  794. goto parse_error;
  795. }
  796. break;
  797. case AMF_CSI_DEPENDENCIES:
  798. if (strstr_rs (line, "}")) {
  799. current_parse = AMF_CSI;
  800. } else if ((loc = strstr_rs (line, "saAmfCSIDependency=")) != 0) {
  801. csi_dependencies_cnt++;
  802. csi->saAmfCSIDependencies = realloc (csi->saAmfCSIDependencies,
  803. (csi_dependencies_cnt + 1) * sizeof(SaNameT));
  804. csi->saAmfCSIDependencies[csi_dependencies_cnt] = NULL;
  805. csi->saAmfCSIDependencies[csi_dependencies_cnt - 1] =
  806. amf_malloc (sizeof(SaNameT));
  807. setSaNameT (
  808. csi->saAmfCSIDependencies[csi_dependencies_cnt - 1], loc);
  809. } else {
  810. goto parse_error;
  811. }
  812. break;
  813. case AMF_CSI_ATTRIBUTE:
  814. if ((loc = strstr_rs (line, "}")) != 0) {
  815. current_parse = AMF_CSI;
  816. } else {
  817. value = rm_beginning_ws (line);
  818. attribute->value = realloc (attribute->value,
  819. sizeof (SaStringT) * (csi_attr_cnt + 1));
  820. attribute->value[csi_attr_cnt - 1] =
  821. amf_malloc (strlen (value) + 1);
  822. strcpy (attribute->value[csi_attr_cnt - 1], value);
  823. attribute->value[csi_attr_cnt] = NULL;
  824. csi_attr_cnt++;
  825. }
  826. break;
  827. case AMF_CS_TYPE:
  828. if ((loc = strstr_rs (line, "}")) != 0) {
  829. current_parse = AMF_APPLICATION;
  830. }
  831. break;
  832. default:
  833. error_reason = "Invalid state\n";
  834. goto parse_error;
  835. break;
  836. }
  837. }
  838. fclose (fp);
  839. return cluster;
  840. parse_error:
  841. sprintf (buf, "parse error at %s: %d: %s\n",
  842. filename, line_number, error_reason);
  843. *error_string = buf;
  844. fclose (fp);
  845. return NULL;
  846. }
  847. static void print_csi_assignment (struct amf_comp *comp,
  848. struct amf_csi_assignment *csi_assignment)
  849. {
  850. log_printf (LOG_INFO, " safCSI=%s\n", csi_assignment->csi->name.value);
  851. log_printf (LOG_INFO, " HA state: %s\n",
  852. ha_state_text[csi_assignment->saAmfCSICompHAState]);
  853. }
  854. static void print_si_assignment (struct amf_su *su,
  855. struct amf_si_assignment *si_assignment)
  856. {
  857. log_printf (LOG_INFO, " safSi=%s\n", si_assignment->si->name.value);
  858. log_printf (LOG_INFO, " HA state: %s\n",
  859. ha_state_text[si_assignment->saAmfSISUHAState]);
  860. }
  861. void amf_runtime_attributes_print (struct amf_cluster *cluster)
  862. {
  863. struct amf_node *node;
  864. struct amf_application *app;
  865. struct amf_sg *sg;
  866. struct amf_su *su;
  867. struct amf_comp *comp;
  868. struct amf_si *si;
  869. struct amf_csi *csi;
  870. log_printf (LOG_INFO, "AMF runtime attributes:");
  871. log_printf (LOG_INFO, "===================================================");
  872. log_printf (LOG_INFO, "safCluster=%s", getSaNameT(&cluster->name));
  873. log_printf (LOG_INFO, " admin state: %s\n",
  874. admin_state_text[cluster->saAmfClusterAdminState]);
  875. log_printf (LOG_INFO, " state: %u\n", cluster->state);
  876. for (node = cluster->node_head; node != NULL; node = node->next) {
  877. log_printf (LOG_INFO, " safNode=%s\n", getSaNameT (&node->name));
  878. log_printf (LOG_INFO, " CLM Node: %s\n", getSaNameT (&node->saAmfNodeClmNode));
  879. log_printf (LOG_INFO, " node ID: %u\n", node->nodeid);
  880. log_printf (LOG_INFO, " admin state: %s\n",
  881. admin_state_text[node->saAmfNodeAdminState]);
  882. log_printf (LOG_INFO, " oper state: %s\n",
  883. oper_state_text[node->saAmfNodeOperState]);
  884. log_printf (LOG_INFO, " acsm state: %u\n", node->acsm_state);
  885. }
  886. for (app = cluster->application_head; app != NULL; app = app->next) {
  887. log_printf (LOG_INFO, " safApp=%s\n", getSaNameT(&app->name));
  888. log_printf (LOG_INFO, " admin state: %s\n",
  889. admin_state_text[app->saAmfApplicationAdminState]);
  890. log_printf (LOG_INFO, " num_sg: %d\n", app->saAmfApplicationCurrNumSG);
  891. for (sg = app->sg_head; sg != NULL; sg = sg->next) {
  892. log_printf (LOG_INFO, " safSg=%s\n", getSaNameT(&sg->name));
  893. log_printf (LOG_INFO, " avail_state: %u\n",
  894. sg->avail_state);
  895. log_printf (LOG_INFO, " admin state: %s\n",
  896. admin_state_text[sg->saAmfSGAdminState]);
  897. log_printf (LOG_INFO, " assigned SUs %d\n",
  898. sg->saAmfSGNumCurrAssignedSUs);
  899. log_printf (LOG_INFO, " non inst. spare SUs %d\n",
  900. sg->saAmfSGNumCurrNonInstantiatedSpareSUs);
  901. log_printf (LOG_INFO, " inst. spare SUs %d\n",
  902. sg->saAmfSGNumCurrInstantiatedSpareSUs);
  903. for (su = sg->su_head; su != NULL; su = su->next) {
  904. log_printf (LOG_INFO, " safSU=%s\n", getSaNameT(&su->name));
  905. log_printf (LOG_INFO, " oper state: %s\n",
  906. oper_state_text[su->saAmfSUOperState]);
  907. log_printf (LOG_INFO, " admin state: %s\n",
  908. admin_state_text[su->saAmfSUAdminState]);
  909. log_printf (LOG_INFO, " readiness state: %s\n",
  910. readiness_state_text[amf_su_get_saAmfSUReadinessState (su)]);
  911. log_printf (LOG_INFO, " presence state: %s\n",
  912. presence_state_text[su->saAmfSUPresenceState]);
  913. log_printf (LOG_INFO, " hosted by node %s\n",
  914. su->saAmfSUHostedByNode.value);
  915. log_printf (LOG_INFO, " num active SIs %d\n",
  916. amf_su_get_saAmfSUNumCurrActiveSIs (su));
  917. log_printf (LOG_INFO, " num standby SIs %d\n",
  918. amf_su_get_saAmfSUNumCurrStandbySIs (su));
  919. log_printf (LOG_INFO, " restart count %d\n",
  920. su->saAmfSURestartCount);
  921. log_printf (LOG_INFO, " restart control state %d\n",
  922. su->restart_control_state);
  923. log_printf (LOG_INFO, " SU failover cnt %d\n", su->su_failover_cnt);
  924. log_printf (LOG_INFO, " assigned SIs:");
  925. amf_su_foreach_si_assignment (su, print_si_assignment);
  926. for (comp = su->comp_head; comp != NULL; comp = comp->next) {
  927. log_printf (LOG_INFO, " safComp=%s\n", getSaNameT(&comp->name));
  928. log_printf (LOG_INFO, " oper state: %s\n",
  929. oper_state_text[comp->saAmfCompOperState]);
  930. log_printf (LOG_INFO, " readiness state: %s\n",
  931. readiness_state_text[amf_comp_get_saAmfCompReadinessState (comp)]);
  932. log_printf (LOG_INFO, " presence state: %s\n",
  933. presence_state_text[comp->saAmfCompPresenceState]);
  934. log_printf (LOG_INFO, " num active CSIs %d\n",
  935. amf_comp_get_saAmfCompNumCurrActiveCsi (comp));
  936. log_printf (LOG_INFO, " num standby CSIs %d\n",
  937. amf_comp_get_saAmfCompNumCurrStandbyCsi (comp));
  938. log_printf (LOG_INFO, " restart count %d\n",
  939. comp->saAmfCompRestartCount);
  940. log_printf (LOG_INFO, " assigned CSIs:");
  941. amf_comp_foreach_csi_assignment (
  942. comp, print_csi_assignment);
  943. }
  944. }
  945. }
  946. for (si = app->si_head; si != NULL; si = si->next) {
  947. log_printf (LOG_INFO, " safSi=%s\n", getSaNameT(&si->name));
  948. log_printf (LOG_INFO, " admin state: %s\n",
  949. admin_state_text[si->saAmfSIAdminState]);
  950. log_printf (LOG_INFO, " assignm. state: %s\n",
  951. assignment_state_text[
  952. amf_si_get_saAmfSIAssignmentState (si)]);
  953. log_printf (LOG_INFO, " active assignments: %d\n",
  954. amf_si_get_saAmfSINumCurrActiveAssignments (si));
  955. log_printf (LOG_INFO, " standby assignments: %d\n",
  956. amf_si_get_saAmfSINumCurrStandbyAssignments (si));
  957. for (csi = si->csi_head; csi != NULL; csi = csi->next) {
  958. log_printf (LOG_INFO, " safCsi=%s\n", getSaNameT(&csi->name));
  959. }
  960. }
  961. }
  962. log_printf (LOG_INFO, "===================================================");
  963. }
  964. /* to be removed... */
  965. int amf_enabled (struct objdb_iface_ver0 *objdb)
  966. {
  967. unsigned int object_service_handle;
  968. char *value;
  969. int enabled = 0;
  970. objdb->object_find_reset (OBJECT_PARENT_HANDLE);
  971. if (objdb->object_find (
  972. OBJECT_PARENT_HANDLE,
  973. "amf",
  974. strlen ("amf"),
  975. &object_service_handle) == 0) {
  976. value = NULL;
  977. if (!objdb->object_key_get (object_service_handle,
  978. "mode",
  979. strlen ("mode"),
  980. (void *)&value,
  981. NULL) && value) {
  982. if (strcmp (value, "enabled") == 0) {
  983. enabled = 1;
  984. } else
  985. if (strcmp (value, "disabled") == 0) {
  986. enabled = 0;
  987. }
  988. }
  989. }
  990. return enabled;
  991. }
  992. const char *amf_admin_state (int state)
  993. {
  994. return admin_state_text[state];
  995. }
  996. const char *amf_op_state (int state)
  997. {
  998. return oper_state_text[state];
  999. }
  1000. const char *amf_presence_state (int state)
  1001. {
  1002. return presence_state_text[state];
  1003. }
  1004. const char *amf_ha_state (int state)
  1005. {
  1006. return ha_state_text[state];
  1007. }
  1008. const char *amf_readiness_state (int state)
  1009. {
  1010. return readiness_state_text[state];
  1011. }
  1012. const char *amf_assignment_state (int state)
  1013. {
  1014. return assignment_state_text[state];
  1015. }
  1016. #define ALIGN_ADDR(addr) ((addr) + (4 - ((unsigned long)(addr) % 4)))
  1017. char *amf_serialize_SaNameT (char *buf, int *size, int *offset, SaNameT *name)
  1018. {
  1019. char *tmp = buf;
  1020. if ((*size - *offset ) < sizeof (SaNameT)) {
  1021. *size += sizeof (SaNameT);
  1022. tmp = realloc (buf, *size);
  1023. if (tmp == NULL) {
  1024. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1025. }
  1026. }
  1027. memcpy (&tmp[*offset], name, sizeof (SaNameT));
  1028. (*offset) += sizeof (SaNameT);
  1029. return tmp;
  1030. }
  1031. char *amf_serialize_SaStringT (char *buf, int *size, int *offset, SaStringT str)
  1032. {
  1033. unsigned int len;
  1034. if (str != NULL) {
  1035. len = strlen ((char*)str);
  1036. } else {
  1037. len = 0;
  1038. }
  1039. return amf_serialize_opaque (buf, size, offset, str, len);
  1040. }
  1041. char *amf_serialize_SaUint32T (char *buf, int *size, int *offset, SaUint32T num)
  1042. {
  1043. char *tmp = buf;
  1044. if ((*size - *offset ) < sizeof (SaUint32T)) {
  1045. *size += sizeof (SaUint32T);
  1046. tmp = realloc (buf, *size);
  1047. if (tmp == NULL) {
  1048. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1049. }
  1050. }
  1051. *((SaUint32T *)&tmp[*offset]) = num;
  1052. (*offset) += sizeof (SaUint32T);
  1053. return tmp;
  1054. }
  1055. char *amf_serialize_SaUint64T (char *buf, SaUint64T num)
  1056. {
  1057. *((SaUint64T *)buf) = num;
  1058. return buf + sizeof (SaUint64T);
  1059. }
  1060. char *amf_serialize_opaque (
  1061. char *buf, int *size, int *offset, char *src, int cnt)
  1062. {
  1063. unsigned int required_size;
  1064. char *tmp = buf;
  1065. required_size = cnt + sizeof (SaUint32T);
  1066. if ((*size - *offset ) < required_size) {
  1067. *size += required_size;
  1068. tmp = realloc (buf, *size);
  1069. if (tmp == NULL) {
  1070. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1071. }
  1072. }
  1073. *((SaUint32T *)&tmp[*offset]) = cnt;
  1074. (*offset) += sizeof (SaUint32T);
  1075. memcpy (&tmp[*offset], src, cnt);
  1076. (*offset) += cnt;
  1077. return tmp;
  1078. }
  1079. char *amf_deserialize_SaNameT (char *buf, SaNameT *name)
  1080. {
  1081. memcpy (name, buf, sizeof (SaNameT));
  1082. return (buf + sizeof (SaNameT));
  1083. }
  1084. char *amf_deserialize_SaStringT (char *buf, SaStringT *str)
  1085. {
  1086. int len;
  1087. char *tmp, *tmp_str;
  1088. len = *((SaUint32T *)buf);
  1089. tmp = buf + sizeof (SaUint32T);
  1090. if (len > 0) {
  1091. tmp_str = amf_malloc (len + 1);
  1092. memcpy (tmp_str, tmp, len);
  1093. tmp_str[len] = '\0';
  1094. *str = tmp_str;
  1095. } else {
  1096. *str = NULL;
  1097. }
  1098. tmp += len;
  1099. return tmp;
  1100. }
  1101. char *amf_deserialize_SaUint32T (char *buf, SaUint32T *num)
  1102. {
  1103. *num = *((SaUint32T *)buf);
  1104. return buf + sizeof (SaUint32T);
  1105. }
  1106. char *amf_deserialize_SaUint64T (char *buf, SaUint64T *num)
  1107. {
  1108. *num = *((SaUint64T *)buf);
  1109. return buf + sizeof (SaUint64T);
  1110. }
  1111. char *amf_deserialize_opaque (char *buf, char *dst, int *cnt)
  1112. {
  1113. *cnt = *((SaUint32T *)buf);
  1114. memcpy (dst, buf + sizeof (SaUint32T), *cnt);
  1115. return buf + *cnt + sizeof (SaUint32T);
  1116. }
  1117. void *_amf_malloc (size_t size, char *file, unsigned int line)
  1118. {
  1119. void *tmp = malloc (size);
  1120. if (tmp == NULL) {
  1121. log_printf (LOG_LEVEL_ERROR, "AMF out-of-memory at %s:%u", file, line);
  1122. openais_exit_error (AIS_DONE_OUT_OF_MEMORY);
  1123. }
  1124. return tmp;
  1125. }
  1126. int sa_amf_grep_one_sub_match(const char *string, char *pattern,
  1127. SaNameT *matches_arr)
  1128. {
  1129. int status;
  1130. regex_t re;
  1131. size_t nmatch = 2;
  1132. regmatch_t pmatch[nmatch];
  1133. int i;
  1134. ENTER("'%s %s'",string, pattern);
  1135. if (regcomp(&re, pattern, REG_EXTENDED) != 0) {
  1136. status = 0;
  1137. goto out;
  1138. }
  1139. status = regexec(&re, string, nmatch, pmatch, 0);
  1140. if (status != 0) {
  1141. regfree(&re);
  1142. status = 0;
  1143. goto out;
  1144. } else {
  1145. for (i = 0; i < nmatch; i++) {
  1146. int sub_string_len;
  1147. sub_string_len = pmatch[i].rm_eo - pmatch[i].rm_so;
  1148. if (i==1) {
  1149. memcpy(matches_arr[i].value, string + pmatch[i].rm_so,
  1150. sub_string_len);
  1151. matches_arr[i].value[sub_string_len] = '\0';
  1152. }
  1153. }
  1154. status = 1;
  1155. regfree(&re);
  1156. }
  1157. out:
  1158. return status;
  1159. }
  1160. int sa_amf_grep(const char *string, char *pattern, size_t nmatch,
  1161. SaNameT *matches_arr)
  1162. {
  1163. int status;
  1164. regex_t re;
  1165. regmatch_t pmatch[nmatch];
  1166. int i;
  1167. ENTER("'%s %s'",string, pattern);
  1168. if (regcomp(&re, pattern, REG_EXTENDED) != 0) {
  1169. status = 0;
  1170. goto out;
  1171. }
  1172. status = regexec(&re, string, nmatch, pmatch, 0);
  1173. if (status != 0) {
  1174. regfree(&re);
  1175. status = 0;
  1176. goto out;
  1177. } else {
  1178. for (i = 0; i < nmatch; i++) {
  1179. int sub_string_len;
  1180. sub_string_len = pmatch[i].rm_eo - pmatch[i].rm_so;
  1181. memcpy(matches_arr[i].value, string + pmatch[i].rm_so,
  1182. sub_string_len);
  1183. matches_arr[i].value[sub_string_len] = '\0';
  1184. matches_arr[i].length = sub_string_len;
  1185. }
  1186. status = 1;
  1187. regfree(&re);
  1188. }
  1189. out:
  1190. return status;
  1191. }
  1192. void amf_msg_mcast (int id, void *buf, size_t len)
  1193. {
  1194. struct req_exec_amf_msg msg;
  1195. struct iovec iov[2];
  1196. int iov_cnt;
  1197. int res;
  1198. // ENTER ("%u, %p, %u", id, buf, len);
  1199. msg.header.size = sizeof (msg);
  1200. msg.header.id = SERVICE_ID_MAKE (AMF_SERVICE, id);
  1201. iov[0].iov_base = &msg;
  1202. iov[0].iov_len = sizeof (msg);
  1203. if (buf == NULL) {
  1204. msg.header.size = sizeof (msg);
  1205. iov_cnt = 1;
  1206. } else {
  1207. msg.header.size = sizeof (msg) + len;
  1208. iov[1].iov_base = buf;
  1209. iov[1].iov_len = len;
  1210. iov_cnt = 2;
  1211. }
  1212. res = totempg_groups_mcast_joined (
  1213. openais_group_handle, iov, iov_cnt, TOTEMPG_AGREED);
  1214. if (res != 0) {
  1215. dprintf("Unable to send %d bytes\n", msg.header.size);
  1216. openais_exit_error (AIS_DONE_FATAL_ERR);
  1217. }
  1218. }
  1219. void amf_util_init (void)
  1220. {
  1221. log_init ("AMF");
  1222. }