clm.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. /*
  2. * Copyright (c) 2002-2005 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 <unistd.h>
  49. #include <netinet/in.h>
  50. #include <arpa/inet.h>
  51. #include "../include/ais_types.h"
  52. #include "../include/saClm.h"
  53. #include "../include/ais_msg.h"
  54. #include "../include/ipc_clm.h"
  55. #include "../include/list.h"
  56. #include "../include/queue.h"
  57. #include "aispoll.h"
  58. #include "totempg.h"
  59. #include "parse.h"
  60. #include "main.h"
  61. #include "mempool.h"
  62. #include "handlers.h"
  63. #define LOG_SERVICE LOG_SERVICE_CLM
  64. #include "print.h"
  65. SaClmClusterChangesT thisClusterNodeLastChange = SA_CLM_NODE_JOINED;
  66. SaClmClusterNodeT thisClusterNode;
  67. #define NODE_MAX 16
  68. SaClmClusterNodeT clusterNodes[NODE_MAX];
  69. int clusterNodeEntries = 0;
  70. static DECLARE_LIST_INIT (library_notification_send_listhead);
  71. static int should_send_nodejoin = 0;
  72. SaClmClusterNodeT *clm_get_by_nodeid (struct in_addr node_id)
  73. {
  74. SaClmClusterNodeT *ret = NULL;
  75. int i;
  76. if (node_id.s_addr == SA_CLM_LOCAL_NODE_ID) {
  77. return (&clusterNodes[0]);
  78. }
  79. for (i = 0; i < clusterNodeEntries; i++) {
  80. if (clusterNodes[i].nodeId == node_id.s_addr) {
  81. ret = &clusterNodes[i];
  82. break;
  83. }
  84. }
  85. return (ret);
  86. }
  87. /*
  88. * Service Interfaces required by service_message_handler struct
  89. */
  90. static int clm_exec_init_fn (void);
  91. static int clm_confchg_fn (
  92. enum totem_configuration_type configuration_type,
  93. struct in_addr *member_list, void *member_list_private,
  94. int member_list_entries,
  95. struct in_addr *left_list, void *left_list_private,
  96. int left_list_entries,
  97. struct in_addr *joined_list, void *joined_list_private,
  98. int joined_list_entries,
  99. struct memb_ring_id *ring_id);
  100. static void clm_sync_init (void);
  101. static int clm_sync_process (void);
  102. static void clm_sync_activate (void);
  103. static void clm_sync_abort (void);
  104. static int message_handler_req_exec_clm_nodejoin (void *message, struct in_addr source_addr, int endian_conversion_required);
  105. static int message_handler_req_clm_init (struct conn_info *conn_info,
  106. void *message);
  107. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info,
  108. void *message);
  109. static int message_handler_req_clm_clustertrack (struct conn_info *conn_info,
  110. void *message);
  111. static int message_handler_req_clm_trackstop (struct conn_info *conn_info,
  112. void *message);
  113. static int message_handler_req_clm_nodeget (struct conn_info *conn_info,
  114. void *message);
  115. static int message_handler_req_clm_nodegetasync (struct conn_info *conn_info,
  116. void *message);
  117. static int clm_exit_fn (struct conn_info *conn_info);
  118. struct libais_handler clm_libais_handlers[] =
  119. {
  120. { /* 0 */
  121. .libais_handler_fn = message_handler_req_lib_activatepoll,
  122. .response_size = sizeof (struct res_lib_activatepoll),
  123. .response_id = MESSAGE_RES_LIB_ACTIVATEPOLL, // TODO RESPONSE
  124. },
  125. { /* 1 */
  126. .libais_handler_fn = message_handler_req_clm_clustertrack,
  127. .response_size = sizeof (struct res_clm_clustertrack),
  128. .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE
  129. },
  130. { /* 2 */
  131. .libais_handler_fn = message_handler_req_clm_trackstop,
  132. .response_size = sizeof (struct res_clm_trackstop),
  133. .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE
  134. },
  135. { /* 3 */
  136. .libais_handler_fn = message_handler_req_clm_nodeget,
  137. .response_size = sizeof (struct res_clm_nodeget),
  138. .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE
  139. },
  140. { /* 4 */
  141. .libais_handler_fn = message_handler_req_clm_nodegetasync,
  142. .response_size = sizeof (struct res_clm_nodegetasync),
  143. .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE
  144. }
  145. };
  146. static int (*clm_aisexec_handler_fns[]) (void *, struct in_addr source_addr, int endian_conversion_required) = {
  147. message_handler_req_exec_clm_nodejoin
  148. };
  149. struct service_handler clm_service_handler = {
  150. .libais_handlers = clm_libais_handlers,
  151. .libais_handlers_count = sizeof (clm_libais_handlers) / sizeof (struct libais_handler),
  152. .aisexec_handler_fns = clm_aisexec_handler_fns,
  153. .aisexec_handler_fns_count = sizeof (clm_aisexec_handler_fns) / sizeof (int (*)),
  154. .confchg_fn = clm_confchg_fn,
  155. .libais_init_fn = message_handler_req_clm_init,
  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. static int clm_exec_init_fn (void)
  165. {
  166. memset (clusterNodes, 0, sizeof (SaClmClusterNodeT) * NODE_MAX);
  167. /*
  168. * Build local cluster node data structure
  169. */
  170. thisClusterNode.nodeId = this_ip.sin_addr.s_addr;
  171. memcpy (&thisClusterNode.nodeAddress.value, &this_ip.sin_addr,
  172. sizeof (struct in_addr));
  173. thisClusterNode.nodeAddress.length = sizeof (struct in_addr);
  174. strcpy (thisClusterNode.nodeName.value, (char *)inet_ntoa (this_ip.sin_addr));
  175. thisClusterNode.nodeName.length = strlen (thisClusterNode.nodeName.value);
  176. thisClusterNode.member = 1;
  177. {
  178. struct sysinfo s_info;
  179. time_t current_time;
  180. sysinfo (&s_info);
  181. current_time = time (NULL);
  182. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  183. thisClusterNode.bootTimestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000;
  184. }
  185. #ifdef DEBUG
  186. printSaClmClusterNodeT ("this cluster node", &thisClusterNode);
  187. #endif
  188. memcpy (&clusterNodes[0], &thisClusterNode, sizeof (SaClmClusterNodeT));
  189. clusterNodeEntries = 1;
  190. return (0);
  191. }
  192. static int clm_exit_fn (struct conn_info *conn_info)
  193. {
  194. /*
  195. * Delete track entry if there is one
  196. */
  197. list_del (&conn_info->conn_list);
  198. return (0);
  199. }
  200. static void libraryNotificationCurrentState (struct conn_info *conn_info)
  201. {
  202. struct res_clm_trackcallback res_clm_trackcallback;
  203. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  204. int i;
  205. if ((conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CURRENT) == 0) {
  206. return;
  207. }
  208. /*
  209. * Turn off track current
  210. */
  211. conn_info->ais_ci.u.libclm_ci.trackFlags &= ~SA_TRACK_CURRENT;
  212. /*
  213. * Build notification list
  214. */
  215. for (i = 0; i < clusterNodeEntries; i++) {
  216. clusterNotification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  217. memcpy (&clusterNotification[i].clusterNode, &clusterNodes[i],
  218. sizeof (SaClmClusterNodeT));
  219. }
  220. /*
  221. * Send track response
  222. */
  223. res_clm_trackcallback.header.size = sizeof (struct res_clm_trackcallback) +
  224. sizeof (SaClmClusterNotificationT) * i;
  225. res_clm_trackcallback.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  226. res_clm_trackcallback.header.error = SA_OK;
  227. res_clm_trackcallback.viewNumber = 0;
  228. res_clm_trackcallback.numberOfItems = i;
  229. res_clm_trackcallback.numberOfMembers = i;
  230. libais_send_response (conn_info, &res_clm_trackcallback, sizeof (struct res_clm_trackcallback));
  231. libais_send_response (conn_info, clusterNotification, sizeof (SaClmClusterNotificationT) * i);
  232. }
  233. void library_notification_send (SaClmClusterNotificationT *cluster_notification_entries,
  234. int notify_entries)
  235. {
  236. struct res_clm_trackcallback res_clm_trackcallback;
  237. struct conn_info *conn_info;
  238. struct list_head *list;
  239. for (list = library_notification_send_listhead.next;
  240. list != &library_notification_send_listhead;
  241. list = list->next) {
  242. conn_info = list_entry (list, struct conn_info, conn_list);
  243. /*
  244. * Send notifications to all CLM listeners
  245. */
  246. if (notify_entries) {
  247. res_clm_trackcallback.header.size = sizeof (struct res_clm_trackcallback) +
  248. (notify_entries * sizeof (SaClmClusterNotificationT));
  249. res_clm_trackcallback.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  250. res_clm_trackcallback.header.error = SA_OK;
  251. res_clm_trackcallback.viewNumber = 0;
  252. res_clm_trackcallback.numberOfItems = notify_entries;
  253. res_clm_trackcallback.numberOfMembers = notify_entries;
  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.clusterChange = SA_CLM_NODE_JOINED;
  269. clusterNotification.clusterNode.member = 1;
  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].clusterChange = SA_CLM_NODE_LEFT;
  293. clusterNotification[notifyEntries].clusterNode.member = 0;
  294. notifyEntries += 1;
  295. break;
  296. }
  297. }
  298. }
  299. library_notification_send (clusterNotification, notifyEntries);
  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. }
  318. static int clm_nodejoin_send (void)
  319. {
  320. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  321. struct iovec req_exec_clm_iovec;
  322. int result;
  323. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  324. req_exec_clm_nodejoin.header.id = MESSAGE_REQ_EXEC_CLM_NODEJOIN;
  325. // TODO dont use memcpy, use iovecs !!
  326. memcpy (&req_exec_clm_nodejoin.clusterNode, &thisClusterNode,
  327. sizeof (SaClmClusterNodeT));
  328. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  329. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  330. result = totempg_mcast (&req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  331. return (result);
  332. }
  333. static int clm_confchg_fn (
  334. enum totem_configuration_type configuration_type,
  335. struct in_addr *member_list, void *member_list_private,
  336. int member_list_entries,
  337. struct in_addr *left_list, void *left_list_private,
  338. int left_list_entries,
  339. struct in_addr *joined_list, void *joined_list_private,
  340. 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. if (joined_list_entries > 0) {
  359. should_send_nodejoin = 1;
  360. }
  361. for (i = 0; i < left_list_entries; i++) {
  362. nodes[i] = left_list[i].s_addr;
  363. }
  364. libraryNotificationLeave (nodes, i);
  365. return (0);
  366. }
  367. /*
  368. * This is a noop for this service
  369. */
  370. static void clm_sync_init (void)
  371. {
  372. return;
  373. }
  374. /*
  375. * If a processor joined in the configuration change and clm_sync_activate hasn't
  376. * yet been called, issue a node join to share CLM specific data about the processor
  377. */
  378. static int clm_sync_process (void)
  379. {
  380. /*
  381. * Send node information to other nodes
  382. */
  383. if (should_send_nodejoin) {
  384. return (clm_nodejoin_send ());
  385. }
  386. return (0);
  387. }
  388. /*
  389. * This is a noop for this service
  390. */
  391. static void clm_sync_activate (void)
  392. {
  393. should_send_nodejoin = 0;
  394. return;
  395. }
  396. /*
  397. * This is a noop for this service
  398. */
  399. static void clm_sync_abort (void)
  400. {
  401. return;
  402. }
  403. static void exec_clm_nodejoin_endian_conversion (struct req_exec_clm_nodejoin *in,
  404. struct req_exec_clm_nodejoin *out)
  405. {
  406. // TODO this isn't complete yet
  407. // TODO SaNameT needs to be packed and aligned
  408. memmove (&out->clusterNode.nodeName.value[0],
  409. &in->clusterNode.nodeName.value[2],
  410. SA_MAX_NAME_LENGTH);
  411. }
  412. static int message_handler_req_exec_clm_nodejoin (void *message, struct in_addr source_addr, int endian_conversion_required)
  413. {
  414. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  415. struct req_exec_clm_nodejoin req_exec_clm_nodejoin_storage;
  416. int found;
  417. int i;
  418. if (endian_conversion_required) {
  419. exec_clm_nodejoin_endian_conversion (message, &req_exec_clm_nodejoin_storage);
  420. req_exec_clm_nodejoin = &req_exec_clm_nodejoin_storage;
  421. } else {
  422. req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  423. }
  424. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", req_exec_clm_nodejoin->clusterNode.nodeName.value);
  425. /*
  426. * Determine if nodejoin already received
  427. */
  428. for (found = 0, i = 0; i < clusterNodeEntries; i++) {
  429. if (memcmp (&clusterNodes[i], &req_exec_clm_nodejoin->clusterNode,
  430. sizeof (SaClmClusterNodeT)) == 0) {
  431. found = 1;
  432. }
  433. }
  434. /*
  435. * If not received, add to internal list
  436. */
  437. if (found == 0) {
  438. memcpy (&clusterNodes[clusterNodeEntries],
  439. &req_exec_clm_nodejoin->clusterNode,
  440. sizeof (SaClmClusterNodeT));
  441. clusterNodeEntries += 1;
  442. libraryNotificationJoin (req_exec_clm_nodejoin->clusterNode.nodeId);
  443. }
  444. return (0);
  445. }
  446. static int message_handler_req_clm_init (struct conn_info *conn_info, void *message)
  447. {
  448. SaErrorT error = SA_ERR_SECURITY;
  449. struct res_lib_init res_lib_init;
  450. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  451. if (conn_info->authenticated) {
  452. conn_info->service = SOCKET_SERVICE_CLM;
  453. error = SA_OK;
  454. }
  455. res_lib_init.header.size = sizeof (struct res_lib_init);
  456. res_lib_init.header.id = MESSAGE_RES_INIT;
  457. res_lib_init.header.error = error;
  458. libais_send_response (conn_info, &res_lib_init, sizeof (res_lib_init));
  459. list_init (&conn_info->conn_list);
  460. if (conn_info->authenticated) {
  461. return (0);
  462. }
  463. return (-1);
  464. }
  465. static int message_handler_req_lib_activatepoll (struct conn_info *conn_info, void *message)
  466. {
  467. struct res_lib_activatepoll res_lib_activatepoll;
  468. res_lib_activatepoll.header.size = sizeof (struct res_lib_activatepoll);
  469. res_lib_activatepoll.header.id = MESSAGE_RES_LIB_ACTIVATEPOLL;
  470. res_lib_activatepoll.header.error = SA_OK;
  471. libais_send_response (conn_info, &res_lib_activatepoll,
  472. sizeof (struct res_lib_activatepoll));
  473. return (0);
  474. }
  475. int message_handler_req_clm_clustertrack (struct conn_info *conn_info, void *message)
  476. {
  477. struct req_clm_clustertrack *req_clm_clustertrack = (struct req_clm_clustertrack *)message;
  478. conn_info->ais_ci.u.libclm_ci.trackFlags = req_clm_clustertrack->trackFlags;
  479. list_add (&conn_info->conn_list, &library_notification_send_listhead);
  480. libraryNotificationCurrentState (conn_info);
  481. return (0);
  482. }
  483. static int message_handler_req_clm_trackstop (struct conn_info *conn_info, void *message)
  484. {
  485. conn_info->ais_ci.u.libclm_ci.trackFlags = 0;
  486. list_del (&conn_info->conn_list);
  487. return (0);
  488. }
  489. static int message_handler_req_clm_nodeget (struct conn_info *conn_info, void *message)
  490. {
  491. struct req_clm_nodeget *req_clm_nodeget = (struct req_clm_nodeget *)message;
  492. struct res_clm_nodeget res_clm_nodeget;
  493. SaClmClusterNodeT *clusterNode = 0;
  494. int valid = 0;
  495. int i;
  496. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_clm_nodeget->nodeId);
  497. if (req_clm_nodeget->nodeId == SA_CLM_LOCAL_NODE_ID) {
  498. clusterNode = &clusterNodes[0];
  499. valid = 1;
  500. } else
  501. for (i = 0; i < clusterNodeEntries; i++) {
  502. if (clusterNodes[i].nodeId == req_clm_nodeget->nodeId) {
  503. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  504. clusterNode = &clusterNodes[i];
  505. valid = 1;
  506. break;
  507. }
  508. }
  509. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  510. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  511. res_clm_nodeget.header.error = SA_OK;
  512. res_clm_nodeget.invocation = req_clm_nodeget->invocation;
  513. res_clm_nodeget.valid = valid;
  514. if (valid) {
  515. memcpy (&res_clm_nodeget.clusterNode, clusterNode, sizeof (SaClmClusterNodeT));
  516. }
  517. libais_send_response (conn_info, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  518. return (0);
  519. }
  520. static int message_handler_req_clm_nodegetasync (struct conn_info *conn_info, void *message)
  521. {
  522. struct req_clm_nodegetasync *req_clm_nodegetasync = (struct req_clm_nodegetasync *)message;
  523. struct res_clm_nodegetasync res_clm_nodegetasync;
  524. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  525. SaClmClusterNodeT *clusterNode = 0;
  526. int error = SA_AIS_ERR_INVALID_PARAM;
  527. int i;
  528. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_clm_nodegetasync->nodeId);
  529. if (req_clm_nodegetasync->nodeId == SA_CLM_LOCAL_NODE_ID) {
  530. clusterNode = &clusterNodes[0];
  531. error = SA_AIS_OK;
  532. } else
  533. for (i = 0; i < clusterNodeEntries; i++) {
  534. if (clusterNodes[i].nodeId == req_clm_nodegetasync->nodeId) {
  535. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  536. clusterNode = &clusterNodes[i];
  537. error = SA_AIS_OK;
  538. break;
  539. }
  540. }
  541. /*
  542. * Respond to library request
  543. */
  544. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  545. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  546. res_clm_nodegetasync.header.error = SA_OK;
  547. libais_send_response (conn_info, &res_clm_nodegetasync,
  548. sizeof (struct res_clm_nodegetasync));
  549. /*
  550. * Send async response
  551. */
  552. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  553. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  554. res_clm_nodegetcallback.header.error = error;
  555. res_clm_nodegetcallback.invocation = req_clm_nodegetasync->invocation;
  556. if (error == SA_AIS_OK) {
  557. memcpy (&res_clm_nodegetcallback.clusterNode, clusterNode,
  558. sizeof (SaClmClusterNodeT));
  559. }
  560. libais_send_response (conn_info, &res_clm_nodegetcallback,
  561. sizeof (struct res_clm_nodegetcallback));
  562. return (0);
  563. }