clm.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. * vi: set autoindent tabstop=4 shiftwidth=4 :
  3. *
  4. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@mvista.com)
  9. *
  10. * This software licensed under BSD license, the text of which follows:
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * - Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * - Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * - Neither the name of the MontaVista Software, Inc. nor the names of its
  21. * contributors may be used to endorse or promote products derived from this
  22. * software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  25. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  26. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  27. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  28. * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  30. * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  31. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  32. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  33. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  34. * THE POSSIBILITY OF SUCH DAMAGE.
  35. */
  36. #include <sys/types.h>
  37. #include <sys/socket.h>
  38. #include <sys/un.h>
  39. #include <sys/sysinfo.h>
  40. #include <sys/ioctl.h>
  41. #include <netinet/in.h>
  42. #include <sys/uio.h>
  43. #include <unistd.h>
  44. #include <fcntl.h>
  45. #include <stdlib.h>
  46. #include <stdio.h>
  47. #include <errno.h>
  48. #include <signal.h>
  49. #include <time.h>
  50. #include <unistd.h>
  51. #include <netinet/in.h>
  52. #include <arpa/inet.h>
  53. #include "../include/saAis.h"
  54. #include "../include/saClm.h"
  55. #include "../include/ipc_gen.h"
  56. #include "../include/ipc_clm.h"
  57. #include "../include/list.h"
  58. #include "../include/queue.h"
  59. #include "../lcr/lcr_comp.h"
  60. #include "aispoll.h"
  61. #include "totempg.h"
  62. #include "main.h"
  63. #include "mempool.h"
  64. #include "handlers.h"
  65. #define LOG_SERVICE LOG_SERVICE_CLM
  66. #include "print.h"
  67. enum clm_message_req_types {
  68. MESSAGE_REQ_EXEC_CLM_NODEJOIN = 0
  69. };
  70. SaClmClusterChangesT thisClusterNodeLastChange = SA_CLM_NODE_JOINED;
  71. SaClmClusterNodeT thisClusterNode;
  72. #define NODE_MAX 16
  73. static SaClmClusterNodeT clusterNodes[NODE_MAX];
  74. static int clusterNodeEntries = 0;
  75. static unsigned long long view_current = 0;
  76. static unsigned long long view_initial = 0;
  77. static DECLARE_LIST_INIT (library_notification_send_listhead);
  78. SaClmClusterNodeT *clm_get_by_nodeid (unsigned int node_id)
  79. {
  80. SaClmClusterNodeT *ret = NULL;
  81. int i;
  82. if (node_id == SA_CLM_LOCAL_NODE_ID) {
  83. return (&clusterNodes[0]);
  84. }
  85. for (i = 0; i < clusterNodeEntries; i++) {
  86. if (clusterNodes[i].nodeId == node_id) {
  87. ret = &clusterNodes[i];
  88. break;
  89. }
  90. }
  91. return (ret);
  92. }
  93. /*
  94. * Service Interfaces required by service_message_handler struct
  95. */
  96. static void clm_confchg_fn (
  97. enum totem_configuration_type configuration_type,
  98. struct totem_ip_address *member_list, int member_list_entries,
  99. struct totem_ip_address *left_list, int left_list_entries,
  100. struct totem_ip_address *joined_list, int joined_list_entries,
  101. struct memb_ring_id *ring_id);
  102. static void clm_sync_init (void);
  103. static int clm_sync_process (void);
  104. static void clm_sync_activate (void);
  105. static void clm_sync_abort (void);
  106. static int clm_exec_init_fn (struct openais_config *);
  107. static int clm_lib_init_fn (struct conn_info *conn_info);
  108. static int clm_lib_exit_fn (struct conn_info *conn_info);
  109. static void message_handler_req_exec_clm_nodejoin (
  110. void *message,
  111. struct totem_ip_address *source_addr);
  112. static void exec_clm_nodejoin_endian_convert (void *msg);
  113. static void message_handler_req_lib_clm_clustertrack (struct conn_info *conn_info,
  114. void *message);
  115. static void message_handler_req_lib_clm_trackstop (struct conn_info *conn_info,
  116. void *message);
  117. static void message_handler_req_lib_clm_nodeget (struct conn_info *conn_info,
  118. void *message);
  119. static void message_handler_req_lib_clm_nodegetasync (struct conn_info *conn_info,
  120. void *message);
  121. /*
  122. * Executive Handler Definition
  123. */
  124. static struct openais_lib_handler clm_lib_handlers[] =
  125. {
  126. { /* 0 */
  127. .lib_handler_fn = message_handler_req_lib_clm_clustertrack,
  128. .response_size = sizeof (struct res_lib_clm_clustertrack),
  129. .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE
  130. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  131. },
  132. { /* 1 */
  133. .lib_handler_fn = message_handler_req_lib_clm_trackstop,
  134. .response_size = sizeof (struct res_lib_clm_trackstop),
  135. .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE
  136. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  137. },
  138. { /* 2 */
  139. .lib_handler_fn = message_handler_req_lib_clm_nodeget,
  140. .response_size = sizeof (struct res_clm_nodeget),
  141. .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE
  142. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  143. },
  144. { /* 3 */
  145. .lib_handler_fn = message_handler_req_lib_clm_nodegetasync,
  146. .response_size = sizeof (struct res_clm_nodegetasync),
  147. .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE
  148. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  149. }
  150. };
  151. static struct openais_exec_handler clm_exec_handlers[] =
  152. {
  153. {
  154. .exec_handler_fn = message_handler_req_exec_clm_nodejoin,
  155. .exec_endian_convert_fn = exec_clm_nodejoin_endian_convert
  156. }
  157. };
  158. struct openais_service_handler clm_service_handler = {
  159. .name = (unsigned char*)"openais cluster membership service B.01.01",
  160. .id = CLM_SERVICE,
  161. .lib_init_fn = clm_lib_init_fn,
  162. .lib_exit_fn = clm_lib_exit_fn,
  163. .lib_handlers = clm_lib_handlers,
  164. .lib_handlers_count = sizeof (clm_lib_handlers) / sizeof (struct openais_lib_handler),
  165. .exec_init_fn = clm_exec_init_fn,
  166. .exec_dump_fn = NULL,
  167. .exec_handlers = clm_exec_handlers,
  168. .exec_handlers_count = sizeof (clm_exec_handlers) / sizeof (struct openais_exec_handler),
  169. .confchg_fn = clm_confchg_fn,
  170. .sync_init = clm_sync_init,
  171. .sync_process = clm_sync_process,
  172. .sync_activate = clm_sync_activate,
  173. .sync_abort = clm_sync_abort,
  174. };
  175. /*
  176. * Dynamic loader definition
  177. */
  178. #ifdef BUILD_DYNAMIC
  179. struct openais_service_handler *clm_get_service_handler_ver0 (void);
  180. struct openais_service_handler_iface_ver0 clm_service_handler_iface = {
  181. .openais_get_service_handler_ver0 = clm_get_service_handler_ver0
  182. };
  183. struct lcr_iface openais_clm_ver0[1] = {
  184. {
  185. .name = "openais_clm",
  186. .version = 0,
  187. .versions_replace = 0,
  188. .versions_replace_count = 0,
  189. .dependencies = 0,
  190. .dependency_count = 0,
  191. .constructor = NULL,
  192. .destructor = NULL,
  193. .interfaces = (void **)&clm_service_handler_iface,
  194. }
  195. };
  196. struct lcr_comp clm_comp_ver0 = {
  197. .iface_count = 1,
  198. .ifaces = openais_clm_ver0
  199. };
  200. int lcr_comp_get (struct lcr_comp **component)
  201. {
  202. *component = &clm_comp_ver0;
  203. return (0);
  204. }
  205. struct openais_service_handler *clm_get_service_handler_ver0 (void)
  206. {
  207. return (&clm_service_handler);
  208. }
  209. #endif /* BUILD_DYNAMIC */
  210. struct req_exec_clm_nodejoin {
  211. struct req_header header;
  212. SaClmClusterNodeT clusterNode;
  213. };
  214. static int clm_exec_init_fn (struct openais_config *openais_config)
  215. {
  216. memset (clusterNodes, 0, sizeof (SaClmClusterNodeT) * NODE_MAX);
  217. /*
  218. * Build local cluster node data structure
  219. */
  220. sprintf ((char *)thisClusterNode.nodeAddress.value, "%s", totemip_print (this_ip));
  221. thisClusterNode.nodeAddress.length = strlen ((char *)thisClusterNode.nodeAddress.value);
  222. if (this_ip->family == AF_INET) {
  223. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET;
  224. } else
  225. if (this_ip->family == AF_INET6) {
  226. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET6;
  227. } else {
  228. assert (0);
  229. }
  230. strcpy ((char *)thisClusterNode.nodeName.value, (char *)thisClusterNode.nodeAddress.value);
  231. thisClusterNode.nodeName.length = thisClusterNode.nodeAddress.length;
  232. thisClusterNode.nodeId = this_ip->nodeid;
  233. printf ("setting B to %x\n", this_ip->nodeid);
  234. thisClusterNode.member = 1;
  235. {
  236. struct sysinfo s_info;
  237. time_t current_time;
  238. sysinfo (&s_info);
  239. current_time = time (NULL);
  240. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  241. thisClusterNode.bootTimestamp = ((SaTimeT)(current_time - s_info.uptime)) * 1000000000;
  242. }
  243. #ifdef DEBUG
  244. printSaClmClusterNodeT ("this cluster node", &thisClusterNode);
  245. #endif
  246. memcpy (&clusterNodes[0], &thisClusterNode, sizeof (SaClmClusterNodeT));
  247. clusterNodeEntries = 1;
  248. main_clm_get_by_nodeid = clm_get_by_nodeid;
  249. return (0);
  250. }
  251. static int clm_lib_exit_fn (struct conn_info *conn_info)
  252. {
  253. /*
  254. * Delete track entry if there is one
  255. */
  256. list_del (&conn_info->conn_list);
  257. return (0);
  258. }
  259. static void library_notification_send (SaClmClusterNotificationT *cluster_notification_entries,
  260. int notify_entries)
  261. {
  262. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  263. struct conn_info *conn_info;
  264. struct list_head *list;
  265. int i;
  266. if (notify_entries == 0) {
  267. return;
  268. }
  269. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  270. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  271. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  272. res_lib_clm_clustertrack.view = view_current;
  273. for (list = library_notification_send_listhead.next;
  274. list != &library_notification_send_listhead;
  275. list = list->next) {
  276. conn_info = list_entry (list, struct conn_info, conn_list);
  277. /*
  278. * Track current and changes
  279. */
  280. if (conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CHANGES) {
  281. /*
  282. * Copy all cluster nodes
  283. */
  284. for (i = 0; i < clusterNodeEntries; i++) {
  285. memcpy (&res_lib_clm_clustertrack.notification[i].clusterNode,
  286. &clusterNodes[i], sizeof (SaClmClusterNodeT));
  287. res_lib_clm_clustertrack.notification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  288. res_lib_clm_clustertrack.notification[i].clusterNode.member = 1;
  289. }
  290. /*
  291. * Copy change_only notificaiton
  292. */
  293. res_lib_clm_clustertrack.numberOfItems = notify_entries + i;
  294. memcpy (&res_lib_clm_clustertrack.notification[i],
  295. cluster_notification_entries,
  296. sizeof (SaClmClusterNotificationT) * notify_entries);
  297. } else
  298. /*
  299. * Track only changes
  300. */
  301. if (conn_info->ais_ci.u.libclm_ci.trackFlags & SA_TRACK_CHANGES_ONLY) {
  302. res_lib_clm_clustertrack.numberOfItems = notify_entries;
  303. memcpy (&res_lib_clm_clustertrack.notification,
  304. cluster_notification_entries,
  305. sizeof (SaClmClusterNotificationT) * notify_entries);
  306. }
  307. /*
  308. * Send notifications to all CLM listeners
  309. */
  310. libais_send_response (conn_info, &res_lib_clm_clustertrack,
  311. sizeof (struct res_lib_clm_clustertrack));
  312. }
  313. }
  314. static void notification_join (SaClmClusterNodeT *cluster_node)
  315. {
  316. SaClmClusterNotificationT notification;
  317. /*
  318. * Generate notification element
  319. */
  320. notification.clusterChange = SA_CLM_NODE_JOINED;
  321. notification.clusterNode.member = 1;
  322. memcpy (&notification.clusterNode, cluster_node,
  323. sizeof (SaClmClusterNodeT));
  324. library_notification_send (&notification, 1);
  325. }
  326. static void libraryNotificationLeave (SaClmNodeIdT *nodes, int nodes_entries)
  327. {
  328. SaClmClusterNotificationT clusterNotification[NODE_MAX];
  329. int i, j;
  330. int notifyEntries;
  331. /*
  332. * Determine notification list
  333. */
  334. for (notifyEntries = 0, i = 0; i < clusterNodeEntries; i++) {
  335. for (j = 0; j < nodes_entries; j++) {
  336. if (clusterNodes[i].nodeId == nodes[j]) {
  337. memcpy (&clusterNotification[notifyEntries].clusterNode,
  338. &clusterNodes[i],
  339. sizeof (SaClmClusterNodeT));
  340. clusterNotification[notifyEntries].clusterChange = SA_CLM_NODE_LEFT;
  341. clusterNotification[notifyEntries].clusterNode.member = 0;
  342. notifyEntries += 1;
  343. break;
  344. }
  345. }
  346. }
  347. /*
  348. * Remove entries from clusterNodes array
  349. */
  350. for (i = 0; i < nodes_entries; i++) {
  351. for (j = 0; j < clusterNodeEntries;) {
  352. if (nodes[i] == clusterNodes[j].nodeId) {
  353. clusterNodeEntries -= 1;
  354. memmove (&clusterNodes[j], &clusterNodes[j + 1],
  355. (clusterNodeEntries - j) * sizeof (SaClmClusterNodeT));
  356. } else {
  357. /*
  358. * next clusterNode entry
  359. */
  360. j++;
  361. }
  362. }
  363. }
  364. library_notification_send (clusterNotification, notifyEntries);
  365. }
  366. static int clm_nodejoin_send (void)
  367. {
  368. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  369. struct iovec req_exec_clm_iovec;
  370. int result;
  371. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  372. req_exec_clm_nodejoin.header.id =
  373. SERVICE_ID_MAKE (CLM_SERVICE, MESSAGE_REQ_EXEC_CLM_NODEJOIN);
  374. // TODO dont use memcpy, use iovecs !!
  375. thisClusterNode.initialViewNumber = view_initial;
  376. memcpy (&req_exec_clm_nodejoin.clusterNode, &thisClusterNode,
  377. sizeof (SaClmClusterNodeT));
  378. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  379. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  380. result = totempg_groups_mcast_joined (openais_group_handle, &req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  381. return (result);
  382. }
  383. static void clm_confchg_fn (
  384. enum totem_configuration_type configuration_type,
  385. struct totem_ip_address *member_list, int member_list_entries,
  386. struct totem_ip_address *left_list, int left_list_entries,
  387. struct totem_ip_address *joined_list, int joined_list_entries,
  388. struct memb_ring_id *ring_id)
  389. {
  390. int i;
  391. SaClmNodeIdT nodes[NODE_MAX];
  392. view_current = ring_id->seq / 4;
  393. if (view_initial == 0) {
  394. view_initial = ring_id->seq / 4;
  395. }
  396. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  397. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  398. for (i = 0; i < member_list_entries; i++) {
  399. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&member_list[i]));
  400. }
  401. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  402. for (i = 0; i < left_list_entries; i++) {
  403. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&left_list[i]));
  404. }
  405. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  406. for (i = 0; i < joined_list_entries; i++) {
  407. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totemip_print (&joined_list[i]));
  408. }
  409. for (i = 0; i < left_list_entries; i++) {
  410. nodes[i] = left_list[i].nodeid;
  411. }
  412. libraryNotificationLeave (nodes, i);
  413. /*
  414. * Load the thisClusterNode data structure in case we are
  415. * transitioning to network interface up or down
  416. */
  417. sprintf ((char *)thisClusterNode.nodeAddress.value, "%s", totemip_print (this_ip));
  418. thisClusterNode.nodeAddress.length = strlen ((char *)thisClusterNode.nodeAddress.value);
  419. if (this_ip->family == AF_INET) {
  420. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET;
  421. } else
  422. if (this_ip->family == AF_INET6) {
  423. thisClusterNode.nodeAddress.family = SA_CLM_AF_INET6;
  424. } else {
  425. assert (0);
  426. }
  427. strcpy ((char *)thisClusterNode.nodeName.value,
  428. (char *)thisClusterNode.nodeAddress.value);
  429. thisClusterNode.nodeName.length = thisClusterNode.nodeAddress.length;
  430. thisClusterNode.nodeId = this_ip->nodeid;
  431. }
  432. /*
  433. * This is a noop for this service
  434. */
  435. static void clm_sync_init (void)
  436. {
  437. return;
  438. }
  439. /*
  440. * If a processor joined in the configuration change and clm_sync_activate hasn't
  441. * yet been called, issue a node join to share CLM specific data about the processor
  442. */
  443. static int clm_sync_process (void)
  444. {
  445. /*
  446. * Send node information to other nodes
  447. */
  448. return (clm_nodejoin_send ());
  449. }
  450. /*
  451. * This is a noop for this service
  452. */
  453. static void clm_sync_activate (void)
  454. {
  455. return;
  456. }
  457. /*
  458. * This is a noop for this service
  459. */
  460. static void clm_sync_abort (void)
  461. {
  462. return;
  463. }
  464. static void exec_clm_nodejoin_endian_convert (void *msg)
  465. {
  466. }
  467. static void message_handler_req_exec_clm_nodejoin (
  468. void *message,
  469. struct totem_ip_address *source_addr)
  470. {
  471. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  472. int found = 0;
  473. int i;
  474. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n", req_exec_clm_nodejoin->clusterNode.nodeName.value);
  475. /*
  476. * Determine if nodejoin already received
  477. */
  478. for (found = 0, i = 0; i < clusterNodeEntries; i++) {
  479. if (clusterNodes[i].nodeId == req_exec_clm_nodejoin->clusterNode.nodeId) {
  480. found = 1;
  481. }
  482. }
  483. /*
  484. * If not received, add to internal list
  485. */
  486. if (found == 0) {
  487. notification_join (&req_exec_clm_nodejoin->clusterNode);
  488. memcpy (&clusterNodes[clusterNodeEntries],
  489. &req_exec_clm_nodejoin->clusterNode,
  490. sizeof (SaClmClusterNodeT));
  491. clusterNodeEntries += 1;
  492. }
  493. }
  494. static int clm_lib_init_fn (struct conn_info *conn_info)
  495. {
  496. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  497. list_init (&conn_info->conn_list);
  498. return (0);
  499. }
  500. static void message_handler_req_lib_clm_clustertrack (struct conn_info *conn_info, void *message)
  501. {
  502. struct req_lib_clm_clustertrack *req_lib_clm_clustertrack = (struct req_lib_clm_clustertrack *)message;
  503. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  504. int i;
  505. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  506. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKSTART;
  507. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  508. res_lib_clm_clustertrack.view = view_current;
  509. res_lib_clm_clustertrack.numberOfItems = 0;
  510. if (req_lib_clm_clustertrack->trackFlags & SA_TRACK_CURRENT) {
  511. for (i = 0; i < clusterNodeEntries; i++) {
  512. res_lib_clm_clustertrack.notification[i].clusterChange = SA_CLM_NODE_NO_CHANGE;
  513. memcpy (&res_lib_clm_clustertrack.notification[i].clusterNode,
  514. &clusterNodes[i], sizeof (SaClmClusterNodeT));
  515. }
  516. res_lib_clm_clustertrack.numberOfItems = clusterNodeEntries;
  517. }
  518. /*
  519. * Record requests for cluster tracking
  520. */
  521. if (req_lib_clm_clustertrack->trackFlags & SA_TRACK_CHANGES ||
  522. req_lib_clm_clustertrack->trackFlags & SA_TRACK_CHANGES_ONLY) {
  523. conn_info->conn_info_partner->ais_ci.u.libclm_ci.trackFlags =
  524. req_lib_clm_clustertrack->trackFlags;
  525. conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled = 1;
  526. list_add (&conn_info->conn_info_partner->conn_list,
  527. &library_notification_send_listhead);
  528. }
  529. libais_send_response (conn_info, &res_lib_clm_clustertrack,
  530. sizeof (struct res_lib_clm_clustertrack));
  531. if (req_lib_clm_clustertrack->return_in_callback) {
  532. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  533. libais_send_response (conn_info->conn_info_partner,
  534. &res_lib_clm_clustertrack,
  535. sizeof (struct res_lib_clm_clustertrack));
  536. }
  537. }
  538. static void message_handler_req_lib_clm_trackstop (struct conn_info *conn_info, void *message)
  539. {
  540. struct res_lib_clm_trackstop res_lib_clm_trackstop;
  541. res_lib_clm_trackstop.header.size = sizeof (struct res_lib_clm_trackstop);
  542. res_lib_clm_trackstop.header.id = MESSAGE_RES_CLM_TRACKSTOP;
  543. if (conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled) {
  544. res_lib_clm_trackstop.header.error = SA_AIS_OK;
  545. } else {
  546. res_lib_clm_trackstop.header.error = SA_AIS_ERR_NOT_EXIST;
  547. }
  548. conn_info->conn_info_partner->ais_ci.u.libclm_ci.trackFlags = 0;
  549. conn_info->conn_info_partner->ais_ci.u.libclm_ci.tracking_enabled = 0;
  550. list_del (&conn_info->conn_info_partner->conn_list);
  551. libais_send_response (conn_info, &res_lib_clm_trackstop,
  552. sizeof (struct res_lib_clm_trackstop));
  553. }
  554. static void message_handler_req_lib_clm_nodeget (struct conn_info *conn_info, void *message)
  555. {
  556. struct req_lib_clm_nodeget *req_lib_clm_nodeget = (struct req_lib_clm_nodeget *)message;
  557. struct res_clm_nodeget res_clm_nodeget;
  558. SaClmClusterNodeT *clusterNode = 0;
  559. int valid = 0;
  560. int i;
  561. log_printf (LOG_LEVEL_NOTICE, "nodeget: trying to find node %x\n", (int)req_lib_clm_nodeget->nodeId);
  562. if (req_lib_clm_nodeget->nodeId == SA_CLM_LOCAL_NODE_ID) {
  563. clusterNode = &clusterNodes[0];
  564. valid = 1;
  565. } else
  566. for (i = 0; i < clusterNodeEntries; i++) {
  567. if (clusterNodes[i].nodeId == req_lib_clm_nodeget->nodeId) {
  568. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  569. clusterNode = &clusterNodes[i];
  570. valid = 1;
  571. break;
  572. }
  573. }
  574. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  575. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  576. res_clm_nodeget.header.error = SA_AIS_OK;
  577. res_clm_nodeget.invocation = req_lib_clm_nodeget->invocation;
  578. res_clm_nodeget.valid = valid;
  579. if (valid) {
  580. memcpy (&res_clm_nodeget.clusterNode, clusterNode, sizeof (SaClmClusterNodeT));
  581. }
  582. libais_send_response (conn_info, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  583. }
  584. static void message_handler_req_lib_clm_nodegetasync (struct conn_info *conn_info, void *message)
  585. {
  586. struct req_lib_clm_nodegetasync *req_lib_clm_nodegetasync = (struct req_lib_clm_nodegetasync *)message;
  587. struct res_clm_nodegetasync res_clm_nodegetasync;
  588. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  589. SaClmClusterNodeT *clusterNode = 0;
  590. int error = SA_AIS_ERR_INVALID_PARAM;
  591. int i;
  592. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n", (int)req_lib_clm_nodegetasync->nodeId);
  593. if (req_lib_clm_nodegetasync->nodeId == SA_CLM_LOCAL_NODE_ID) {
  594. clusterNode = &clusterNodes[0];
  595. error = SA_AIS_OK;
  596. } else
  597. for (i = 0; i < clusterNodeEntries; i++) {
  598. if (clusterNodes[i].nodeId == req_lib_clm_nodegetasync->nodeId) {
  599. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  600. clusterNode = &clusterNodes[i];
  601. error = SA_AIS_OK;
  602. break;
  603. }
  604. }
  605. /*
  606. * Respond to library request
  607. */
  608. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  609. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  610. res_clm_nodegetasync.header.error = SA_AIS_OK;
  611. libais_send_response (conn_info, &res_clm_nodegetasync,
  612. sizeof (struct res_clm_nodegetasync));
  613. /*
  614. * Send async response
  615. */
  616. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  617. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  618. res_clm_nodegetcallback.header.error = error;
  619. res_clm_nodegetcallback.invocation = req_lib_clm_nodegetasync->invocation;
  620. if (error == SA_AIS_OK) {
  621. memcpy (&res_clm_nodegetcallback.clusterNode, clusterNode,
  622. sizeof (SaClmClusterNodeT));
  623. }
  624. libais_send_response (conn_info->conn_info_partner, &res_clm_nodegetcallback,
  625. sizeof (struct res_clm_nodegetcallback));
  626. }