amfutil.c 44 KB

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