amf.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977
  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. int res;
  346. char *error_string;
  347. char hostname[HOST_NAME_MAX + 1];
  348. struct amf_node *node;
  349. log_init ("AMF");
  350. if (!amf_enabled (objdb)) {
  351. return 0;
  352. }
  353. res = amf_config_read (&amf_cluster, &error_string);
  354. if (res == -1) {
  355. log_printf (LOG_LEVEL_ERROR, error_string);
  356. return res;
  357. }
  358. if (gethostname (hostname, sizeof(hostname)) == -1) {
  359. log_printf (LOG_LEVEL_ERROR, "gethostname failed: %d", errno);
  360. return -1;
  361. }
  362. /* look for this node */
  363. for (node = amf_cluster.node_head; node != NULL; node = node->next) {
  364. if (strcmp(hostname, getSaNameT (&node->name)) == 0) {
  365. this_amf_node = node;
  366. }
  367. }
  368. if (this_amf_node != NULL) {
  369. amf_cluster_init();
  370. amf_application_init();
  371. amf_sg_init();
  372. amf_su_init();
  373. amf_comp_init();
  374. amf_si_init();
  375. this_amf_node->saAmfNodeOperState = SA_AMF_OPERATIONAL_ENABLED;
  376. amf_cluster_start (&amf_cluster);
  377. } else {
  378. log_printf (LOG_LEVEL_INFO,
  379. "This CLM node (%s) is not configured as an AMF node, disabling.",
  380. hostname);
  381. }
  382. return (0);
  383. }
  384. static void amf_confchg_fn (
  385. enum totem_configuration_type configuration_type,
  386. unsigned int *member_list, int member_list_entries,
  387. unsigned int *left_list, int left_list_entries,
  388. unsigned int *joined_list, int joined_list_entries,
  389. struct memb_ring_id *ring_id)
  390. {
  391. dprintf ("amf_confchg_fn : type = %d,mnum = %d,jnum = %d,lnum = %d\n",
  392. configuration_type,member_list_entries,
  393. joined_list_entries,left_list_entries);
  394. }
  395. static int amf_lib_exit_fn (void *conn)
  396. {
  397. struct amf_comp *comp;
  398. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  399. assert (amf_pd != NULL);
  400. comp = amf_pd->comp;
  401. assert (comp != NULL);
  402. comp->conn = NULL;
  403. dprintf ("Lib exit from comp %s\n", getSaNameT (&comp->name));
  404. return (0);
  405. }
  406. static int amf_lib_init_fn (void *conn)
  407. {
  408. struct amf_pd *amf_pd = (struct amf_pd *)openais_conn_private_data_get (conn);
  409. list_init (&amf_pd->list);
  410. return (0);
  411. }
  412. #if 0
  413. static int comp_inservice_count (struct amf_su *unit)
  414. {
  415. struct amf_comp *comp;
  416. int answer = 0;
  417. for (comp = unit->comp_head; comp != NULL; comp = comp->next) {
  418. if (comp->saAmfCompReadinessState == SA_AMF_READINESS_IN_SERVICE) {
  419. answer += 1;
  420. }
  421. }
  422. return (answer);
  423. }
  424. #endif
  425. /*
  426. * Executive Message Implementation
  427. */
  428. static void message_handler_req_exec_amf_comp_register (
  429. void *message, unsigned int nodeid)
  430. {
  431. struct res_lib_amf_componentregister res_lib;
  432. struct req_exec_amf_comp_register *req_exec = message;
  433. struct amf_comp *comp;
  434. SaAisErrorT error;
  435. comp = amf_comp_find (&amf_cluster, &req_exec->compName);
  436. assert (comp != NULL);
  437. ENTER ("'%s'", comp->name.value);
  438. error = amf_comp_register (comp);
  439. if (amf_su_is_local (comp->su)) {
  440. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  441. res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
  442. res_lib.header.error = error;
  443. openais_conn_send_response (
  444. comp->conn, &res_lib, sizeof (struct res_lib_amf_componentregister));
  445. }
  446. }
  447. static void message_handler_req_exec_amf_comp_error_report (
  448. void *message, unsigned int nodeid)
  449. {
  450. struct req_exec_amf_comp_error_report *req_exec = message;
  451. struct amf_comp *comp;
  452. comp = amf_comp_find (&amf_cluster, &req_exec->erroneousComponent);
  453. assert (comp != NULL);
  454. amf_comp_error_report (comp, req_exec->recommendedRecovery);
  455. }
  456. static void message_handler_req_exec_amf_clc_cleanup_completed (
  457. void *message, unsigned int nodeid)
  458. {
  459. struct req_exec_amf_clc_cleanup_completed *req_exec = message;
  460. struct amf_comp *comp;
  461. comp = amf_comp_find (&amf_cluster, &req_exec->compName);
  462. if (comp == NULL) {
  463. log_printf (LOG_ERR, "'%s' not found", &req_exec->compName.value);
  464. return;
  465. }
  466. amf_comp_cleanup_completed (comp);
  467. }
  468. static void message_handler_req_exec_amf_healthcheck_tmo (
  469. void *message, unsigned int nodeid)
  470. {
  471. struct req_exec_amf_healthcheck_tmo *req_exec = message;
  472. struct amf_comp *comp;
  473. struct amf_healthcheck *healthcheck;
  474. comp = amf_comp_find (&amf_cluster, &req_exec->compName);
  475. if (comp == NULL) {
  476. log_printf (LOG_ERR, "'%s' not found", &req_exec->compName.value);
  477. return;
  478. }
  479. healthcheck = amf_comp_find_healthcheck (comp, &req_exec->safHealthcheckKey);
  480. amf_comp_healthcheck_tmo (comp, healthcheck);
  481. }
  482. static void message_handler_req_exec_amf_response (
  483. void *message, unsigned int nodeid)
  484. {
  485. struct req_exec_amf_response *req_exec = message;
  486. struct amf_comp *comp;
  487. struct res_lib_amf_response res_lib;
  488. SaAisErrorT retval;
  489. comp = amf_comp_response_2 (req_exec->invocation, req_exec->error, &retval);
  490. assert (comp != NULL);
  491. if (amf_su_is_local (comp->su)) {
  492. res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
  493. res_lib.header.size = sizeof (struct res_lib_amf_response);
  494. res_lib.header.error = retval;
  495. openais_conn_send_response (comp->conn, &res_lib, sizeof (res_lib));
  496. }
  497. }
  498. /*
  499. * Library Interface Implementation
  500. */
  501. static void message_handler_req_lib_amf_componentregister (
  502. void *conn,
  503. void *msg)
  504. {
  505. struct req_lib_amf_componentregister *req_lib = msg;
  506. struct amf_comp *comp;
  507. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  508. if (comp) {
  509. struct req_exec_amf_comp_register req_exec;
  510. struct iovec iovec;
  511. struct amf_pd *amf_pd = openais_conn_private_data_get (conn);
  512. TRACE2("Lib comp register '%s'", &req_lib->compName.value);
  513. comp->conn = conn;
  514. amf_pd->comp = comp;
  515. req_exec.header.size = sizeof (struct req_exec_amf_comp_register);
  516. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  517. MESSAGE_REQ_EXEC_AMF_COMPONENT_REGISTER);
  518. memcpy (&req_exec.compName, &req_lib->compName, sizeof (SaNameT));
  519. memcpy (&req_exec.proxyCompName,
  520. &req_lib->proxyCompName, sizeof (SaNameT));
  521. iovec.iov_base = (char *)&req_exec;
  522. iovec.iov_len = sizeof (req_exec);
  523. assert (totempg_groups_mcast_joined (openais_group_handle,
  524. &iovec, 1, TOTEMPG_AGREED) == 0);
  525. } else {
  526. struct res_lib_amf_componentregister res_lib;
  527. log_printf (LOG_ERR, "Lib comp register: comp '%s' not found", &req_lib->compName.value);
  528. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTREGISTER;
  529. res_lib.header.size = sizeof (struct res_lib_amf_componentregister);
  530. res_lib.header.error = SA_AIS_ERR_INVALID_PARAM;
  531. openais_conn_send_response (
  532. conn, &res_lib, sizeof (struct res_lib_amf_componentregister));
  533. }
  534. }
  535. static void message_handler_req_lib_amf_componentunregister (
  536. void *conn,
  537. void *msg)
  538. {
  539. #ifdef COMPILE_OUT
  540. struct req_lib_amf_componentunregister *req_lib_amf_componentunregister = (struct req_lib_amf_componentunregister *)message;
  541. struct req_exec_amf_componentunregister req_exec_amf_componentunregister;
  542. struct iovec iovec;
  543. struct amf_comp *component;
  544. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componentunregister()\n");
  545. req_exec_amf_componentunregister.header.size = sizeof (struct req_exec_amf_componentunregister);
  546. req_exec_amf_componentunregister.header.id =
  547. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTUNREGISTER);
  548. message_source_set (&req_exec_amf_componentunregister.source, conn_info);
  549. memcpy (&req_exec_amf_componentunregister.req_lib_amf_componentunregister,
  550. req_lib_amf_componentunregister,
  551. sizeof (struct req_lib_amf_componentunregister));
  552. component = amf_comp_find (&amf_cluster, &req_lib_amf_componentunregister->compName);
  553. if (component && component->registered && component->local) {
  554. // component->probableCause = SA_AMF_NOT_RESPONDING;
  555. }
  556. iovec.iov_base = (char *)&req_exec_amf_componentunregister;
  557. iovec.iov_len = sizeof (req_exec_amf_componentunregister);
  558. assert (totempg_groups_mcast_joined (openais_group_handle,
  559. &iovec, 1, TOTEMPG_AGREED) == 0);
  560. #endif
  561. }
  562. static void message_handler_req_lib_amf_pmstart (
  563. void *conn,
  564. void *msg)
  565. {
  566. }
  567. static void message_handler_req_lib_amf_pmstop (
  568. void *conn,
  569. void *msg)
  570. {
  571. }
  572. static void message_handler_req_lib_amf_healthcheckstart (
  573. void *conn, void *msg)
  574. {
  575. struct req_lib_amf_healthcheckstart *req_lib = msg;
  576. struct res_lib_amf_healthcheckstart res_lib;
  577. struct amf_comp *comp;
  578. SaAisErrorT error = SA_AIS_OK;
  579. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  580. if (comp != NULL) {
  581. comp->conn = conn;
  582. error = amf_comp_healthcheck_start (
  583. comp, &req_lib->healthcheckKey, req_lib->invocationType,
  584. req_lib->recommendedRecovery);
  585. } else {
  586. log_printf (LOG_ERR, "Healthcheckstart: Component '%s' not found",
  587. req_lib->compName.value);
  588. error = SA_AIS_ERR_NOT_EXIST;
  589. }
  590. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTART;
  591. res_lib.header.size = sizeof (res_lib);
  592. res_lib.header.error = error;
  593. openais_conn_send_response (conn, &res_lib,
  594. sizeof (struct res_lib_amf_healthcheckstart));
  595. }
  596. static void message_handler_req_lib_amf_healthcheckconfirm (
  597. void *conn, void *msg)
  598. {
  599. struct req_lib_amf_healthcheckconfirm *req_lib = msg;
  600. struct res_lib_amf_healthcheckconfirm res_lib;
  601. struct amf_comp *comp;
  602. SaAisErrorT error = SA_AIS_OK;
  603. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  604. if (comp != NULL) {
  605. error = amf_comp_healthcheck_confirm (
  606. comp, &req_lib->healthcheckKey, req_lib->healthcheckResult);
  607. } else {
  608. log_printf (LOG_ERR, "Healthcheck confirm: Component '%s' not found",
  609. req_lib->compName.value);
  610. error = SA_AIS_ERR_NOT_EXIST;
  611. }
  612. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKCONFIRM;
  613. res_lib.header.size = sizeof (res_lib);
  614. res_lib.header.error = error;
  615. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  616. }
  617. static void message_handler_req_lib_amf_healthcheckstop (
  618. void *conn, void *msg)
  619. {
  620. struct req_lib_amf_healthcheckstop *req_lib = msg;
  621. struct res_lib_amf_healthcheckstop res_lib;
  622. struct amf_comp *comp;
  623. SaAisErrorT error = SA_AIS_OK;
  624. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  625. if (comp != NULL) {
  626. error = amf_comp_healthcheck_stop (comp, &req_lib->healthcheckKey);
  627. } else {
  628. log_printf (LOG_ERR, "Healthcheckstop: Component '%s' not found",
  629. req_lib->compName.value);
  630. error = SA_AIS_ERR_NOT_EXIST;
  631. }
  632. res_lib.header.id = MESSAGE_RES_AMF_HEALTHCHECKSTOP;
  633. res_lib.header.size = sizeof (res_lib);
  634. res_lib.header.error = error;
  635. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  636. }
  637. static void message_handler_req_lib_amf_hastateget (void *conn, void *msg)
  638. {
  639. struct req_lib_amf_hastateget *req_lib = msg;
  640. struct res_lib_amf_hastateget res_lib;
  641. struct amf_comp *comp;
  642. SaAmfHAStateT ha_state;
  643. SaAisErrorT error;
  644. comp = amf_comp_find (&amf_cluster, &req_lib->compName);
  645. if (comp != NULL) {
  646. error = amf_comp_hastate_get (comp, &req_lib->csiName, &ha_state);
  647. res_lib.haState = ha_state;
  648. res_lib.header.error = error;
  649. } else {
  650. log_printf (LOG_ERR, "HA state get: Component '%s' not found",
  651. req_lib->compName.value);
  652. error = SA_AIS_ERR_NOT_EXIST;
  653. }
  654. res_lib.header.id = MESSAGE_RES_AMF_HASTATEGET;
  655. res_lib.header.size = sizeof (struct res_lib_amf_hastateget);
  656. res_lib.header.error = error;
  657. openais_conn_send_response (conn, &res_lib,
  658. sizeof (struct res_lib_amf_hastateget));
  659. }
  660. static void message_handler_req_lib_amf_protectiongrouptrack (
  661. void *conn,
  662. void *msg)
  663. {
  664. #ifdef COMPILE_OUT
  665. struct req_lib_amf_protectiongrouptrack *req_lib_amf_protectiongrouptrack = (struct req_lib_amf_protectiongrouptrack *)message;
  666. struct res_lib_amf_protectiongrouptrack res_lib_amf_protectiongrouptrack;
  667. struct libamf_ci_trackentry *track = 0;
  668. int i;
  669. struct saAmfProtectionGroup *amfProtectionGroup;
  670. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrack()\n");
  671. amfProtectionGroup = protectiongroup_find (&req_lib_amf_protectiongrouptrack->csiName);
  672. if (amfProtectionGroup) {
  673. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrack: Got valid track start on CSI: %s.\n", getSaNameT (&req_lib_amf_protectiongrouptrack->csiName));
  674. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  675. if (conn_info->ais_ci.u.libamf_ci.tracks[i].active == 0) {
  676. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  677. break;
  678. }
  679. }
  680. if (track == 0) {
  681. grow_amf_track_table (conn_info, 1);
  682. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  683. }
  684. track->active = 1;
  685. track->trackFlags = req_lib_amf_protectiongrouptrack->trackFlags;
  686. track->notificationBufferAddress = req_lib_amf_protectiongrouptrack->notificationBufferAddress;
  687. memcpy (&track->csiName,
  688. &req_lib_amf_protectiongrouptrack->csiName, sizeof (SaNameT));
  689. conn_info->ais_ci.u.libamf_ci.trackActive += 1;
  690. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  691. /*
  692. * If SA_TRACK_CURRENT is specified, write out all current connections
  693. */
  694. } else {
  695. log_printf (LOG_LEVEL_DEBUG, "invalid track start, csi not registered with system.\n");
  696. }
  697. res_lib_amf_protectiongrouptrack.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACK;
  698. res_lib_amf_protectiongrouptrack.header.size = sizeof (struct res_lib_amf_protectiongrouptrack);
  699. res_lib_amf_protectiongrouptrack.header.error = SA_ERR_NOT_EXIST;
  700. if (amfProtectionGroup) {
  701. res_lib_amf_protectiongrouptrack.header.error = SA_AIS_OK;
  702. }
  703. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrack,
  704. sizeof (struct res_lib_amf_protectiongrouptrack));
  705. if (amfProtectionGroup &&
  706. req_lib_amf_protectiongrouptrack->trackFlags & SA_TRACK_CURRENT) {
  707. protectiongroup_notification_send (conn_info,
  708. track->notificationBufferAddress,
  709. amfProtectionGroup,
  710. 0,
  711. 0,
  712. SA_TRACK_CHANGES_ONLY);
  713. track->trackFlags &= ~SA_TRACK_CURRENT;
  714. }
  715. #endif
  716. }
  717. static void message_handler_req_lib_amf_csiquiescingcomplete (
  718. void *conn,
  719. void *msg)
  720. {
  721. }
  722. static void message_handler_req_lib_amf_protectiongrouptrackstop (
  723. void *conn,
  724. void *msg)
  725. {
  726. #ifdef COMPILE_OUT
  727. struct req_lib_amf_protectiongrouptrackstop *req_lib_amf_protectiongrouptrackstop = (struct req_lib_amf_protectiongrouptrackstop *)message;
  728. struct res_lib_amf_protectiongrouptrackstop res_lib_amf_protectiongrouptrackstop;
  729. struct libamf_ci_trackentry *track = 0;
  730. int i;
  731. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_protectiongrouptrackstop()\n");
  732. for (i = 0; i < conn_info->ais_ci.u.libamf_ci.trackEntries; i++) {
  733. if (name_match (&req_lib_amf_protectiongrouptrackstop->csiName,
  734. &conn_info->ais_ci.u.libamf_ci.tracks[i].csiName)) {
  735. track = &conn_info->ais_ci.u.libamf_ci.tracks[i];
  736. }
  737. }
  738. if (track) {
  739. log_printf (LOG_LEVEL_DEBUG, "protectiongrouptrackstop: Trackstop on CSI: %s\n", getSaNameT (&req_lib_amf_protectiongrouptrackstop->csiName));
  740. memset (track, 0, sizeof (struct libamf_ci_trackentry));
  741. conn_info->ais_ci.u.libamf_ci.trackActive -= 1;
  742. if (conn_info->ais_ci.u.libamf_ci.trackActive == 0) {
  743. list_del (&conn_info->conn_list);
  744. }
  745. }
  746. res_lib_amf_protectiongrouptrackstop.header.id = MESSAGE_RES_AMF_PROTECTIONGROUPTRACKSTOP;
  747. res_lib_amf_protectiongrouptrackstop.header.size = sizeof (struct res_lib_amf_protectiongrouptrackstop);
  748. res_lib_amf_protectiongrouptrackstop.header.error = SA_ERR_NOT_EXIST;
  749. if (track) {
  750. res_lib_amf_protectiongrouptrackstop.header.error = SA_AIS_OK;
  751. }
  752. openais_conn_send_response (conn, &res_lib_amf_protectiongrouptrackstop,
  753. sizeof (struct res_lib_amf_protectiongrouptrackstop));
  754. #endif
  755. }
  756. static void message_handler_req_lib_amf_componenterrorreport (
  757. void *conn,
  758. void *msg)
  759. {
  760. struct req_lib_amf_componenterrorreport *req_lib = msg;
  761. struct amf_comp *comp;
  762. comp = amf_comp_find (&amf_cluster, &req_lib->erroneousComponent);
  763. if (comp != NULL) {
  764. struct req_exec_amf_comp_error_report req_exec;
  765. struct iovec iovec;
  766. TRACE2("Lib comp error report for '%s'", &comp->name.value);
  767. req_exec.header.size = sizeof (struct req_exec_amf_comp_error_report);
  768. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  769. MESSAGE_REQ_EXEC_AMF_COMPONENT_ERROR_REPORT);
  770. memcpy (&req_exec.reportingComponent, &req_lib->reportingComponent,
  771. sizeof (SaNameT));
  772. memcpy (&req_exec.erroneousComponent, &req_lib->erroneousComponent,
  773. sizeof (SaNameT));
  774. memcpy (&req_exec.errorDetectionTime, &req_lib->errorDetectionTime,
  775. sizeof (SaTimeT));
  776. memcpy (&req_exec.recommendedRecovery, &req_lib->recommendedRecovery,
  777. sizeof (SaAmfRecommendedRecoveryT));
  778. memcpy (&req_exec.ntfIdentifier, &req_lib->ntfIdentifier,
  779. sizeof (SaNtfIdentifierT));
  780. iovec.iov_base = (char *)&req_exec;
  781. iovec.iov_len = sizeof (req_exec);
  782. assert (totempg_groups_mcast_joined (
  783. openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  784. } else {
  785. struct res_lib_amf_componenterrorreport res_lib;
  786. log_printf (LOG_ERR, "Component %s not found",
  787. &req_lib->erroneousComponent.value);
  788. res_lib.header.size = sizeof (struct res_lib_amf_componenterrorreport);
  789. res_lib.header.id = MESSAGE_RES_AMF_COMPONENTERRORREPORT;
  790. res_lib.header.error = SA_AIS_ERR_NOT_EXIST;
  791. openais_conn_send_response (conn, &res_lib,
  792. sizeof (struct res_lib_amf_componenterrorreport));
  793. }
  794. }
  795. static void message_handler_req_lib_amf_componenterrorclear (
  796. void *conn,
  797. void *msg)
  798. {
  799. #ifdef COMPILLE_OUT
  800. struct req_lib_amf_componenterrorclear *req_lib_amf_componenterrorclear = (struct req_lib_amf_componenterrorclear *)message;
  801. struct req_exec_amf_componenterrorclear req_exec_amf_componenterrorclear;
  802. struct iovec iovec;
  803. log_printf (LOG_LEVEL_FROM_LIB, "Handle : message_handler_req_lib_amf_componenterrorclear()\n");
  804. req_exec_amf_componenterrorclear.header.size = sizeof (struct req_exec_amf_componenterrorclear);
  805. req_exec_amf_componenterrorclear.header.id =
  806. SERVICE_ID_MAKE (AMF_SERVICE, MESSAGE_REQ_EXEC_AMF_COMPONENTERRORCLEAR);
  807. message_source_set (&req_exec_amf_componenterrorclear.source, conn_info);
  808. memcpy (&req_exec_amf_componenterrorclear.req_lib_amf_componenterrorclear,
  809. req_lib_amf_componenterrorclear,
  810. sizeof (struct req_lib_amf_componenterrorclear));
  811. iovec.iov_base = (char *)&req_exec_amf_componenterrorclear;
  812. iovec.iov_len = sizeof (req_exec_amf_componenterrorclear);
  813. assert (totempg_groups_mcast_joined (openais_group_handle,
  814. &iovec, 1, TOTEMPG_AGREED) == 0);
  815. #endif
  816. }
  817. static void message_handler_req_lib_amf_response (void *conn, void *msg)
  818. {
  819. struct req_lib_amf_response *req_lib = msg;
  820. int multicast;
  821. SaAisErrorT retval;
  822. /*
  823. * This is an optimisation to avoid multicast of healthchecks while keeping
  824. * a nice design. We multicast and make lib responses from this file.
  825. */
  826. multicast = amf_comp_response_1 (
  827. req_lib->invocation, req_lib->error, &retval);
  828. if (multicast) {
  829. struct req_exec_amf_response req_exec;
  830. struct iovec iovec;
  831. req_exec.header.size = sizeof (struct req_exec_amf_response);
  832. req_exec.header.id = SERVICE_ID_MAKE (AMF_SERVICE,
  833. MESSAGE_REQ_EXEC_AMF_RESPONSE);
  834. req_exec.invocation = req_lib->invocation;
  835. req_exec.error = req_lib->error;
  836. iovec.iov_base = (char *)&req_exec;
  837. iovec.iov_len = sizeof (req_exec);
  838. assert (totempg_groups_mcast_joined (
  839. openais_group_handle, &iovec, 1, TOTEMPG_AGREED) == 0);
  840. } else {
  841. struct res_lib_amf_response res_lib;
  842. res_lib.header.id = MESSAGE_RES_AMF_RESPONSE;
  843. res_lib.header.size = sizeof (struct res_lib_amf_response);
  844. res_lib.header.error = retval;
  845. openais_conn_send_response (conn, &res_lib, sizeof (res_lib));
  846. }
  847. }
  848. static void amf_dump_fn (void)
  849. {
  850. amf_runtime_attributes_print (&amf_cluster);
  851. }