clm.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. static SaClmClusterNodeT clusterNodes[NODE_MAX];
  74. static 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 void 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_lib_init_fn (void *conn);
  108. static int clm_lib_exit_fn (void *conn);
  109. static void message_handler_req_exec_clm_nodejoin (
  110. void *message,
  111. struct totem_ip_address *source_addr);
  112. static void exec_clm_nodejoin_endian_convert (void *msg);
  113. static void message_handler_req_lib_clm_clustertrack (void *conn, void *message);
  114. static void message_handler_req_lib_clm_trackstop (void *conn, void *message);
  115. static void message_handler_req_lib_clm_nodeget (void *conn, void *message);
  116. static void message_handler_req_lib_clm_nodegetasync (void *conn, void *message);
  117. struct clm_pd {
  118. SaUint8T trackFlags;
  119. int tracking_enabled;
  120. struct list_head list;
  121. void *conn;
  122. };
  123. /*
  124. * Executive Handler Definition
  125. */
  126. static struct openais_lib_handler clm_lib_handlers[] =
  127. {
  128. { /* 0 */
  129. .lib_handler_fn = message_handler_req_lib_clm_clustertrack,
  130. .response_size = sizeof (struct res_lib_clm_clustertrack),
  131. .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE
  132. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  133. },
  134. { /* 1 */
  135. .lib_handler_fn = message_handler_req_lib_clm_trackstop,
  136. .response_size = sizeof (struct res_lib_clm_trackstop),
  137. .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE
  138. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  139. },
  140. { /* 2 */
  141. .lib_handler_fn = message_handler_req_lib_clm_nodeget,
  142. .response_size = sizeof (struct res_clm_nodeget),
  143. .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE
  144. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  145. },
  146. { /* 3 */
  147. .lib_handler_fn = message_handler_req_lib_clm_nodegetasync,
  148. .response_size = sizeof (struct res_clm_nodegetasync),
  149. .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE
  150. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  151. }
  152. };
  153. static struct openais_exec_handler clm_exec_handlers[] =
  154. {
  155. {
  156. .exec_handler_fn = message_handler_req_exec_clm_nodejoin,
  157. .exec_endian_convert_fn = exec_clm_nodejoin_endian_convert
  158. }
  159. };
  160. struct openais_service_handler clm_service_handler = {
  161. .name = (unsigned char*)"openais cluster membership service B.01.01",
  162. .id = CLM_SERVICE,
  163. .private_data_size = sizeof (struct clm_pd),
  164. .lib_init_fn = clm_lib_init_fn,
  165. .lib_exit_fn = clm_lib_exit_fn,
  166. .lib_handlers = clm_lib_handlers,
  167. .lib_handlers_count = sizeof (clm_lib_handlers) / sizeof (struct openais_lib_handler),
  168. .exec_init_fn = clm_exec_init_fn,
  169. .exec_dump_fn = NULL,
  170. .exec_handlers = clm_exec_handlers,
  171. .exec_handlers_count = sizeof (clm_exec_handlers) / sizeof (struct openais_exec_handler),
  172. .confchg_fn = clm_confchg_fn,
  173. .sync_init = clm_sync_init,
  174. .sync_process = clm_sync_process,
  175. .sync_activate = clm_sync_activate,
  176. .sync_abort = clm_sync_abort,
  177. };
  178. /*
  179. * Dynamic loader definition
  180. */
  181. #ifdef BUILD_DYNAMIC
  182. struct openais_service_handler *clm_get_service_handler_ver0 (void);
  183. struct openais_service_handler_iface_ver0 clm_service_handler_iface = {
  184. .openais_get_service_handler_ver0 = clm_get_service_handler_ver0
  185. };
  186. struct lcr_iface openais_clm_ver0[1] = {
  187. {
  188. .name = "openais_clm",
  189. .version = 0,
  190. .versions_replace = 0,
  191. .versions_replace_count = 0,
  192. .dependencies = 0,
  193. .dependency_count = 0,
  194. .constructor = NULL,
  195. .destructor = NULL,
  196. .interfaces = (void **)&clm_service_handler_iface,
  197. }
  198. };
  199. struct lcr_comp clm_comp_ver0 = {
  200. .iface_count = 1,
  201. .ifaces = openais_clm_ver0
  202. };
  203. int lcr_comp_get (struct lcr_comp **component)
  204. {
  205. *component = &clm_comp_ver0;
  206. return (0);
  207. }
  208. struct openais_service_handler *clm_get_service_handler_ver0 (void)
  209. {
  210. return (&clm_service_handler);
  211. }
  212. #endif /* BUILD_DYNAMIC */
  213. struct req_exec_clm_nodejoin {
  214. struct req_header header;
  215. SaClmClusterNodeT clusterNode;
  216. };
  217. static int clm_exec_init_fn (struct openais_config *openais_config)
  218. {
  219. memset (clusterNodes, 0, sizeof (SaClmClusterNodeT) * NODE_MAX);
  220. /*
  221. * Build local cluster node data structure
  222. */
  223. sprintf ((char *)thisClusterNode.nodeAddress.value, "%s", totemip_print (this_ip));
  224. thisClusterNode.nodeAddress.length = strlen ((char *)thisClusterNode.nodeAddress.value);
  225. if (this_ip->family == AF_INET) {
  226. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET;
  227. } else
  228. if (this_ip->family == AF_INET6) {
  229. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET6;
  230. } else {
  231. assert (0);
  232. }
  233. strcpy ((char *)thisClusterNode.nodeName.value, (char *)thisClusterNode.nodeAddress.value);
  234. thisClusterNode.nodeName.length = thisClusterNode.nodeAddress.length;
  235. thisClusterNode.nodeId = this_ip->nodeid;
  236. printf ("setting B to %x\n", this_ip->nodeid);
  237. thisClusterNode.member = 1;
  238. {
  239. struct sysinfo s_info;
  240. time_t current_time;
  241. sysinfo (&s_info);
  242. current_time = time (NULL);
  243. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  244. thisClusterNode.bootTimestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000;
  245. }
  246. memcpy (&clusterNodes[0], &thisClusterNode, sizeof (SaClmClusterNodeT));
  247. clusterNodeEntries = 1;
  248. main_clm_get_by_nodeid = clm_get_by_nodeid;
  249. return (0);
  250. }
  251. static int clm_lib_exit_fn (void *conn)
  252. {
  253. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  254. /*
  255. * Delete track entry if there is one
  256. */
  257. list_del (&clm_pd->list);
  258. clm_pd->conn = conn;
  259. return (0);
  260. }
  261. static void library_notification_send (SaClmClusterNotificationT *cluster_notification_entries,
  262. int notify_entries)
  263. {
  264. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  265. struct clm_pd *clm_pd;
  266. struct list_head *list;
  267. int i;
  268. if (notify_entries == 0) {
  269. return;
  270. }
  271. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  272. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  273. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  274. res_lib_clm_clustertrack.view = view_current;
  275. for (list = library_notification_send_listhead.next;
  276. list != &library_notification_send_listhead;
  277. list = list->next) {
  278. clm_pd = list_entry (list, struct clm_pd, list);
  279. /*
  280. * Track current and changes
  281. */
  282. if (clm_pd->trackFlags & SA_TRACK_CHANGES) {
  283. /*
  284. * Copy all cluster nodes
  285. */
  286. for (i = 0; i < clusterNodeEntries; i++) {
  287. memcpy (&res_lib_clm_clustertrack.notification[i].clusterNode,
  288. &clusterNodes[i], sizeof (SaClmClusterNodeT));
  289. res_lib_clm_clustertrack.notification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  290. res_lib_clm_clustertrack.notification[i].clusterNode.member = 1;
  291. }
  292. /*
  293. * Copy change_only notificaiton
  294. */
  295. res_lib_clm_clustertrack.numberOfItems = notify_entries + i;
  296. memcpy (&res_lib_clm_clustertrack.notification[i],
  297. cluster_notification_entries,
  298. sizeof (SaClmClusterNotificationT) * notify_entries);
  299. } else
  300. /*
  301. * Track only changes
  302. */
  303. if (clm_pd->trackFlags & SA_TRACK_CHANGES_ONLY) {
  304. res_lib_clm_clustertrack.numberOfItems = notify_entries;
  305. memcpy (&res_lib_clm_clustertrack.notification,
  306. cluster_notification_entries,
  307. sizeof (SaClmClusterNotificationT) * notify_entries);
  308. }
  309. /*
  310. * Send notifications to all CLM listeners
  311. */
  312. openais_conn_send_response (clm_pd->conn,
  313. &res_lib_clm_clustertrack,
  314. sizeof (struct res_lib_clm_clustertrack));
  315. }
  316. }
  317. static void notification_join (SaClmClusterNodeT *cluster_node)
  318. {
  319. SaClmClusterNotificationT notification;
  320. /*
  321. * Generate notification element
  322. */
  323. notification.clusterChange = SA_CLM_NODE_JOINED;
  324. notification.clusterNode.member = 1;
  325. memcpy (&notification.clusterNode, cluster_node,
  326. sizeof (SaClmClusterNodeT));
  327. library_notification_send (&notification, 1);
  328. }
  329. static void libraryNotificationLeave (SaClmNodeIdT *nodes, int nodes_entries)
  330. {
  331. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  332. int i, j;
  333. int notifyEntries;
  334. /*
  335. * Determine notification list
  336. */
  337. for (notifyEntries = 0, i = 0; i < clusterNodeEntries; i++) {
  338. for (j = 0; j < nodes_entries; j++) {
  339. if (clusterNodes[i].nodeId == nodes[j]) {
  340. memcpy (&clusterNotification[notifyEntries].clusterNode,
  341. &clusterNodes[i],
  342. sizeof (SaClmClusterNodeT));
  343. clusterNotification[notifyEntries].clusterChange = SA_CLM_NODE_LEFT;
  344. clusterNotification[notifyEntries].clusterNode.member = 0;
  345. notifyEntries += 1;
  346. break;
  347. }
  348. }
  349. }
  350. /*
  351. * Remove entries from clusterNodes array
  352. */
  353. for (i = 0; i < nodes_entries; i++) {
  354. for (j = 0; j < clusterNodeEntries;) {
  355. if (nodes[i] == clusterNodes[j].nodeId) {
  356. clusterNodeEntries -= 1;
  357. memmove (&clusterNodes[j], &clusterNodes[j + 1],
  358. (clusterNodeEntries - j) * sizeof (SaClmClusterNodeT));
  359. } else {
  360. /*
  361. * next clusterNode entry
  362. */
  363. j++;
  364. }
  365. }
  366. }
  367. library_notification_send (clusterNotification, notifyEntries);
  368. }
  369. static int clm_nodejoin_send (void)
  370. {
  371. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  372. struct iovec req_exec_clm_iovec;
  373. int result;
  374. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  375. req_exec_clm_nodejoin.header.id =
  376. SERVICE_ID_MAKE (CLM_SERVICE, MESSAGE_REQ_EXEC_CLM_NODEJOIN);
  377. // TODO dont use memcpy, use iovecs !!
  378. thisClusterNode.initialViewNumber = view_initial;
  379. memcpy (&req_exec_clm_nodejoin.clusterNode, &thisClusterNode,
  380. sizeof (SaClmClusterNodeT));
  381. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  382. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  383. result = totempg_groups_mcast_joined (openais_group_handle, &req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  384. return (result);
  385. }
  386. static void clm_confchg_fn (
  387. enum totem_configuration_type configuration_type,
  388. struct totem_ip_address *member_list, int member_list_entries,
  389. struct totem_ip_address *left_list, int left_list_entries,
  390. struct totem_ip_address *joined_list, int joined_list_entries,
  391. struct memb_ring_id *ring_id)
  392. {
  393. int i;
  394. SaClmNodeIdT nodes[NODE_MAX];
  395. view_current = ring_id->seq / 4;
  396. if (view_initial == 0) {
  397. view_initial = ring_id->seq / 4;
  398. }
  399. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  400. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  401. for (i = 0; i < member_list_entries; i++) {
  402. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&member_list[i]));
  403. }
  404. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  405. for (i = 0; i < left_list_entries; i++) {
  406. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&left_list[i]));
  407. }
  408. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  409. for (i = 0; i < joined_list_entries; i++) {
  410. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&joined_list[i]));
  411. }
  412. for (i = 0; i < left_list_entries; i++) {
  413. nodes[i] = left_list[i].nodeid;
  414. }
  415. libraryNotificationLeave (nodes, i);
  416. /*
  417. * Load the thisClusterNode data structure in case we are
  418. * transitioning to network interface up or down
  419. */
  420. sprintf ((char *)thisClusterNode.nodeAddress.value, "%s", totemip_print (this_ip));
  421. thisClusterNode.nodeAddress.length = strlen ((char *)thisClusterNode.nodeAddress.value);
  422. if (this_ip->family == AF_INET) {
  423. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET;
  424. } else
  425. if (this_ip->family == AF_INET6) {
  426. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET6;
  427. } else {
  428. assert (0);
  429. }
  430. strcpy ((char *)thisClusterNode.nodeName.value,
  431. (char *)thisClusterNode.nodeAddress.value);
  432. thisClusterNode.nodeName.length = thisClusterNode.nodeAddress.length;
  433. thisClusterNode.nodeId = this_ip->nodeid;
  434. }
  435. /*
  436. * This is a noop for this service
  437. */
  438. static void clm_sync_init (void)
  439. {
  440. return;
  441. }
  442. /*
  443. * If a processor joined in the configuration change and clm_sync_activate hasn't
  444. * yet been called, issue a node join to share CLM specific data about the processor
  445. */
  446. static int clm_sync_process (void)
  447. {
  448. /*
  449. * Send node information to other nodes
  450. */
  451. return (clm_nodejoin_send ());
  452. }
  453. /*
  454. * This is a noop for this service
  455. */
  456. static void clm_sync_activate (void)
  457. {
  458. return;
  459. }
  460. /*
  461. * This is a noop for this service
  462. */
  463. static void clm_sync_abort (void)
  464. {
  465. return;
  466. }
  467. static void exec_clm_nodejoin_endian_convert (void *msg)
  468. {
  469. }
  470. static void message_handler_req_exec_clm_nodejoin (
  471. void *message,
  472. struct totem_ip_address *source_addr)
  473. {
  474. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  475. int found = 0;
  476. int i;
  477. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", req_exec_clm_nodejoin->clusterNode.nodeName.value);
  478. /*
  479. * Determine if nodejoin already received
  480. */
  481. for (found = 0, i = 0; i < clusterNodeEntries; i++) {
  482. if (clusterNodes[i].nodeId == req_exec_clm_nodejoin->clusterNode.nodeId) {
  483. found = 1;
  484. }
  485. }
  486. /*
  487. * If not received, add to internal list
  488. */
  489. if (found == 0) {
  490. notification_join (&req_exec_clm_nodejoin->clusterNode);
  491. memcpy (&clusterNodes[clusterNodeEntries],
  492. &req_exec_clm_nodejoin->clusterNode,
  493. sizeof (SaClmClusterNodeT));
  494. clusterNodeEntries += 1;
  495. }
  496. }
  497. static int clm_lib_init_fn (void *conn)
  498. {
  499. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  500. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  501. list_init (&clm_pd->list);
  502. return (0);
  503. }
  504. static void message_handler_req_lib_clm_clustertrack (void *conn, void *msg)
  505. {
  506. struct req_lib_clm_clustertrack *req_lib_clm_clustertrack = (struct req_lib_clm_clustertrack *)msg;
  507. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  508. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  509. int i;
  510. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  511. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKSTART;
  512. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  513. res_lib_clm_clustertrack.view = view_current;
  514. res_lib_clm_clustertrack.numberOfItems = 0;
  515. if (req_lib_clm_clustertrack->trackFlags & SA_TRACK_CURRENT) {
  516. for (i = 0; i < clusterNodeEntries; i++) {
  517. res_lib_clm_clustertrack.notification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  518. memcpy (&res_lib_clm_clustertrack.notification[i].clusterNode,
  519. &clusterNodes[i], sizeof (SaClmClusterNodeT));
  520. }
  521. res_lib_clm_clustertrack.numberOfItems = clusterNodeEntries;
  522. }
  523. /*
  524. * Record requests for cluster tracking
  525. */
  526. if (req_lib_clm_clustertrack->trackFlags & SA_TRACK_CHANGES ||
  527. req_lib_clm_clustertrack->trackFlags & SA_TRACK_CHANGES_ONLY) {
  528. clm_pd->trackFlags = req_lib_clm_clustertrack->trackFlags;
  529. clm_pd->tracking_enabled = 1;
  530. list_add (&clm_pd->list, &library_notification_send_listhead);
  531. }
  532. openais_conn_send_response (conn, &res_lib_clm_clustertrack,
  533. sizeof (struct res_lib_clm_clustertrack));
  534. if (req_lib_clm_clustertrack->return_in_callback) {
  535. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  536. openais_conn_send_response (
  537. openais_conn_partner_get (conn),
  538. &res_lib_clm_clustertrack,
  539. sizeof (struct res_lib_clm_clustertrack));
  540. }
  541. }
  542. static void message_handler_req_lib_clm_trackstop (void *conn, void *msg)
  543. {
  544. struct res_lib_clm_trackstop res_lib_clm_trackstop;
  545. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  546. res_lib_clm_trackstop.header.size = sizeof (struct res_lib_clm_trackstop);
  547. res_lib_clm_trackstop.header.id = MESSAGE_RES_CLM_TRACKSTOP;
  548. if (clm_pd->tracking_enabled) {
  549. res_lib_clm_trackstop.header.error = SA_AIS_OK;
  550. clm_pd->tracking_enabled = 0;
  551. } else {
  552. res_lib_clm_trackstop.header.error = SA_AIS_ERR_NOT_EXIST;
  553. }
  554. list_del (&clm_pd->list);
  555. openais_conn_send_response (conn, &res_lib_clm_trackstop,
  556. sizeof (struct res_lib_clm_trackstop));
  557. }
  558. static void message_handler_req_lib_clm_nodeget (void *conn, void *msg)
  559. {
  560. struct req_lib_clm_nodeget *req_lib_clm_nodeget = (struct req_lib_clm_nodeget *)msg;
  561. struct res_clm_nodeget res_clm_nodeget;
  562. SaClmClusterNodeT *clusterNode = 0;
  563. int valid = 0;
  564. int i;
  565. log_printf (LOG_LEVEL_NOTICE, "nodeget: trying to find node %x\n", (int)req_lib_clm_nodeget->nodeId);
  566. if (req_lib_clm_nodeget->nodeId == SA_CLM_LOCAL_NODE_ID) {
  567. clusterNode = &clusterNodes[0];
  568. valid = 1;
  569. } else
  570. for (i = 0; i < clusterNodeEntries; i++) {
  571. if (clusterNodes[i].nodeId == req_lib_clm_nodeget->nodeId) {
  572. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  573. clusterNode = &clusterNodes[i];
  574. valid = 1;
  575. break;
  576. }
  577. }
  578. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  579. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  580. res_clm_nodeget.header.error = SA_AIS_OK;
  581. res_clm_nodeget.invocation = req_lib_clm_nodeget->invocation;
  582. res_clm_nodeget.valid = valid;
  583. if (valid) {
  584. memcpy (&res_clm_nodeget.clusterNode, clusterNode, sizeof (SaClmClusterNodeT));
  585. }
  586. openais_conn_send_response (conn, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  587. }
  588. static void message_handler_req_lib_clm_nodegetasync (void *conn, void *msg)
  589. {
  590. struct req_lib_clm_nodegetasync *req_lib_clm_nodegetasync = (struct req_lib_clm_nodegetasync *)msg;
  591. struct res_clm_nodegetasync res_clm_nodegetasync;
  592. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  593. SaClmClusterNodeT *clusterNode = 0;
  594. int error = SA_AIS_ERR_INVALID_PARAM;
  595. int i;
  596. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_lib_clm_nodegetasync->nodeId);
  597. if (req_lib_clm_nodegetasync->nodeId == SA_CLM_LOCAL_NODE_ID) {
  598. clusterNode = &clusterNodes[0];
  599. error = SA_AIS_OK;
  600. } else
  601. for (i = 0; i < clusterNodeEntries; i++) {
  602. if (clusterNodes[i].nodeId == req_lib_clm_nodegetasync->nodeId) {
  603. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  604. clusterNode = &clusterNodes[i];
  605. error = SA_AIS_OK;
  606. break;
  607. }
  608. }
  609. /*
  610. * Respond to library request
  611. */
  612. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  613. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  614. res_clm_nodegetasync.header.error = SA_AIS_OK;
  615. openais_conn_send_response (conn, &res_clm_nodegetasync,
  616. sizeof (struct res_clm_nodegetasync));
  617. /*
  618. * Send async response
  619. */
  620. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  621. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  622. res_clm_nodegetcallback.header.error = error;
  623. res_clm_nodegetcallback.invocation = req_lib_clm_nodegetasync->invocation;
  624. if (error == SA_AIS_OK) {
  625. memcpy (&res_clm_nodegetcallback.clusterNode, clusterNode,
  626. sizeof (SaClmClusterNodeT));
  627. }
  628. openais_conn_send_response (openais_conn_partner_get (conn),
  629. &res_clm_nodegetcallback,
  630. sizeof (struct res_clm_nodegetcallback));
  631. }