clm.c 20 KB

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