clm.c 21 KB

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