clm.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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 int clm_exec_init_fn (struct objdb_iface_ver0 *objdb)
  230. {
  231. log_init ("CLM");
  232. memset (cluster_node_entries, 0,
  233. sizeof (mar_clm_cluster_node_t) * PROCESSOR_COUNT_MAX);
  234. /*
  235. * Build local cluster node data structure
  236. */
  237. sprintf ((char *)my_cluster_node.node_address.value, "%s",
  238. totemip_print (this_ip));
  239. my_cluster_node.node_address.length =
  240. strlen ((char *)my_cluster_node.node_address.value);
  241. if (this_ip->family == AF_INET) {
  242. my_cluster_node.node_address.family = SA_CLM_AF_INET;
  243. } else
  244. if (this_ip->family == AF_INET6) {
  245. my_cluster_node.node_address.family = SA_CLM_AF_INET6;
  246. } else {
  247. assert (0);
  248. }
  249. strcpy ((char *)my_cluster_node.node_name.value,
  250. (char *)my_cluster_node.node_address.value);
  251. my_cluster_node.node_name.length =
  252. my_cluster_node.node_address.length;
  253. my_cluster_node.node_id = this_ip->nodeid;
  254. my_cluster_node.member = 1;
  255. {
  256. #ifndef NANOSEC
  257. #define NANOSEC 1000000000
  258. #endif
  259. #if defined(OPENAIS_LINUX)
  260. struct sysinfo s_info;
  261. time_t current_time;
  262. sysinfo (&s_info);
  263. current_time = time (NULL);
  264. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  265. my_cluster_node.boot_timestamp = ((SaTimeT)(current_time - s_info.uptime)) * NANOSEC;
  266. #elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  267. int mib[2] = { CTL_KERN, KERN_BOOTTIME };
  268. struct timeval boot_time;
  269. size_t size = sizeof(boot_time);
  270. if ( sysctl(mib, 2, &boot_time, &size, NULL, 0) == -1 )
  271. boot_time.tv_sec = time (NULL);
  272. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  273. my_cluster_node.boot_timestamp = ((SaTimeT)boot_time.tv_sec) * NANOSEC;
  274. #elif defined(OPENAIS_SOLARIS)
  275. struct utmpx ut, *utp;
  276. ut.ut_type = BOOT_TIME;
  277. setutxent();
  278. if ((utp = getutxid(&ut)) == NULL) {
  279. my_cluster_node.boot_timestamp = ((SaTimeT)time(NULL)) * NANOSEC;
  280. } else {
  281. my_cluster_node.boot_timestamp = ((SaTimeT)utp->ut_xtime) * NANOSEC;
  282. }
  283. endutxent();
  284. #else
  285. #warning "no bootime support"
  286. #endif
  287. }
  288. memcpy (&cluster_node_entries[0], &my_cluster_node, sizeof (mar_clm_cluster_node_t));
  289. cluster_node_count = 1;
  290. main_clm_get_by_nodeid = clm_get_by_nodeid;
  291. return (0);
  292. }
  293. static int clm_lib_exit_fn (void *conn)
  294. {
  295. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  296. /*
  297. * Delete track entry if there is one
  298. */
  299. list_del (&clm_pd->list);
  300. clm_pd->conn = conn;
  301. return (0);
  302. }
  303. static void library_notification_send (
  304. mar_clm_cluster_notification_t *cluster_notification_entries,
  305. int notify_count)
  306. {
  307. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  308. struct clm_pd *clm_pd;
  309. struct list_head *list;
  310. int i;
  311. if (notify_count == 0) {
  312. return;
  313. }
  314. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  315. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  316. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  317. res_lib_clm_clustertrack.view = view_current;
  318. for (list = library_notification_send_listhead.next;
  319. list != &library_notification_send_listhead;
  320. list = list->next) {
  321. clm_pd = list_entry (list, struct clm_pd, list);
  322. /*
  323. * Track current and changes
  324. */
  325. if (clm_pd->track_flags & SA_TRACK_CHANGES) {
  326. /*
  327. * Copy all cluster nodes
  328. */
  329. for (i = 0; i < cluster_node_count; i++) {
  330. memcpy (&res_lib_clm_clustertrack.notification[i].cluster_node,
  331. &cluster_node_entries[i], sizeof (mar_clm_cluster_node_t));
  332. res_lib_clm_clustertrack.notification[i].cluster_change = SA_CLM_NODE_NO_CHANGE;
  333. res_lib_clm_clustertrack.notification[i].cluster_node.member = 1;
  334. }
  335. /*
  336. * Copy change_only notificaiton
  337. */
  338. res_lib_clm_clustertrack.number_of_items = notify_count + i;
  339. memcpy (&res_lib_clm_clustertrack.notification[i],
  340. cluster_notification_entries,
  341. sizeof (mar_clm_cluster_notification_t) * notify_count);
  342. } else
  343. /*
  344. * Track only changes
  345. */
  346. if (clm_pd->track_flags & SA_TRACK_CHANGES_ONLY) {
  347. res_lib_clm_clustertrack.number_of_items = notify_count;
  348. memcpy (&res_lib_clm_clustertrack.notification,
  349. cluster_notification_entries,
  350. sizeof (mar_clm_cluster_notification_t) * notify_count);
  351. }
  352. /*
  353. * Send notifications to all CLM listeners
  354. */
  355. openais_conn_send_response (
  356. clm_pd->conn,
  357. &res_lib_clm_clustertrack,
  358. sizeof (struct res_lib_clm_clustertrack));
  359. }
  360. }
  361. static void notification_join (mar_clm_cluster_node_t *cluster_node)
  362. {
  363. mar_clm_cluster_notification_t notification;
  364. /*
  365. * Generate notification element
  366. */
  367. notification.cluster_change = SA_CLM_NODE_JOINED;
  368. notification.cluster_node.member = 1;
  369. memcpy (&notification.cluster_node, cluster_node,
  370. sizeof (mar_clm_cluster_node_t));
  371. library_notification_send (&notification, 1);
  372. }
  373. static void lib_notification_leave (unsigned int *nodes, int nodes_entries)
  374. {
  375. mar_clm_cluster_notification_t cluster_notification[PROCESSOR_COUNT_MAX];
  376. int i, j;
  377. int notify_count;
  378. /*
  379. * Determine notification list
  380. */
  381. for (notify_count = 0, i = 0; i < cluster_node_count; i++) {
  382. for (j = 0; j < nodes_entries; j++) {
  383. if (cluster_node_entries[i].node_id == nodes[j]) {
  384. memcpy (&cluster_notification[notify_count].cluster_node,
  385. &cluster_node_entries[i],
  386. sizeof (mar_clm_cluster_node_t));
  387. cluster_notification[notify_count].cluster_change = SA_CLM_NODE_LEFT;
  388. cluster_notification[notify_count].cluster_node.member = 0;
  389. notify_count += 1;
  390. break;
  391. }
  392. }
  393. }
  394. /*
  395. * Remove entries from cluster_node_entries array
  396. */
  397. for (i = 0; i < nodes_entries; i++) {
  398. for (j = 0; j < cluster_node_count;) {
  399. if (nodes[i] == cluster_node_entries[j].node_id) {
  400. cluster_node_count -= 1;
  401. memmove (&cluster_node_entries[j], &cluster_node_entries[j + 1],
  402. (cluster_node_count - j) * sizeof (mar_clm_cluster_node_t));
  403. } else {
  404. /*
  405. * next cluster_node entry
  406. */
  407. j++;
  408. }
  409. }
  410. }
  411. library_notification_send (cluster_notification, notify_count);
  412. }
  413. static int clm_nodejoin_send (void)
  414. {
  415. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  416. struct iovec req_exec_clm_iovec;
  417. int result;
  418. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  419. req_exec_clm_nodejoin.header.id =
  420. SERVICE_ID_MAKE (CLM_SERVICE, MESSAGE_REQ_EXEC_CLM_NODEJOIN);
  421. my_cluster_node.initial_view_number = view_initial;
  422. memcpy (&req_exec_clm_nodejoin.cluster_node, &my_cluster_node,
  423. sizeof (mar_clm_cluster_node_t));
  424. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  425. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  426. result = totempg_groups_mcast_joined (openais_group_handle, &req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  427. return (result);
  428. }
  429. static void clm_confchg_fn (
  430. enum totem_configuration_type configuration_type,
  431. unsigned int *member_list, int member_list_entries,
  432. unsigned int *left_list, int left_list_entries,
  433. unsigned int *joined_list, int joined_list_entries,
  434. struct memb_ring_id *ring_id)
  435. {
  436. int i;
  437. unsigned int node_ids[PROCESSOR_COUNT_MAX];
  438. view_current = ring_id->seq / 4;
  439. if (view_initial == 0) {
  440. view_initial = ring_id->seq / 4;
  441. }
  442. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  443. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  444. for (i = 0; i < member_list_entries; i++) {
  445. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (member_list[i]));
  446. }
  447. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  448. for (i = 0; i < left_list_entries; i++) {
  449. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (left_list[i]));
  450. }
  451. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  452. for (i = 0; i < joined_list_entries; i++) {
  453. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (joined_list[i]));
  454. }
  455. for (i = 0; i < left_list_entries; i++) {
  456. node_ids[i] = left_list[i];
  457. }
  458. lib_notification_leave (node_ids, i);
  459. /*
  460. * Load the my_cluster_node data structure in case we are
  461. * transitioning to network interface up or down
  462. */
  463. sprintf ((char *)my_cluster_node.node_address.value, "%s", totemip_print (this_ip));
  464. my_cluster_node.node_address.length = strlen ((char *)my_cluster_node.node_address.value);
  465. if (this_ip->family == AF_INET) {
  466. my_cluster_node.node_address.family = SA_CLM_AF_INET;
  467. } else
  468. if (this_ip->family == AF_INET6) {
  469. my_cluster_node.node_address.family = SA_CLM_AF_INET6;
  470. } else {
  471. assert (0);
  472. }
  473. strcpy ((char *)my_cluster_node.node_name.value,
  474. (char *)my_cluster_node.node_address.value);
  475. my_cluster_node.node_name.length = my_cluster_node.node_address.length;
  476. my_cluster_node.node_id = this_ip->nodeid;
  477. }
  478. /*
  479. * This is a noop for this service
  480. */
  481. static void clm_sync_init (void)
  482. {
  483. return;
  484. }
  485. /*
  486. * If a processor joined in the configuration change and clm_sync_activate hasn't
  487. * yet been called, issue a node join to share CLM specific data about the processor
  488. */
  489. static int clm_sync_process (void)
  490. {
  491. /*
  492. * Send node information to other nodes
  493. */
  494. return (clm_nodejoin_send ());
  495. }
  496. /*
  497. * This is a noop for this service
  498. */
  499. static void clm_sync_activate (void)
  500. {
  501. return;
  502. }
  503. /*
  504. * This is a noop for this service
  505. */
  506. static void clm_sync_abort (void)
  507. {
  508. return;
  509. }
  510. static void exec_clm_nodejoin_endian_convert (void *msg)
  511. {
  512. struct req_exec_clm_nodejoin *node_join = msg;
  513. swab_mar_req_header_t (&node_join->header);
  514. swab_mar_clm_cluster_node_t (&node_join->cluster_node);
  515. }
  516. static void message_handler_req_exec_clm_nodejoin (
  517. void *message,
  518. unsigned int nodeid)
  519. {
  520. struct req_exec_clm_nodejoin *req_exec_clm_nodejoin = (struct req_exec_clm_nodejoin *)message;
  521. int found = 0;
  522. int i;
  523. log_printf (LOG_LEVEL_NOTICE, "got nodejoin message %s\n",
  524. req_exec_clm_nodejoin->cluster_node.node_name.value);
  525. /*
  526. * Determine if nodejoin already received
  527. */
  528. for (found = 0, i = 0; i < cluster_node_count; i++) {
  529. if (cluster_node_entries[i].node_id == req_exec_clm_nodejoin->cluster_node.node_id) {
  530. found = 1;
  531. }
  532. }
  533. /*
  534. * If not received, add to internal list
  535. */
  536. if (found == 0) {
  537. notification_join (&req_exec_clm_nodejoin->cluster_node);
  538. memcpy (&cluster_node_entries[cluster_node_count],
  539. &req_exec_clm_nodejoin->cluster_node,
  540. sizeof (mar_clm_cluster_node_t));
  541. cluster_node_count += 1;
  542. }
  543. }
  544. static int clm_lib_init_fn (void *conn)
  545. {
  546. log_printf (LOG_LEVEL_DEBUG, "Got request to initalize cluster membership service.\n");
  547. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  548. list_init (&clm_pd->list);
  549. clm_pd->conn = conn;
  550. return (0);
  551. }
  552. static void message_handler_req_lib_clm_clustertrack (void *conn, void *msg)
  553. {
  554. struct req_lib_clm_clustertrack *req_lib_clm_clustertrack = (struct req_lib_clm_clustertrack *)msg;
  555. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  556. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  557. int i;
  558. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  559. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKSTART;
  560. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  561. res_lib_clm_clustertrack.view = view_current;
  562. res_lib_clm_clustertrack.number_of_items = 0;
  563. /*
  564. * If an immediate listing of the current cluster membership
  565. * is requested, generate membership list
  566. */
  567. if (req_lib_clm_clustertrack->track_flags & SA_TRACK_CURRENT ||
  568. req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES) {
  569. for (i = 0; i < cluster_node_count; i++) {
  570. res_lib_clm_clustertrack.notification[i].cluster_change = SA_CLM_NODE_NO_CHANGE;
  571. memcpy (&res_lib_clm_clustertrack.notification[i].cluster_node,
  572. &cluster_node_entries[i], sizeof (mar_clm_cluster_node_t));
  573. }
  574. res_lib_clm_clustertrack.number_of_items = cluster_node_count;
  575. }
  576. /*
  577. * Record requests for cluster tracking
  578. */
  579. if (req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES ||
  580. req_lib_clm_clustertrack->track_flags & SA_TRACK_CHANGES_ONLY) {
  581. clm_pd->track_flags = req_lib_clm_clustertrack->track_flags;
  582. clm_pd->tracking_enabled = 1;
  583. list_add (&clm_pd->list, &library_notification_send_listhead);
  584. }
  585. openais_conn_send_response (conn, &res_lib_clm_clustertrack,
  586. sizeof (struct res_lib_clm_clustertrack));
  587. if (req_lib_clm_clustertrack->return_in_callback) {
  588. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  589. openais_conn_send_response (
  590. openais_conn_partner_get (conn),
  591. &res_lib_clm_clustertrack,
  592. sizeof (struct res_lib_clm_clustertrack));
  593. }
  594. }
  595. static void message_handler_req_lib_clm_trackstop (void *conn, void *msg)
  596. {
  597. struct res_lib_clm_trackstop res_lib_clm_trackstop;
  598. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  599. res_lib_clm_trackstop.header.size = sizeof (struct res_lib_clm_trackstop);
  600. res_lib_clm_trackstop.header.id = MESSAGE_RES_CLM_TRACKSTOP;
  601. if (clm_pd->tracking_enabled) {
  602. res_lib_clm_trackstop.header.error = SA_AIS_OK;
  603. clm_pd->tracking_enabled = 0;
  604. } else {
  605. res_lib_clm_trackstop.header.error = SA_AIS_ERR_NOT_EXIST;
  606. }
  607. list_del (&clm_pd->list);
  608. list_init (&clm_pd->list);
  609. openais_conn_send_response (conn, &res_lib_clm_trackstop,
  610. sizeof (struct res_lib_clm_trackstop));
  611. }
  612. static void message_handler_req_lib_clm_nodeget (void *conn, void *msg)
  613. {
  614. struct req_lib_clm_nodeget *req_lib_clm_nodeget = (struct req_lib_clm_nodeget *)msg;
  615. struct res_clm_nodeget res_clm_nodeget;
  616. mar_clm_cluster_node_t *cluster_node = 0;
  617. int valid = 0;
  618. int i;
  619. log_printf (LOG_LEVEL_NOTICE, "nodeget: trying to find node %x\n",
  620. (int)req_lib_clm_nodeget->node_id);
  621. if (req_lib_clm_nodeget->node_id == SA_CLM_LOCAL_NODE_ID) {
  622. cluster_node = &cluster_node_entries[0];
  623. valid = 1;
  624. } else
  625. for (i = 0; i < cluster_node_count; i++) {
  626. if (cluster_node_entries[i].node_id == req_lib_clm_nodeget->node_id) {
  627. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  628. cluster_node = &cluster_node_entries[i];
  629. valid = 1;
  630. break;
  631. }
  632. }
  633. res_clm_nodeget.header.size = sizeof (struct res_clm_nodeget);
  634. res_clm_nodeget.header.id = MESSAGE_RES_CLM_NODEGET;
  635. res_clm_nodeget.header.error = SA_AIS_OK;
  636. res_clm_nodeget.invocation = req_lib_clm_nodeget->invocation;
  637. res_clm_nodeget.valid = valid;
  638. if (valid) {
  639. memcpy (&res_clm_nodeget.cluster_node, cluster_node, sizeof (mar_clm_cluster_node_t));
  640. }
  641. openais_conn_send_response (conn, &res_clm_nodeget, sizeof (struct res_clm_nodeget));
  642. }
  643. static void message_handler_req_lib_clm_nodegetasync (void *conn, void *msg)
  644. {
  645. struct req_lib_clm_nodegetasync *req_lib_clm_nodegetasync = (struct req_lib_clm_nodegetasync *)msg;
  646. struct res_clm_nodegetasync res_clm_nodegetasync;
  647. struct res_clm_nodegetcallback res_clm_nodegetcallback;
  648. mar_clm_cluster_node_t *cluster_node = 0;
  649. int error = SA_AIS_ERR_INVALID_PARAM;
  650. int i;
  651. log_printf (LOG_LEVEL_DEBUG, "nodeget: trying to find node %x\n",
  652. (int)req_lib_clm_nodegetasync->node_id);
  653. if (req_lib_clm_nodegetasync->node_id == SA_CLM_LOCAL_NODE_ID) {
  654. cluster_node = &cluster_node_entries[0];
  655. error = SA_AIS_OK;
  656. } else
  657. for (i = 0; i < cluster_node_count; i++) {
  658. if (cluster_node_entries[i].node_id == req_lib_clm_nodegetasync->node_id) {
  659. log_printf (LOG_LEVEL_DEBUG, "found host that matches one desired in nodeget.\n");
  660. cluster_node = &cluster_node_entries[i];
  661. error = SA_AIS_OK;
  662. break;
  663. }
  664. }
  665. /*
  666. * Respond to library request
  667. */
  668. res_clm_nodegetasync.header.size = sizeof (struct res_clm_nodegetasync);
  669. res_clm_nodegetasync.header.id = MESSAGE_RES_CLM_NODEGETASYNC;
  670. res_clm_nodegetasync.header.error = SA_AIS_OK;
  671. openais_conn_send_response (conn, &res_clm_nodegetasync,
  672. sizeof (struct res_clm_nodegetasync));
  673. /*
  674. * Send async response
  675. */
  676. res_clm_nodegetcallback.header.size = sizeof (struct res_clm_nodegetcallback);
  677. res_clm_nodegetcallback.header.id = MESSAGE_RES_CLM_NODEGETCALLBACK;
  678. res_clm_nodegetcallback.header.error = error;
  679. res_clm_nodegetcallback.invocation = req_lib_clm_nodegetasync->invocation;
  680. if (error == SA_AIS_OK) {
  681. memcpy (&res_clm_nodegetcallback.cluster_node, cluster_node,
  682. sizeof (mar_clm_cluster_node_t));
  683. }
  684. openais_conn_send_response (openais_conn_partner_get (conn),
  685. &res_clm_nodegetcallback,
  686. sizeof (struct res_clm_nodegetcallback));
  687. }