diff --git a/WHATS_NEW b/WHATS_NEW index 4859e3cdd..c9c0579e7 100644 --- a/WHATS_NEW +++ b/WHATS_NEW @@ -3,6 +3,7 @@ Version 2.02.03 - Propagate partial mode around cluster. Fix archive file expiration. Fix dmeventd build. + clvmd now uses libcman rather than cman ioctls. Version 2.02.02 - 7th February 2006 =================================== diff --git a/daemons/clvmd/Makefile.in b/daemons/clvmd/Makefile.in index fa1b362ef..aeb7da84b 100644 --- a/daemons/clvmd/Makefile.in +++ b/daemons/clvmd/Makefile.in @@ -46,17 +46,17 @@ endif ifeq ("$(CMAN)", "yes") SOURCES += clvmd-cman.c - LMLIBS += -ldlm + LMLIBS += -ldlm -lcman CFLAGS += -DUSE_CMAN endif TARGETS = \ clvmd -LVMLIBS = -llvm +LVMLIBS = -llvm -lpthread ifeq ("@DMEVENTD@", "yes") - LVMLIBS += -ldevmapper-event -lpthread + LVMLIBS += -ldevmapper-event endif ifeq ("@DEVMAPPER@", "yes") diff --git a/daemons/clvmd/clvmd-cman.c b/daemons/clvmd/clvmd-cman.c index 2d9214d89..024762193 100644 --- a/daemons/clvmd/clvmd-cman.c +++ b/daemons/clvmd/clvmd-cman.c @@ -46,19 +46,23 @@ #define LOCKSPACE_NAME "clvmd" -static int cluster_sock; static int num_nodes; -static struct cl_cluster_node *nodes = NULL; +static struct cman_node *nodes = NULL; +static struct cman_node this_node; static int count_nodes; /* size of allocated nodes array */ static int max_updown_nodes = 50; /* Current size of the allocated array */ /* Node up/down status, indexed by nodeid */ static int *node_updown = NULL; static dlm_lshandle_t *lockspace; +static cman_handle_t c_handle; static void count_clvmds_running(void); static void get_members(void); static int nodeid_from_csid(char *csid); static int name_from_nodeid(int nodeid, char *name); +static void event_callback(cman_handle_t handle, void *private, int reason, int arg); +static void data_callback(cman_handle_t handle, void *private, + char *buf, int len, uint8_t port, int nodeid); struct lock_wait { pthread_cond_t cond; @@ -68,30 +72,23 @@ struct lock_wait { static int _init_cluster(void) { - struct sockaddr_cl saddr; - int port = CLUSTER_PORT_CLVMD; - /* Open the cluster communication socket */ - cluster_sock = socket(AF_CLUSTER, SOCK_DGRAM, CLPROTO_CLIENT); - if (cluster_sock == -1) { - /* Don't print an error here because we could be just probing for CMAN */ + c_handle = cman_init(NULL); + if (!c_handle) { + syslog(LOG_ERR, "Can't open cluster manager socket: %m"); return -1; } - /* Set Close-on-exec */ - fcntl(cluster_sock, F_SETFD, 1); - /* Bind to our port number on the cluster. - Writes to this will block if the cluster loses quorum */ - saddr.scl_family = AF_CLUSTER; - saddr.scl_port = port; - - if (bind - (cluster_sock, (struct sockaddr *) &saddr, - sizeof(struct sockaddr_cl))) { + if (cman_start_recv_data(c_handle, data_callback, CLUSTER_PORT_CLVMD)) { syslog(LOG_ERR, "Can't bind cluster socket: %m"); return -1; } + if (cman_start_notification(c_handle, event_callback)) { + syslog(LOG_ERR, "Can't start cluster event listening"); + return -1; + } + /* Get the cluster members list */ get_members(); count_clvmds_running(); @@ -114,63 +111,46 @@ static void _cluster_init_completed(void) static int _get_main_cluster_fd() { - return cluster_sock; + return cman_get_fd(c_handle); } static int _get_num_nodes() { - return num_nodes; + int i; + int nnodes = 0; + + /* return number of ACTIVE nodes */ + for (i=0; i count_nodes && nodes) { free(nodes); @@ -341,28 +294,19 @@ static void get_members() if (nodes == NULL) { count_nodes = num_nodes + 10; /* Overallocate a little */ - nodes = malloc(count_nodes * sizeof(struct cl_cluster_node)); + nodes = malloc(count_nodes * sizeof(struct cman_node)); if (!nodes) { log_error("Unable to allocate nodes array\n"); exit(5); } } - nodelist.max_members = count_nodes; - nodelist.nodes = nodes; - num_nodes = ioctl(cluster_sock, SIOCCLUSTER_GETMEMBERS, &nodelist); - if (num_nodes <= 0) { + status = cman_get_nodes(c_handle, count_nodes, &retnodes, nodes); + if (status < 0) { log_error("Unable to get node details"); exit(6); } - /* Sanity check struct */ - if (nodes[0].size != sizeof(struct cl_cluster_node)) { - log_error - ("sizeof(cl_cluster_node) does not match size returned from the kernel: aborting\n"); - exit(10); - } - if (node_updown == NULL) { node_updown = (int *) malloc(sizeof(int) * @@ -371,7 +315,6 @@ static void get_members() sizeof(int) * max(num_nodes, max_updown_nodes)); } } -} /* Convert a node name to a CSID */ static int _csid_from_name(char *csid, char *name) @@ -379,8 +322,8 @@ static int _csid_from_name(char *csid, char *name) int i; for (i = 0; i < num_nodes; i++) { - if (strcmp(name, nodes[i].name) == 0) { - memcpy(csid, &nodes[i].node_id, CMAN_MAX_CSID_LEN); + if (strcmp(name, nodes[i].cn_name) == 0) { + memcpy(csid, &nodes[i].cn_nodeid, CMAN_MAX_CSID_LEN); return 0; } } @@ -393,8 +336,8 @@ static int _name_from_csid(char *csid, char *name) int i; for (i = 0; i < num_nodes; i++) { - if (memcmp(csid, &nodes[i].node_id, CMAN_MAX_CSID_LEN) == 0) { - strcpy(name, nodes[i].name); + if (memcmp(csid, &nodes[i].cn_nodeid, CMAN_MAX_CSID_LEN) == 0) { + strcpy(name, nodes[i].cn_name); return 0; } } @@ -409,8 +352,8 @@ static int name_from_nodeid(int nodeid, char *name) int i; for (i = 0; i < num_nodes; i++) { - if (nodeid == nodes[i].node_id) { - strcpy(name, nodes[i].name); + if (nodeid == nodes[i].cn_nodeid) { + strcpy(name, nodes[i].cn_name); return 0; } } @@ -431,7 +374,7 @@ static int nodeid_from_csid(char *csid) static int _is_quorate() { - return ioctl(cluster_sock, SIOCCLUSTER_ISQUORATE, 0); + return cman_is_quorate(c_handle); } static void sync_ast_routine(void *arg) diff --git a/daemons/clvmd/clvmd-comms.h b/daemons/clvmd/clvmd-comms.h index 5b99bf4c8..b4e62a976 100644 --- a/daemons/clvmd/clvmd-comms.h +++ b/daemons/clvmd/clvmd-comms.h @@ -56,15 +56,18 @@ struct cluster_ops *init_gulm_cluster(void); #endif #ifdef USE_CMAN -# include "cnxman-socket.h" +# include "libcman.h" # define CMAN_MAX_CSID_LEN 4 # ifndef MAX_CSID_LEN # define MAX_CSID_LEN CMAN_MAX_CSID_LEN # endif # undef MAX_CLUSTER_MEMBER_NAME_LEN -# define MAX_CLUSTER_MEMBER_NAME_LEN CMAN_MAX_CLUSTER_MEMBER_NAME_LEN +# define MAX_CLUSTER_MEMBER_NAME_LEN CMAN_MAX_NODENAME_LEN +# define CMAN_MAX_CLUSTER_MESSAGE 1500 +# define CLUSTER_PORT_CLVMD 11 struct cluster_ops *init_cman_cluster(void); #endif + #endif diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c index b9e2c8718..7832ccf14 100644 --- a/daemons/clvmd/clvmd.c +++ b/daemons/clvmd/clvmd.c @@ -247,7 +247,7 @@ int main(int argc, char *argv[]) if ((clops = init_cman_cluster())) { max_csid_len = CMAN_MAX_CSID_LEN; max_cluster_message = CMAN_MAX_CLUSTER_MESSAGE; - max_cluster_member_name_len = CMAN_MAX_CLUSTER_MEMBER_NAME_LEN; + max_cluster_member_name_len = CMAN_MAX_NODENAME_LEN; syslog(LOG_NOTICE, "Cluster LVM daemon started - connected to CMAN"); } #endif @@ -509,6 +509,7 @@ static void main_loop(int local_sock, int cmd_timeout) int quorate = clops->is_quorate(); /* Wait on the cluster FD and all local sockets/pipes */ + local_client_head.fd = clops->get_main_cluster_fd(); FD_ZERO(&in); for (thisfd = &local_client_head; thisfd != NULL; thisfd = thisfd->next) {