clm.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805
  1. /*
  2. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006 Red Hat, Inc.
  4. * Copyright (C) 2006 Sun Microsystems, Inc.
  5. *
  6. * All rights reserved.
  7. *
  8. * Author: Steven Dake (sdake@redhat.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. #if defined(OPENAIS_LINUX)
  40. #include <sys/sysinfo.h>
  41. #elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  42. #include <sys/sysctl.h>
  43. #elif defined(OPENAIS_SOLARIS)
  44. #include <utmpx.h>
  45. #endif
  46. #include <sys/ioctl.h>
  47. #include <netinet/in.h>
  48. #include <sys/uio.h>
  49. #include <unistd.h>
  50. #include <fcntl.h>
  51. #include <stdlib.h>
  52. #include <stdio.h>
  53. #include <errno.h>
  54. #include <signal.h>
  55. #include <time.h>
  56. #include <unistd.h>
  57. #include <netinet/in.h>
  58. #include <arpa/inet.h>
  59. #include "swab.h"
  60. #include "totem.h"
  61. #include "../include/saAis.h"
  62. #include "../include/saClm.h"
  63. #include "../include/ipc_gen.h"
  64. #include "../include/ipc_clm.h"
  65. #include "../include/mar_gen.h"
  66. #include "../include/mar_clm.h"
  67. #include "../include/list.h"
  68. #include "../include/queue.h"
  69. #include "../lcr/lcr_comp.h"
  70. #include "totempg.h"
  71. #include "main.h"
  72. #include "ipc.h"
  73. #include "mempool.h"
  74. #include "service.h"
  75. #include "print.h"
  76. enum clm_message_req_types {
  77. MESSAGE_REQ_EXEC_CLM_NODEJOIN = 0
  78. };
  79. mar_clm_cluster_change_t my_cluster_node_last_change = SA_CLM_NODE_JOINED;
  80. mar_clm_cluster_node_t my_cluster_node;
  81. static mar_clm_cluster_node_t cluster_node_entries[PROCESSOR_COUNT_MAX];
  82. static int cluster_node_count = 0;
  83. static unsigned long long view_current = 0;
  84. static unsigned long long view_initial = 0;
  85. static DECLARE_LIST_INIT (library_notification_send_listhead);
  86. SaClmClusterNodeT *clm_get_by_nodeid (unsigned int node_id)
  87. {
  88. static SaClmClusterNodeT cluster_node;
  89. int i;
  90. if (node_id == SA_CLM_LOCAL_NODE_ID) {
  91. marshall_from_mar_clm_cluster_node_t (
  92. &cluster_node,
  93. &cluster_node_entries[0]);
  94. return (&cluster_node);
  95. }
  96. for (i = 0; i < cluster_node_count; i++) {
  97. if (cluster_node_entries[i].node_id == node_id) {
  98. marshall_from_mar_clm_cluster_node_t (
  99. &cluster_node,
  100. &cluster_node_entries[i]);
  101. return (&cluster_node);
  102. break;
  103. }
  104. }
  105. return (NULL);
  106. }
  107. /*
  108. * Service Interfaces required by service_message_handler struct
  109. */
  110. static void clm_confchg_fn (
  111. enum totem_configuration_type configuration_type,
  112. unsigned int *member_list, int member_list_entries,
  113. unsigned int *left_list, int left_list_entries,
  114. unsigned int *joined_list, int joined_list_entries,
  115. struct memb_ring_id *ring_id);
  116. static void clm_sync_init (void);
  117. static int clm_sync_process (void);
  118. static void clm_sync_activate (void);
  119. static void clm_sync_abort (void);
  120. static int clm_exec_init_fn (struct objdb_iface_ver0 *objdb);
  121. static int clm_lib_init_fn (void *conn);
  122. static int clm_lib_exit_fn (void *conn);
  123. static void message_handler_req_exec_clm_nodejoin (
  124. void *message,
  125. unsigned int nodeid);
  126. static void exec_clm_nodejoin_endian_convert (void *msg);
  127. static void message_handler_req_lib_clm_clustertrack (void *conn, void *message);
  128. static void message_handler_req_lib_clm_trackstop (void *conn, void *message);
  129. static void message_handler_req_lib_clm_nodeget (void *conn, void *message);
  130. static void message_handler_req_lib_clm_nodegetasync (void *conn, void *message);
  131. struct clm_pd {
  132. unsigned char track_flags;
  133. int tracking_enabled;
  134. struct list_head list;
  135. void *conn;
  136. };
  137. /*
  138. * Executive Handler Definition
  139. */
  140. static struct openais_lib_handler clm_lib_service[] =
  141. {
  142. { /* 0 */
  143. .lib_handler_fn = message_handler_req_lib_clm_clustertrack,
  144. .response_size = sizeof (struct res_lib_clm_clustertrack),
  145. .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE
  146. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  147. },
  148. { /* 1 */
  149. .lib_handler_fn = message_handler_req_lib_clm_trackstop,
  150. .response_size = sizeof (struct res_lib_clm_trackstop),
  151. .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE
  152. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  153. },
  154. { /* 2 */
  155. .lib_handler_fn = message_handler_req_lib_clm_nodeget,
  156. .response_size = sizeof (struct res_clm_nodeget),
  157. .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE
  158. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  159. },
  160. { /* 3 */
  161. .lib_handler_fn = message_handler_req_lib_clm_nodegetasync,
  162. .response_size = sizeof (struct res_clm_nodegetasync),
  163. .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE
  164. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED
  165. }
  166. };
  167. static struct openais_exec_handler clm_exec_service[] =
  168. {
  169. {
  170. .exec_handler_fn = message_handler_req_exec_clm_nodejoin,
  171. .exec_endian_convert_fn = exec_clm_nodejoin_endian_convert
  172. }
  173. };
  174. struct openais_service_handler clm_service_handler = {
  175. .name = "openais cluster membership service B.01.01",
  176. .id = CLM_SERVICE,
  177. .private_data_size = sizeof (struct clm_pd),
  178. .flow_control = OPENAIS_FLOW_CONTROL_NOT_REQUIRED,
  179. .lib_init_fn = clm_lib_init_fn,
  180. .lib_exit_fn = clm_lib_exit_fn,
  181. .lib_service = clm_lib_service,
  182. .lib_service_count = sizeof (clm_lib_service) / sizeof (struct openais_lib_handler),
  183. .exec_init_fn = clm_exec_init_fn,
  184. .exec_dump_fn = NULL,
  185. .exec_service = clm_exec_service,
  186. .exec_service_count = sizeof (clm_exec_service) / sizeof (struct openais_exec_handler),
  187. .confchg_fn = clm_confchg_fn,
  188. .sync_init = clm_sync_init,
  189. .sync_process = clm_sync_process,
  190. .sync_activate = clm_sync_activate,
  191. .sync_abort = clm_sync_abort,
  192. };
  193. /*
  194. * Dynamic loader definition
  195. */
  196. static struct openais_service_handler *clm_get_service_handler_ver0 (void);
  197. static struct openais_service_handler_iface_ver0 clm_service_handler_iface = {
  198. .openais_get_service_handler_ver0 = clm_get_service_handler_ver0
  199. };
  200. static struct lcr_iface openais_clm_ver0[1] = {
  201. {
  202. .name = "openais_clm",
  203. .version = 0,
  204. .versions_replace = 0,
  205. .versions_replace_count = 0,
  206. .dependencies = 0,
  207. .dependency_count = 0,
  208. .constructor = NULL,
  209. .destructor = NULL,
  210. .interfaces = NULL
  211. }
  212. };
  213. static struct lcr_comp clm_comp_ver0 = {
  214. .iface_count = 1,
  215. .ifaces = openais_clm_ver0
  216. };
  217. static struct openais_service_handler *clm_get_service_handler_ver0 (void)
  218. {
  219. return (&clm_service_handler);
  220. }
  221. __attribute__ ((constructor)) static void clm_comp_register (void) {
  222. lcr_interfaces_set (&openais_clm_ver0[0], &clm_service_handler_iface);
  223. lcr_component_register (&clm_comp_ver0);
  224. }
  225. struct req_exec_clm_nodejoin {
  226. mar_req_header_t header __attribute__((aligned(8)));
  227. mar_clm_cluster_node_t cluster_node __attribute__((aligned(8)));
  228. };
  229. static void my_cluster_node_load (void)
  230. {
  231. struct totem_ip_address interfaces[INTERFACE_MAX];
  232. unsigned int iface_count;
  233. char **status;
  234. const char *iface_string;
  235. totempg_ifaces_get (
  236. totempg_my_nodeid_get (),
  237. interfaces,
  238. &status,
  239. &iface_count);
  240. iface_string = totemip_print (&interfaces[0]);
  241. sprintf ((char *)my_cluster_node.node_address.value, "%s",
  242. iface_string);
  243. my_cluster_node.node_address.length =
  244. strlen ((char *)my_cluster_node.node_address.value);
  245. if (totempg_my_family_get () == AF_INET) {
  246. my_cluster_node.node_address.family = SA_CLM_AF_INET;
  247. } else
  248. if (totempg_my_family_get () == AF_INET6) {
  249. my_cluster_node.node_address.family = SA_CLM_AF_INET6;
  250. } else {
  251. assert (0);
  252. }
  253. strcpy ((char *)my_cluster_node.node_name.value,
  254. (char *)my_cluster_node.node_address.value);
  255. my_cluster_node.node_name.length =
  256. my_cluster_node.node_address.length;
  257. my_cluster_node.node_id = totempg_my_nodeid_get ();
  258. my_cluster_node.member = 1;
  259. memcpy (&cluster_node_entries[0], &my_cluster_node,
  260. sizeof (mar_clm_cluster_node_t));
  261. }
  262. static int clm_exec_init_fn (struct objdb_iface_ver0 *objdb)
  263. {
  264. log_init ("CLM");
  265. memset (cluster_node_entries, 0,
  266. sizeof (mar_clm_cluster_node_t) * PROCESSOR_COUNT_MAX);
  267. {
  268. #ifndef NANOSEC
  269. #define NANOSEC 1000000000
  270. #endif
  271. #if defined(OPENAIS_LINUX)
  272. struct sysinfo s_info;
  273. time_t current_time;
  274. sysinfo (&s_info);
  275. current_time = time (NULL);
  276. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  277. my_cluster_node.boot_timestamp = ((SaTimeT)(current_time - s_info.uptime)) * NANOSEC;
  278. #elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  279. int mib[2] = { CTL_KERN, KERN_BOOTTIME };
  280. struct timeval boot_time;
  281. size_t size = sizeof(boot_time);
  282. if ( sysctl(mib, 2, &boot_time, &size, NULL, 0) == -1 )
  283. boot_time.tv_sec = time (NULL);
  284. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  285. my_cluster_node.boot_timestamp = ((SaTimeT)boot_time.tv_sec) * NANOSEC;
  286. #elif defined(OPENAIS_SOLARIS)
  287. struct utmpx ut, *utp;
  288. ut.ut_type = BOOT_TIME;
  289. setutxent();
  290. if ((utp = getutxid(&ut)) == NULL) {
  291. my_cluster_node.boot_timestamp = ((SaTimeT)time(NULL)) * NANOSEC;
  292. } else {
  293. my_cluster_node.boot_timestamp = ((SaTimeT)utp->ut_xtime) * NANOSEC;
  294. }
  295. endutxent();
  296. #else
  297. #warning "no bootime support"
  298. #endif
  299. }
  300. cluster_node_count = 1;
  301. main_clm_get_by_nodeid = clm_get_by_nodeid;
  302. return (0);
  303. }
  304. static int clm_lib_exit_fn (void *conn)
  305. {
  306. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  307. /*
  308. * Delete track entry if there is one
  309. */
  310. list_del (&clm_pd->list);
  311. clm_pd->conn = conn;
  312. return (0);
  313. }
  314. static void library_notification_send (
  315. mar_clm_cluster_notification_t *cluster_notification_entries,
  316. int notify_count)
  317. {
  318. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  319. struct clm_pd *clm_pd;
  320. struct list_head *list;
  321. int i;
  322. if (notify_count == 0) {
  323. return;
  324. }
  325. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  326. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  327. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  328. res_lib_clm_clustertrack.view = view_current;
  329. for (list = library_notification_send_listhead.next;
  330. list != &library_notification_send_listhead;
  331. list = list->next) {
  332. clm_pd = list_entry (list, struct clm_pd, list);
  333. /*
  334. * Track current and changes
  335. */
  336. if (clm_pd->track_flags & SA_TRACK_CHANGES) {
  337. /*
  338. * Copy all cluster nodes
  339. */
  340. for (i = 0; i < cluster_node_count; i++) {
  341. memcpy (&res_lib_clm_clustertrack.notification[i].cluster_node,
  342. &cluster_node_entries[i], sizeof (mar_clm_cluster_node_t));
  343. res_lib_clm_clustertrack.notification[i].cluster_change = SA_CLM_NODE_NO_CHANGE;
  344. res_lib_clm_clustertrack.notification[i].cluster_node.member = 1;
  345. }
  346. /*
  347. * Copy change_only notificaiton
  348. */
  349. res_lib_clm_clustertrack.number_of_items = notify_count + i;
  350. memcpy (&res_lib_clm_clustertrack.notification[i],
  351. cluster_notification_entries,
  352. sizeof (mar_clm_cluster_notification_t) * notify_count);
  353. } else
  354. /*
  355. * Track only changes
  356. */
  357. if (clm_pd->track_flags & SA_TRACK_CHANGES_ONLY) {
  358. res_lib_clm_clustertrack.number_of_items = notify_count;
  359. memcpy (&res_lib_clm_clustertrack.notification,
  360. cluster_notification_entries,
  361. sizeof (mar_clm_cluster_notification_t) * notify_count);
  362. }
  363. /*
  364. * Send notifications to all CLM listeners
  365. */
  366. openais_conn_send_response (
  367. clm_pd->conn,
  368. &res_lib_clm_clustertrack,
  369. sizeof (struct res_lib_clm_clustertrack));
  370. }
  371. }
  372. static void notification_join (mar_clm_cluster_node_t *cluster_node)
  373. {
  374. mar_clm_cluster_notification_t notification;
  375. /*
  376. * Generate notification element
  377. */
  378. notification.cluster_change = SA_CLM_NODE_JOINED;
  379. notification.cluster_node.member = 1;
  380. memcpy (&notification.cluster_node, cluster_node,
  381. sizeof (mar_clm_cluster_node_t));
  382. library_notification_send (&notification, 1);
  383. }
  384. static void lib_notification_leave (unsigned int *nodes, int nodes_entries)
  385. {
  386. mar_clm_cluster_notification_t cluster_notification[PROCESSOR_COUNT_MAX];
  387. int i, j;
  388. int notify_count;
  389. /*
  390. * Determine notification list
  391. */
  392. for (notify_count = 0, i = 0; i < cluster_node_count; i++) {
  393. for (j = 0; j < nodes_entries; j++) {
  394. if (cluster_node_entries[i].node_id == nodes[j]) {
  395. memcpy (&cluster_notification[notify_count].cluster_node,
  396. &cluster_node_entries[i],
  397. sizeof (mar_clm_cluster_node_t));
  398. cluster_notification[notify_count].cluster_change = SA_CLM_NODE_LEFT;
  399. cluster_notification[notify_count].cluster_node.member = 0;
  400. notify_count += 1;
  401. break;
  402. }
  403. }
  404. }
  405. /*
  406. * Remove entries from cluster_node_entries array
  407. */
  408. for (i = 0; i < nodes_entries; i++) {
  409. for (j = 0; j < cluster_node_count;) {
  410. if (nodes[i] == cluster_node_entries[j].node_id) {
  411. cluster_node_count -= 1;
  412. memmove (&cluster_node_entries[j], &cluster_node_entries[j + 1],
  413. (cluster_node_count - j) * sizeof (mar_clm_cluster_node_t));
  414. } else {
  415. /*
  416. * next cluster_node entry
  417. */
  418. j++;
  419. }
  420. }
  421. }
  422. library_notification_send (cluster_notification, notify_count);
  423. }
  424. static int clm_nodejoin_send (void)
  425. {
  426. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  427. struct iovec req_exec_clm_iovec;
  428. int result;
  429. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  430. req_exec_clm_nodejoin.header.id =
  431. SERVICE_ID_MAKE (CLM_SERVICE, MESSAGE_REQ_EXEC_CLM_NODEJOIN);
  432. my_cluster_node.initial_view_number = view_initial;
  433. memcpy (&req_exec_clm_nodejoin.cluster_node, &my_cluster_node,
  434. sizeof (mar_clm_cluster_node_t));
  435. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  436. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  437. result = totempg_groups_mcast_joined (openais_group_handle, &req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  438. return (result);
  439. }
  440. static void clm_confchg_fn (
  441. enum totem_configuration_type configuration_type,
  442. unsigned int *member_list, int member_list_entries,
  443. unsigned int *left_list, int left_list_entries,
  444. unsigned int *joined_list, int joined_list_entries,
  445. struct memb_ring_id *ring_id)
  446. {
  447. int i;
  448. unsigned int node_ids[PROCESSOR_COUNT_MAX];
  449. view_current = ring_id->seq / 4;
  450. if (view_initial == 0) {
  451. view_initial = ring_id->seq / 4;
  452. }
  453. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  454. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  455. for (i = 0; i < member_list_entries; i++) {
  456. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (member_list[i]));
  457. }
  458. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  459. for (i = 0; i < left_list_entries; i++) {
  460. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (left_list[i]));
  461. }
  462. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  463. for (i = 0; i < joined_list_entries; i++) {
  464. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (joined_list[i]));
  465. }
  466. for (i = 0; i < left_list_entries; i++) {
  467. node_ids[i] = left_list[i];
  468. }
  469. lib_notification_leave (node_ids, i);
  470. /*
  471. * Load the my_cluster_node data structure in case we are
  472. * transitioning to network interface up or down
  473. */
  474. my_cluster_node_load ();
  475. }
  476. /*
  477. * This is a noop for this service
  478. */
  479. static void clm_sync_init (void)
  480. {
  481. return;
  482. }
  483. /*
  484. * If a processor joined in the configuration change and clm_sync_activate hasn't
  485. * yet been called, issue a node join to share CLM specific data about the processor
  486. */
  487. static int clm_sync_process (void)
  488. {
  489. /*
  490. * Send node information to other nodes
  491. */
  492. return (clm_nodejoin_send ());
  493. }
  494. /*
  495. * This is a noop for this service
  496. */
  497. static void clm_sync_activate (void)
  498. {
  499. return;
  500. }
  501. /*
  502. * This is a noop for this service
  503. */
  504. static void clm_sync_abort (void)
  505. {
  506. return;
  507. }
  508. static void exec_clm_nodejoin_endian_convert (void *msg)
  509. {
  510. struct req_exec_clm_nodejoin *node_join = msg;
  511. swab_mar_req_header_t (&node_join->header);
  512. swab_mar_clm_cluster_node_t (&node_join->cluster_node);
  513. }
  514. static void message_handler_req_exec_clm_nodejoin (
  515. void *message,
  516. unsigned int nodeid)
  517. {
  518. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  519. int found = 0;
  520. int i;
  521. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n",
  522. req_exec_clm_nodejoin->cluster_node.node_name.value);
  523. /*
  524. * Determine if nodejoin already received
  525. */
  526. for (found = 0, i = 0; i < cluster_node_count; i++) {
  527. if (cluster_node_entries[i].node_id == req_exec_clm_nodejoin->cluster_node.node_id) {
  528. found = 1;
  529. }
  530. }
  531. /*
  532. * If not received, add to internal list
  533. */
  534. if (found == 0) {
  535. notification_join (&req_exec_clm_nodejoin->cluster_node);
  536. memcpy (&cluster_node_entries[cluster_node_count],
  537. &req_exec_clm_nodejoin->cluster_node,
  538. sizeof (mar_clm_cluster_node_t));
  539. cluster_node_count += 1;
  540. }
  541. }
  542. static int clm_lib_init_fn (void *conn)
  543. {
  544. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  545. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  546. list_init (&clm_pd->list);
  547. clm_pd->conn = conn;
  548. return (0);
  549. }
  550. static void message_handler_req_lib_clm_clustertrack (void *conn, void *msg)
  551. {
  552. struct req_lib_clm_clustertrack *req_lib_clm_clustertrack = (struct req_lib_clm_clustertrack *)msg;
  553. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  554. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  555. int i;
  556. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  557. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKSTART;
  558. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  559. res_lib_clm_clustertrack.view = view_current;
  560. res_lib_clm_clustertrack.number_of_items = 0;
  561. /*
  562. * If an immediate listing of the current cluster membership
  563. * is requested, generate membership list
  564. */
  565. if (req_lib_clm_clustertrack->track_flags & SA_TRACK_CURRENT ||
  566. req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES) {
  567. for (i = 0; i < cluster_node_count; i++) {
  568. res_lib_clm_clustertrack.notification[i].cluster_change = SA_CLM_NODE_NO_CHANGE;
  569. memcpy (&res_lib_clm_clustertrack.notification[i].cluster_node,
  570. &cluster_node_entries[i], sizeof (mar_clm_cluster_node_t));
  571. }
  572. res_lib_clm_clustertrack.number_of_items = cluster_node_count;
  573. }
  574. /*
  575. * Record requests for cluster tracking
  576. */
  577. if (req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES ||
  578. req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES_ONLY) {
  579. clm_pd->track_flags = req_lib_clm_clustertrack->track_flags;
  580. clm_pd->tracking_enabled = 1;
  581. list_add (&clm_pd->list, &library_notification_send_listhead);
  582. }
  583. openais_conn_send_response (conn, &res_lib_clm_clustertrack,
  584. sizeof (struct res_lib_clm_clustertrack));
  585. if (req_lib_clm_clustertrack->return_in_callback) {
  586. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  587. openais_conn_send_response (
  588. openais_conn_partner_get (conn),
  589. &res_lib_clm_clustertrack,
  590. sizeof (struct res_lib_clm_clustertrack));
  591. }
  592. }
  593. static void message_handler_req_lib_clm_trackstop (void *conn, void *msg)
  594. {
  595. struct res_lib_clm_trackstop res_lib_clm_trackstop;
  596. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  597. res_lib_clm_trackstop.header.size = sizeof (struct res_lib_clm_trackstop);
  598. res_lib_clm_trackstop.header.id = MESSAGE_RES_CLM_TRACKSTOP;
  599. if (clm_pd->tracking_enabled) {
  600. res_lib_clm_trackstop.header.error = SA_AIS_OK;
  601. clm_pd->tracking_enabled = 0;
  602. } else {
  603. res_lib_clm_trackstop.header.error = SA_AIS_ERR_NOT_EXIST;
  604. }
  605. list_del (&clm_pd->list);
  606. list_init (&clm_pd->list);
  607. openais_conn_send_response (conn, &res_lib_clm_trackstop,
  608. sizeof (struct res_lib_clm_trackstop));
  609. }
  610. static void message_handler_req_lib_clm_nodeget (void *conn, void *msg)
  611. {
  612. struct req_lib_clm_nodeget *req_lib_clm_nodeget = (struct req_lib_clm_nodeget *)msg;
  613. struct res_clm_nodeget res_clm_nodeget;
  614. mar_clm_cluster_node_t *cluster_node = 0;
  615. int valid = 0;
  616. int i;
  617. log_printf (LOG_LEVEL_NOTICE, "nodeget: trying to find node %x\n",
  618. (int)req_lib_clm_nodeget->node_id);
  619. if (req_lib_clm_nodeget->node_id == SA_CLM_LOCAL_NODE_ID) {
  620. cluster_node = &cluster_node_entries[0];
  621. valid = 1;
  622. } else
  623. for (i = 0; i < cluster_node_count; i++) {
  624. if (cluster_node_entries[i].node_id == req_lib_clm_nodeget->node_id) {
  625. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  626. cluster_node = &cluster_node_entries[i];
  627. valid = 1;
  628. break;
  629. }
  630. }
  631. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  632. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  633. res_clm_nodeget.header.error = SA_AIS_OK;
  634. res_clm_nodeget.invocation = req_lib_clm_nodeget->invocation;
  635. res_clm_nodeget.valid = valid;
  636. if (valid) {
  637. memcpy (&res_clm_nodeget.cluster_node, cluster_node, sizeof (mar_clm_cluster_node_t));
  638. }
  639. openais_conn_send_response (conn, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  640. }
  641. static void message_handler_req_lib_clm_nodegetasync (void *conn, void *msg)
  642. {
  643. struct req_lib_clm_nodegetasync *req_lib_clm_nodegetasync = (struct req_lib_clm_nodegetasync *)msg;
  644. struct res_clm_nodegetasync res_clm_nodegetasync;
  645. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  646. mar_clm_cluster_node_t *cluster_node = 0;
  647. int error = SA_AIS_ERR_INVALID_PARAM;
  648. int i;
  649. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n",
  650. (int)req_lib_clm_nodegetasync->node_id);
  651. if (req_lib_clm_nodegetasync->node_id == SA_CLM_LOCAL_NODE_ID) {
  652. cluster_node = &cluster_node_entries[0];
  653. error = SA_AIS_OK;
  654. } else
  655. for (i = 0; i < cluster_node_count; i++) {
  656. if (cluster_node_entries[i].node_id == req_lib_clm_nodegetasync->node_id) {
  657. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  658. cluster_node = &cluster_node_entries[i];
  659. error = SA_AIS_OK;
  660. break;
  661. }
  662. }
  663. /*
  664. * Respond to library request
  665. */
  666. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  667. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  668. res_clm_nodegetasync.header.error = SA_AIS_OK;
  669. openais_conn_send_response (conn, &res_clm_nodegetasync,
  670. sizeof (struct res_clm_nodegetasync));
  671. /*
  672. * Send async response
  673. */
  674. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  675. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  676. res_clm_nodegetcallback.header.error = error;
  677. res_clm_nodegetcallback.invocation = req_lib_clm_nodegetasync->invocation;
  678. if (error == SA_AIS_OK) {
  679. memcpy (&res_clm_nodegetcallback.cluster_node, cluster_node,
  680. sizeof (mar_clm_cluster_node_t));
  681. }
  682. openais_conn_send_response (openais_conn_partner_get (conn),
  683. &res_clm_nodegetcallback,
  684. sizeof (struct res_clm_nodegetcallback));
  685. }