clm.c 24 KB

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