clm.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  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. };
  152. static int clm_exec_init_fn (void)
  153. {
  154. int res;
  155. res = gmi_recovery_plug_create (&clm_recovery_plug_handle);
  156. if (res != 0) {
  157. log_printf(LOG_LEVEL_ERROR,
  158. "Could not create recovery plug for clm service.\n");
  159. return (-1);
  160. }
  161. memset (clusterNodes, 0, sizeof (SaClmClusterNodeT) * NODE_MAX);
  162. /*
  163. * Build local cluster node data structure
  164. */
  165. thisClusterNode.nodeId = this_ip.sin_addr.s_addr;
  166. memcpy (&thisClusterNode.nodeAddress.value, &this_ip.sin_addr, sizeof (struct in_addr));
  167. thisClusterNode.nodeAddress.length = sizeof (struct in_addr);
  168. strcpy (thisClusterNode.nodeName.value, (char *)inet_ntoa (this_ip.sin_addr));
  169. thisClusterNode.nodeName.length = strlen (thisClusterNode.nodeName.value);
  170. strcpy (thisClusterNode.clusterName.value, "mvlcge");
  171. thisClusterNode.clusterName.length = strlen ("mvlcge");
  172. thisClusterNode.member = 1;
  173. {
  174. struct sysinfo s_info;
  175. time_t current_time;
  176. sysinfo (&s_info);
  177. current_time = time (NULL);
  178. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  179. thisClusterNode.bootTimestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000;
  180. }
  181. #ifdef DEBUG
  182. printSaClmClusterNodeT ("this cluster node", &thisClusterNode);
  183. #endif
  184. memcpy (&clusterNodes[0], &thisClusterNode, sizeof (SaClmClusterNodeT));
  185. clusterNodeEntries = 1;
  186. return (0);
  187. }
  188. static int clm_exit_fn (struct conn_info *conn_info)
  189. {
  190. /*
  191. * Delete track entry if there is one
  192. */
  193. list_del (&conn_info->conn_list);
  194. return (0);
  195. }
  196. static void libraryNotificationCurrentState (struct conn_info *conn_info)
  197. {
  198. struct res_clm_trackcallback res_clm_trackcallback;
  199. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  200. int i;
  201. if ((conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CURRENT) == 0) {
  202. return;
  203. }
  204. /*
  205. * Turn off track current
  206. */
  207. conn_info->ais_ci.u.libclm_ci.trackFlags &= ~SA_TRACK_CURRENT;
  208. /*
  209. * Build notification list
  210. */
  211. for (i = 0; i < clusterNodeEntries; i++) {
  212. clusterNotification[i].clusterChanges = SA_CLM_NODE_NO_CHANGE;
  213. memcpy (&clusterNotification[i].clusterNode, &clusterNodes[i],
  214. sizeof (SaClmClusterNodeT));
  215. }
  216. /*
  217. * Send track response
  218. */
  219. res_clm_trackcallback.header.size = sizeof (struct res_clm_trackcallback) +
  220. sizeof (SaClmClusterNotificationT) * i;
  221. res_clm_trackcallback.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  222. res_clm_trackcallback.header.error = SA_OK;
  223. res_clm_trackcallback.viewNumber = 0;
  224. res_clm_trackcallback.numberOfItems = i;
  225. res_clm_trackcallback.numberOfMembers = i;
  226. res_clm_trackcallback.notificationBufferAddress =
  227. conn_info->ais_ci.u.libclm_ci.notificationBufferAddress;
  228. libais_send_response (conn_info, &res_clm_trackcallback, sizeof (struct res_clm_trackcallback));
  229. libais_send_response (conn_info, clusterNotification, sizeof (SaClmClusterNotificationT) * i);
  230. }
  231. void library_notification_send (SaClmClusterNotificationT *cluster_notification_entries,
  232. int notify_entries)
  233. {
  234. struct res_clm_trackcallback res_clm_trackcallback;
  235. struct conn_info *conn_info;
  236. struct list_head *list;
  237. for (list = library_notification_send_listhead.next;
  238. list != &library_notification_send_listhead;
  239. list = list->next) {
  240. conn_info = list_entry (list, struct conn_info, conn_list);
  241. /*
  242. * Send notifications to all CLM listeners
  243. */
  244. if (notify_entries) {
  245. res_clm_trackcallback.header.size = sizeof (struct res_clm_trackcallback) +
  246. (notify_entries * sizeof (SaClmClusterNotificationT));
  247. res_clm_trackcallback.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  248. res_clm_trackcallback.header.error = SA_OK;
  249. res_clm_trackcallback.viewNumber = 0;
  250. res_clm_trackcallback.numberOfItems = notify_entries;
  251. res_clm_trackcallback.numberOfMembers = notify_entries;
  252. res_clm_trackcallback.notificationBufferAddress =
  253. conn_info->ais_ci.u.libclm_ci.notificationBufferAddress;
  254. libais_send_response (conn_info, &res_clm_trackcallback,
  255. sizeof (struct res_clm_trackcallback));
  256. libais_send_response (conn_info, cluster_notification_entries,
  257. sizeof (SaClmClusterNotificationT) * notify_entries);
  258. }
  259. }
  260. }
  261. static void libraryNotificationJoin (SaClmNodeIdT node)
  262. {
  263. SaClmClusterNotificationT clusterNotification;
  264. int i;
  265. /*
  266. * Generate notification element
  267. */
  268. clusterNotification.clusterChanges = SA_CLM_NODE_JOINED;
  269. for (i = 0; i < clusterNodeEntries; i++) {
  270. if (node == clusterNodes[i].nodeId) {
  271. memcpy (&clusterNotification.clusterNode, &clusterNodes[i],
  272. sizeof (SaClmClusterNodeT));
  273. }
  274. }
  275. library_notification_send (&clusterNotification, 1);
  276. }
  277. static void libraryNotificationLeave (SaClmNodeIdT *nodes, int nodes_entries)
  278. {
  279. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  280. int i, j;
  281. int notifyEntries;
  282. /*
  283. * Determine notification list
  284. */
  285. for (notifyEntries = 0, i = 0; i < clusterNodeEntries; i++) {
  286. for (j = 0; j < nodes_entries; j++) {
  287. if (clusterNodes[i].nodeId == nodes[j]) {
  288. memcpy (&clusterNotification[notifyEntries].clusterNode,
  289. &clusterNodes[i],
  290. sizeof (SaClmClusterNodeT));
  291. clusterNotification[notifyEntries].clusterChanges = SA_CLM_NODE_LEFT;
  292. notifyEntries += 1;
  293. break;
  294. }
  295. }
  296. }
  297. library_notification_send (clusterNotification, notifyEntries);
  298. /*
  299. * Remove entries from clusterNodes array
  300. */
  301. for (i = 0; i < nodes_entries; i++) {
  302. for (j = 0; j < clusterNodeEntries;) {
  303. if (nodes[i] == clusterNodes[j].nodeId) {
  304. clusterNodeEntries -= 1;
  305. memmove (&clusterNodes[j], &clusterNodes[j + 1],
  306. (clusterNodeEntries - j) * sizeof (SaClmClusterNodeT));
  307. } else {
  308. /*
  309. * next clusterNode entry
  310. */
  311. j++;
  312. }
  313. }
  314. }
  315. }
  316. static int clmNodeJoinSend (void)
  317. {
  318. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  319. struct iovec req_exec_clm_iovec;
  320. int result;
  321. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  322. req_exec_clm_nodejoin.header.id = MESSAGE_REQ_EXEC_CLM_NODEJOIN;
  323. // TODO dont use memcpy, use iovecs !!
  324. memcpy (&req_exec_clm_nodejoin.clusterNode, &thisClusterNode,
  325. sizeof (SaClmClusterNodeT));
  326. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  327. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  328. result = gmi_mcast (&aisexec_groupname, &req_exec_clm_iovec, 1, GMI_PRIO_RECOVERY);
  329. return (result);
  330. }
  331. static int clm_confchg_fn (
  332. enum gmi_configuration_type configuration_type,
  333. struct sockaddr_in *member_list, int member_list_entries,
  334. struct sockaddr_in *left_list, int left_list_entries,
  335. struct sockaddr_in *joined_list, int joined_list_entries) {
  336. int i;
  337. SaClmNodeIdT nodes[NODE_MAX];
  338. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  339. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  340. for (i = 0; i < member_list_entries; i++) {
  341. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (member_list[i].sin_addr));
  342. }
  343. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  344. for (i = 0; i < left_list_entries; i++) {
  345. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (left_list[i].sin_addr));
  346. }
  347. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  348. for (i = 0; i < joined_list_entries; i++) {
  349. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", inet_ntoa (joined_list[i].sin_addr));
  350. }
  351. /*
  352. * Send node information to other nodes
  353. */
  354. if (joined_list_entries) {
  355. assert (clmNodeJoinSend () == 0);
  356. }
  357. for (i = 0; i < left_list_entries; i++) {
  358. nodes[i] = left_list[i].sin_addr.s_addr;
  359. }
  360. libraryNotificationLeave (nodes, i);
  361. if (configuration_type == GMI_CONFIGURATION_REGULAR) {
  362. gmi_recovery_plug_unplug (clm_recovery_plug_handle);
  363. }
  364. return (0);
  365. }
  366. static int message_handler_req_exec_clm_nodejoin (void *message, struct in_addr source_addr)
  367. {
  368. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  369. int found;
  370. int i;
  371. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", req_exec_clm_nodejoin->clusterNode.nodeName.value);
  372. /*
  373. * Determine if nodejoin already received
  374. */
  375. for (found = 0, i = 0; i < clusterNodeEntries; i++) {
  376. if (memcmp (&clusterNodes[i], &req_exec_clm_nodejoin->clusterNode,
  377. sizeof (SaClmClusterNodeT)) == 0) {
  378. found = 1;
  379. }
  380. }
  381. /*
  382. * If not received, add to internal list
  383. */
  384. if (found == 0) {
  385. memcpy (&clusterNodes[clusterNodeEntries],
  386. &req_exec_clm_nodejoin->clusterNode,
  387. sizeof (SaClmClusterNodeT));
  388. clusterNodeEntries += 1;
  389. libraryNotificationJoin (req_exec_clm_nodejoin->clusterNode.nodeId);
  390. }
  391. return (0);
  392. }
  393. static int message_handler_req_clm_init (struct conn_info *conn_info, void *message)
  394. {
  395. SaErrorT error = SA_ERR_SECURITY;
  396. struct res_lib_init res_lib_init;
  397. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  398. if (conn_info->authenticated) {
  399. conn_info->service = SOCKET_SERVICE_CLM;
  400. error = SA_OK;
  401. }
  402. res_lib_init.header.size = sizeof (struct res_lib_init);
  403. res_lib_init.header.id = MESSAGE_RES_INIT;
  404. res_lib_init.header.error = error;
  405. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  406. list_init (&conn_info->conn_list);
  407. if (conn_info->authenticated) {
  408. return (0);
  409. }
  410. return (-1);
  411. }
  412. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  413. {
  414. struct res_lib_activatepoll res_lib_activatepoll;
  415. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  416. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  417. res_lib_activatepoll.header.error = SA_OK;
  418. libais_send_response (conn_info, &res_lib_activatepoll,
  419. sizeof (struct res_lib_activatepoll));
  420. return (0);
  421. }
  422. int message_handler_req_clm_trackstart (struct conn_info *conn_info, void *message)
  423. {
  424. struct req_clm_trackstart *req_clm_trackstart = (struct req_clm_trackstart *)message;
  425. conn_info->ais_ci.u.libclm_ci.trackFlags = req_clm_trackstart->trackFlags;
  426. conn_info->ais_ci.u.libclm_ci.notificationBufferAddress = req_clm_trackstart->notificationBufferAddress;
  427. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  428. libraryNotificationCurrentState (conn_info);
  429. return (0);
  430. }
  431. static int message_handler_req_clm_trackstop (struct conn_info *conn_info, void *message)
  432. {
  433. conn_info->ais_ci.u.libclm_ci.trackFlags = 0;
  434. conn_info->ais_ci.u.libclm_ci.notificationBufferAddress = 0;
  435. list_del (&conn_info->conn_list);
  436. return (0);
  437. }
  438. static int message_handler_req_clm_nodeget (struct conn_info *conn_info, void *message)
  439. {
  440. struct req_clm_nodeget *req_clm_nodeget = (struct req_clm_nodeget *)message;
  441. struct res_clm_nodeget res_clm_nodeget;
  442. SaClmClusterNodeT *clusterNode = 0;
  443. int valid = 0;
  444. int i;
  445. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_clm_nodeget->nodeId);
  446. if (req_clm_nodeget->nodeId == SA_CLM_LOCAL_NODE_ID) {
  447. clusterNode = &clusterNodes[0];
  448. valid = 1;
  449. } else
  450. for (i = 0; i < clusterNodeEntries; i++) {
  451. if (clusterNodes[i].nodeId == req_clm_nodeget->nodeId) {
  452. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  453. clusterNode = &clusterNodes[i];
  454. valid = 1;
  455. break;
  456. }
  457. }
  458. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  459. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  460. res_clm_nodeget.header.error = SA_OK;
  461. res_clm_nodeget.invocation = req_clm_nodeget->invocation;
  462. res_clm_nodeget.valid = valid;
  463. if (valid) {
  464. memcpy (&res_clm_nodeget.clusterNode, clusterNode, sizeof (SaClmClusterNodeT));
  465. }
  466. libais_send_response (conn_info, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  467. return (0);
  468. }
  469. static int message_handler_req_clm_nodegetasync (struct conn_info *conn_info, void *message)
  470. {
  471. struct req_clm_nodegetasync *req_clm_nodegetasync = (struct req_clm_nodegetasync *)message;
  472. struct res_clm_nodegetasync res_clm_nodegetasync;
  473. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  474. SaClmClusterNodeT *clusterNode = 0;
  475. int valid = 0;
  476. int i;
  477. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_clm_nodegetasync->nodeId);
  478. if (req_clm_nodegetasync->nodeId == SA_CLM_LOCAL_NODE_ID) {
  479. clusterNode = &clusterNodes[0];
  480. valid = 1;
  481. } else
  482. for (i = 0; i < clusterNodeEntries; i++) {
  483. if (clusterNodes[i].nodeId == req_clm_nodegetasync->nodeId) {
  484. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  485. clusterNode = &clusterNodes[i];
  486. valid = 1;
  487. break;
  488. }
  489. }
  490. /*
  491. * Respond to library request
  492. */
  493. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  494. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  495. res_clm_nodegetasync.header.error = SA_OK;
  496. libais_send_response (conn_info, &res_clm_nodegetasync,
  497. sizeof (struct res_clm_nodegetasync));
  498. /*
  499. * Send async response
  500. */
  501. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  502. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  503. res_clm_nodegetcallback.header.error = SA_OK;
  504. res_clm_nodegetcallback.invocation = req_clm_nodegetasync->invocation;
  505. res_clm_nodegetcallback.clusterNodeAddress = req_clm_nodegetasync->clusterNodeAddress;
  506. res_clm_nodegetcallback.valid = valid;
  507. if (valid) {
  508. memcpy (&res_clm_nodegetcallback.clusterNode, clusterNode,
  509. sizeof (SaClmClusterNodeT));
  510. }
  511. libais_send_response (conn_info, &res_clm_nodegetcallback,
  512. sizeof (struct res_clm_nodegetcallback));
  513. return (0);
  514. }