clm.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * vi: set autoindent tabstop=4 shiftwidth=4 :
  3. *
  4. * Copyright (c) 2002-2005 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/ais_types.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 "aispoll.h"
  60. #include "totempg.h"
  61. #include "main.h"
  62. #include "mempool.h"
  63. #include "handlers.h"
  64. #define LOG_SERVICE LOG_SERVICE_CLM
  65. #include "print.h"
  66. SaClmClusterChangesT thisClusterNodeLastChange = SA_CLM_NODE_JOINED;
  67. SaClmClusterNodeT thisClusterNode;
  68. #define NODE_MAX 16
  69. SaClmClusterNodeT clusterNodes[NODE_MAX];
  70. int clusterNodeEntries = 0;
  71. static DECLARE_LIST_INIT (library_notification_send_listhead);
  72. SaClmClusterNodeT *clm_get_by_nodeid (struct in_addr node_id)
  73. {
  74. SaClmClusterNodeT *ret = NULL;
  75. int i;
  76. if (node_id.s_addr == SA_CLM_LOCAL_NODE_ID) {
  77. return (&clusterNodes[0]);
  78. }
  79. for (i = 0; i < clusterNodeEntries; i++) {
  80. if (clusterNodes[i].nodeId == node_id.s_addr) {
  81. ret = &clusterNodes[i];
  82. break;
  83. }
  84. }
  85. return (ret);
  86. }
  87. /*
  88. * Service Interfaces required by service_message_handler struct
  89. */
  90. static int clm_confchg_fn (
  91. enum totem_configuration_type configuration_type,
  92. struct in_addr *member_list, int member_list_entries,
  93. struct in_addr *left_list, int left_list_entries,
  94. struct in_addr *joined_list, int joined_list_entries,
  95. struct memb_ring_id *ring_id);
  96. static void clm_sync_init (void);
  97. static int clm_sync_process (void);
  98. static void clm_sync_activate (void);
  99. static void clm_sync_abort (void);
  100. static int clm_exec_init_fn (struct openais_config *);
  101. static int clm_init_two_fn (struct conn_info *conn_info);
  102. static int clm_exit_fn (struct conn_info *conn_info);
  103. static int message_handler_req_exec_clm_nodejoin (void *message, struct in_addr source_addr,
  104. int endian_conversion_required);
  105. static int message_handler_req_clm_clustertrack (struct conn_info *conn_info,
  106. void *message);
  107. static int message_handler_req_lib_clm_trackstop (struct conn_info *conn_info,
  108. void *message);
  109. static int message_handler_req_clm_nodeget (struct conn_info *conn_info,
  110. void *message);
  111. static int message_handler_req_clm_nodegetasync (struct conn_info *conn_info,
  112. void *message);
  113. static int clm_exit_fn (struct conn_info *conn_info);
  114. /*
  115. * Executive Handler Definition
  116. */
  117. struct libais_handler clm_libais_handlers[] =
  118. {
  119. { /* 0 */
  120. .libais_handler_fn = message_handler_req_clm_clustertrack,
  121. .response_size = sizeof (struct res_clm_clustertrack),
  122. .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE
  123. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  124. },
  125. { /* 1 */
  126. .libais_handler_fn = message_handler_req_lib_clm_trackstop,
  127. .response_size = sizeof (struct res_lib_clm_trackstop),
  128. .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE
  129. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  130. },
  131. { /* 2 */
  132. .libais_handler_fn = message_handler_req_clm_nodeget,
  133. .response_size = sizeof (struct res_clm_nodeget),
  134. .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE
  135. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  136. },
  137. { /* 3 */
  138. .libais_handler_fn = message_handler_req_clm_nodegetasync,
  139. .response_size = sizeof (struct res_clm_nodegetasync),
  140. .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE
  141. .flow_control = FLOW_CONTROL_NOT_REQUIRED
  142. }
  143. };
  144. static int (*clm_aisexec_handler_fns[]) (void *, struct in_addr source_addr, int endian_conversion_required) = {
  145. message_handler_req_exec_clm_nodejoin
  146. };
  147. struct service_handler clm_service_handler = {
  148. .libais_handlers = clm_libais_handlers,
  149. .libais_handlers_count = sizeof (clm_libais_handlers) / sizeof (struct libais_handler),
  150. .aisexec_handler_fns = clm_aisexec_handler_fns,
  151. .aisexec_handler_fns_count = sizeof (clm_aisexec_handler_fns) / sizeof (int (*)),
  152. .confchg_fn = clm_confchg_fn,
  153. .libais_init_two_fn = clm_init_two_fn,
  154. .libais_exit_fn = clm_exit_fn,
  155. .exec_init_fn = clm_exec_init_fn,
  156. .exec_dump_fn = 0,
  157. .sync_init = clm_sync_init,
  158. .sync_process = clm_sync_process,
  159. .sync_activate = clm_sync_activate,
  160. .sync_abort = clm_sync_abort,
  161. };
  162. struct req_exec_clm_nodejoin {
  163. struct req_header header;
  164. SaClmClusterNodeT clusterNode;
  165. };
  166. static int clm_exec_init_fn (struct openais_config *openais_config)
  167. {
  168. memset (clusterNodes, 0, sizeof (SaClmClusterNodeT) * NODE_MAX);
  169. /*
  170. * Build local cluster node data structure
  171. */
  172. thisClusterNode.nodeId = this_ip->sin_addr.s_addr;
  173. memcpy (&thisClusterNode.nodeAddress.value, &this_ip->sin_addr,
  174. sizeof (struct in_addr));
  175. thisClusterNode.nodeAddress.length = sizeof (struct in_addr);
  176. strcpy (thisClusterNode.nodeName.value, (char *)inet_ntoa (this_ip->sin_addr));
  177. thisClusterNode.nodeName.length = strlen (thisClusterNode.nodeName.value);
  178. thisClusterNode.member = 1;
  179. {
  180. struct sysinfo s_info;
  181. time_t current_time;
  182. sysinfo (&s_info);
  183. current_time = time (NULL);
  184. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  185. thisClusterNode.bootTimestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000;
  186. }
  187. #ifdef DEBUG
  188. printSaClmClusterNodeT ("this cluster node", &thisClusterNode);
  189. #endif
  190. memcpy (&clusterNodes[0], &thisClusterNode, sizeof (SaClmClusterNodeT));
  191. clusterNodeEntries = 1;
  192. return (0);
  193. }
  194. static int clm_exit_fn (struct conn_info *conn_info)
  195. {
  196. /*
  197. * Delete track entry if there is one
  198. */
  199. list_del (&conn_info->conn_list);
  200. return (0);
  201. }
  202. static void libraryNotificationCurrentState (struct conn_info *conn_info)
  203. {
  204. struct res_clm_trackcallback res_clm_trackcallback;
  205. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  206. int i;
  207. if ((conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CURRENT) == 0) {
  208. return;
  209. }
  210. /*
  211. * Turn off track current
  212. */
  213. conn_info->ais_ci.u.libclm_ci.trackFlags &= ~SA_TRACK_CURRENT;
  214. /*
  215. * Build notification list
  216. */
  217. for (i = 0; i < clusterNodeEntries; i++) {
  218. clusterNotification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  219. memcpy (&clusterNotification[i].clusterNode, &clusterNodes[i],
  220. sizeof (SaClmClusterNodeT));
  221. }
  222. /*
  223. * Send track response
  224. */
  225. res_clm_trackcallback.header.size = sizeof (struct res_clm_trackcallback) +
  226. sizeof (SaClmClusterNotificationT) * i;
  227. res_clm_trackcallback.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  228. res_clm_trackcallback.header.error = SA_OK;
  229. res_clm_trackcallback.viewNumber = 0;
  230. res_clm_trackcallback.numberOfItems = i;
  231. res_clm_trackcallback.numberOfMembers = i;
  232. libais_send_response (conn_info, &res_clm_trackcallback, sizeof (struct res_clm_trackcallback));
  233. libais_send_response (conn_info, clusterNotification, sizeof (SaClmClusterNotificationT) * i);
  234. }
  235. void library_notification_send (SaClmClusterNotificationT *cluster_notification_entries,
  236. int notify_entries)
  237. {
  238. struct res_clm_trackcallback res_clm_trackcallback;
  239. struct conn_info *conn_info;
  240. struct list_head *list;
  241. for (list = library_notification_send_listhead.next;
  242. list != &library_notification_send_listhead;
  243. list = list->next) {
  244. conn_info = list_entry (list, struct conn_info, conn_list);
  245. /*
  246. * Send notifications to all CLM listeners
  247. */
  248. if (notify_entries) {
  249. res_clm_trackcallback.header.size = sizeof (struct res_clm_trackcallback) +
  250. (notify_entries * sizeof (SaClmClusterNotificationT));
  251. res_clm_trackcallback.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  252. res_clm_trackcallback.header.error = SA_OK;
  253. res_clm_trackcallback.viewNumber = 0;
  254. res_clm_trackcallback.numberOfItems = notify_entries;
  255. res_clm_trackcallback.numberOfMembers = notify_entries;
  256. libais_send_response (conn_info, &res_clm_trackcallback,
  257. sizeof (struct res_clm_trackcallback));
  258. libais_send_response (conn_info, cluster_notification_entries,
  259. sizeof (SaClmClusterNotificationT) * notify_entries);
  260. }
  261. }
  262. }
  263. static void libraryNotificationJoin (SaClmNodeIdT node)
  264. {
  265. SaClmClusterNotificationT clusterNotification;
  266. int i;
  267. /*
  268. * Generate notification element
  269. */
  270. clusterNotification.clusterChange = SA_CLM_NODE_JOINED;
  271. clusterNotification.clusterNode.member = 1;
  272. for (i = 0; i < clusterNodeEntries; i++) {
  273. if (node == clusterNodes[i].nodeId) {
  274. memcpy (&clusterNotification.clusterNode, &clusterNodes[i],
  275. sizeof (SaClmClusterNodeT));
  276. }
  277. }
  278. library_notification_send (&clusterNotification, 1);
  279. }
  280. static void libraryNotificationLeave (SaClmNodeIdT *nodes, int nodes_entries)
  281. {
  282. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  283. int i, j;
  284. int notifyEntries;
  285. /*
  286. * Determine notification list
  287. */
  288. for (notifyEntries = 0, i = 0; i < clusterNodeEntries; i++) {
  289. for (j = 0; j < nodes_entries; j++) {
  290. if (clusterNodes[i].nodeId == nodes[j]) {
  291. memcpy (&clusterNotification[notifyEntries].clusterNode,
  292. &clusterNodes[i],
  293. sizeof (SaClmClusterNodeT));
  294. clusterNotification[notifyEntries].clusterChange = SA_CLM_NODE_LEFT;
  295. clusterNotification[notifyEntries].clusterNode.member = 0;
  296. notifyEntries += 1;
  297. break;
  298. }
  299. }
  300. }
  301. library_notification_send (clusterNotification, notifyEntries);
  302. /*
  303. * Remove entries from clusterNodes array
  304. */
  305. for (i = 0; i < nodes_entries; i++) {
  306. for (j = 0; j < clusterNodeEntries;) {
  307. if (nodes[i] == clusterNodes[j].nodeId) {
  308. clusterNodeEntries -= 1;
  309. memmove (&clusterNodes[j], &clusterNodes[j + 1],
  310. (clusterNodeEntries - j) * sizeof (SaClmClusterNodeT));
  311. } else {
  312. /*
  313. * next clusterNode entry
  314. */
  315. j++;
  316. }
  317. }
  318. }
  319. }
  320. static int clm_nodejoin_send (void)
  321. {
  322. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  323. struct iovec req_exec_clm_iovec;
  324. int result;
  325. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  326. req_exec_clm_nodejoin.header.id = MESSAGE_REQ_EXEC_CLM_NODEJOIN;
  327. // TODO dont use memcpy, use iovecs !!
  328. memcpy (&req_exec_clm_nodejoin.clusterNode, &thisClusterNode,
  329. sizeof (SaClmClusterNodeT));
  330. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  331. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  332. result = totempg_mcast (&req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  333. return (result);
  334. }
  335. static int clm_confchg_fn (
  336. enum totem_configuration_type configuration_type,
  337. struct in_addr *member_list, int member_list_entries,
  338. struct in_addr *left_list, int left_list_entries,
  339. struct in_addr *joined_list, int joined_list_entries,
  340. struct memb_ring_id *ring_id)
  341. {
  342. int i;
  343. SaClmNodeIdT nodes[NODE_MAX];
  344. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  345. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  346. for (i = 0; i < member_list_entries; i++) {
  347. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (member_list[i]));
  348. }
  349. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  350. for (i = 0; i < left_list_entries; i++) {
  351. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (left_list[i]));
  352. }
  353. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  354. for (i = 0; i < joined_list_entries; i++) {
  355. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (joined_list[i]));
  356. }
  357. for (i = 0; i < left_list_entries; i++) {
  358. nodes[i] = left_list[i].s_addr;
  359. }
  360. libraryNotificationLeave (nodes, i);
  361. /*
  362. * Load the thisClusterNode data structure in case we are
  363. * transitioning to network interface up or down
  364. */
  365. thisClusterNode.nodeId = this_ip->sin_addr.s_addr;
  366. memcpy (&thisClusterNode.nodeAddress.value, &this_ip->sin_addr,
  367. sizeof (struct in_addr));
  368. thisClusterNode.nodeAddress.length = sizeof (struct in_addr);
  369. strcpy (thisClusterNode.nodeName.value, (char *)inet_ntoa (this_ip->sin_addr));
  370. thisClusterNode.nodeName.length = strlen (thisClusterNode.nodeName.value);
  371. return (0);
  372. }
  373. /*
  374. * This is a noop for this service
  375. */
  376. static void clm_sync_init (void)
  377. {
  378. return;
  379. }
  380. /*
  381. * If a processor joined in the configuration change and clm_sync_activate hasn't
  382. * yet been called, issue a node join to share CLM specific data about the processor
  383. */
  384. static int clm_sync_process (void)
  385. {
  386. /*
  387. * Send node information to other nodes
  388. */
  389. return (clm_nodejoin_send ());
  390. return (0);
  391. }
  392. /*
  393. * This is a noop for this service
  394. */
  395. static void clm_sync_activate (void)
  396. {
  397. return;
  398. }
  399. /*
  400. * This is a noop for this service
  401. */
  402. static void clm_sync_abort (void)
  403. {
  404. return;
  405. }
  406. static void exec_clm_nodejoin_endian_conversion (struct req_exec_clm_nodejoin *in,
  407. struct req_exec_clm_nodejoin *out)
  408. {
  409. // TODO this isn't complete yet
  410. // TODO SaNameT needs to be packed and aligned
  411. memmove (&out->clusterNode.nodeName.value[0],
  412. &in->clusterNode.nodeName.value[2],
  413. SA_MAX_NAME_LENGTH);
  414. }
  415. static int message_handler_req_exec_clm_nodejoin (void *message, struct in_addr source_addr,
  416. int endian_conversion_required)
  417. {
  418. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  419. struct req_exec_clm_nodejoin req_exec_clm_nodejoin_storage;
  420. int found;
  421. int i;
  422. if (endian_conversion_required) {
  423. exec_clm_nodejoin_endian_conversion (message, &req_exec_clm_nodejoin_storage);
  424. req_exec_clm_nodejoin = &req_exec_clm_nodejoin_storage;
  425. } else {
  426. req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  427. }
  428. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", req_exec_clm_nodejoin->clusterNode.nodeName.value);
  429. /*
  430. * Determine if nodejoin already received
  431. */
  432. for (found = 0, i = 0; i < clusterNodeEntries; i++) {
  433. if (memcmp (&clusterNodes[i], &req_exec_clm_nodejoin->clusterNode,
  434. sizeof (SaClmClusterNodeT)) == 0) {
  435. found = 1;
  436. }
  437. }
  438. /*
  439. * If not received, add to internal list
  440. */
  441. if (found == 0) {
  442. memcpy (&clusterNodes[clusterNodeEntries],
  443. &req_exec_clm_nodejoin->clusterNode,
  444. sizeof (SaClmClusterNodeT));
  445. clusterNodeEntries += 1;
  446. libraryNotificationJoin (req_exec_clm_nodejoin->clusterNode.nodeId);
  447. }
  448. return (0);
  449. }
  450. static int clm_init_two_fn (struct conn_info *conn_info)
  451. {
  452. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  453. list_init (&conn_info->conn_list);
  454. return (0);
  455. }
  456. int message_handler_req_clm_clustertrack (struct conn_info *conn_info, void *message)
  457. {
  458. struct req_clm_clustertrack *req_clm_clustertrack = (struct req_clm_clustertrack *)message;
  459. conn_info->conn_info_partner->ais_ci.u.libclm_ci.trackFlags = req_clm_clustertrack->trackFlags;
  460. conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled = 1;
  461. list_add (&conn_info->conn_info_partner->conn_list, &library_notification_send_listhead);
  462. libraryNotificationCurrentState (conn_info->conn_info_partner);
  463. return (0);
  464. }
  465. static int message_handler_req_lib_clm_trackstop (struct conn_info *conn_info, void *message)
  466. {
  467. struct res_lib_clm_trackstop res_lib_clm_trackstop;
  468. res_lib_clm_trackstop.header.size = sizeof (struct res_lib_clm_trackstop);
  469. res_lib_clm_trackstop.header.id = MESSAGE_RES_CLM_TRACKSTOP;
  470. if (conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled) {
  471. res_lib_clm_trackstop.header.error = SA_OK;
  472. } else {
  473. res_lib_clm_trackstop.header.error = SA_AIS_ERR_NOT_EXIST;
  474. }
  475. conn_info->conn_info_partner->ais_ci.u.libclm_ci.trackFlags = 0;
  476. conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled = 0;
  477. list_del (&conn_info->conn_info_partner->conn_list);
  478. libais_send_response (conn_info, &res_lib_clm_trackstop,
  479. sizeof (struct res_lib_clm_trackstop));
  480. return (0);
  481. }
  482. static int message_handler_req_clm_nodeget (struct conn_info *conn_info, void *message)
  483. {
  484. struct req_clm_nodeget *req_clm_nodeget = (struct req_clm_nodeget *)message;
  485. struct res_clm_nodeget res_clm_nodeget;
  486. SaClmClusterNodeT *clusterNode = 0;
  487. int valid = 0;
  488. int i;
  489. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_clm_nodeget->nodeId);
  490. if (req_clm_nodeget->nodeId == SA_CLM_LOCAL_NODE_ID) {
  491. clusterNode = &clusterNodes[0];
  492. valid = 1;
  493. } else
  494. for (i = 0; i < clusterNodeEntries; i++) {
  495. if (clusterNodes[i].nodeId == req_clm_nodeget->nodeId) {
  496. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  497. clusterNode = &clusterNodes[i];
  498. valid = 1;
  499. break;
  500. }
  501. }
  502. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  503. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  504. res_clm_nodeget.header.error = SA_OK;
  505. res_clm_nodeget.invocation = req_clm_nodeget->invocation;
  506. res_clm_nodeget.valid = valid;
  507. printf ("valid is %d\n", res_clm_nodeget.valid);
  508. if (valid) {
  509. memcpy (&res_clm_nodeget.clusterNode, clusterNode, sizeof (SaClmClusterNodeT));
  510. }
  511. libais_send_response (conn_info, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  512. return (0);
  513. }
  514. static int message_handler_req_clm_nodegetasync (struct conn_info *conn_info, void *message)
  515. {
  516. struct req_clm_nodegetasync *req_clm_nodegetasync = (struct req_clm_nodegetasync *)message;
  517. struct res_clm_nodegetasync res_clm_nodegetasync;
  518. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  519. SaClmClusterNodeT *clusterNode = 0;
  520. int error = SA_AIS_ERR_INVALID_PARAM;
  521. int i;
  522. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_clm_nodegetasync->nodeId);
  523. if (req_clm_nodegetasync->nodeId == SA_CLM_LOCAL_NODE_ID) {
  524. clusterNode = &clusterNodes[0];
  525. error = SA_AIS_OK;
  526. } else
  527. for (i = 0; i < clusterNodeEntries; i++) {
  528. if (clusterNodes[i].nodeId == req_clm_nodegetasync->nodeId) {
  529. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  530. clusterNode = &clusterNodes[i];
  531. error = SA_AIS_OK;
  532. break;
  533. }
  534. }
  535. /*
  536. * Respond to library request
  537. */
  538. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  539. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  540. res_clm_nodegetasync.header.error = SA_OK;
  541. libais_send_response (conn_info, &res_clm_nodegetasync,
  542. sizeof (struct res_clm_nodegetasync));
  543. /*
  544. * Send async response
  545. */
  546. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  547. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  548. res_clm_nodegetcallback.header.error = error;
  549. res_clm_nodegetcallback.invocation = req_clm_nodegetasync->invocation;
  550. if (error == SA_AIS_OK) {
  551. memcpy (&res_clm_nodegetcallback.clusterNode, clusterNode,
  552. sizeof (SaClmClusterNodeT));
  553. }
  554. libais_send_response (conn_info->conn_info_partner, &res_clm_nodegetcallback,
  555. sizeof (struct res_clm_nodegetcallback));
  556. return (0);
  557. }