cluster/cman daemon/ais.c daemon/cnxman-privat ...
CVSROOT: /cvs/cluster
Module name: cluster
Changes by: pcaulfield at sourceware.org 2006-08-17 13:22:40
Modified files:
cman/daemon : ais.c cnxman-private.h cnxman-socket.h
commands.c commands.h daemon.c daemon.h
cman/lib : libcman.c libcman.h
cman/tests : libtest.c
Log message:
Add a confchg callback to libcman, similar to the openAIS ones. this gives a race-free notification of cluster change deltas and will probably simplify client code hugely.
(or it would if most of it hadn't already been written!)
Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/daemon/ais.c.diff?cvsroot=cluster&r1=1.38&r2=1.39
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/daemon/cnxman-private.h.diff?cvsroot=cluster&r1=1.22&r2=1.23
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/daemon/cnxman-socket.h.diff?cvsroot=cluster&r1=1.15&r2=1.16
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/daemon/commands.c.diff?cvsroot=cluster&r1=1.47&r2=1.48
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/daemon/commands.h.diff?cvsroot=cluster&r1=1.12&r2=1.13
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/daemon/daemon.c.diff?cvsroot=cluster&r1=1.30&r2=1.31
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/daemon/daemon.h.diff?cvsroot=cluster&r1=1.5&r2=1.6
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/lib/libcman.c.diff?cvsroot=cluster&r1=1.25&r2=1.26
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/lib/libcman.h.diff?cvsroot=cluster&r1=1.26&r2=1.27
http://sourceware.org/cgi-bin/cvsweb.cgi/cluster/cman/tests/libtest.c.diff?cvsroot=cluster&r1=1.4&r2=1.5
cman/daemon/ais.c +33 -1
@@ -34,6 +34,7 @@#include <openais/service/config.h> #include <openais/lcr/lcr_comp.h> #include <openais/service/swab.h> +#include <openais/service/print.h> #include "cnxman-socket.h" #include "commands.h"
@@ -60,6 +61,7 @@static char errorstring[512 ];static int startup_pipe;static unsigned int debug_mask; +static int first_trans =1 ;static struct objdb_iface_ver0 *global_objdb;static totempg_groups_handle group_handle;static struct totempg_group cman_group[1 ] = {
@@ -390,6 +392,9 @@ {int i;static int last_memb_count =0 ; +static int saved_left_list_entries; +static int saved_left_list_size; +static unsigned int *saved_left_list =NULL ;P_AIS ("confchg_fn called type = %d, seq=%lld\n" , configuration_type, ring_id->seq);
@@ -401,10 +406,37 @@for (i=0 ; i<joined_list_entries; i++)add_ais_node (joined_list[i], incarnation, member_list_entries); +/* Save the left list for later so we can do a consolidated confchg message */ +if (configuration_type ==TOTEM_CONFIGURATION_TRANSITIONAL ) { +if (saved_left_list ==NULL ) { + saved_left_list_size = left_list_entries*2 ; + saved_left_list =malloc (sizeof (int ) * saved_left_list_size); +if (!saved_left_list) { +log_printf (LOG_LEVEL_CRIT ,"cannot allocate memory for confchg message" ); +exit (3 ); + } + } +if (saved_left_list_size < left_list_entries) { + saved_left_list_size = left_list_entries*2 ; + saved_left_list =realloc (saved_left_list,sizeof (int ) * saved_left_list_size); +if (!saved_left_list) { +log_printf (LOG_LEVEL_CRIT ,"cannot reallocate memory for confchg message" ); +exit (3 ); + } + } + saved_left_list_entries = left_list_entries; +memcpy (saved_left_list, left_list, left_list_entries *sizeof (int )); + } +if (configuration_type ==TOTEM_CONFIGURATION_REGULAR ) {P_AIS ("last memb_count = %d, current = %d\n" , last_memb_count, member_list_entries); -send_transition_msg (last_memb_count); +send_transition_msg (last_memb_count, first_trans); last_memb_count = member_list_entries; + first_trans =0 ; + +cman_send_confchg (member_list, member_list_entries, + saved_left_list, saved_left_list_entries, + joined_list, joined_list_entries); } }
cman/daemon/cnxman-private.h +2 -1
@@ -70,7 +70,7 @@struct cl_transmsg {unsigned char cmd; -unsigned char pad; +unsigned char first_trans;uint16_t cluster_id;int high_nodeid;int expected_votes;
@@ -129,6 +129,7 @@uint32_t port;/* If bound client */ enum {SHUTDOWN_REPLY_UNK =0 ,SHUTDOWN_REPLY_YES ,SHUTDOWN_REPLY_NO } shutdown_reply;uint32_t events;/* Registered for events */ +uint32_t confchg;/* Registered for confchg */ struct list write_msgs;/* Queued messages to go to data clients */ struct cl_comms_socket *clsock;struct connection *next;
cman/daemon/cnxman-socket.h +12 -0
@@ -50,10 +50,13 @@#define CMAN_CMD_UPDATE_FENCE_INFO 0x800000bd#define CMAN_CMD_GET_FENCE_INFO 0x000000be#define CMAN_CMD_GET_NODEADDRS 0x000000bf +#define CMAN_CMD_START_CONFCHG 0x000000c0 +#define CMAN_CMD_STOP_CONFCHG 0x000000c1#define CMAN_CMD_DATA 0x00000100#define CMAN_CMD_BIND 0x00000101#define CMAN_CMD_EVENT 0x00000102 +#define CMAN_CMD_CONFCHG 0x00000103#define CMAN_CMDFLAG_PRIV 0x80000000#define CMAN_CMDFLAG_REPLY 0x40000000
@@ -150,6 +153,15 @@int arg; }; +/* confchg message */ +struct sock_confchg_message { +struct sock_header header; +int member_entries; +int left_entries; +int joined_entries; +unsigned int entries[];// In above order. +}; +/* Flags */ #define CMAN_EXTRA_FLAG_2NODE 1#define CMAN_EXTRA_FLAG_ERROR 2
cman/daemon/commands.c +40 -1
71 lines not on this page · raw message
cman/daemon/commands.h +6 -1
@@ -24,12 +24,17 @@extern void commands_init (void );extern int process_command (struct connection *con,int cmd,char *cmdbuf,char **retbuf,int *retlen,int retsize,int offset); -extern void send_transition_msg (int last_memb_count); +extern void send_transition_msg (int last_memb_count,int first_trans);extern void add_ais_node (int nodeid,uint64_t incarnation,int total_members);extern void del_ais_node (int nodeid);extern void add_ccs_node (char *name,int nodeid,int votes,int expected_votes);extern void override_expected (int expected); +extern void cman_send_confchg (unsigned int *member_list,int member_list_entries, +unsigned int *left_list,int left_list_entries, +unsigned int *joined_list,int joined_list_entries); + +/* Startup stuff called from cmanccs: */ extern int cman_set_nodename (char *name);
cman/daemon/daemon.c +10 -0
@@ -412,6 +412,16 @@ } } +void notify_confchg (struct sock_header *message) +{ +struct connection *thiscon; + + list_iterate_items(thiscon, &client_list) { +if (thiscon->confchg) +send_reply_message (thiscon, message); + } +} +void wake_daemon (void ) {P_DAEMON ("Wake daemon called\n" );
cman/daemon/daemon.h +1 -1
@@ -18,7 +18,7 @@extern void cman_set_realtime (void );extern int cman_init (void );extern int cman_finish (void ); - +extern void notify_confchg (struct sock_header *message);extern volatile sig_atomic_t quit_threads;extern int num_connections;
cman/lib/libcman.c +44 -4
74 lines not on this page · raw message
cman/lib/libcman.h +14 -0
@@ -181,6 +181,11 @@ char *buf, int len, uint8_t port, int nodeid); +typedef void (*cman_confchgcallback_t )(cman_handle_t handle,void *private, +unsigned int *member_list,int member_list_entries, +unsigned int *left_list,int left_list_entries, +unsigned int *joined_list,int joined_list_entries); +/* * cman_init returns the handle you need to pass to the other API calls. * cman_admin_init opens admin socket for privileged operations.
@@ -203,6 +208,15 @@int cman_start_notification (cman_handle_t handle,cman_callback_t callback);int cman_stop_notification (cman_handle_t handle); +/* +* Start/stop AIS-style confchg callbacks. These are less racy than the +* old cman callbacks in that the caller will get one for each AIS +* confchg message and it will contain all of the nodes that joined & +* left in that transition. +*/ +int cman_start_confchg (cman_handle_t handle,cman_confchgcallback_t callback); +int cman_stop_confchg (cman_handle_t handle); +/* Call this if you get a TRY_SHUTDOWN event to signal whether you * will let cman shutdown or not. */
cman/tests/libtest.c +26 -1
@@ -10,6 +10,24 @@printf ("callback called reason = %d, arg=%d\n" , reason, arg); } +static void confchg_callback (cman_handle_t handle,void *private, +unsigned int *member_list,int member_list_entries, +unsigned int *left_list,int left_list_entries, +unsigned int *joined_list,int joined_list_entries) +{ +int i; +printf ("Confchg callback\n" ); +printf ("member_list: %d entries:\n" , member_list_entries); +for (i=0 ; i<member_list_entries; i++) +printf (" %d\n" , member_list[i]); +printf ("left_list: %d entries:\n" , left_list_entries); +for (i=0 ; i<left_list_entries; i++) +printf (" %d\n" , left_list[i]); +printf ("joined_list: %d entries:\n" , joined_list_entries); +for (i=0 ; i<joined_list_entries; i++) +printf (" %d\n" , joined_list[i]); +} +static void print_node (cman_node_t *node) {printf (" node id %d\n" , node->cn_nodeid);
@@ -87,10 +105,17 @@perror ("get_node failed" ); } -if (!cman_start_notification (h, cman_callback)) +if (cman_start_notification (h, cman_callback)) {perror ("start_notification" ); } + +if (cman_start_confchg (h, confchg_callback)) + { +perror ("start_confchg" ); + } + +while (1 ) {int ret =cman_dispatch (h,CMAN_DISPATCH_BLOCKING |CMAN_DISPATCH_ALL );if (ret ==-1 ) {