amf.c 31 KB

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