amfutil.c 43 KB

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