amfutil.c 39 KB

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