4
0

amfutil.c 40 KB

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