amfutil.c 42 KB

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