amfutil.c 44 KB

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