clm.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. /*
  2. * vi: set autoindent tabstop=4 shiftwidth=4 :
  3. *
  4. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@mvista.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <sys/types.h>
  37. #include <sys/socket.h>
  38. #include <sys/un.h>
  39. #include <sys/sysinfo.h>
  40. #include <sys/ioctl.h>
  41. #include <netinet/in.h>
  42. #include <sys/uio.h>
  43. #include <unistd.h>
  44. #include <fcntl.h>
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47. #include <errno.h>
  48. #include <signal.h>
  49. #include <time.h>
  50. #include <unistd.h>
  51. #include <netinet/in.h>
  52. #include <arpa/inet.h>
  53. #include "../include/saAis.h"
  54. #include "../include/saClm.h"
  55. #include "../include/ipc_gen.h"
  56. #include "../include/ipc_clm.h"
  57. #include "../include/list.h"
  58. #include "../include/queue.h"
  59. #include "../lcr/lcr_comp.h"
  60. #include "aispoll.h"
  61. #include "totempg.h"
  62. #include "main.h"
  63. #include "mempool.h"
  64. #include "handlers.h"
  65. #define LOG_SERVICE LOG_SERVICE_CLM
  66. #include "print.h"
  67. enum clm_message_req_types {
  68. MESSAGE_REQ_EXEC_CLM_NODEJOIN = 0
  69. };
  70. SaClmClusterChangesT thisClusterNodeLastChange = SA_CLM_NODE_JOINED;
  71. SaClmClusterNodeT thisClusterNode;
  72. #define NODE_MAX 16
  73. SaClmClusterNodeT clusterNodes[NODE_MAX];
  74. int clusterNodeEntries = 0;
  75. static unsigned long long view_current = 0;
  76. static unsigned long long view_initial = 0;
  77. static DECLARE_LIST_INIT (library_notification_send_listhead);
  78. SaClmClusterNodeT *clm_get_by_nodeid (unsigned int node_id)
  79. {
  80. SaClmClusterNodeT *ret = NULL;
  81. int i;
  82. if (node_id == SA_CLM_LOCAL_NODE_ID) {
  83. return (&clusterNodes[0]);
  84. }
  85. for (i = 0; i < clusterNodeEntries; i++) {
  86. if (clusterNodes[i].nodeId == node_id) {
  87. ret = &clusterNodes[i];
  88. break;
  89. }
  90. }
  91. return (ret);
  92. }
  93. /*
  94. * Service Interfaces required by service_message_handler struct
  95. */
  96. static int clm_confchg_fn (
  97. enum totem_configuration_type configuration_type,
  98. struct totem_ip_address *member_list, int member_list_entries,
  99. struct totem_ip_address *left_list, int left_list_entries,
  100. struct totem_ip_address *joined_list, int joined_list_entries,
  101. struct memb_ring_id *ring_id);
  102. static void clm_sync_init (void);
  103. static int clm_sync_process (void);
  104. static void clm_sync_activate (void);
  105. static void clm_sync_abort (void);
  106. static int clm_exec_init_fn (struct openais_config *);
  107. static int clm_init_two_fn (struct conn_info *conn_info);
  108. static int clm_exit_fn (struct conn_info *conn_info);
  109. static int message_handler_req_exec_clm_nodejoin (void *message, struct totem_ip_address *source_addr,
  110. int endian_conversion_required);
  111. static int message_handler_req_lib_clm_clustertrack (struct conn_info *conn_info,
  112. void *message);
  113. static int message_handler_req_lib_clm_trackstop (struct conn_info *conn_info,
  114. void *message);
  115. static int message_handler_req_lib_clm_nodeget (struct conn_info *conn_info,
  116. void *message);
  117. static int message_handler_req_lib_clm_nodegetasync (struct conn_info *conn_info,
  118. void *message);
  119. static int clm_exit_fn (struct conn_info *conn_info);
  120. /*
  121. * Executive Handler Definition
  122. */
  123. struct libais_handler clm_libais_handlers[] =
  124. {
  125. { /* 0 */
  126. .libais_handler_fn = message_handler_req_lib_clm_clustertrack,
  127. .response_size = sizeof (struct res_lib_clm_clustertrack),
  128. .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE
  129. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  130. },
  131. { /* 1 */
  132. .libais_handler_fn = message_handler_req_lib_clm_trackstop,
  133. .response_size = sizeof (struct res_lib_clm_trackstop),
  134. .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE
  135. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  136. },
  137. { /* 2 */
  138. .libais_handler_fn = message_handler_req_lib_clm_nodeget,
  139. .response_size = sizeof (struct res_clm_nodeget),
  140. .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE
  141. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  142. },
  143. { /* 3 */
  144. .libais_handler_fn = message_handler_req_lib_clm_nodegetasync,
  145. .response_size = sizeof (struct res_clm_nodegetasync),
  146. .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE
  147. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  148. }
  149. };
  150. static int (*clm_aisexec_handler_fns[]) (void *, struct totem_ip_address *source_addr, int endian_conversion_required) = {
  151. message_handler_req_exec_clm_nodejoin
  152. };
  153. struct service_handler clm_service_handler = {
  154. .name = "openais cluster membership service B.01.01",
  155. .id = CLM_SERVICE,
  156. .libais_handlers = clm_libais_handlers,
  157. .libais_handlers_count = sizeof (clm_libais_handlers) / sizeof (struct libais_handler),
  158. .aisexec_handler_fns = clm_aisexec_handler_fns,
  159. .aisexec_handler_fns_count = sizeof (clm_aisexec_handler_fns) / sizeof (int (*)),
  160. .confchg_fn = clm_confchg_fn,
  161. .libais_init_two_fn = clm_init_two_fn,
  162. .libais_exit_fn = clm_exit_fn,
  163. .exec_init_fn = clm_exec_init_fn,
  164. .exec_dump_fn = 0,
  165. .sync_init = clm_sync_init,
  166. .sync_process = clm_sync_process,
  167. .sync_activate = clm_sync_activate,
  168. .sync_abort = clm_sync_abort,
  169. };
  170. #ifdef BUILD_DYNAMIC
  171. struct service_handler *clm_get_handler_ver0 (void);
  172. struct aisexec_iface_ver0 clm_service_handler_iface = {
  173. .test = NULL,
  174. .get_handler_ver0 = clm_get_handler_ver0
  175. };
  176. struct lcr_iface openais_clm_ver0[1] = {
  177. {
  178. .name = "openais_clm",
  179. .version = 0,
  180. .versions_replace = 0,
  181. .versions_replace_count = 0,
  182. .dependencies = 0,
  183. .dependency_count = 0,
  184. .constructor = NULL,
  185. .destructor = NULL,
  186. .interfaces = (void **)&clm_service_handler_iface,
  187. }
  188. };
  189. struct lcr_comp clm_comp_ver0 = {
  190. .iface_count = 1,
  191. .ifaces = openais_clm_ver0
  192. };
  193. extern int lcr_comp_get (struct lcr_comp **component)
  194. {
  195. *component = &clm_comp_ver0;
  196. return (0);
  197. }
  198. struct service_handler *clm_get_handler_ver0 (void)
  199. {
  200. return (&clm_service_handler);
  201. }
  202. #endif /* BUILD_DYNAMIC */
  203. struct req_exec_clm_nodejoin {
  204. struct req_header header;
  205. SaClmClusterNodeT clusterNode;
  206. };
  207. static int clm_exec_init_fn (struct openais_config *openais_config)
  208. {
  209. memset (clusterNodes, 0, sizeof (SaClmClusterNodeT) * NODE_MAX);
  210. /*
  211. * Build local cluster node data structure
  212. */
  213. sprintf ((char *)thisClusterNode.nodeAddress.value, "%s", totemip_print (this_ip));
  214. thisClusterNode.nodeAddress.length = strlen ((char *)thisClusterNode.nodeAddress.value);
  215. if (this_ip->family == AF_INET) {
  216. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET;
  217. } else
  218. if (this_ip->family == AF_INET6) {
  219. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET6;
  220. } else {
  221. assert (0);
  222. }
  223. strcpy ((char *)thisClusterNode.nodeName.value, (char *)thisClusterNode.nodeAddress.value);
  224. thisClusterNode.nodeName.length = thisClusterNode.nodeAddress.length;
  225. thisClusterNode.nodeId = this_ip->nodeid;
  226. printf ("setting B to %x\n", this_ip->nodeid);
  227. thisClusterNode.member = 1;
  228. {
  229. struct sysinfo s_info;
  230. time_t current_time;
  231. sysinfo (&s_info);
  232. current_time = time (NULL);
  233. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  234. thisClusterNode.bootTimestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000;
  235. }
  236. #ifdef DEBUG
  237. printSaClmClusterNodeT ("this cluster node", &thisClusterNode);
  238. #endif
  239. memcpy (&clusterNodes[0], &thisClusterNode, sizeof (SaClmClusterNodeT));
  240. clusterNodeEntries = 1;
  241. main_clm_get_by_nodeid = clm_get_by_nodeid;
  242. return (0);
  243. }
  244. static int clm_exit_fn (struct conn_info *conn_info)
  245. {
  246. /*
  247. * Delete track entry if there is one
  248. */
  249. list_del (&conn_info->conn_list);
  250. return (0);
  251. }
  252. void library_notification_send (SaClmClusterNotificationT *cluster_notification_entries,
  253. int notify_entries)
  254. {
  255. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  256. struct conn_info *conn_info;
  257. struct list_head *list;
  258. int i;
  259. if (notify_entries == 0) {
  260. return;
  261. }
  262. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  263. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  264. res_lib_clm_clustertrack.header.error = SA_OK;
  265. res_lib_clm_clustertrack.view = view_current;
  266. for (list = library_notification_send_listhead.next;
  267. list != &library_notification_send_listhead;
  268. list = list->next) {
  269. conn_info = list_entry (list, struct conn_info, conn_list);
  270. /*
  271. * Track current and changes
  272. */
  273. if (conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CHANGES) {
  274. /*
  275. * Copy all cluster nodes
  276. */
  277. for (i = 0; i < clusterNodeEntries; i++) {
  278. memcpy (&res_lib_clm_clustertrack.notification[i].clusterNode,
  279. &clusterNodes[i], sizeof (SaClmClusterNodeT));
  280. res_lib_clm_clustertrack.notification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  281. res_lib_clm_clustertrack.notification[i].clusterNode.member = 1;
  282. }
  283. /*
  284. * Copy change_only notificaiton
  285. */
  286. res_lib_clm_clustertrack.numberOfItems = notify_entries + i;
  287. memcpy (&res_lib_clm_clustertrack.notification[i],
  288. cluster_notification_entries,
  289. sizeof (SaClmClusterNotificationT) * notify_entries);
  290. } else
  291. /*
  292. * Track only changes
  293. */
  294. if (conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CHANGES_ONLY) {
  295. res_lib_clm_clustertrack.numberOfItems = notify_entries;
  296. memcpy (&res_lib_clm_clustertrack.notification,
  297. cluster_notification_entries,
  298. sizeof (SaClmClusterNotificationT) * notify_entries);
  299. }
  300. /*
  301. * Send notifications to all CLM listeners
  302. */
  303. libais_send_response (conn_info, &res_lib_clm_clustertrack,
  304. sizeof (struct res_lib_clm_clustertrack));
  305. }
  306. }
  307. static void notification_join (SaClmClusterNodeT *cluster_node)
  308. {
  309. SaClmClusterNotificationT notification;
  310. /*
  311. * Generate notification element
  312. */
  313. notification.clusterChange = SA_CLM_NODE_JOINED;
  314. notification.clusterNode.member = 1;
  315. memcpy (&notification.clusterNode, cluster_node,
  316. sizeof (SaClmClusterNodeT));
  317. library_notification_send (&notification, 1);
  318. }
  319. static void libraryNotificationLeave (SaClmNodeIdT *nodes, int nodes_entries)
  320. {
  321. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  322. int i, j;
  323. int notifyEntries;
  324. /*
  325. * Determine notification list
  326. */
  327. for (notifyEntries = 0, i = 0; i < clusterNodeEntries; i++) {
  328. for (j = 0; j < nodes_entries; j++) {
  329. if (clusterNodes[i].nodeId == nodes[j]) {
  330. memcpy (&clusterNotification[notifyEntries].clusterNode,
  331. &clusterNodes[i],
  332. sizeof (SaClmClusterNodeT));
  333. clusterNotification[notifyEntries].clusterChange = SA_CLM_NODE_LEFT;
  334. clusterNotification[notifyEntries].clusterNode.member = 0;
  335. notifyEntries += 1;
  336. break;
  337. }
  338. }
  339. }
  340. /*
  341. * Remove entries from clusterNodes array
  342. */
  343. for (i = 0; i < nodes_entries; i++) {
  344. for (j = 0; j < clusterNodeEntries;) {
  345. if (nodes[i] == clusterNodes[j].nodeId) {
  346. clusterNodeEntries -= 1;
  347. memmove (&clusterNodes[j], &clusterNodes[j + 1],
  348. (clusterNodeEntries - j) * sizeof (SaClmClusterNodeT));
  349. } else {
  350. /*
  351. * next clusterNode entry
  352. */
  353. j++;
  354. }
  355. }
  356. }
  357. library_notification_send (clusterNotification, notifyEntries);
  358. }
  359. static int clm_nodejoin_send (void)
  360. {
  361. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  362. struct iovec req_exec_clm_iovec;
  363. int result;
  364. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  365. req_exec_clm_nodejoin.header.id =
  366. SERVICE_ID_MAKE (CLM_SERVICE, MESSAGE_REQ_EXEC_CLM_NODEJOIN);
  367. // TODO dont use memcpy, use iovecs !!
  368. thisClusterNode.initialViewNumber = view_initial;
  369. memcpy (&req_exec_clm_nodejoin.clusterNode, &thisClusterNode,
  370. sizeof (SaClmClusterNodeT));
  371. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  372. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  373. result = totempg_groups_mcast_joined (openais_group_handle, &req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  374. return (result);
  375. }
  376. static int clm_confchg_fn (
  377. enum totem_configuration_type configuration_type,
  378. struct totem_ip_address *member_list, int member_list_entries,
  379. struct totem_ip_address *left_list, int left_list_entries,
  380. struct totem_ip_address *joined_list, int joined_list_entries,
  381. struct memb_ring_id *ring_id)
  382. {
  383. int i;
  384. SaClmNodeIdT nodes[NODE_MAX];
  385. view_current = ring_id->seq / 4;
  386. if (view_initial == 0) {
  387. view_initial = ring_id->seq / 4;
  388. }
  389. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  390. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  391. for (i = 0; i < member_list_entries; i++) {
  392. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&member_list[i]));
  393. }
  394. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  395. for (i = 0; i < left_list_entries; i++) {
  396. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&left_list[i]));
  397. }
  398. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  399. for (i = 0; i < joined_list_entries; i++) {
  400. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&joined_list[i]));
  401. }
  402. for (i = 0; i < left_list_entries; i++) {
  403. nodes[i] = left_list[i].nodeid;
  404. }
  405. libraryNotificationLeave (nodes, i);
  406. /*
  407. * Load the thisClusterNode data structure in case we are
  408. * transitioning to network interface up or down
  409. */
  410. sprintf ((char *)thisClusterNode.nodeAddress.value, "%s", totemip_print (this_ip));
  411. thisClusterNode.nodeAddress.length = strlen ((char *)thisClusterNode.nodeAddress.value);
  412. if (this_ip->family == AF_INET) {
  413. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET;
  414. } else
  415. if (this_ip->family == AF_INET6) {
  416. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET6;
  417. } else {
  418. assert (0);
  419. }
  420. strcpy ((char *)thisClusterNode.nodeName.value,
  421. (char *)thisClusterNode.nodeAddress.value);
  422. thisClusterNode.nodeName.length = thisClusterNode.nodeAddress.length;
  423. thisClusterNode.nodeId = this_ip->nodeid;
  424. return (0);
  425. }
  426. /*
  427. * This is a noop for this service
  428. */
  429. static void clm_sync_init (void)
  430. {
  431. return;
  432. }
  433. /*
  434. * If a processor joined in the configuration change and clm_sync_activate hasn't
  435. * yet been called, issue a node join to share CLM specific data about the processor
  436. */
  437. static int clm_sync_process (void)
  438. {
  439. /*
  440. * Send node information to other nodes
  441. */
  442. return (clm_nodejoin_send ());
  443. }
  444. /*
  445. * This is a noop for this service
  446. */
  447. static void clm_sync_activate (void)
  448. {
  449. return;
  450. }
  451. /*
  452. * This is a noop for this service
  453. */
  454. static void clm_sync_abort (void)
  455. {
  456. return;
  457. }
  458. static void exec_clm_nodejoin_endian_conversion (struct req_exec_clm_nodejoin *in,
  459. struct req_exec_clm_nodejoin *out)
  460. {
  461. // TODO this isn't complete yet
  462. // TODO SaNameT needs to be packed and aligned
  463. memmove (&out->clusterNode.nodeName.value[0],
  464. &in->clusterNode.nodeName.value[2],
  465. SA_MAX_NAME_LENGTH);
  466. }
  467. static int message_handler_req_exec_clm_nodejoin (void *message, struct totem_ip_address *source_addr,
  468. int endian_conversion_required)
  469. {
  470. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  471. struct req_exec_clm_nodejoin req_exec_clm_nodejoin_storage;
  472. int found = 0;
  473. int i;
  474. if (endian_conversion_required) {
  475. exec_clm_nodejoin_endian_conversion (message, &req_exec_clm_nodejoin_storage);
  476. req_exec_clm_nodejoin = &req_exec_clm_nodejoin_storage;
  477. } else {
  478. req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  479. }
  480. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", req_exec_clm_nodejoin->clusterNode.nodeName.value);
  481. /*
  482. * Determine if nodejoin already received
  483. */
  484. for (found = 0, i = 0; i < clusterNodeEntries; i++) {
  485. if (clusterNodes[i].nodeId == req_exec_clm_nodejoin->clusterNode.nodeId) {
  486. found = 1;
  487. }
  488. }
  489. /*
  490. * If not received, add to internal list
  491. */
  492. if (found == 0) {
  493. notification_join (&req_exec_clm_nodejoin->clusterNode);
  494. memcpy (&clusterNodes[clusterNodeEntries],
  495. &req_exec_clm_nodejoin->clusterNode,
  496. sizeof (SaClmClusterNodeT));
  497. clusterNodeEntries += 1;
  498. }
  499. return (0);
  500. }
  501. static int clm_init_two_fn (struct conn_info *conn_info)
  502. {
  503. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  504. list_init (&conn_info->conn_list);
  505. return (0);
  506. }
  507. int message_handler_req_lib_clm_clustertrack (struct conn_info *conn_info, void *message)
  508. {
  509. struct req_lib_clm_clustertrack *req_lib_clm_clustertrack = (struct req_lib_clm_clustertrack *)message;
  510. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  511. int i;
  512. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  513. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKSTART;
  514. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  515. res_lib_clm_clustertrack.view = view_current;
  516. res_lib_clm_clustertrack.numberOfItems = 0;
  517. if (req_lib_clm_clustertrack->trackFlags & SA_TRACK_CURRENT) {
  518. for (i = 0; i < clusterNodeEntries; i++) {
  519. res_lib_clm_clustertrack.notification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  520. memcpy (&res_lib_clm_clustertrack.notification[i].clusterNode,
  521. &clusterNodes[i], sizeof (SaClmClusterNodeT));
  522. }
  523. res_lib_clm_clustertrack.numberOfItems = clusterNodeEntries;
  524. }
  525. /*
  526. * Record requests for cluster tracking
  527. */
  528. if (req_lib_clm_clustertrack->trackFlags & SA_TRACK_CHANGES ||
  529. req_lib_clm_clustertrack->trackFlags & SA_TRACK_CHANGES_ONLY) {
  530. conn_info->conn_info_partner->ais_ci.u.libclm_ci.trackFlags =
  531. req_lib_clm_clustertrack->trackFlags;
  532. conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled = 1;
  533. list_add (&conn_info->conn_info_partner->conn_list,
  534. &library_notification_send_listhead);
  535. }
  536. libais_send_response (conn_info, &res_lib_clm_clustertrack,
  537. sizeof (struct res_lib_clm_clustertrack));
  538. if (req_lib_clm_clustertrack->return_in_callback) {
  539. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  540. libais_send_response (conn_info->conn_info_partner,
  541. &res_lib_clm_clustertrack,
  542. sizeof (struct res_lib_clm_clustertrack));
  543. }
  544. return (0);
  545. }
  546. static int message_handler_req_lib_clm_trackstop (struct conn_info *conn_info, void *message)
  547. {
  548. struct res_lib_clm_trackstop res_lib_clm_trackstop;
  549. res_lib_clm_trackstop.header.size = sizeof (struct res_lib_clm_trackstop);
  550. res_lib_clm_trackstop.header.id = MESSAGE_RES_CLM_TRACKSTOP;
  551. if (conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled) {
  552. res_lib_clm_trackstop.header.error = SA_OK;
  553. } else {
  554. res_lib_clm_trackstop.header.error = SA_AIS_ERR_NOT_EXIST;
  555. }
  556. conn_info->conn_info_partner->ais_ci.u.libclm_ci.trackFlags = 0;
  557. conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled = 0;
  558. list_del (&conn_info->conn_info_partner->conn_list);
  559. libais_send_response (conn_info, &res_lib_clm_trackstop,
  560. sizeof (struct res_lib_clm_trackstop));
  561. return (0);
  562. }
  563. static int message_handler_req_lib_clm_nodeget (struct conn_info *conn_info, void *message)
  564. {
  565. struct req_lib_clm_nodeget *req_lib_clm_nodeget = (struct req_lib_clm_nodeget *)message;
  566. struct res_clm_nodeget res_clm_nodeget;
  567. SaClmClusterNodeT *clusterNode = 0;
  568. int valid = 0;
  569. int i;
  570. log_printf (LOG_LEVEL_NOTICE, "nodeget: trying to find node %x\n", (int)req_lib_clm_nodeget->nodeId);
  571. if (req_lib_clm_nodeget->nodeId == SA_CLM_LOCAL_NODE_ID) {
  572. clusterNode = &clusterNodes[0];
  573. valid = 1;
  574. } else
  575. for (i = 0; i < clusterNodeEntries; i++) {
  576. if (clusterNodes[i].nodeId == req_lib_clm_nodeget->nodeId) {
  577. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  578. clusterNode = &clusterNodes[i];
  579. valid = 1;
  580. break;
  581. }
  582. }
  583. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  584. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  585. res_clm_nodeget.header.error = SA_OK;
  586. res_clm_nodeget.invocation = req_lib_clm_nodeget->invocation;
  587. res_clm_nodeget.valid = valid;
  588. if (valid) {
  589. memcpy (&res_clm_nodeget.clusterNode, clusterNode, sizeof (SaClmClusterNodeT));
  590. }
  591. libais_send_response (conn_info, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  592. return (0);
  593. }
  594. static int message_handler_req_lib_clm_nodegetasync (struct conn_info *conn_info, void *message)
  595. {
  596. struct req_lib_clm_nodegetasync *req_lib_clm_nodegetasync = (struct req_lib_clm_nodegetasync *)message;
  597. struct res_clm_nodegetasync res_clm_nodegetasync;
  598. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  599. SaClmClusterNodeT *clusterNode = 0;
  600. int error = SA_AIS_ERR_INVALID_PARAM;
  601. int i;
  602. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_lib_clm_nodegetasync->nodeId);
  603. if (req_lib_clm_nodegetasync->nodeId == SA_CLM_LOCAL_NODE_ID) {
  604. clusterNode = &clusterNodes[0];
  605. error = SA_AIS_OK;
  606. } else
  607. for (i = 0; i < clusterNodeEntries; i++) {
  608. if (clusterNodes[i].nodeId == req_lib_clm_nodegetasync->nodeId) {
  609. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  610. clusterNode = &clusterNodes[i];
  611. error = SA_AIS_OK;
  612. break;
  613. }
  614. }
  615. /*
  616. * Respond to library request
  617. */
  618. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  619. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  620. res_clm_nodegetasync.header.error = SA_OK;
  621. libais_send_response (conn_info, &res_clm_nodegetasync,
  622. sizeof (struct res_clm_nodegetasync));
  623. /*
  624. * Send async response
  625. */
  626. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  627. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  628. res_clm_nodegetcallback.header.error = error;
  629. res_clm_nodegetcallback.invocation = req_lib_clm_nodegetasync->invocation;
  630. if (error == SA_AIS_OK) {
  631. memcpy (&res_clm_nodegetcallback.clusterNode, clusterNode,
  632. sizeof (SaClmClusterNodeT));
  633. }
  634. libais_send_response (conn_info->conn_info_partner, &res_clm_nodegetcallback,
  635. sizeof (struct res_clm_nodegetcallback));
  636. return (0);
  637. }