clm.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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 = (unsigned char*)"openais cluster membership service B.01.01",
  175. .id = CLM_SERVICE,
  176. .private_data_size = sizeof (struct clm_pd),
  177. .lib_init_fn = clm_lib_init_fn,
  178. .lib_exit_fn = clm_lib_exit_fn,
  179. .lib_service = clm_lib_service,
  180. .lib_service_count = sizeof (clm_lib_service) / sizeof (struct openais_lib_handler),
  181. .exec_init_fn = clm_exec_init_fn,
  182. .exec_dump_fn = NULL,
  183. .exec_service = clm_exec_service,
  184. .exec_service_count = sizeof (clm_exec_service) / sizeof (struct openais_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 openais_service_handler *clm_get_service_handler_ver0 (void);
  195. static struct openais_service_handler_iface_ver0 clm_service_handler_iface = {
  196. .openais_get_service_handler_ver0 = clm_get_service_handler_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 openais_service_handler *clm_get_service_handler_ver0 (void)
  216. {
  217. return (&clm_service_handler);
  218. }
  219. __attribute__ ((constructor)) static void clm_comp_register (void) {
  220. lcr_interfaces_set (&openais_clm_ver0[0], &clm_service_handler_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 int clm_exec_init_fn (struct objdb_iface_ver0 *objdb)
  228. {
  229. log_init ("CLM");
  230. memset (cluster_node_entries, 0,
  231. sizeof (mar_clm_cluster_node_t) * PROCESSOR_COUNT_MAX);
  232. /*
  233. * Build local cluster node data structure
  234. */
  235. sprintf ((char *)my_cluster_node.node_address.value, "%s",
  236. totemip_print (this_ip));
  237. my_cluster_node.node_address.length =
  238. strlen ((char *)my_cluster_node.node_address.value);
  239. if (this_ip->family == AF_INET) {
  240. my_cluster_node.node_address.family = SA_CLM_AF_INET;
  241. } else
  242. if (this_ip->family == AF_INET6) {
  243. my_cluster_node.node_address.family = SA_CLM_AF_INET6;
  244. } else {
  245. assert (0);
  246. }
  247. strcpy ((char *)my_cluster_node.node_name.value,
  248. (char *)my_cluster_node.node_address.value);
  249. my_cluster_node.node_name.length =
  250. my_cluster_node.node_address.length;
  251. my_cluster_node.node_id = this_ip->nodeid;
  252. my_cluster_node.member = 1;
  253. {
  254. #ifndef NANOSEC
  255. #define NANOSEC 1000000000
  256. #endif
  257. #if defined(OPENAIS_LINUX)
  258. struct sysinfo s_info;
  259. time_t current_time;
  260. sysinfo (&s_info);
  261. current_time = time (NULL);
  262. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  263. my_cluster_node.boot_timestamp = ((SaTimeT)(current_time - s_info.uptime)) * NANOSEC;
  264. #elif defined(OPENAIS_BSD) || defined(OPENAIS_DARWIN)
  265. int mib[2] = { CTL_KERN, KERN_BOOTTIME };
  266. struct timeval boot_time;
  267. size_t size = sizeof(boot_time);
  268. if ( sysctl(mib, 2, &boot_time, &size, NULL, 0) == -1 )
  269. boot_time.tv_sec = time (NULL);
  270. /* (currenttime (s) - uptime (s)) * 1 billion (ns) / 1 (s) */
  271. my_cluster_node.boot_timestamp = ((SaTimeT)boot_time.tv_sec) * NANOSEC;
  272. #elif defined(OPENAIS_SOLARIS)
  273. struct utmpx ut, *utp;
  274. ut.ut_type = BOOT_TIME;
  275. setutxent();
  276. if ((utp = getutxid(&ut)) == NULL) {
  277. my_cluster_node.boot_timestamp = ((SaTimeT)time(NULL)) * NANOSEC;
  278. } else {
  279. my_cluster_node.boot_timestamp = ((SaTimeT)utp->ut_xtime) * NANOSEC;
  280. }
  281. endutxent();
  282. #else
  283. #warning "no bootime support"
  284. #endif
  285. }
  286. memcpy (&cluster_node_entries[0], &my_cluster_node, sizeof (mar_clm_cluster_node_t));
  287. cluster_node_count = 1;
  288. main_clm_get_by_nodeid = clm_get_by_nodeid;
  289. return (0);
  290. }
  291. static int clm_lib_exit_fn (void *conn)
  292. {
  293. struct clm_pd *clm_pd = (struct clm_pd *)openais_conn_private_data_get (conn);
  294. /*
  295. * Delete track entry if there is one
  296. */
  297. list_del (&clm_pd->list);
  298. clm_pd->conn = conn;
  299. return (0);
  300. }
  301. static void library_notification_send (
  302. mar_clm_cluster_notification_t *cluster_notification_entries,
  303. int notify_count)
  304. {
  305. struct res_lib_clm_clustertrack res_lib_clm_clustertrack;
  306. struct clm_pd *clm_pd;
  307. struct list_head *list;
  308. int i;
  309. if (notify_count == 0) {
  310. return;
  311. }
  312. res_lib_clm_clustertrack.header.size = sizeof (struct res_lib_clm_clustertrack);
  313. res_lib_clm_clustertrack.header.id = MESSAGE_RES_CLM_TRACKCALLBACK;
  314. res_lib_clm_clustertrack.header.error = SA_AIS_OK;
  315. res_lib_clm_clustertrack.view = view_current;
  316. for (list = library_notification_send_listhead.next;
  317. list != &library_notification_send_listhead;
  318. list = list->next) {
  319. clm_pd = list_entry (list, struct clm_pd, list);
  320. /*
  321. * Track current and changes
  322. */
  323. if (clm_pd->track_flags & SA_TRACK_CHANGES) {
  324. /*
  325. * Copy all cluster nodes
  326. */
  327. for (i = 0; i < cluster_node_count; i++) {
  328. memcpy (&res_lib_clm_clustertrack.notification[i].cluster_node,
  329. &cluster_node_entries[i], sizeof (mar_clm_cluster_node_t));
  330. res_lib_clm_clustertrack.notification[i].cluster_change = SA_CLM_NODE_NO_CHANGE;
  331. res_lib_clm_clustertrack.notification[i].cluster_node.member = 1;
  332. }
  333. /*
  334. * Copy change_only notificaiton
  335. */
  336. res_lib_clm_clustertrack.number_of_items = notify_count + i;
  337. memcpy (&res_lib_clm_clustertrack.notification[i],
  338. cluster_notification_entries,
  339. sizeof (mar_clm_cluster_notification_t) * notify_count);
  340. } else
  341. /*
  342. * Track only changes
  343. */
  344. if (clm_pd->track_flags & SA_TRACK_CHANGES_ONLY) {
  345. res_lib_clm_clustertrack.number_of_items = notify_count;
  346. memcpy (&res_lib_clm_clustertrack.notification,
  347. cluster_notification_entries,
  348. sizeof (mar_clm_cluster_notification_t) * notify_count);
  349. }
  350. /*
  351. * Send notifications to all CLM listeners
  352. */
  353. openais_conn_send_response (
  354. clm_pd->conn,
  355. &res_lib_clm_clustertrack,
  356. sizeof (struct res_lib_clm_clustertrack));
  357. }
  358. }
  359. static void notification_join (mar_clm_cluster_node_t *cluster_node)
  360. {
  361. mar_clm_cluster_notification_t notification;
  362. /*
  363. * Generate notification element
  364. */
  365. notification.cluster_change = SA_CLM_NODE_JOINED;
  366. notification.cluster_node.member = 1;
  367. memcpy (&notification.cluster_node, cluster_node,
  368. sizeof (mar_clm_cluster_node_t));
  369. library_notification_send (&notification, 1);
  370. }
  371. static void lib_notification_leave (unsigned int *nodes, int nodes_entries)
  372. {
  373. mar_clm_cluster_notification_t cluster_notification[PROCESSOR_COUNT_MAX];
  374. int i, j;
  375. int notify_count;
  376. /*
  377. * Determine notification list
  378. */
  379. for (notify_count = 0, i = 0; i < cluster_node_count; i++) {
  380. for (j = 0; j < nodes_entries; j++) {
  381. if (cluster_node_entries[i].node_id == nodes[j]) {
  382. memcpy (&cluster_notification[notify_count].cluster_node,
  383. &cluster_node_entries[i],
  384. sizeof (mar_clm_cluster_node_t));
  385. cluster_notification[notify_count].cluster_change = SA_CLM_NODE_LEFT;
  386. cluster_notification[notify_count].cluster_node.member = 0;
  387. notify_count += 1;
  388. break;
  389. }
  390. }
  391. }
  392. /*
  393. * Remove entries from cluster_node_entries array
  394. */
  395. for (i = 0; i < nodes_entries; i++) {
  396. for (j = 0; j < cluster_node_count;) {
  397. if (nodes[i] == cluster_node_entries[j].node_id) {
  398. cluster_node_count -= 1;
  399. memmove (&cluster_node_entries[j], &cluster_node_entries[j + 1],
  400. (cluster_node_count - j) * sizeof (mar_clm_cluster_node_t));
  401. } else {
  402. /*
  403. * next cluster_node entry
  404. */
  405. j++;
  406. }
  407. }
  408. }
  409. library_notification_send (cluster_notification, notify_count);
  410. }
  411. static int clm_nodejoin_send (void)
  412. {
  413. struct req_exec_clm_nodejoin req_exec_clm_nodejoin;
  414. struct iovec req_exec_clm_iovec;
  415. int result;
  416. req_exec_clm_nodejoin.header.size = sizeof (struct req_exec_clm_nodejoin);
  417. req_exec_clm_nodejoin.header.id =
  418. SERVICE_ID_MAKE (CLM_SERVICE, MESSAGE_REQ_EXEC_CLM_NODEJOIN);
  419. my_cluster_node.initial_view_number = view_initial;
  420. memcpy (&req_exec_clm_nodejoin.cluster_node, &my_cluster_node,
  421. sizeof (mar_clm_cluster_node_t));
  422. req_exec_clm_iovec.iov_base = (char *)&req_exec_clm_nodejoin;
  423. req_exec_clm_iovec.iov_len = sizeof (req_exec_clm_nodejoin);
  424. result = totempg_groups_mcast_joined (openais_group_handle, &req_exec_clm_iovec, 1, TOTEMPG_AGREED);
  425. return (result);
  426. }
  427. static void clm_confchg_fn (
  428. enum totem_configuration_type configuration_type,
  429. unsigned int *member_list, int member_list_entries,
  430. unsigned int *left_list, int left_list_entries,
  431. unsigned int *joined_list, int joined_list_entries,
  432. struct memb_ring_id *ring_id)
  433. {
  434. int i;
  435. unsigned int node_ids[PROCESSOR_COUNT_MAX];
  436. view_current = ring_id->seq / 4;
  437. if (view_initial == 0) {
  438. view_initial = ring_id->seq / 4;
  439. }
  440. log_printf (LOG_LEVEL_NOTICE, "CLM CONFIGURATION CHANGE\n");
  441. log_printf (LOG_LEVEL_NOTICE, "New Configuration:\n");
  442. for (i = 0; i < member_list_entries; i++) {
  443. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (member_list[i]));
  444. }
  445. log_printf (LOG_LEVEL_NOTICE, "Members Left:\n");
  446. for (i = 0; i < left_list_entries; i++) {
  447. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (left_list[i]));
  448. }
  449. log_printf (LOG_LEVEL_NOTICE, "Members Joined:\n");
  450. for (i = 0; i < joined_list_entries; i++) {
  451. log_printf (LOG_LEVEL_NOTICE, "\t%s\n", totempg_ifaces_print (joined_list[i]));
  452. }
  453. for (i = 0; i < left_list_entries; i++) {
  454. node_ids[i] = left_list[i];
  455. }
  456. lib_notification_leave (node_ids, i);
  457. /*
  458. * Load the my_cluster_node data structure in case we are
  459. * transitioning to network interface up or down
  460. */
  461. sprintf ((char *)my_cluster_node.node_address.value, "%s", totemip_print (this_ip));
  462. my_cluster_node.node_address.length = strlen ((char *)my_cluster_node.node_address.value);
  463. if (this_ip->family == AF_INET) {
  464. my_cluster_node.node_address.family = SA_CLM_AF_INET;
  465. } else
  466. if (this_ip->family == AF_INET6) {
  467. my_cluster_node.node_address.family = SA_CLM_AF_INET6;
  468. } else {
  469. assert (0);
  470. }
  471. strcpy ((char *)my_cluster_node.node_name.value,
  472. (char *)my_cluster_node.node_address.value);
  473. my_cluster_node.node_name.length = my_cluster_node.node_address.length;
  474. my_cluster_node.node_id = this_ip->nodeid;
  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. }