clm.c 20 KB

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