clm.c 22 KB

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