amfutil.c 44 KB

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