4
0

clm.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613
  1. /*
  2. * Copyright (c) 2002-2004 MontaVista Software, Inc.
  3. *
  4. * All rights reserved.
  5. *
  6. * Author: Steven Dake (sdake@mvista.com)
  7. *
  8. * This software licensed under BSD license, the text of which follows:
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. *
  13. * - Redistributions of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * - Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  19. * contributors may be used to endorse or promote products derived from this
  20. * software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  23. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  24. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  25. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  26. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  27. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  28. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  31. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  32. * THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #include <sys/types.h>
  35. #include <sys/socket.h>
  36. #include <sys/un.h>
  37. #include <sys/sysinfo.h>
  38. #include <sys/ioctl.h>
  39. #include <netinet/in.h>
  40. #include <sys/uio.h>
  41. #include <unistd.h>
  42. #include <fcntl.h>
  43. #include <stdlib.h>
  44. #include <stdio.h>
  45. #include <errno.h>
  46. #include <signal.h>
  47. #include <time.h>
  48. #include <netinet/in.h>
  49. #include <arpa/inet.h>
  50. #include "../include/ais_types.h"
  51. #include "../include/ais_msg.h"
  52. #include "../include/list.h"
  53. #include "../include/queue.h"
  54. #include "aispoll.h"
  55. #include "gmi.h"
  56. #include "parse.h"
  57. #include "main.h"
  58. #include "print.h"
  59. #include "mempool.h"
  60. #include "handlers.h"
  61. SaClmClusterChangesT thisClusterNodeLastChange = SA_CLM_NODE_JOINED;
  62. SaClmClusterNodeT thisClusterNode;
  63. #define NODE_MAX 16
  64. SaClmClusterNodeT clusterNodes[NODE_MAX];
  65. int clusterNodeEntries = 0;
  66. static DECLARE_LIST_INIT (library_notification_send_listhead);
  67. static gmi_recovery_plug_handle clm_recovery_plug_handle;
  68. SaClmClusterNodeT *clm_get_by_nodeid (struct in_addr node_id)
  69. {
  70. SaClmClusterNodeT *ret = NULL;
  71. int i;
  72. if (node_id.s_addr == SA_CLM_LOCAL_NODE_ID) {
  73. return (&clusterNodes[0]);
  74. }
  75. for (i = 0; i < clusterNodeEntries; i++) {
  76. if (clusterNodes[i].nodeId == node_id.s_addr) {
  77. ret = &clusterNodes[i];
  78. break;
  79. }
  80. }
  81. return (ret);
  82. }
  83. /*
  84. * Service Interfaces required by service_message_handler struct
  85. */
  86. static int clm_exec_init_fn (void);
  87. static int clm_confchg_fn (
  88. enum gmi_configuration_type configuration_type,
  89. struct sockaddr_in *member_list, int member_list_entries,
  90. struct sockaddr_in *left_list, int left_list_entries,
  91. struct sockaddr_in *joined_list, int joined_list_entries);
  92. static int message_handler_req_exec_clm_nodejoin (void *message, struct in_addr source_addr);
  93. static int message_handler_req_clm_init (struct conn_info *conn_info,
  94. void *message);
  95. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info,
  96. void *message);
  97. static int message_handler_req_clm_trackstart (struct conn_info *conn_info,
  98. void *message);
  99. static int message_handler_req_clm_trackstop (struct conn_info *conn_info,
  100. void *message);
  101. static int message_handler_req_clm_nodeget (struct conn_info *conn_info,
  102. void *message);
  103. static int message_handler_req_clm_nodegetasync (struct conn_info *conn_info,
  104. void *message);
  105. static int clm_exit_fn (struct conn_info *conn_info);
  106. struct libais_handler clm_libais_handlers[] =
  107. {
  108. { /* 0 */
  109. .libais_handler_fn = message_handler_req_lib_activatepoll,
  110. .response_size = sizeof (struct res_lib_activatepoll),
  111. .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL, // TODO RESPONSE
  112. .gmi_prio = GMI_PRIO_RECOVERY
  113. },
  114. { /* 1 */
  115. .libais_handler_fn = message_handler_req_clm_trackstart,
  116. .response_size = sizeof (struct res_clm_trackstart),
  117. .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE
  118. .gmi_prio = GMI_PRIO_RECOVERY
  119. },
  120. { /* 2 */
  121. .libais_handler_fn = message_handler_req_clm_trackstop,
  122. .response_size = sizeof (struct res_clm_trackstop),
  123. .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE
  124. .gmi_prio = GMI_PRIO_RECOVERY
  125. },
  126. { /* 3 */
  127. .libais_handler_fn = message_handler_req_clm_nodeget,
  128. .response_size = sizeof (struct res_clm_nodeget),
  129. .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE
  130. .gmi_prio = GMI_PRIO_RECOVERY
  131. },
  132. { /* 4 */
  133. .libais_handler_fn = message_handler_req_clm_nodegetasync,
  134. .response_size = sizeof (struct res_clm_nodegetasync),
  135. .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE
  136. .gmi_prio = GMI_PRIO_RECOVERY
  137. }
  138. };
  139. static int (*clm_aisexec_handler_fns[]) (void *, struct in_addr source_addr) = {
  140. message_handler_req_exec_clm_nodejoin
  141. };
  142. struct service_handler clm_service_handler = {
  143. .libais_handlers = clm_libais_handlers,
  144. .libais_handlers_count = sizeof (clm_libais_handlers) / sizeof (struct libais_handler),
  145. .aisexec_handler_fns = clm_aisexec_handler_fns,
  146. .aisexec_handler_fns_count = sizeof (clm_aisexec_handler_fns) / sizeof (int (*)),
  147. .confchg_fn = clm_confchg_fn,
  148. .libais_init_fn = message_handler_req_clm_init,
  149. .libais_exit_fn = clm_exit_fn,
  150. .exec_init_fn = clm_exec_init_fn,
  151. .exec_dump_fn = 0
  152. };
  153. static int clm_exec_init_fn (void)
  154. {
  155. int res;
  156. res = gmi_recovery_plug_create (&clm_recovery_plug_handle);
  157. if (res != 0) {
  158. log_printf(LOG_LEVEL_ERROR,
  159. "Could not create recovery plug for clm service.\n");
  160. return (-1);
  161. }
  162. memset (clusterNodes, 0, sizeof (SaClmClusterNodeT) * NODE_MAX);
  163. /*
  164. * Build local cluster node data structure
  165. */
  166. thisClusterNode.nodeId = this_ip.sin_addr.s_addr;
  167. memcpy (&thisClusterNode.nodeAddress.value, &this_ip.sin_addr, sizeof (struct in_addr));
  168. thisClusterNode.nodeAddress.length = sizeof (struct in_addr);
  169. strcpy (thisClusterNode.nodeName.value, (char *)inet_ntoa (this_ip.sin_addr));
  170. thisClusterNode.nodeName.length = strlen (thisClusterNode.nodeName.value);
  171. strcpy (thisClusterNode.clusterName.value, "mvlcge");
  172. thisClusterNode.clusterName.length = strlen ("mvlcge");
  173. thisClusterNode.member = 1;
  174. {
  175. struct sysinfo s_info;
  176. time_t current_time;
  177. sysinfo (&s_info);
  178. current_time = time (NULL);
  179. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  180. thisClusterNode.bootTimestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000;
  181. }
  182. #ifdef DEBUG
  183. printSaClmClusterNodeT ("this cluster node", &thisClusterNode);
  184. #endif
  185. memcpy (&clusterNodes[0], &thisClusterNode, sizeof (SaClmClusterNodeT));
  186. clusterNodeEntries = 1;
  187. return (0);
  188. }
  189. static int clm_exit_fn (struct conn_info *conn_info)
  190. {
  191. /*
  192. * Delete track entry if there is one
  193. */
  194. list_del (&conn_info->conn_list);
  195. return (0);
  196. }
  197. static void libraryNotificationCurrentState (struct conn_info *conn_info)
  198. {
  199. struct res_clm_trackcallback res_clm_trackcallback;
  200. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  201. int i;
  202. if ((conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CURRENT) == 0) {
  203. return;
  204. }
  205. /*
  206. * Turn off track current
  207. */
  208. conn_info->ais_ci.u.libclm_ci.trackFlags &= ~SA_TRACK_CURRENT;
  209. /*
  210. * Build notification list
  211. */
  212. for (i = 0; i < clusterNodeEntries; i++) {
  213. clusterNotification[i].clusterChanges = SA_CLM_NODE_NO_CHANGE;
  214. memcpy (&clusterNotification[i].clusterNode, &clusterNodes[i],
  215. sizeof (SaClmClusterNodeT));
  216. }
  217. /*
  218. * Send track response
  219. */
  220. res_clm_trackcallback.header.size = sizeof (struct res_clm_trackcallback) +
  221. sizeof (SaClmClusterNotificationT) * i;
  222. res_clm_trackcallback.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  223. res_clm_trackcallback.header.error = SA_OK;
  224. res_clm_trackcallback.viewNumber = 0;
  225. res_clm_trackcallback.numberOfItems = i;
  226. res_clm_trackcallback.numberOfMembers = i;
  227. res_clm_trackcallback.notificationBufferAddress =
  228. conn_info->ais_ci.u.libclm_ci.notificationBufferAddress;
  229. libais_send_response (conn_info, &res_clm_trackcallback, sizeof (struct res_clm_trackcallback));
  230. libais_send_response (conn_info, clusterNotification, sizeof (SaClmClusterNotificationT) * i);
  231. }
  232. void library_notification_send (SaClmClusterNotificationT *cluster_notification_entries,
  233. int notify_entries)
  234. {
  235. struct res_clm_trackcallback res_clm_trackcallback;
  236. struct conn_info *conn_info;
  237. struct list_head *list;
  238. for (list = library_notification_send_listhead.next;
  239. list != &library_notification_send_listhead;
  240. list = list->next) {
  241. conn_info = list_entry (list, struct conn_info, conn_list);
  242. /*
  243. * Send notifications to all CLM listeners
  244. */
  245. if (notify_entries) {
  246. res_clm_trackcallback.header.size = sizeof (struct res_clm_trackcallback) +
  247. (notify_entries * sizeof (SaClmClusterNotificationT));
  248. res_clm_trackcallback.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  249. res_clm_trackcallback.header.error = SA_OK;
  250. res_clm_trackcallback.viewNumber = 0;
  251. res_clm_trackcallback.numberOfItems = notify_entries;
  252. res_clm_trackcallback.numberOfMembers = notify_entries;
  253. res_clm_trackcallback.notificationBufferAddress =
  254. conn_info->ais_ci.u.libclm_ci.notificationBufferAddress;
  255. libais_send_response (conn_info, &res_clm_trackcallback,
  256. sizeof (struct res_clm_trackcallback));
  257. libais_send_response (conn_info, cluster_notification_entries,
  258. sizeof (SaClmClusterNotificationT) * notify_entries);
  259. }
  260. }
  261. }
  262. static void libraryNotificationJoin (SaClmNodeIdT node)
  263. {
  264. SaClmClusterNotificationT clusterNotification;
  265. int i;
  266. /*
  267. * Generate notification element
  268. */
  269. clusterNotification.clusterChanges = SA_CLM_NODE_JOINED;
  270. for (i = 0; i < clusterNodeEntries; i++) {
  271. if (node == clusterNodes[i].nodeId) {
  272. memcpy (&clusterNotification.clusterNode, &clusterNodes[i],
  273. sizeof (SaClmClusterNodeT));
  274. }
  275. }
  276. library_notification_send (&clusterNotification, 1);
  277. }
  278. static void libraryNotificationLeave (SaClmNodeIdT *nodes, int nodes_entries)
  279. {
  280. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  281. int i, j;
  282. int notifyEntries;
  283. /*
  284. * Determine notification list
  285. */
  286. for (notifyEntries = 0, i = 0; i < clusterNodeEntries; i++) {
  287. for (j = 0; j < nodes_entries; j++) {
  288. if (clusterNodes[i].nodeId == nodes[j]) {
  289. memcpy (&clusterNotification[notifyEntries].clusterNode,
  290. &clusterNodes[i],
  291. sizeof (SaClmClusterNodeT));
  292. clusterNotification[notifyEntries].clusterChanges = SA_CLM_NODE_LEFT;
  293. notifyEntries += 1;
  294. break;
  295. }
  296. }
  297. }
  298. library_notification_send (clusterNotification, notifyEntries);
  299. /*
  300. * Remove entries from clusterNodes array
  301. */
  302. for (i = 0; i < nodes_entries; i++) {
  303. for (j = 0; j < clusterNodeEntries;) {
  304. if (nodes[i] == clusterNodes[j].nodeId) {
  305. clusterNodeEntries -= 1;
  306. memmove (&clusterNodes[j], &clusterNodes[j + 1],
  307. (clusterNodeEntries - j) * sizeof (SaClmClusterNodeT));
  308. } else {
  309. /*
  310. * next clusterNode entry
  311. */
  312. j++;
  313. }
  314. }
  315. }
  316. }
  317. static int clmNodeJoinSend (void)
  318. {
  319. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  320. struct iovec req_exec_clm_iovec;
  321. int result;
  322. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  323. req_exec_clm_nodejoin.header.id = MESSAGE_REQ_EXEC_CLM_NODEJOIN;
  324. // TODO dont use memcpy, use iovecs !!
  325. memcpy (&req_exec_clm_nodejoin.clusterNode, &thisClusterNode,
  326. sizeof (SaClmClusterNodeT));
  327. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  328. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  329. result = gmi_mcast (&aisexec_groupname, &req_exec_clm_iovec, 1, GMI_PRIO_RECOVERY);
  330. return (result);
  331. }
  332. static int clm_confchg_fn (
  333. enum gmi_configuration_type configuration_type,
  334. struct sockaddr_in *member_list, int member_list_entries,
  335. struct sockaddr_in *left_list, int left_list_entries,
  336. struct sockaddr_in *joined_list, int joined_list_entries) {
  337. int i;
  338. SaClmNodeIdT nodes[NODE_MAX];
  339. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  340. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  341. for (i = 0; i < member_list_entries; i++) {
  342. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (member_list[i].sin_addr));
  343. }
  344. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  345. for (i = 0; i < left_list_entries; i++) {
  346. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (left_list[i].sin_addr));
  347. }
  348. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  349. for (i = 0; i < joined_list_entries; i++) {
  350. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (joined_list[i].sin_addr));
  351. }
  352. /*
  353. * Send node information to other nodes
  354. */
  355. if (joined_list_entries) {
  356. assert (clmNodeJoinSend () == 0);
  357. }
  358. for (i = 0; i < left_list_entries; i++) {
  359. nodes[i] = left_list[i].sin_addr.s_addr;
  360. }
  361. libraryNotificationLeave (nodes, i);
  362. if (configuration_type == GMI_CONFIGURATION_REGULAR) {
  363. gmi_recovery_plug_unplug (clm_recovery_plug_handle);
  364. }
  365. return (0);
  366. }
  367. static int message_handler_req_exec_clm_nodejoin (void *message, struct in_addr source_addr)
  368. {
  369. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  370. int found;
  371. int i;
  372. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", req_exec_clm_nodejoin->clusterNode.nodeName.value);
  373. /*
  374. * Determine if nodejoin already received
  375. */
  376. for (found = 0, i = 0; i < clusterNodeEntries; i++) {
  377. if (memcmp (&clusterNodes[i], &req_exec_clm_nodejoin->clusterNode,
  378. sizeof (SaClmClusterNodeT)) == 0) {
  379. found = 1;
  380. }
  381. }
  382. /*
  383. * If not received, add to internal list
  384. */
  385. if (found == 0) {
  386. memcpy (&clusterNodes[clusterNodeEntries],
  387. &req_exec_clm_nodejoin->clusterNode,
  388. sizeof (SaClmClusterNodeT));
  389. clusterNodeEntries += 1;
  390. libraryNotificationJoin (req_exec_clm_nodejoin->clusterNode.nodeId);
  391. }
  392. return (0);
  393. }
  394. static int message_handler_req_clm_init (struct conn_info *conn_info, void *message)
  395. {
  396. SaErrorT error = SA_ERR_SECURITY;
  397. struct res_lib_init res_lib_init;
  398. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  399. if (conn_info->authenticated) {
  400. conn_info->service = SOCKET_SERVICE_CLM;
  401. error = SA_OK;
  402. }
  403. res_lib_init.header.size = sizeof (struct res_lib_init);
  404. res_lib_init.header.id = MESSAGE_RES_INIT;
  405. res_lib_init.header.error = error;
  406. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  407. list_init (&conn_info->conn_list);
  408. if (conn_info->authenticated) {
  409. return (0);
  410. }
  411. return (-1);
  412. }
  413. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  414. {
  415. struct res_lib_activatepoll res_lib_activatepoll;
  416. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  417. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  418. res_lib_activatepoll.header.error = SA_OK;
  419. libais_send_response (conn_info, &res_lib_activatepoll,
  420. sizeof (struct res_lib_activatepoll));
  421. return (0);
  422. }
  423. int message_handler_req_clm_trackstart (struct conn_info *conn_info, void *message)
  424. {
  425. struct req_clm_trackstart *req_clm_trackstart = (struct req_clm_trackstart *)message;
  426. conn_info->ais_ci.u.libclm_ci.trackFlags = req_clm_trackstart->trackFlags;
  427. conn_info->ais_ci.u.libclm_ci.notificationBufferAddress = req_clm_trackstart->notificationBufferAddress;
  428. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  429. libraryNotificationCurrentState (conn_info);
  430. return (0);
  431. }
  432. static int message_handler_req_clm_trackstop (struct conn_info *conn_info, void *message)
  433. {
  434. conn_info->ais_ci.u.libclm_ci.trackFlags = 0;
  435. conn_info->ais_ci.u.libclm_ci.notificationBufferAddress = 0;
  436. list_del (&conn_info->conn_list);
  437. return (0);
  438. }
  439. static int message_handler_req_clm_nodeget (struct conn_info *conn_info, void *message)
  440. {
  441. struct req_clm_nodeget *req_clm_nodeget = (struct req_clm_nodeget *)message;
  442. struct res_clm_nodeget res_clm_nodeget;
  443. SaClmClusterNodeT *clusterNode = 0;
  444. int valid = 0;
  445. int i;
  446. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_clm_nodeget->nodeId);
  447. if (req_clm_nodeget->nodeId == SA_CLM_LOCAL_NODE_ID) {
  448. clusterNode = &clusterNodes[0];
  449. valid = 1;
  450. } else
  451. for (i = 0; i < clusterNodeEntries; i++) {
  452. if (clusterNodes[i].nodeId == req_clm_nodeget->nodeId) {
  453. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  454. clusterNode = &clusterNodes[i];
  455. valid = 1;
  456. break;
  457. }
  458. }
  459. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  460. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  461. res_clm_nodeget.header.error = SA_OK;
  462. res_clm_nodeget.invocation = req_clm_nodeget->invocation;
  463. res_clm_nodeget.valid = valid;
  464. if (valid) {
  465. memcpy (&res_clm_nodeget.clusterNode, clusterNode, sizeof (SaClmClusterNodeT));
  466. }
  467. libais_send_response (conn_info, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  468. return (0);
  469. }
  470. static int message_handler_req_clm_nodegetasync (struct conn_info *conn_info, void *message)
  471. {
  472. struct req_clm_nodegetasync *req_clm_nodegetasync = (struct req_clm_nodegetasync *)message;
  473. struct res_clm_nodegetasync res_clm_nodegetasync;
  474. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  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_nodegetasync->nodeId);
  479. if (req_clm_nodegetasync->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_nodegetasync->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. /*
  492. * Respond to library request
  493. */
  494. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  495. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  496. res_clm_nodegetasync.header.error = SA_OK;
  497. libais_send_response (conn_info, &res_clm_nodegetasync,
  498. sizeof (struct res_clm_nodegetasync));
  499. /*
  500. * Send async response
  501. */
  502. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  503. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  504. res_clm_nodegetcallback.header.error = SA_OK;
  505. res_clm_nodegetcallback.invocation = req_clm_nodegetasync->invocation;
  506. res_clm_nodegetcallback.clusterNodeAddress = req_clm_nodegetasync->clusterNodeAddress;
  507. res_clm_nodegetcallback.valid = valid;
  508. if (valid) {
  509. memcpy (&res_clm_nodegetcallback.clusterNode, clusterNode,
  510. sizeof (SaClmClusterNodeT));
  511. }
  512. libais_send_response (conn_info, &res_clm_nodegetcallback,
  513. sizeof (struct res_clm_nodegetcallback));
  514. return (0);
  515. }