amfutil.c 44 KB

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