amfutil.c 44 KB

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