clm.c 22 KB

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