clm.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /*
  2. * Copyright (c) 2002-2006 MontaVista Software, Inc.
  3. * Copyright (c) 2006-2007 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 <corosync/ipc_gen.h>
  60. #include <corosync/mar_gen.h>
  61. #include <corosync/engine/swab.h>
  62. #include <corosync/engine/coroapi.h>
  63. #include <corosync/list.h>
  64. #include <corosync/engine/logsys.h>
  65. #include <corosync/lcr/lcr_comp.h>
  66. #include "../include/saAis.h"
  67. #include "../include/saClm.h"
  68. #include "../include/ipc_clm.h"
  69. #include "../include/mar_clm.h"
  70. LOGSYS_DECLARE_SUBSYS ("CLM", LOG_INFO);
  71. enum clm_message_req_types {
  72. MESSAGE_REQ_EXEC_CLM_NODEJOIN = 0
  73. };
  74. mar_clm_cluster_change_t my_cluster_node_last_change = SA_CLM_NODE_JOINED;
  75. mar_clm_cluster_node_t my_cluster_node;
  76. static struct corosync_api_v1 *api;
  77. static mar_clm_cluster_node_t cluster_node_entries[PROCESSOR_COUNT_MAX];
  78. static int cluster_node_count = 0;
  79. static unsigned long long view_current = 0;
  80. static unsigned long long view_initial = 0;
  81. static DECLARE_LIST_INIT (library_notification_send_listhead);
  82. SaClmClusterNodeT *clm_get_by_nodeid (unsigned int node_id)
  83. {
  84. static SaClmClusterNodeT cluster_node;
  85. int i;
  86. if (node_id == SA_CLM_LOCAL_NODE_ID) {
  87. marshall_from_mar_clm_cluster_node_t (
  88. &cluster_node,
  89. &cluster_node_entries[0]);
  90. return (&cluster_node);
  91. }
  92. for (i = 0; i < cluster_node_count; i++) {
  93. if (cluster_node_entries[i].node_id == node_id) {
  94. marshall_from_mar_clm_cluster_node_t (
  95. &cluster_node,
  96. &cluster_node_entries[i]);
  97. return (&cluster_node);
  98. break;
  99. }
  100. }
  101. return (NULL);
  102. }
  103. /*
  104. * Service Interfaces required by service_message_handler struct
  105. */
  106. static void clm_confchg_fn (
  107. enum totem_configuration_type configuration_type,
  108. unsigned int *member_list, int member_list_entries,
  109. unsigned int *left_list, int left_list_entries,
  110. unsigned int *joined_list, int joined_list_entries,
  111. struct memb_ring_id *ring_id);
  112. static void clm_sync_init (void);
  113. static int clm_sync_process (void);
  114. static void clm_sync_activate (void);
  115. static void clm_sync_abort (void);
  116. static int clm_exec_init_fn (struct corosync_api_v1 *corosync_api);
  117. static int clm_exec_exit_fn (void);
  118. static int clm_lib_init_fn (void *conn);
  119. static int clm_lib_exit_fn (void *conn);
  120. static void message_handler_req_exec_clm_nodejoin (
  121. void *message,
  122. unsigned int nodeid);
  123. static void exec_clm_nodejoin_endian_convert (void *msg);
  124. static void message_handler_req_lib_clm_clustertrack (void *conn, void *message);
  125. static void message_handler_req_lib_clm_trackstop (void *conn, void *message);
  126. static void message_handler_req_lib_clm_nodeget (void *conn, void *message);
  127. static void message_handler_req_lib_clm_nodegetasync (void *conn, void *message);
  128. struct clm_pd {
  129. unsigned char track_flags;
  130. int tracking_enabled;
  131. struct list_head list;
  132. void *conn;
  133. };
  134. /*
  135. * Executive Handler Definition
  136. */
  137. static struct corosync_lib_handler clm_lib_engine[] =
  138. {
  139. { /* 0 */
  140. .lib_handler_fn = message_handler_req_lib_clm_clustertrack,
  141. .response_size = sizeof (struct res_lib_clm_clustertrack),
  142. .response_id = MESSAGE_RES_CLM_TRACKSTART, // TODO RESPONSE
  143. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  144. },
  145. { /* 1 */
  146. .lib_handler_fn = message_handler_req_lib_clm_trackstop,
  147. .response_size = sizeof (struct res_lib_clm_trackstop),
  148. .response_id = MESSAGE_RES_CLM_TRACKSTOP, // TODO RESPONSE
  149. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  150. },
  151. { /* 2 */
  152. .lib_handler_fn = message_handler_req_lib_clm_nodeget,
  153. .response_size = sizeof (struct res_clm_nodeget),
  154. .response_id = MESSAGE_RES_CLM_NODEGET, // TODO RESPONSE
  155. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  156. },
  157. { /* 3 */
  158. .lib_handler_fn = message_handler_req_lib_clm_nodegetasync,
  159. .response_size = sizeof (struct res_clm_nodegetasync),
  160. .response_id = MESSAGE_RES_CLM_NODEGETCALLBACK, // TODO RESPONSE
  161. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED
  162. }
  163. };
  164. static struct corosync_exec_handler clm_exec_engine[] =
  165. {
  166. {
  167. .exec_handler_fn = message_handler_req_exec_clm_nodejoin,
  168. .exec_endian_convert_fn = exec_clm_nodejoin_endian_convert
  169. }
  170. };
  171. struct corosync_service_engine clm_service_engine = {
  172. .name = "openais cluster membership service B.01.01",
  173. .id = CLM_SERVICE,
  174. .private_data_size = sizeof (struct clm_pd),
  175. .flow_control = COROSYNC_LIB_FLOW_CONTROL_NOT_REQUIRED,
  176. .lib_init_fn = clm_lib_init_fn,
  177. .lib_exit_fn = clm_lib_exit_fn,
  178. .lib_engine = clm_lib_engine,
  179. .lib_engine_count = sizeof (clm_lib_engine) / sizeof (struct corosync_lib_handler),
  180. .exec_init_fn = clm_exec_init_fn,
  181. .exec_exit_fn = clm_exec_exit_fn,
  182. .exec_dump_fn = NULL,
  183. .exec_engine = clm_exec_engine,
  184. .exec_engine_count = sizeof (clm_exec_engine) / sizeof (struct corosync_exec_handler),
  185. .confchg_fn = clm_confchg_fn,
  186. .sync_init = clm_sync_init,
  187. .sync_process = clm_sync_process,
  188. .sync_activate = clm_sync_activate,
  189. .sync_abort = clm_sync_abort,
  190. };
  191. /*
  192. * Dynamic loader definition
  193. */
  194. static struct corosync_service_engine *clm_get_service_engine_ver0 (void);
  195. static struct corosync_service_engine_iface_ver0 clm_service_engine_iface = {
  196. .corosync_get_service_engine_ver0 = clm_get_service_engine_ver0
  197. };
  198. static struct lcr_iface openais_clm_ver0[1] = {
  199. {
  200. .name = "openais_clm",
  201. .version = 0,
  202. .versions_replace = 0,
  203. .versions_replace_count = 0,
  204. .dependencies = 0,
  205. .dependency_count = 0,
  206. .constructor = NULL,
  207. .destructor = NULL,
  208. .interfaces = NULL
  209. }
  210. };
  211. static struct lcr_comp clm_comp_ver0 = {
  212. .iface_count = 1,
  213. .ifaces = openais_clm_ver0
  214. };
  215. static struct corosync_service_engine *clm_get_service_engine_ver0 (void)
  216. {
  217. return (&clm_service_engine);
  218. }
  219. __attribute__ ((constructor)) static void clm_comp_register (void) {
  220. lcr_interfaces_set (&openais_clm_ver0[0], &clm_service_engine_iface);
  221. lcr_component_register (&clm_comp_ver0);
  222. }
  223. struct req_exec_clm_nodejoin {
  224. mar_req_header_t header __attribute__((aligned(8)));
  225. mar_clm_cluster_node_t cluster_node __attribute__((aligned(8)));
  226. };
  227. static void my_cluster_node_load (void)
  228. {
  229. struct totem_ip_address interfaces[INTERFACE_MAX];
  230. unsigned int iface_count;
  231. char **status;
  232. const char *iface_string;
  233. api->totem_ifaces_get (
  234. api->totem_nodeid_get (),
  235. interfaces,
  236. &status,
  237. &iface_count);
  238. iface_string = api->totem_ip_print (&interfaces[0]);
  239. sprintf ((char *)my_cluster_node.node_address.value, "%s",
  240. iface_string);
  241. my_cluster_node.node_address.length =
  242. strlen ((char *)my_cluster_node.node_address.value);
  243. if (api->totem_family_get () == AF_INET) {
  244. my_cluster_node.node_address.family = SA_CLM_AF_INET;
  245. } else
  246. if (api->totem_family_get () == AF_INET6) {
  247. my_cluster_node.node_address.family = SA_CLM_AF_INET6;
  248. } else {
  249. assert (0);
  250. }
  251. strcpy ((char *)my_cluster_node.node_name.value,
  252. (char *)my_cluster_node.node_address.value);
  253. my_cluster_node.node_name.length =
  254. my_cluster_node.node_address.length;
  255. my_cluster_node.node_id = api->totem_nodeid_get ();
  256. my_cluster_node.member = 1;
  257. memcpy (&cluster_node_entries[0], &my_cluster_node,
  258. sizeof (mar_clm_cluster_node_t));
  259. }
  260. static int clm_exec_init_fn (struct corosync_api_v1 *corosync_api)
  261. {
  262. api = corosync_api;
  263. memset (cluster_node_entries, 0,
  264. sizeof (mar_clm_cluster_node_t) * PROCESSOR_COUNT_MAX);
  265. {
  266. #ifndef NANOSEC
  267. #define NANOSEC 1000000000
  268. #endif
  269. #if defined(OPENAIS_LINUX)
  270. struct sysinfo s_info;
  271. time_t current_time;
  272. sysinfo (&s_info);
  273. current_time = time (NULL);
  274. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  275. my_cluster_node.boot_timestamp = ((SaTimeT)(current_time - s_info.uptime)) * NANOSEC;
  276. #elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  277. int mib[2] = { CTL_KERN, KERN_BOOTTIME };
  278. struct timeval boot_time;
  279. size_t size = sizeof(boot_time);
  280. if ( sysctl(mib, 2, &boot_time, &size, NULL, 0) == -1 )
  281. boot_time.tv_sec = time (NULL);
  282. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  283. my_cluster_node.boot_timestamp = ((SaTimeT)boot_time.tv_sec) * NANOSEC;
  284. #elif defined(OPENAIS_SOLARIS)
  285. struct utmpx ut, *utp;
  286. ut.ut_type = BOOT_TIME;
  287. setutxent();
  288. if ((utp = getutxid(&ut)) == NULL) {
  289. my_cluster_node.boot_timestamp = ((SaTimeT)time(NULL)) * NANOSEC;
  290. } else {
  291. my_cluster_node.boot_timestamp = ((SaTimeT)utp->ut_xtime) * NANOSEC;
  292. }
  293. endutxent();
  294. #else
  295. #warning "no bootime support"
  296. #endif
  297. }
  298. cluster_node_count = 1;
  299. //TODO main_clm_get_by_nodeid = clm_get_by_nodeid;
  300. return (0);
  301. }
  302. static int clm_exec_exit_fn (void)
  303. {
  304. return (0);
  305. }
  306. static int clm_lib_exit_fn (void *conn)
  307. {
  308. struct clm_pd *clm_pd = (struct clm_pd *)api->ipc_private_data_get (conn);
  309. /*
  310. * Delete track entry if there is one
  311. */
  312. list_del (&clm_pd->list);
  313. clm_pd->conn = conn;
  314. return (0);
  315. }
  316. static void library_notification_send (
  317. mar_clm_cluster_notification_t *cluster_notification_entries,
  318. int notify_count)
  319. {
  320. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  321. struct clm_pd *clm_pd;
  322. struct list_head *list;
  323. int i;
  324. if (notify_count == 0) {
  325. return;
  326. }
  327. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  328. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  329. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  330. res_lib_clm_clustertrack.view = view_current;
  331. for (list = library_notification_send_listhead.next;
  332. list != &library_notification_send_listhead;
  333. list = list->next) {
  334. clm_pd = list_entry (list, struct clm_pd, list);
  335. /*
  336. * Track current and changes
  337. */
  338. if (clm_pd->track_flags & SA_TRACK_CHANGES) {
  339. /*
  340. * Copy all cluster nodes
  341. */
  342. for (i = 0; i < cluster_node_count; i++) {
  343. memcpy (&res_lib_clm_clustertrack.notification[i].cluster_node,
  344. &cluster_node_entries[i], sizeof (mar_clm_cluster_node_t));
  345. res_lib_clm_clustertrack.notification[i].cluster_change = SA_CLM_NODE_NO_CHANGE;
  346. res_lib_clm_clustertrack.notification[i].cluster_node.member = 1;
  347. }
  348. /*
  349. * Copy change_only notificaiton
  350. */
  351. res_lib_clm_clustertrack.number_of_items = notify_count + i;
  352. memcpy (&res_lib_clm_clustertrack.notification[i],
  353. cluster_notification_entries,
  354. sizeof (mar_clm_cluster_notification_t) * notify_count);
  355. } else
  356. /*
  357. * Track only changes
  358. */
  359. if (clm_pd->track_flags & SA_TRACK_CHANGES_ONLY) {
  360. res_lib_clm_clustertrack.number_of_items = notify_count;
  361. memcpy (&res_lib_clm_clustertrack.notification,
  362. cluster_notification_entries,
  363. sizeof (mar_clm_cluster_notification_t) * notify_count);
  364. }
  365. /*
  366. * Send notifications to all CLM listeners
  367. */
  368. api->ipc_conn_send_response (
  369. clm_pd->conn,
  370. &res_lib_clm_clustertrack,
  371. sizeof (struct res_lib_clm_clustertrack));
  372. }
  373. }
  374. static void notification_join (mar_clm_cluster_node_t *cluster_node)
  375. {
  376. mar_clm_cluster_notification_t notification;
  377. /*
  378. * Generate notification element
  379. */
  380. notification.cluster_change = SA_CLM_NODE_JOINED;
  381. notification.cluster_node.member = 1;
  382. memcpy (&notification.cluster_node, cluster_node,
  383. sizeof (mar_clm_cluster_node_t));
  384. library_notification_send (&notification, 1);
  385. }
  386. static void lib_notification_leave (unsigned int *nodes, int nodes_entries)
  387. {
  388. mar_clm_cluster_notification_t cluster_notification[PROCESSOR_COUNT_MAX];
  389. int i, j;
  390. int notify_count;
  391. /*
  392. * Determine notification list
  393. */
  394. for (notify_count = 0, i = 0; i < cluster_node_count; i++) {
  395. for (j = 0; j < nodes_entries; j++) {
  396. if (cluster_node_entries[i].node_id == nodes[j]) {
  397. memcpy (&cluster_notification[notify_count].cluster_node,
  398. &cluster_node_entries[i],
  399. sizeof (mar_clm_cluster_node_t));
  400. cluster_notification[notify_count].cluster_change = SA_CLM_NODE_LEFT;
  401. cluster_notification[notify_count].cluster_node.member = 0;
  402. notify_count += 1;
  403. break;
  404. }
  405. }
  406. }
  407. /*
  408. * Remove entries from cluster_node_entries array
  409. */
  410. for (i = 0; i < nodes_entries; i++) {
  411. for (j = 0; j < cluster_node_count;) {
  412. if (nodes[i] == cluster_node_entries[j].node_id) {
  413. cluster_node_count -= 1;
  414. memmove (&cluster_node_entries[j], &cluster_node_entries[j + 1],
  415. (cluster_node_count - j) * sizeof (mar_clm_cluster_node_t));
  416. } else {
  417. /*
  418. * next cluster_node entry
  419. */
  420. j++;
  421. }
  422. }
  423. }
  424. library_notification_send (cluster_notification, notify_count);
  425. }
  426. static int clm_nodejoin_send (void)
  427. {
  428. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  429. struct iovec req_exec_clm_iovec;
  430. int result;
  431. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  432. req_exec_clm_nodejoin.header.id =
  433. SERVICE_ID_MAKE (CLM_SERVICE, MESSAGE_REQ_EXEC_CLM_NODEJOIN);
  434. my_cluster_node.initial_view_number = view_initial;
  435. memcpy (&req_exec_clm_nodejoin.cluster_node, &my_cluster_node,
  436. sizeof (mar_clm_cluster_node_t));
  437. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  438. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  439. result = api->totem_mcast (&req_exec_clm_iovec, 1, TOTEM_AGREED);
  440. return (result);
  441. }
  442. static void clm_confchg_fn (
  443. enum totem_configuration_type configuration_type,
  444. unsigned int *member_list, int member_list_entries,
  445. unsigned int *left_list, int left_list_entries,
  446. unsigned int *joined_list, int joined_list_entries,
  447. struct memb_ring_id *ring_id)
  448. {
  449. int i;
  450. unsigned int node_ids[PROCESSOR_COUNT_MAX];
  451. view_current = ring_id->seq / 4;
  452. if (view_initial == 0) {
  453. view_initial = ring_id->seq / 4;
  454. }
  455. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  456. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  457. for (i = 0; i < member_list_entries; i++) {
  458. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", api->totem_ifaces_print (member_list[i]));
  459. }
  460. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  461. for (i = 0; i < left_list_entries; i++) {
  462. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", api->totem_ifaces_print (left_list[i]));
  463. }
  464. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  465. for (i = 0; i < joined_list_entries; i++) {
  466. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", api->totem_ifaces_print (joined_list[i]));
  467. }
  468. for (i = 0; i < left_list_entries; i++) {
  469. node_ids[i] = left_list[i];
  470. }
  471. lib_notification_leave (node_ids, i);
  472. /*
  473. * Load the my_cluster_node data structure in case we are
  474. * transitioning to network interface up or down
  475. */
  476. my_cluster_node_load ();
  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 *)api->ipc_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 *)api->ipc_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. api->ipc_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. api->ipc_conn_send_response (
  590. api->ipc_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 *)api->ipc_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. api->ipc_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. api->ipc_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. api->ipc_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. api->ipc_conn_send_response (api->ipc_conn_partner_get (conn),
  685. &res_clm_nodegetcallback,
  686. sizeof (struct res_clm_nodegetcallback));
  687. }