amf.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. /** @file exec/amf.c
  2. *
  3. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  4. * Author: Steven Dake (sdake@mvista.com)
  5. *
  6. * Copyright (c) 2006 Ericsson AB.
  7. * Author: Hans Feldt
  8. * Description:
  9. * - Introduced AMF B.02 information model
  10. * - Use DN in API and multicast messages
  11. * - (Re-)Introduction of event based multicast messages
  12. * - Refactoring of code into several AMF files
  13. *
  14. * All rights reserved.
  15. *
  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 Main
  44. *
  45. * The functions in this file are responsible for:
  46. * - starting the AMF service (amf_exec_init_fn)
  47. * - build the information model from the configuration file or by
  48. * synchronising the state with an already started AMF node
  49. * - receiving AMF library requests (message_handler_req_lib_*)
  50. * - distributing AMF library requests to the cluster
  51. * - receiving multicasts (message_handler_req_exec_*) and dispatch the
  52. * requests to a component instance
  53. * - send responses to the AMF library (return values for API calls)
  54. * - handling EVS configuration change events (node leave/join)
  55. * - handling node synchronisation events (amf_sync_*)
  56. * - printing the AMF runtime attributes upon user request (USR2 signal)
  57. *
  58. * Some API requests are responded to directly in the lib message_handler.
  59. * This is normally done when the API request parameters are wrong, e.g. a
  60. * component cannot be found. In that case, the error handling must be taken
  61. * care of in the lib message handler.
  62. *
  63. */
  64. #include <sys/types.h>
  65. #include <sys/uio.h>
  66. #include <sys/socket.h>
  67. #include <sys/un.h>
  68. #include <sys/types.h>
  69. #include <sys/wait.h>
  70. #include <netinet/in.h>
  71. #include <arpa/inet.h>
  72. #include <unistd.h>
  73. #include <fcntl.h>
  74. #include <stdlib.h>
  75. #include <stdio.h>
  76. #include <errno.h>
  77. #include <signal.h>
  78. #include <string.h>
  79. #include <pthread.h>
  80. #include <assert.h>
  81. #include "../include/saAis.h"
  82. #include "../include/saAmf.h"
  83. #include "../include/ipc_gen.h"
  84. #include "../include/ipc_amf.h"
  85. #include "../include/list.h"
  86. #include "../lcr/lcr_comp.h"
  87. #include "totempg.h"
  88. #include "aispoll.h"
  89. #include "mempool.h"
  90. #include "util.h"
  91. #include "amf.h"
  92. #include "main.h"
  93. #include "ipc.h"
  94. #include "service.h"
  95. #include "objdb.h"
  96. #include "print.h"
  97. #define LOG_LEVEL_FROM_LIB LOG_LEVEL_DEBUG
  98. #define LOG_LEVEL_FROM_GMI LOG_LEVEL_DEBUG
  99. #define LOG_LEVEL_ENTER_FUNC LOG_LEVEL_DEBUG
  100. #ifndef HOST_NAME_MAX
  101. # define HOST_NAME_MAX 255
  102. #endif
  103. static void amf_confchg_fn (
  104. enum totem_configuration_type configuration_type,
  105. unsigned int *member_list, int member_list_entries,
  106. unsigned int *left_list, int left_list_entries,
  107. unsigned int *joined_list, int joined_list_entries,
  108. struct memb_ring_id *ring_id);
  109. static int amf_lib_exit_fn (void *conn);
  110. static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb);
  111. static int amf_lib_init_fn (void *conn);
  112. static void message_handler_req_lib_amf_componentregister (void *conn, void *msg);
  113. static void message_handler_req_lib_amf_componentunregister (void *conn, void *msg);
  114. static void message_handler_req_lib_amf_pmstart (void *conn, void *msg);
  115. static void message_handler_req_lib_amf_pmstop (void *conn, void *msg);
  116. static void message_handler_req_lib_amf_healthcheckstart (void *conn, void *msg);
  117. static void message_handler_req_lib_amf_healthcheckconfirm (void *conn, void *msg);
  118. static void message_handler_req_lib_amf_healthcheckstop (void *conn, void *msg);
  119. static void message_handler_req_lib_amf_hastateget (void *conn, void *message);
  120. static void message_handler_req_lib_amf_csiquiescingcomplete (void *conn, void *msg);
  121. static void message_handler_req_lib_amf_protectiongrouptrack (void *conn, void *msg);
  122. static void message_handler_req_lib_amf_protectiongrouptrackstop (void *conn, void *msg);
  123. static void message_handler_req_lib_amf_componenterrorreport (void *conn, void *msg);
  124. static void message_handler_req_lib_amf_componenterrorclear (void *conn, void *msg);
  125. static void message_handler_req_lib_amf_response (void *conn, void *msg);
  126. static void message_handler_req_exec_amf_comp_register (
  127. void *message, unsigned int nodeid);
  128. static void message_handler_req_exec_amf_comp_error_report (
  129. void *message, unsigned int nodeid);
  130. static void message_handler_req_exec_amf_clc_cleanup_completed (
  131. void *message, unsigned int nodeid);
  132. static void message_handler_req_exec_amf_healthcheck_tmo (
  133. void *message, unsigned int nodeid);
  134. static void message_handler_req_exec_amf_response (
  135. void *message, unsigned int nodeid);
  136. static void amf_dump_fn (void);
  137. static void amf_sync_init (void);
  138. static int amf_sync_process (void);
  139. static void amf_sync_abort (void);
  140. static void amf_sync_activate (void);
  141. struct amf_pd {
  142. struct amf_comp *comp;
  143. struct list_head list;
  144. };
  145. /*
  146. * Service Handler Definition
  147. */
  148. static struct openais_lib_handler amf_lib_service[] =
  149. {
  150. { /* 0 */
  151. .lib_handler_fn = message_handler_req_lib_amf_componentregister,
  152. .response_size = sizeof (struct res_lib_amf_componentregister),
  153. .response_id = MESSAGE_RES_AMF_COMPONENTREGISTER,
  154. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  155. },
  156. { /* 1 */
  157. .lib_handler_fn = message_handler_req_lib_amf_componentunregister,
  158. .response_size = sizeof (struct res_lib_amf_componentunregister),
  159. .response_id = MESSAGE_RES_AMF_COMPONENTUNREGISTER,
  160. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  161. },
  162. { /* 2 */
  163. .lib_handler_fn = message_handler_req_lib_amf_pmstart,
  164. .response_size = sizeof (struct res_lib_amf_pmstart),
  165. .response_id = MESSAGE_RES_AMF_PMSTART,
  166. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  167. },
  168. { /* 3 */
  169. .lib_handler_fn = message_handler_req_lib_amf_pmstop,
  170. .response_size = sizeof (struct res_lib_amf_pmstop),
  171. .response_id = MESSAGE_RES_AMF_PMSTOP,
  172. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  173. },
  174. { /* 4 */
  175. .lib_handler_fn = message_handler_req_lib_amf_healthcheckstart,
  176. .response_size = sizeof (struct res_lib_amf_healthcheckstart),
  177. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTART,
  178. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  179. },
  180. { /* 5 */
  181. .lib_handler_fn = message_handler_req_lib_amf_healthcheckconfirm,
  182. .response_size = sizeof (struct res_lib_amf_healthcheckconfirm),
  183. .response_id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM,
  184. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  185. },
  186. { /* 6 */
  187. .lib_handler_fn = message_handler_req_lib_amf_healthcheckstop,
  188. .response_size = sizeof (struct res_lib_amf_healthcheckstop),
  189. .response_id = MESSAGE_RES_AMF_HEALTHCHECKSTOP,
  190. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  191. },
  192. { /* 7 */
  193. .lib_handler_fn = message_handler_req_lib_amf_hastateget,
  194. .response_size = sizeof (struct res_lib_amf_hastateget),
  195. .response_id = MESSAGE_RES_AMF_HASTATEGET,
  196. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  197. },
  198. { /* 8 */
  199. .lib_handler_fn = message_handler_req_lib_amf_csiquiescingcomplete,
  200. .response_size = sizeof (struct res_lib_amf_csiquiescingcomplete),
  201. .response_id = MESSAGE_RES_AMF_CSIQUIESCINGCOMPLETE,
  202. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  203. },
  204. { /* 9 */
  205. .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrack,
  206. .response_size = sizeof (struct res_lib_amf_protectiongrouptrack),
  207. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK,
  208. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  209. },
  210. { /* 10 */
  211. .lib_handler_fn = message_handler_req_lib_amf_protectiongrouptrackstop,
  212. .response_size = sizeof (struct res_lib_amf_protectiongrouptrackstop),
  213. .response_id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP,
  214. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  215. },
  216. { /* 11 */
  217. .lib_handler_fn = message_handler_req_lib_amf_componenterrorreport,
  218. .response_size = sizeof (struct res_lib_amf_componenterrorreport),
  219. .response_id = MESSAGE_RES_AMF_COMPONENTERRORREPORT,
  220. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  221. },
  222. { /* 12 */
  223. .lib_handler_fn = message_handler_req_lib_amf_componenterrorclear,
  224. .response_size = sizeof (struct res_lib_amf_componenterrorclear),
  225. .response_id = MESSAGE_RES_AMF_COMPONENTERRORCLEAR,
  226. .flow_control = OPENAIS_FLOW_CONTROL_REQUIRED
  227. },
  228. { /* 13 */
  229. .lib_handler_fn = message_handler_req_lib_amf_response,
  230. .response_size = sizeof (struct res_lib_amf_response),
  231. .response_id = MESSAGE_RES_AMF_RESPONSE, // TODO
  232. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  233. },
  234. };
  235. /*
  236. * Multicast message handlers
  237. */
  238. static struct openais_exec_handler amf_exec_service[] = {
  239. {
  240. .exec_handler_fn = message_handler_req_exec_amf_comp_register,
  241. },
  242. {
  243. .exec_handler_fn = message_handler_req_exec_amf_comp_error_report,
  244. },
  245. {
  246. .exec_handler_fn = message_handler_req_exec_amf_clc_cleanup_completed,
  247. },
  248. {
  249. .exec_handler_fn = message_handler_req_exec_amf_healthcheck_tmo,
  250. },
  251. {
  252. .exec_handler_fn = message_handler_req_exec_amf_response,
  253. }
  254. };
  255. /*
  256. * Exports the interface for the service
  257. */
  258. static struct openais_service_handler amf_service_handler = {
  259. .name = (unsigned char *)"openais availability management framework B.01.01",
  260. .id = AMF_SERVICE,
  261. .private_data_size = sizeof (struct amf_pd),
  262. .lib_init_fn = amf_lib_init_fn,
  263. .lib_exit_fn = amf_lib_exit_fn,
  264. .lib_service = amf_lib_service,
  265. .lib_service_count = sizeof (amf_lib_service) / sizeof (struct openais_lib_handler),
  266. .exec_init_fn = amf_exec_init_fn,
  267. .exec_service = amf_exec_service,
  268. .exec_service_count = sizeof (amf_exec_service) / sizeof (struct openais_exec_handler),
  269. .confchg_fn = amf_confchg_fn,
  270. .exec_dump_fn = amf_dump_fn,
  271. .sync_init = amf_sync_init,
  272. .sync_process = amf_sync_process,
  273. .sync_activate = amf_sync_activate,
  274. .sync_abort = amf_sync_abort,
  275. };
  276. struct amf_node *this_amf_node;
  277. struct amf_cluster amf_cluster;
  278. static struct openais_service_handler *amf_get_handler_ver0 (void);
  279. static struct openais_service_handler_iface_ver0 amf_service_handler_iface = {
  280. .openais_get_service_handler_ver0 = amf_get_handler_ver0
  281. };
  282. static struct lcr_iface openais_amf_ver0[1] = {
  283. {
  284. .name = "openais_amf",
  285. .version = 0,
  286. .versions_replace = 0,
  287. .versions_replace_count = 0,
  288. .dependencies = 0,
  289. .dependency_count = 0,
  290. .constructor = NULL,
  291. .destructor = NULL,
  292. .interfaces = NULL
  293. }
  294. };
  295. static struct lcr_comp amf_comp_ver0 = {
  296. .iface_count = 1,
  297. .ifaces = openais_amf_ver0
  298. };
  299. static struct openais_service_handler *amf_get_handler_ver0 (void)
  300. {
  301. return (&amf_service_handler);
  302. }
  303. __attribute__ ((constructor)) static void register_this_component (void)
  304. {
  305. lcr_interfaces_set (&openais_amf_ver0[0], &amf_service_handler_iface);
  306. lcr_component_register (&amf_comp_ver0);
  307. }
  308. struct req_exec_amf_comp_register {
  309. mar_req_header_t header;
  310. SaNameT compName;
  311. SaNameT proxyCompName;
  312. };
  313. struct req_exec_amf_comp_error_report {
  314. mar_req_header_t header;
  315. SaNameT reportingComponent;
  316. SaNameT erroneousComponent;
  317. SaTimeT errorDetectionTime;
  318. SaAmfRecommendedRecoveryT recommendedRecovery;
  319. SaNtfIdentifierT ntfIdentifier;
  320. };
  321. struct req_exec_amf_response {
  322. mar_req_header_t header;
  323. SaInvocationT invocation;
  324. SaAisErrorT error;
  325. };
  326. /* IMPL */
  327. static void amf_sync_init (void)
  328. {
  329. ENTER("");
  330. }
  331. static int amf_sync_process (void)
  332. {
  333. ENTER("");
  334. return 0; /* ready */
  335. }
  336. static void amf_sync_abort (void)
  337. {
  338. ENTER("");
  339. }
  340. static void amf_sync_activate (void)
  341. {
  342. ENTER("");
  343. }
  344. static int amf_exec_init_fn (struct objdb_iface_ver0 *objdb)
  345. {
  346. int res;
  347. char *error_string;
  348. char hostname[HOST_NAME_MAX + 1];
  349. struct amf_node *node;
  350. log_init ("AMF");
  351. if (!amf_enabled (objdb)) {
  352. return 0;
  353. }
  354. res = amf_config_read (&amf_cluster, &error_string);
  355. if (res == -1) {
  356. log_printf (LOG_LEVEL_ERROR, error_string);
  357. return res;
  358. }
  359. if (gethostname (hostname, sizeof(hostname)) == -1) {
  360. log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno);
  361. return -1;
  362. }
  363. /* look for this node */
  364. for (node = amf_cluster.node_head; node != NULL; node = node->next) {
  365. if (strcmp(hostname, getSaNameT (&node->name)) == 0) {
  366. this_amf_node = node;
  367. }
  368. }
  369. if (this_amf_node != NULL) {
  370. amf_cluster_init();
  371. amf_application_init();
  372. amf_sg_init();
  373. amf_su_init();
  374. amf_comp_init();
  375. amf_si_init();
  376. this_amf_node->saAmfNodeOperState = SA_AMF_OPERATIONAL_ENABLED;
  377. amf_cluster_start (&amf_cluster);
  378. } else {
  379. log_printf (LOG_LEVEL_INFO,
  380. "This CLM node (%s) is not configured as an AMF node, disabling.",
  381. hostname);
  382. }
  383. return (0);
  384. }
  385. static void amf_confchg_fn (
  386. enum totem_configuration_type configuration_type,
  387. unsigned int *member_list, int member_list_entries,
  388. unsigned int *left_list, int left_list_entries,
  389. unsigned int *joined_list, int joined_list_entries,
  390. struct memb_ring_id *ring_id)
  391. {
  392. dprintf ("amf_confchg_fn : type = %d,mnum = %d,jnum = %d,lnum = %d\n",
  393. configuration_type,member_list_entries,
  394. joined_list_entries,left_list_entries);
  395. }
  396. static int amf_lib_exit_fn (void *conn)
  397. {
  398. struct amf_comp *comp;
  399. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  400. assert (amf_pd != NULL);
  401. comp = amf_pd->comp;
  402. assert (comp != NULL);
  403. comp->conn = NULL;
  404. dprintf ("Lib exit from comp %s\n", getSaNameT (&comp->name));
  405. return (0);
  406. }
  407. static int amf_lib_init_fn (void *conn)
  408. {
  409. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  410. list_init (&amf_pd->list);
  411. return (0);
  412. }
  413. #if 0
  414. static int comp_inservice_count (struct amf_su *unit)
  415. {
  416. struct amf_comp *comp;
  417. int answer = 0;
  418. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  419. if (comp->saAmfCompReadinessState == SA_AMF_READINESS_IN_SERVICE) {
  420. answer += 1;
  421. }
  422. }
  423. return (answer);
  424. }
  425. #endif
  426. /*
  427. * Executive Message Implementation
  428. */
  429. static void message_handler_req_exec_amf_comp_register (
  430. void *message, unsigned int nodeid)
  431. {
  432. struct res_lib_amf_componentregister res_lib;
  433. struct req_exec_amf_comp_register *req_exec = message;
  434. struct amf_comp *comp;
  435. SaAisErrorT error;
  436. comp = amf_comp_find (&amf_cluster, &req_exec->compName);
  437. assert (comp != NULL);
  438. ENTER ("'%s'", comp->name.value);
  439. error = amf_comp_register (comp);
  440. if (amf_su_is_local (comp->su)) {
  441. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  442. res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
  443. res_lib.header.error = error;
  444. openais_conn_send_response (
  445. comp->conn, &res_lib, sizeof (struct res_lib_amf_componentregister));
  446. }
  447. }
  448. static void message_handler_req_exec_amf_comp_error_report (
  449. void *message, unsigned int nodeid)
  450. {
  451. struct req_exec_amf_comp_error_report *req_exec = message;
  452. struct amf_comp *comp;
  453. comp = amf_comp_find (&amf_cluster, &req_exec->erroneousComponent);
  454. assert (comp != NULL);
  455. amf_comp_error_report (comp, req_exec->recommendedRecovery);
  456. }
  457. static void message_handler_req_exec_amf_clc_cleanup_completed (
  458. void *message, unsigned int nodeid)
  459. {
  460. struct req_exec_amf_clc_cleanup_completed *req_exec = message;
  461. struct amf_comp *comp;
  462. comp = amf_comp_find (&amf_cluster, &req_exec->compName);
  463. if (comp == NULL) {
  464. log_printf (LOG_ERR, "'%s' not found", &req_exec->compName.value);
  465. return;
  466. }
  467. amf_comp_cleanup_completed (comp);
  468. }
  469. static void message_handler_req_exec_amf_healthcheck_tmo (
  470. void *message, unsigned int nodeid)
  471. {
  472. struct req_exec_amf_healthcheck_tmo *req_exec = message;
  473. struct amf_comp *comp;
  474. struct amf_healthcheck *healthcheck;
  475. comp = amf_comp_find (&amf_cluster, &req_exec->compName);
  476. if (comp == NULL) {
  477. log_printf (LOG_ERR, "'%s' not found", &req_exec->compName.value);
  478. return;
  479. }
  480. healthcheck = amf_comp_find_healthcheck (comp, &req_exec->safHealthcheckKey);
  481. amf_comp_healthcheck_tmo (comp, healthcheck);
  482. }
  483. static void message_handler_req_exec_amf_response (
  484. void *message, unsigned int nodeid)
  485. {
  486. struct req_exec_amf_response *req_exec = message;
  487. struct amf_comp *comp;
  488. struct res_lib_amf_response res_lib;
  489. SaAisErrorT retval;
  490. comp = amf_comp_response_2 (req_exec->invocation, req_exec->error, &retval);
  491. assert (comp != NULL);
  492. if (amf_su_is_local (comp->su)) {
  493. res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
  494. res_lib.header.size = sizeof (struct res_lib_amf_response);
  495. res_lib.header.error = retval;
  496. openais_conn_send_response (comp->conn, &res_lib, sizeof (res_lib));
  497. }
  498. }
  499. /*
  500. * Library Interface Implementation
  501. */
  502. static void message_handler_req_lib_amf_componentregister (
  503. void *conn,
  504. void *msg)
  505. {
  506. struct req_lib_amf_componentregister *req_lib = msg;
  507. struct amf_comp *comp;
  508. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  509. if (comp) {
  510. struct req_exec_amf_comp_register req_exec;
  511. struct iovec iovec;
  512. struct amf_pd *amf_pd = openais_conn_private_data_get (conn);
  513. TRACE2("Lib comp register '%s'", &req_lib->compName.value);
  514. comp->conn = conn;
  515. amf_pd->comp = comp;
  516. req_exec.header.size = sizeof (struct req_exec_amf_comp_register);
  517. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  518. MESSAGE_REQ_EXEC_AMF_COMPONENT_REGISTER);
  519. memcpy (&req_exec.compName, &req_lib->compName, sizeof (SaNameT));
  520. memcpy (&req_exec.proxyCompName,
  521. &req_lib->proxyCompName, sizeof (SaNameT));
  522. iovec.iov_base = (char *)&req_exec;
  523. iovec.iov_len = sizeof (req_exec);
  524. assert (totempg_groups_mcast_joined (openais_group_handle,
  525. &iovec, 1, TOTEMPG_AGREED) == 0);
  526. } else {
  527. struct res_lib_amf_componentregister res_lib;
  528. log_printf (LOG_ERR, "Lib comp register: comp '%s' not found", &req_lib->compName.value);
  529. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  530. res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
  531. res_lib.header.error = SA_AIS_ERR_INVALID_PARAM;
  532. openais_conn_send_response (
  533. conn, &res_lib, sizeof (struct res_lib_amf_componentregister));
  534. }
  535. }
  536. static void message_handler_req_lib_amf_componentunregister (
  537. void *conn,
  538. void *msg)
  539. {
  540. #ifdef COMPILE_OUT
  541. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  542. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  543. struct iovec iovec;
  544. struct amf_comp *component;
  545. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  546. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  547. req_exec_amf_componentunregister.header.id =
  548. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  549. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  550. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  551. req_lib_amf_componentunregister,
  552. sizeof (struct req_lib_amf_componentunregister));
  553. component = amf_comp_find (&amf_cluster, &req_lib_amf_componentunregister->compName);
  554. if (component && component->registered && component->local) {
  555. // component->probableCause = SA_AMF_NOT_RESPONDING;
  556. }
  557. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  558. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  559. assert (totempg_groups_mcast_joined (openais_group_handle,
  560. &iovec, 1, TOTEMPG_AGREED) == 0);
  561. #endif
  562. }
  563. static void message_handler_req_lib_amf_pmstart (
  564. void *conn,
  565. void *msg)
  566. {
  567. }
  568. static void message_handler_req_lib_amf_pmstop (
  569. void *conn,
  570. void *msg)
  571. {
  572. }
  573. static void message_handler_req_lib_amf_healthcheckstart (
  574. void *conn, void *msg)
  575. {
  576. struct req_lib_amf_healthcheckstart *req_lib = msg;
  577. struct res_lib_amf_healthcheckstart res_lib;
  578. struct amf_comp *comp;
  579. SaAisErrorT error = SA_AIS_OK;
  580. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  581. if (comp != NULL) {
  582. comp->conn = conn;
  583. error = amf_comp_healthcheck_start (
  584. comp, &req_lib->healthcheckKey, req_lib->invocationType,
  585. req_lib->recommendedRecovery);
  586. } else {
  587. log_printf (LOG_ERR, "Healthcheckstart: Component '%s' not found",
  588. req_lib->compName.value);
  589. error = SA_AIS_ERR_NOT_EXIST;
  590. }
  591. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
  592. res_lib.header.size = sizeof (res_lib);
  593. res_lib.header.error = error;
  594. openais_conn_send_response (conn, &res_lib,
  595. sizeof (struct res_lib_amf_healthcheckstart));
  596. }
  597. static void message_handler_req_lib_amf_healthcheckconfirm (
  598. void *conn, void *msg)
  599. {
  600. struct req_lib_amf_healthcheckconfirm *req_lib = msg;
  601. struct res_lib_amf_healthcheckconfirm res_lib;
  602. struct amf_comp *comp;
  603. SaAisErrorT error = SA_AIS_OK;
  604. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  605. if (comp != NULL) {
  606. error = amf_comp_healthcheck_confirm (
  607. comp, &req_lib->healthcheckKey, req_lib->healthcheckResult);
  608. } else {
  609. log_printf (LOG_ERR, "Healthcheck confirm: Component '%s' not found",
  610. req_lib->compName.value);
  611. error = SA_AIS_ERR_NOT_EXIST;
  612. }
  613. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM;
  614. res_lib.header.size = sizeof (res_lib);
  615. res_lib.header.error = error;
  616. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  617. }
  618. static void message_handler_req_lib_amf_healthcheckstop (
  619. void *conn, void *msg)
  620. {
  621. struct req_lib_amf_healthcheckstop *req_lib = msg;
  622. struct res_lib_amf_healthcheckstop res_lib;
  623. struct amf_comp *comp;
  624. SaAisErrorT error = SA_AIS_OK;
  625. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  626. if (comp != NULL) {
  627. error = amf_comp_healthcheck_stop (comp, &req_lib->healthcheckKey);
  628. } else {
  629. log_printf (LOG_ERR, "Healthcheckstop: Component '%s' not found",
  630. req_lib->compName.value);
  631. error = SA_AIS_ERR_NOT_EXIST;
  632. }
  633. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
  634. res_lib.header.size = sizeof (res_lib);
  635. res_lib.header.error = error;
  636. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  637. }
  638. static void message_handler_req_lib_amf_hastateget (void *conn, void *msg)
  639. {
  640. struct req_lib_amf_hastateget *req_lib = msg;
  641. struct res_lib_amf_hastateget res_lib;
  642. struct amf_comp *comp;
  643. SaAmfHAStateT ha_state;
  644. SaAisErrorT error;
  645. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  646. if (comp != NULL) {
  647. error = amf_comp_hastate_get (comp, &req_lib->csiName, &ha_state);
  648. res_lib.haState = ha_state;
  649. res_lib.header.error = error;
  650. } else {
  651. log_printf (LOG_ERR, "HA state get: Component '%s' not found",
  652. req_lib->compName.value);
  653. error = SA_AIS_ERR_NOT_EXIST;
  654. }
  655. res_lib.header.id = MESSAGE_RES_AMF_HASTATEGET;
  656. res_lib.header.size = sizeof (struct res_lib_amf_hastateget);
  657. res_lib.header.error = error;
  658. openais_conn_send_response (conn, &res_lib,
  659. sizeof (struct res_lib_amf_hastateget));
  660. }
  661. static void message_handler_req_lib_amf_protectiongrouptrack (
  662. void *conn,
  663. void *msg)
  664. {
  665. #ifdef COMPILE_OUT
  666. struct req_lib_amf_protectiongrouptrack *req_lib_amf_protectiongrouptrack = (struct req_lib_amf_protectiongrouptrack *)message;
  667. struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
  668. struct libamf_ci_trackentry *track = 0;
  669. int i;
  670. struct saAmfProtectionGroup *amfProtectionGroup;
  671. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrack()\n");
  672. amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrack->csiName);
  673. if (amfProtectionGroup) {
  674. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrack: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrack->csiName));
  675. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  676. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  677. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  678. break;
  679. }
  680. }
  681. if (track == 0) {
  682. grow_amf_track_table (conn_info, 1);
  683. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  684. }
  685. track->active = 1;
  686. track->trackFlags = req_lib_amf_protectiongrouptrack->trackFlags;
  687. track->notificationBufferAddress = req_lib_amf_protectiongrouptrack->notificationBufferAddress;
  688. memcpy (&track->csiName,
  689. &req_lib_amf_protectiongrouptrack->csiName, sizeof (SaNameT));
  690. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  691. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  692. /*
  693. * If SA_TRACK_CURRENT is specified, write out all current connections
  694. */
  695. } else {
  696. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  697. }
  698. res_lib_amf_protectiongrouptrack.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK;
  699. res_lib_amf_protectiongrouptrack.header.size = sizeof (struct res_lib_amf_protectiongrouptrack);
  700. res_lib_amf_protectiongrouptrack.header.error = SA_ERR_NOT_EXIST;
  701. if (amfProtectionGroup) {
  702. res_lib_amf_protectiongrouptrack.header.error = SA_AIS_OK;
  703. }
  704. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrack,
  705. sizeof (struct res_lib_amf_protectiongrouptrack));
  706. if (amfProtectionGroup &&
  707. req_lib_amf_protectiongrouptrack->trackFlags & SA_TRACK_CURRENT) {
  708. protectiongroup_notification_send (conn_info,
  709. track->notificationBufferAddress,
  710. amfProtectionGroup,
  711. 0,
  712. 0,
  713. SA_TRACK_CHANGES_ONLY);
  714. track->trackFlags &= ~SA_TRACK_CURRENT;
  715. }
  716. #endif
  717. }
  718. static void message_handler_req_lib_amf_csiquiescingcomplete (
  719. void *conn,
  720. void *msg)
  721. {
  722. }
  723. static void message_handler_req_lib_amf_protectiongrouptrackstop (
  724. void *conn,
  725. void *msg)
  726. {
  727. #ifdef COMPILE_OUT
  728. struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
  729. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  730. struct libamf_ci_trackentry *track = 0;
  731. int i;
  732. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
  733. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  734. if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
  735. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  736. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  737. }
  738. }
  739. if (track) {
  740. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
  741. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  742. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  743. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  744. list_del (&conn_info->conn_list);
  745. }
  746. }
  747. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  748. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  749. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  750. if (track) {
  751. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  752. }
  753. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstop,
  754. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  755. #endif
  756. }
  757. static void message_handler_req_lib_amf_componenterrorreport (
  758. void *conn,
  759. void *msg)
  760. {
  761. struct req_lib_amf_componenterrorreport *req_lib = msg;
  762. struct amf_comp *comp;
  763. comp = amf_comp_find (&amf_cluster, &req_lib->erroneousComponent);
  764. if (comp != NULL) {
  765. struct req_exec_amf_comp_error_report req_exec;
  766. struct iovec iovec;
  767. TRACE2("Lib comp error report for '%s'", &comp->name.value);
  768. req_exec.header.size = sizeof (struct req_exec_amf_comp_error_report);
  769. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  770. MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT);
  771. memcpy (&req_exec.reportingComponent, &req_lib->reportingComponent,
  772. sizeof (SaNameT));
  773. memcpy (&req_exec.erroneousComponent, &req_lib->erroneousComponent,
  774. sizeof (SaNameT));
  775. memcpy (&req_exec.errorDetectionTime, &req_lib->errorDetectionTime,
  776. sizeof (SaTimeT));
  777. memcpy (&req_exec.recommendedRecovery, &req_lib->recommendedRecovery,
  778. sizeof (SaAmfRecommendedRecoveryT));
  779. memcpy (&req_exec.ntfIdentifier, &req_lib->ntfIdentifier,
  780. sizeof (SaNtfIdentifierT));
  781. iovec.iov_base = (char *)&req_exec;
  782. iovec.iov_len = sizeof (req_exec);
  783. assert (totempg_groups_mcast_joined (
  784. openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  785. } else {
  786. struct res_lib_amf_componenterrorreport res_lib;
  787. log_printf (LOG_ERR, "Component %s not found",
  788. &req_lib->erroneousComponent.value);
  789. res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  790. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  791. res_lib.header.error = SA_AIS_ERR_NOT_EXIST;
  792. openais_conn_send_response (conn, &res_lib,
  793. sizeof (struct res_lib_amf_componenterrorreport));
  794. }
  795. }
  796. static void message_handler_req_lib_amf_componenterrorclear (
  797. void *conn,
  798. void *msg)
  799. {
  800. #ifdef COMPILLE_OUT
  801. struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
  802. struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
  803. struct iovec iovec;
  804. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
  805. req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
  806. req_exec_amf_componenterrorclear.header.id =
  807. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR);
  808. message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
  809. memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
  810. req_lib_amf_componenterrorclear,
  811. sizeof (struct req_lib_amf_componenterrorclear));
  812. iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
  813. iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
  814. assert (totempg_groups_mcast_joined (openais_group_handle,
  815. &iovec, 1, TOTEMPG_AGREED) == 0);
  816. #endif
  817. }
  818. static void message_handler_req_lib_amf_response (void *conn, void *msg)
  819. {
  820. struct req_lib_amf_response *req_lib = msg;
  821. int multicast;
  822. SaAisErrorT retval;
  823. /*
  824. * This is an optimisation to avoid multicast of healthchecks while keeping
  825. * a nice design. We multicast and make lib responses from this file.
  826. */
  827. multicast = amf_comp_response_1 (
  828. req_lib->invocation, req_lib->error, &retval);
  829. if (multicast) {
  830. struct req_exec_amf_response req_exec;
  831. struct iovec iovec;
  832. req_exec.header.size = sizeof (struct req_exec_amf_response);
  833. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  834. MESSAGE_REQ_EXEC_AMF_RESPONSE);
  835. req_exec.invocation = req_lib->invocation;
  836. req_exec.error = req_lib->error;
  837. iovec.iov_base = (char *)&req_exec;
  838. iovec.iov_len = sizeof (req_exec);
  839. assert (totempg_groups_mcast_joined (
  840. openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  841. } else {
  842. struct res_lib_amf_response res_lib;
  843. res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
  844. res_lib.header.size = sizeof (struct res_lib_amf_response);
  845. res_lib.header.error = retval;
  846. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  847. }
  848. }
  849. static void amf_dump_fn (void)
  850. {
  851. amf_runtime_attributes_print (&amf_cluster);
  852. }