clm.c 19 KB

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