clm.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696
  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 ((char *)thisClusterNode.nodeAddress.value, "%s", inet_ntoa (this_ip->sin_addr));
  176. thisClusterNode.nodeAddress.length = strlen ((char *)thisClusterNode.nodeAddress.value);
  177. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET;
  178. sprintf ((char *)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. int i;
  211. if (notify_entries == 0) {
  212. return;
  213. }
  214. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  215. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  216. res_lib_clm_clustertrack.header.error = SA_OK;
  217. res_lib_clm_clustertrack.view = view_current;
  218. for (list = library_notification_send_listhead.next;
  219. list != &library_notification_send_listhead;
  220. list = list->next) {
  221. conn_info = list_entry (list, struct conn_info, conn_list);
  222. /*
  223. * Track current and changes
  224. */
  225. if (conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CHANGES) {
  226. /*
  227. * Copy all cluster nodes
  228. */
  229. for (i = 0; i < clusterNodeEntries; i++) {
  230. memcpy (&res_lib_clm_clustertrack.notification[i].clusterNode,
  231. &clusterNodes[i], sizeof (SaClmClusterNodeT));
  232. res_lib_clm_clustertrack.notification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  233. res_lib_clm_clustertrack.notification[i].clusterNode.member = 1;
  234. }
  235. /*
  236. * Copy change_only notificaiton
  237. */
  238. res_lib_clm_clustertrack.numberOfItems = notify_entries + i;
  239. memcpy (&res_lib_clm_clustertrack.notification[i],
  240. cluster_notification_entries,
  241. sizeof (SaClmClusterNotificationT) * notify_entries);
  242. } else
  243. /*
  244. * Track only changes
  245. */
  246. if (conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CHANGES_ONLY) {
  247. res_lib_clm_clustertrack.numberOfItems = notify_entries;
  248. memcpy (&res_lib_clm_clustertrack.notification,
  249. cluster_notification_entries,
  250. sizeof (SaClmClusterNotificationT) * notify_entries);
  251. }
  252. /*
  253. * Send notifications to all CLM listeners
  254. */
  255. libais_send_response (conn_info, &res_lib_clm_clustertrack,
  256. sizeof (struct res_lib_clm_clustertrack));
  257. }
  258. }
  259. static void notification_join (SaClmClusterNodeT *cluster_node)
  260. {
  261. SaClmClusterNotificationT notification;
  262. /*
  263. * Generate notification element
  264. */
  265. notification.clusterChange = SA_CLM_NODE_JOINED;
  266. notification.clusterNode.member = 1;
  267. memcpy (&notification.clusterNode, cluster_node,
  268. sizeof (SaClmClusterNodeT));
  269. library_notification_send (&notification, 1);
  270. }
  271. static void libraryNotificationLeave (SaClmNodeIdT *nodes, int nodes_entries)
  272. {
  273. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  274. int i, j;
  275. int notifyEntries;
  276. /*
  277. * Determine notification list
  278. */
  279. for (notifyEntries = 0, i = 0; i < clusterNodeEntries; i++) {
  280. for (j = 0; j < nodes_entries; j++) {
  281. if (clusterNodes[i].nodeId == nodes[j]) {
  282. memcpy (&clusterNotification[notifyEntries].clusterNode,
  283. &clusterNodes[i],
  284. sizeof (SaClmClusterNodeT));
  285. clusterNotification[notifyEntries].clusterChange = SA_CLM_NODE_LEFT;
  286. clusterNotification[notifyEntries].clusterNode.member = 0;
  287. notifyEntries += 1;
  288. break;
  289. }
  290. }
  291. }
  292. /*
  293. * Remove entries from clusterNodes array
  294. */
  295. for (i = 0; i < nodes_entries; i++) {
  296. for (j = 0; j < clusterNodeEntries;) {
  297. if (nodes[i] == clusterNodes[j].nodeId) {
  298. clusterNodeEntries -= 1;
  299. memmove (&clusterNodes[j], &clusterNodes[j + 1],
  300. (clusterNodeEntries - j) * sizeof (SaClmClusterNodeT));
  301. } else {
  302. /*
  303. * next clusterNode entry
  304. */
  305. j++;
  306. }
  307. }
  308. }
  309. library_notification_send (clusterNotification, notifyEntries);
  310. }
  311. static int clm_nodejoin_send (void)
  312. {
  313. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  314. struct iovec req_exec_clm_iovec;
  315. int result;
  316. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  317. req_exec_clm_nodejoin.header.id = MESSAGE_REQ_EXEC_CLM_NODEJOIN;
  318. // TODO dont use memcpy, use iovecs !!
  319. thisClusterNode.initialViewNumber = view_initial;
  320. memcpy (&req_exec_clm_nodejoin.clusterNode, &thisClusterNode,
  321. sizeof (SaClmClusterNodeT));
  322. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  323. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  324. result = totempg_mcast (&req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  325. return (result);
  326. }
  327. static int clm_confchg_fn (
  328. enum totem_configuration_type configuration_type,
  329. struct in_addr *member_list, int member_list_entries,
  330. struct in_addr *left_list, int left_list_entries,
  331. struct in_addr *joined_list, int joined_list_entries,
  332. struct memb_ring_id *ring_id)
  333. {
  334. int i;
  335. SaClmNodeIdT nodes[NODE_MAX];
  336. view_current = ring_id->seq / 4;
  337. if (view_initial == 0) {
  338. view_initial = ring_id->seq / 4;
  339. }
  340. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  341. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  342. for (i = 0; i < member_list_entries; i++) {
  343. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (member_list[i]));
  344. }
  345. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  346. for (i = 0; i < left_list_entries; i++) {
  347. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (left_list[i]));
  348. }
  349. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  350. for (i = 0; i < joined_list_entries; i++) {
  351. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (joined_list[i]));
  352. }
  353. for (i = 0; i < left_list_entries; i++) {
  354. nodes[i] = left_list[i].s_addr;
  355. }
  356. libraryNotificationLeave (nodes, i);
  357. /*
  358. * Load the thisClusterNode data structure in case we are
  359. * transitioning to network interface up or down
  360. */
  361. thisClusterNode.nodeId = this_ip->sin_addr.s_addr;
  362. strcpy ((char *)thisClusterNode.nodeName.value, (char *)inet_ntoa (this_ip->sin_addr));
  363. sprintf ((char *)thisClusterNode.nodeAddress.value, "%s", inet_ntoa (this_ip->sin_addr));
  364. thisClusterNode.nodeAddress.length = strlen ((char *)thisClusterNode.nodeAddress.value);
  365. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET;
  366. sprintf ((char *)thisClusterNode.nodeName.value, "%s", inet_ntoa (this_ip->sin_addr));
  367. thisClusterNode.nodeName.length = strlen ((char *)thisClusterNode.nodeName.value);
  368. return (0);
  369. }
  370. /*
  371. * This is a noop for this service
  372. */
  373. static void clm_sync_init (void)
  374. {
  375. return;
  376. }
  377. /*
  378. * If a processor joined in the configuration change and clm_sync_activate hasn't
  379. * yet been called, issue a node join to share CLM specific data about the processor
  380. */
  381. static int clm_sync_process (void)
  382. {
  383. /*
  384. * Send node information to other nodes
  385. */
  386. return (clm_nodejoin_send ());
  387. }
  388. /*
  389. * This is a noop for this service
  390. */
  391. static void clm_sync_activate (void)
  392. {
  393. return;
  394. }
  395. /*
  396. * This is a noop for this service
  397. */
  398. static void clm_sync_abort (void)
  399. {
  400. return;
  401. }
  402. static void exec_clm_nodejoin_endian_conversion (struct req_exec_clm_nodejoin *in,
  403. struct req_exec_clm_nodejoin *out)
  404. {
  405. // TODO this isn't complete yet
  406. // TODO SaNameT needs to be packed and aligned
  407. memmove (&out->clusterNode.nodeName.value[0],
  408. &in->clusterNode.nodeName.value[2],
  409. SA_MAX_NAME_LENGTH);
  410. }
  411. static int message_handler_req_exec_clm_nodejoin (void *message, struct in_addr source_addr,
  412. int endian_conversion_required)
  413. {
  414. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  415. struct req_exec_clm_nodejoin req_exec_clm_nodejoin_storage;
  416. int found;
  417. int i;
  418. if (endian_conversion_required) {
  419. exec_clm_nodejoin_endian_conversion (message, &req_exec_clm_nodejoin_storage);
  420. req_exec_clm_nodejoin = &req_exec_clm_nodejoin_storage;
  421. } else {
  422. req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  423. }
  424. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", req_exec_clm_nodejoin->clusterNode.nodeName.value);
  425. /*
  426. * Determine if nodejoin already received
  427. */
  428. for (found = 0, i = 0; i < clusterNodeEntries; i++) {
  429. if (memcmp (&clusterNodes[i], &req_exec_clm_nodejoin->clusterNode,
  430. sizeof (SaClmClusterNodeT)) == 0) {
  431. found = 1;
  432. }
  433. }
  434. /*
  435. * If not received, add to internal list
  436. */
  437. if (found == 0) {
  438. notification_join (&req_exec_clm_nodejoin->clusterNode);
  439. memcpy (&clusterNodes[clusterNodeEntries],
  440. &req_exec_clm_nodejoin->clusterNode,
  441. sizeof (SaClmClusterNodeT));
  442. clusterNodeEntries += 1;
  443. }
  444. return (0);
  445. }
  446. static int clm_init_two_fn (struct conn_info *conn_info)
  447. {
  448. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  449. list_init (&conn_info->conn_list);
  450. return (0);
  451. }
  452. int message_handler_req_lib_clm_clustertrack (struct conn_info *conn_info, void *message)
  453. {
  454. struct req_lib_clm_clustertrack *req_lib_clm_clustertrack = (struct req_lib_clm_clustertrack *)message;
  455. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  456. int i;
  457. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  458. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKSTART;
  459. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  460. res_lib_clm_clustertrack.view = view_current;
  461. res_lib_clm_clustertrack.numberOfItems = 0;
  462. if (req_lib_clm_clustertrack->trackFlags & SA_TRACK_CURRENT) {
  463. for (i = 0; i < clusterNodeEntries; i++) {
  464. res_lib_clm_clustertrack.notification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  465. memcpy (&res_lib_clm_clustertrack.notification[i].clusterNode,
  466. &clusterNodes[i], sizeof (SaClmClusterNodeT));
  467. }
  468. res_lib_clm_clustertrack.numberOfItems = clusterNodeEntries;
  469. }
  470. /*
  471. * Record requests for cluster tracking
  472. */
  473. if (req_lib_clm_clustertrack->trackFlags & SA_TRACK_CHANGES ||
  474. req_lib_clm_clustertrack->trackFlags & SA_TRACK_CHANGES_ONLY) {
  475. conn_info->conn_info_partner->ais_ci.u.libclm_ci.trackFlags =
  476. req_lib_clm_clustertrack->trackFlags;
  477. conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled = 1;
  478. list_add (&conn_info->conn_info_partner->conn_list,
  479. &library_notification_send_listhead);
  480. }
  481. libais_send_response (conn_info, &res_lib_clm_clustertrack,
  482. sizeof (struct res_lib_clm_clustertrack));
  483. if (req_lib_clm_clustertrack->return_in_callback) {
  484. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  485. libais_send_response (conn_info->conn_info_partner,
  486. &res_lib_clm_clustertrack,
  487. sizeof (struct res_lib_clm_clustertrack));
  488. }
  489. return (0);
  490. }
  491. static int message_handler_req_lib_clm_trackstop (struct conn_info *conn_info, void *message)
  492. {
  493. struct res_lib_clm_trackstop res_lib_clm_trackstop;
  494. res_lib_clm_trackstop.header.size = sizeof (struct res_lib_clm_trackstop);
  495. res_lib_clm_trackstop.header.id = MESSAGE_RES_CLM_TRACKSTOP;
  496. if (conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled) {
  497. res_lib_clm_trackstop.header.error = SA_OK;
  498. } else {
  499. res_lib_clm_trackstop.header.error = SA_AIS_ERR_NOT_EXIST;
  500. }
  501. conn_info->conn_info_partner->ais_ci.u.libclm_ci.trackFlags = 0;
  502. conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled = 0;
  503. list_del (&conn_info->conn_info_partner->conn_list);
  504. libais_send_response (conn_info, &res_lib_clm_trackstop,
  505. sizeof (struct res_lib_clm_trackstop));
  506. return (0);
  507. }
  508. static int message_handler_req_lib_clm_nodeget (struct conn_info *conn_info, void *message)
  509. {
  510. struct req_lib_clm_nodeget *req_lib_clm_nodeget = (struct req_lib_clm_nodeget *)message;
  511. struct res_clm_nodeget res_clm_nodeget;
  512. SaClmClusterNodeT *clusterNode = 0;
  513. int valid = 0;
  514. int i;
  515. log_printf (LOG_LEVEL_NOTICE, "nodeget: trying to find node %x\n", (int)req_lib_clm_nodeget->nodeId);
  516. if (req_lib_clm_nodeget->nodeId == SA_CLM_LOCAL_NODE_ID) {
  517. clusterNode = &clusterNodes[0];
  518. valid = 1;
  519. } else
  520. for (i = 0; i < clusterNodeEntries; i++) {
  521. if (clusterNodes[i].nodeId == req_lib_clm_nodeget->nodeId) {
  522. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  523. clusterNode = &clusterNodes[i];
  524. valid = 1;
  525. break;
  526. }
  527. }
  528. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  529. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  530. res_clm_nodeget.header.error = SA_OK;
  531. res_clm_nodeget.invocation = req_lib_clm_nodeget->invocation;
  532. res_clm_nodeget.valid = valid;
  533. if (valid) {
  534. memcpy (&res_clm_nodeget.clusterNode, clusterNode, sizeof (SaClmClusterNodeT));
  535. }
  536. libais_send_response (conn_info, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  537. return (0);
  538. }
  539. static int message_handler_req_lib_clm_nodegetasync (struct conn_info *conn_info, void *message)
  540. {
  541. struct req_lib_clm_nodegetasync *req_lib_clm_nodegetasync = (struct req_lib_clm_nodegetasync *)message;
  542. struct res_clm_nodegetasync res_clm_nodegetasync;
  543. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  544. SaClmClusterNodeT *clusterNode = 0;
  545. int error = SA_AIS_ERR_INVALID_PARAM;
  546. int i;
  547. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_lib_clm_nodegetasync->nodeId);
  548. if (req_lib_clm_nodegetasync->nodeId == SA_CLM_LOCAL_NODE_ID) {
  549. clusterNode = &clusterNodes[0];
  550. error = SA_AIS_OK;
  551. } else
  552. for (i = 0; i < clusterNodeEntries; i++) {
  553. if (clusterNodes[i].nodeId == req_lib_clm_nodegetasync->nodeId) {
  554. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  555. clusterNode = &clusterNodes[i];
  556. error = SA_AIS_OK;
  557. break;
  558. }
  559. }
  560. /*
  561. * Respond to library request
  562. */
  563. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  564. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  565. res_clm_nodegetasync.header.error = SA_OK;
  566. libais_send_response (conn_info, &res_clm_nodegetasync,
  567. sizeof (struct res_clm_nodegetasync));
  568. /*
  569. * Send async response
  570. */
  571. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  572. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  573. res_clm_nodegetcallback.header.error = error;
  574. res_clm_nodegetcallback.invocation = req_lib_clm_nodegetasync->invocation;
  575. if (error == SA_AIS_OK) {
  576. memcpy (&res_clm_nodegetcallback.clusterNode, clusterNode,
  577. sizeof (SaClmClusterNodeT));
  578. }
  579. libais_send_response (conn_info->conn_info_partner, &res_clm_nodegetcallback,
  580. sizeof (struct res_clm_nodegetcallback));
  581. return (0);
  582. }