summaryrefslogtreecommitdiffstats
path: root/daemons/clvmd
diff options
context:
space:
mode:
authorPatrick Caulfield <pcaulfie@redhat.com>2005-01-13 13:24:02 +0000
committerPatrick Caulfield <pcaulfie@redhat.com>2005-01-13 13:24:02 +0000
commit5c7fc7c4f7b0d489512ccf11f3301ca50da5272a (patch)
treeeb3960b32901fceb994d73cf6683e77e5c6ca8bd /daemons/clvmd
parente9c761b86958a37361f76e2c16285720744130cb (diff)
downloadlvm2-5c7fc7c4f7b0d489512ccf11f3301ca50da5272a.tar.gz
lvm2-5c7fc7c4f7b0d489512ccf11f3301ca50da5272a.tar.xz
lvm2-5c7fc7c4f7b0d489512ccf11f3301ca50da5272a.zip
You can now build clvmd with cman & gulm support in the same binary.
./configure --with-clvmd wil do this by default. Or you can choose which you want with ./configure --with-clvmd=gulm or ./configure --with-clvmd=cman When clvmd with both included is run, it will automatically detect the cluster manager in use.
Diffstat (limited to 'daemons/clvmd')
-rw-r--r--daemons/clvmd/Makefile.in16
-rw-r--r--daemons/clvmd/clvmd-cman.c73
-rw-r--r--daemons/clvmd/clvmd-comms.h52
-rw-r--r--daemons/clvmd/clvmd-gulm.c109
-rw-r--r--daemons/clvmd/clvmd-gulm.h3
-rw-r--r--daemons/clvmd/clvmd.c97
-rw-r--r--daemons/clvmd/clvmd.h6
-rw-r--r--daemons/clvmd/cnxman-socket.h6
-rw-r--r--daemons/clvmd/system-lv.c2
-rw-r--r--daemons/clvmd/tcp-comms.c54
-rw-r--r--daemons/clvmd/tcp-comms.h10
11 files changed, 288 insertions, 140 deletions
diff --git a/daemons/clvmd/Makefile.in b/daemons/clvmd/Makefile.in
index 0fbd18f1..e09e87c2 100644
--- a/daemons/clvmd/Makefile.in
+++ b/daemons/clvmd/Makefile.in
@@ -23,14 +23,28 @@ SOURCES = \
system-lv.c
ifeq ("@CLVMD@", "gulm")
+ GULM = yes
+endif
+
+ifeq ("@CLVMD@", "cman")
+ CMAN = yes
+endif
+
+ifeq ("@CLVMD@", "all")
+ GULM = yes
+ CMAN = yes
+endif
+
+ifeq ("$(GULM)", "yes")
SOURCES += clvmd-gulm.c tcp-comms.c
LMLIBS += -lccs -lgulm
CFLAGS += -DUSE_GULM
endif
-ifeq ("@CLVMD@", "cman")
+ifeq ("$(CMAN)", "yes")
SOURCES += clvmd-cman.c
LMLIBS += -ldlm
+ CFLAGS += -DUSE_CMAN
endif
TARGETS = \
diff --git a/daemons/clvmd/clvmd-cman.c b/daemons/clvmd/clvmd-cman.c
index 056ce905..3f8c7027 100644
--- a/daemons/clvmd/clvmd-cman.c
+++ b/daemons/clvmd/clvmd-cman.c
@@ -66,7 +66,7 @@ struct lock_wait {
struct dlm_lksb lksb;
};
-int init_cluster()
+static int _init_cluster(void)
{
struct sockaddr_cl saddr;
int port = CLUSTER_PORT_CLVMD;
@@ -74,7 +74,7 @@ int init_cluster()
/* Open the cluster communication socket */
cluster_sock = socket(AF_CLUSTER, SOCK_DGRAM, CLPROTO_CLIENT);
if (cluster_sock == -1) {
- syslog(LOG_ERR, "Can't open cluster manager socket: %m");
+ syslog(LOG_ERR, "Can't open cman cluster manager socket: %m");
return -1;
}
@@ -104,18 +104,18 @@ int init_cluster()
return 0;
}
-int get_main_cluster_fd()
+static int _get_main_cluster_fd()
{
return cluster_sock;
}
-int get_num_nodes()
+static int _get_num_nodes()
{
return num_nodes;
}
/* send_message with the fd check removed */
-int cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
+static int _cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
{
struct iovec iov[2];
struct msghdr msg;
@@ -135,7 +135,7 @@ int cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
if (csid) {
msg.msg_name = &saddr;
msg.msg_namelen = sizeof(saddr);
- memcpy(&saddr.scl_nodeid, csid, MAX_CSID_LEN);
+ memcpy(&saddr.scl_nodeid, csid, CMAN_MAX_CSID_LEN);
} else { /* Cluster broadcast */
msg.msg_name = NULL;
@@ -151,26 +151,26 @@ int cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
return len;
}
-void get_our_csid(char *csid)
+static void _get_our_csid(char *csid)
{
int i;
- memset(csid, 0, MAX_CSID_LEN);
+ memset(csid, 0, CMAN_MAX_CSID_LEN);
for (i = 0; i < num_nodes; i++) {
if (nodes[i].us)
- memcpy(csid, &nodes[i].node_id, MAX_CSID_LEN);
+ memcpy(csid, &nodes[i].node_id, CMAN_MAX_CSID_LEN);
}
}
/* Call a callback routine for each node that known (down mean not running a clvmd) */
-int cluster_do_node_callback(struct local_client *client,
+static int _cluster_do_node_callback(struct local_client *client,
void (*callback) (struct local_client *, char *,
int))
{
int i;
int somedown = 0;
- for (i = 0; i < get_num_nodes(); i++) {
+ for (i = 0; i < _get_num_nodes(); i++) {
callback(client, (char *)&nodes[i].node_id, node_updown[nodes[i].node_id]);
if (!node_updown[nodes[i].node_id])
somedown = -1;
@@ -202,7 +202,7 @@ static void process_oob_msg(char *buf, int len, int nodeid)
}
}
-int cluster_fd_callback(struct local_client *client, char *buf, int len, char *csid,
+static int _cluster_fd_callback(struct local_client *client, char *buf, int len, char *csid,
struct local_client **new_client)
{
struct iovec iov[2];
@@ -254,7 +254,7 @@ int cluster_fd_callback(struct local_client *client, char *buf, int len, char *c
return len;
}
-void add_up_node(char *csid)
+static void _add_up_node(char *csid)
{
/* It's up ! */
int nodeid = nodeid_from_csid(csid);
@@ -278,7 +278,7 @@ void add_up_node(char *csid)
DEBUGLOG("Added new node %d to updown list\n", nodeid);
}
-void cluster_closedown()
+static void _cluster_closedown()
{
unlock_all();
dlm_release_lockspace(LOCKSPACE_NAME, lockspace, 1);
@@ -307,7 +307,7 @@ static int is_listening(int nodeid)
/* Populate the list of CLVMDs running.
called only at startup time */
-void count_clvmds_running(void)
+static void count_clvmds_running(void)
{
int i;
@@ -366,13 +366,13 @@ static void get_members()
}
/* Convert a node name to a CSID */
-int csid_from_name(char *csid, char *name)
+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, MAX_CSID_LEN);
+ memcpy(csid, &nodes[i].node_id, CMAN_MAX_CSID_LEN);
return 0;
}
}
@@ -380,12 +380,12 @@ int csid_from_name(char *csid, char *name)
}
/* Convert a CSID to a node name */
-int name_from_csid(char *csid, char *name)
+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, MAX_CSID_LEN) == 0) {
+ if (memcmp(csid, &nodes[i].node_id, CMAN_MAX_CSID_LEN) == 0) {
strcpy(name, nodes[i].name);
return 0;
}
@@ -396,7 +396,7 @@ int name_from_csid(char *csid, char *name)
}
/* Convert a node ID to a node name */
-int name_from_nodeid(int nodeid, char *name)
+static int name_from_nodeid(int nodeid, char *name)
{
int i;
@@ -416,12 +416,12 @@ static int nodeid_from_csid(char *csid)
{
int nodeid;
- memcpy(&nodeid, csid, MAX_CSID_LEN);
+ memcpy(&nodeid, csid, CMAN_MAX_CSID_LEN);
return nodeid;
}
-int is_quorate()
+static int _is_quorate()
{
return ioctl(cluster_sock, SIOCCLUSTER_ISQUORATE, 0);
}
@@ -435,7 +435,7 @@ static void sync_ast_routine(void *arg)
pthread_mutex_unlock(&lwait->mutex);
}
-int sync_lock(const char *resource, int mode, int flags, int *lockid)
+static int _sync_lock(const char *resource, int mode, int flags, int *lockid)
{
int status;
struct lock_wait lwait;
@@ -478,7 +478,7 @@ int sync_lock(const char *resource, int mode, int flags, int *lockid)
return 0;
}
-int sync_unlock(const char *resource /* UNUSED */, int lockid)
+static int _sync_unlock(const char *resource /* UNUSED */, int lockid)
{
int status;
struct lock_wait lwait;
@@ -505,3 +505,28 @@ int sync_unlock(const char *resource /* UNUSED */, int lockid)
return 0;
}
+
+static struct cluster_ops _cluster_cman_ops = {
+ .cluster_init_completed = NULL,
+ .cluster_send_message = _cluster_send_message,
+ .name_from_csid = _name_from_csid,
+ .csid_from_name = _csid_from_name,
+ .get_num_nodes = _get_num_nodes,
+ .cluster_fd_callback = _cluster_fd_callback,
+ .get_main_cluster_fd = _get_main_cluster_fd,
+ .cluster_do_node_callback = _cluster_do_node_callback,
+ .is_quorate = _is_quorate,
+ .get_our_csid = _get_our_csid,
+ .add_up_node = _add_up_node,
+ .cluster_closedown = _cluster_closedown,
+ .sync_lock = _sync_lock,
+ .sync_unlock = _sync_unlock,
+};
+
+struct cluster_ops *init_cman_cluster(void)
+{
+ if (!_init_cluster())
+ return &_cluster_cman_ops;
+ else
+ return NULL;
+}
diff --git a/daemons/clvmd/clvmd-comms.h b/daemons/clvmd/clvmd-comms.h
index 54017b33..54107e6e 100644
--- a/daemons/clvmd/clvmd-comms.h
+++ b/daemons/clvmd/clvmd-comms.h
@@ -22,33 +22,47 @@
struct local_client;
-extern int cluster_send_message(void *buf, int msglen, char *csid,
+struct cluster_ops {
+ void (*cluster_init_completed) (void);
+
+ int (*cluster_send_message) (void *buf, int msglen, char *csid,
const char *errtext);
-extern int name_from_csid(char *csid, char *name);
-extern int csid_from_name(char *csid, char *name);
-extern int get_num_nodes(void);
-extern int cluster_fd_callback(struct local_client *fd, char *buf, int len,
+ int (*name_from_csid) (char *csid, char *name);
+ int (*csid_from_name) (char *csid, char *name);
+ int (*get_num_nodes) (void);
+ int (*cluster_fd_callback) (struct local_client *fd, char *buf, int len,
char *csid, struct local_client **new_client);
-extern int init_cluster(void);
-extern int get_main_cluster_fd(void); /* gets accept FD or cman cluster socket */
-extern int cluster_do_node_callback(struct local_client *client,
+ int (*get_main_cluster_fd) (void); /* gets accept FD or cman cluster socket */
+ int (*cluster_do_node_callback) (struct local_client *client,
void (*callback) (struct local_client *,
char *csid, int node_up));
-extern int is_quorate(void);
+ int (*is_quorate) (void);
+
+ void (*get_our_csid) (char *csid);
+ void (*add_up_node) (char *csid);
+ void (*cluster_closedown) (void);
-extern void get_our_csid(char *csid);
-extern void add_up_node(char *csid);
-extern void cluster_closedown(void);
+ int (*sync_lock) (const char *resource, int mode, int flags, int *lockid);
+ int (*sync_unlock) (const char *resource, int lockid);
-extern int sync_lock(const char *resource, int mode, int flags, int *lockid);
-extern int sync_unlock(const char *resource, int lockid);
+};
#ifdef USE_GULM
-#include "tcp-comms.h"
-#else
-/* cman */
-#include "cnxman-socket.h"
-#define MAX_CSID_LEN 4
+# include "tcp-comms.h"
+struct cluster_ops *init_gulm_cluster(void);
+#define MAX_CSID_LEN GULM_MAX_CSID_LEN
+#define MAX_CLUSTER_MEMBER_NAME_LEN GULM_MAX_CLUSTER_MEMBER_NAME_LEN
+#endif
+
+#ifdef USE_CMAN
+# include "cnxman-socket.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
+struct cluster_ops *init_cman_cluster(void);
#endif
diff --git a/daemons/clvmd/clvmd-gulm.c b/daemons/clvmd/clvmd-gulm.c
index f1df01bc..235bceb9 100644
--- a/daemons/clvmd/clvmd-gulm.c
+++ b/daemons/clvmd/clvmd-gulm.c
@@ -72,7 +72,7 @@ static volatile int lock_start_flag;
struct node_info
{
enum {NODE_UNKNOWN, NODE_DOWN, NODE_UP, NODE_CLVMD} state;
- char name[MAX_CLUSTER_MEMBER_NAME_LEN];
+ char name[GULM_MAX_CLUSTER_MEMBER_NAME_LEN];
};
struct lock_wait
@@ -88,6 +88,8 @@ static int read_from_core_sock(struct local_client *client, char *buf, int len,
static int read_from_lock_sock(struct local_client *client, char *buf, int len, char *csid,
struct local_client **new_client);
static int get_all_cluster_nodes(void);
+static int _csid_from_name(char *csid, char *name);
+static void _cluster_closedown(void);
/* In tcp-comms.c */
extern struct hash_table *sock_hash;
@@ -123,7 +125,7 @@ static lg_lockspace_callbacks_t lock_callbacks;
static void badsig_handler(int sig)
{
DEBUGLOG("got sig %d\n", sig);
- cluster_closedown();
+ _cluster_closedown();
exit(0);
}
@@ -135,7 +137,7 @@ static void sighup_handler(int sig)
get_all_cluster_nodes();
}
-int init_cluster()
+static int _init_cluster(void)
{
int status;
int ccs_h;
@@ -241,7 +243,7 @@ int init_cluster()
return 0;
}
-void cluster_closedown()
+static void _cluster_closedown(void)
{
DEBUGLOG("cluster_closedown\n");
lg_lock_logout(gulm_if);
@@ -339,7 +341,7 @@ static struct node_info *add_or_set_node(char *name, struct in6_addr *ip, uint8_
{
struct node_info *ninfo;
- ninfo = hash_lookup_binary(node_hash, (char *)ip, MAX_CSID_LEN);
+ ninfo = hash_lookup_binary(node_hash, (char *)ip, GULM_MAX_CSID_LEN);
if (!ninfo)
{
/* If we can't find that node then re-read the config file in case it
@@ -348,7 +350,7 @@ static struct node_info *add_or_set_node(char *name, struct in6_addr *ip, uint8_
get_all_cluster_nodes();
/* Now try again */
- ninfo = hash_lookup_binary(node_hash, (char *)ip, MAX_CSID_LEN);
+ ninfo = hash_lookup_binary(node_hash, (char *)ip, GULM_MAX_CSID_LEN);
if (!ninfo)
{
DEBUGLOG("Ignoring node %s, not part of the SAN cluster\n", name);
@@ -361,6 +363,11 @@ static struct node_info *add_or_set_node(char *name, struct in6_addr *ip, uint8_
return ninfo;
}
+static void _get_our_csid(char *csid)
+{
+ get_our_gulm_csid(csid);
+}
+
static int core_nodelist(void *misc, lglcb_t type, char *name, struct in6_addr *ip, uint8_t state)
{
DEBUGLOG("CORE nodelist\n");
@@ -381,14 +388,14 @@ static int core_nodelist(void *misc, lglcb_t type, char *name, struct in6_addr *
{
if (type == lglcb_stop)
{
- char ourcsid[MAX_CSID_LEN];
+ char ourcsid[GULM_MAX_CSID_LEN];
DEBUGLOG("Got Nodelist, stop\n");
clvmd_cluster_init_completed();
/* Mark ourself as up */
- get_our_csid(ourcsid);
- add_up_node(ourcsid);
+ _get_our_csid(ourcsid);
+ gulm_add_up_node(ourcsid);
}
else
{
@@ -417,7 +424,7 @@ static int core_nodechange(void *misc, char *nodename, struct in6_addr *nodeip,
/* If we don't get nodeip here, try a lookup by name */
if (!nodeip)
- csid_from_name((char *)nodeip, nodename);
+ _csid_from_name((char *)nodeip, nodename);
if (!nodeip)
return 0;
@@ -540,15 +547,15 @@ int get_next_node_csid(void **context, char *csid)
return 0;
}
- memcpy(csid, hash_get_key(node_hash, *context), MAX_CSID_LEN);
+ memcpy(csid, hash_get_key(node_hash, *context), GULM_MAX_CSID_LEN);
return 1;
}
-int name_from_csid(char *csid, char *name)
+int gulm_name_from_csid(char *csid, char *name)
{
struct node_info *ninfo;
- ninfo = hash_lookup_binary(node_hash, csid, MAX_CSID_LEN);
+ ninfo = hash_lookup_binary(node_hash, csid, GULM_MAX_CSID_LEN);
if (!ninfo)
{
sprintf(name, "UNKNOWN %s", print_csid(csid));
@@ -560,7 +567,7 @@ int name_from_csid(char *csid, char *name)
}
-int csid_from_name(char *csid, char *name)
+static int _csid_from_name(char *csid, char *name)
{
struct hash_node *hn;
struct node_info *ninfo;
@@ -570,25 +577,25 @@ int csid_from_name(char *csid, char *name)
ninfo = hash_get_data(node_hash, hn);
if (strcmp(ninfo->name, name) == 0)
{
- memcpy(csid, hash_get_key(node_hash, hn), MAX_CSID_LEN);
+ memcpy(csid, hash_get_key(node_hash, hn), GULM_MAX_CSID_LEN);
return 0;
}
}
return -1;
}
-int get_num_nodes()
+static int _get_num_nodes()
{
DEBUGLOG("num_nodes = %d\n", num_nodes);
return num_nodes;
}
/* Node is now known to be running a clvmd */
-void add_up_node(char *csid)
+void gulm_add_up_node(char *csid)
{
struct node_info *ninfo;
- ninfo = hash_lookup_binary(node_hash, csid, MAX_CSID_LEN);
+ ninfo = hash_lookup_binary(node_hash, csid, GULM_MAX_CSID_LEN);
if (!ninfo)
return;
@@ -601,7 +608,7 @@ void add_down_node(char *csid)
{
struct node_info *ninfo;
- ninfo = hash_lookup_binary(node_hash, csid, MAX_CSID_LEN);
+ ninfo = hash_lookup_binary(node_hash, csid, GULM_MAX_CSID_LEN);
if (!ninfo)
return;
@@ -614,7 +621,7 @@ void add_down_node(char *csid)
}
/* Call a callback for each node, so the caller knows whether it's up or down */
-int cluster_do_node_callback(struct local_client *master_client,
+static int _cluster_do_node_callback(struct local_client *master_client,
void (*callback)(struct local_client *, char *csid, int node_up))
{
struct hash_node *hn;
@@ -622,15 +629,15 @@ int cluster_do_node_callback(struct local_client *master_client,
hash_iterate(hn, node_hash)
{
- char csid[MAX_CSID_LEN];
+ char csid[GULM_MAX_CSID_LEN];
struct local_client *client;
ninfo = hash_get_data(node_hash, hn);
- memcpy(csid, hash_get_key(node_hash, hn), MAX_CSID_LEN);
+ memcpy(csid, hash_get_key(node_hash, hn), GULM_MAX_CSID_LEN);
DEBUGLOG("down_callback. node %s, state = %d\n", ninfo->name, ninfo->state);
- client = hash_lookup_binary(sock_hash, csid, MAX_CSID_LEN);
+ client = hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
if (client)
callback(master_client, csid, ninfo->state == NODE_CLVMD);
}
@@ -742,7 +749,7 @@ static int _unlock_resource(char *resource, int lockid)
To aid unlocking, we store the lock mode in the lockid (as GULM
doesn't use this).
*/
-int sync_lock(const char *resource, int mode, int flags, int *lockid)
+static int _sync_lock(const char *resource, int mode, int flags, int *lockid)
{
int status;
char lock1[strlen(resource)+3];
@@ -786,7 +793,7 @@ int sync_lock(const char *resource, int mode, int flags, int *lockid)
return status;
}
-int sync_unlock(const char *resource, int lockid)
+static int _sync_unlock(const char *resource, int lockid)
{
int status = 0;
char lock1[strlen(resource)+3];
@@ -822,7 +829,7 @@ int sync_unlock(const char *resource, int lockid)
return status;
}
-int is_quorate()
+static int _is_quorate()
{
if (current_corestate == lg_core_Slave ||
current_corestate == lg_core_Master ||
@@ -854,7 +861,7 @@ static int get_all_cluster_nodes()
for (i=1;;i++)
{
char nodekey[256];
- char nodeip[MAX_CSID_LEN];
+ char nodeip[GULM_MAX_CSID_LEN];
int clvmflag = 1;
char *clvmflagstr;
char key[256];
@@ -877,7 +884,7 @@ static int get_all_cluster_nodes()
struct node_info *ninfo;
/* If it's not in the list, then add it */
- ninfo = hash_lookup_binary(node_hash, nodeip, MAX_CSID_LEN);
+ ninfo = hash_lookup_binary(node_hash, nodeip, GULM_MAX_CSID_LEN);
if (!ninfo)
{
ninfo = malloc(sizeof(struct node_info));
@@ -890,7 +897,7 @@ static int get_all_cluster_nodes()
strcpy(ninfo->name, nodename);
ninfo->state = NODE_DOWN;
- hash_insert_binary(node_hash, nodeip, MAX_CSID_LEN, ninfo);
+ hash_insert_binary(node_hash, nodeip, GULM_MAX_CSID_LEN, ninfo);
}
}
else
@@ -906,3 +913,47 @@ static int get_all_cluster_nodes()
return 0;
}
+static void _cluster_init_completed(void)
+{
+ clvmd_cluster_init_completed();
+}
+
+static int _get_main_cluster_fd(void)
+{
+ return get_main_gulm_cluster_fd();
+}
+
+static int _cluster_fd_callback(struct local_client *fd, char *buf, int len, char *csid, struct local_client **new_client)
+{
+ return cluster_fd_gulm_callback(fd, buf, len, csid, new_client);
+}
+
+static int _cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
+{
+ return gulm_cluster_send_message(buf, msglen, csid, errtext);
+}
+
+static struct cluster_ops _cluster_gulm_ops = {
+ .cluster_init_completed = _cluster_init_completed,
+ .cluster_send_message = _cluster_send_message,
+ .name_from_csid = gulm_name_from_csid,
+ .csid_from_name = _csid_from_name,
+ .get_num_nodes = _get_num_nodes,
+ .cluster_fd_callback = _cluster_fd_callback,
+ .get_main_cluster_fd = _get_main_cluster_fd,
+ .cluster_do_node_callback = _cluster_do_node_callback,
+ .is_quorate = _is_quorate,
+ .get_our_csid = _get_our_csid,
+ .add_up_node = gulm_add_up_node,
+ .cluster_closedown = _cluster_closedown,
+ .sync_lock = _sync_lock,
+ .sync_unlock = _sync_unlock,
+};
+
+struct cluster_ops *init_gulm_cluster(void)
+{
+ if (!_init_cluster())
+ return &_cluster_gulm_ops;
+ else
+ return NULL;
+}
diff --git a/daemons/clvmd/clvmd-gulm.h b/daemons/clvmd/clvmd-gulm.h
index 07726faa..7e961a75 100644
--- a/daemons/clvmd/clvmd-gulm.h
+++ b/daemons/clvmd/clvmd-gulm.h
@@ -7,3 +7,6 @@ extern int gulm_fd(void);
extern int get_ip_address(char *node, char *addr);
extern void tcp_remove_client(char *csid);
extern int alloc_client(int fd, char *csid, struct local_client **new_client);
+
+void gulm_add_up_node(char *csid);
+int gulm_name_from_csid(char *csid, char *name);
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 9a86f6f1..032671be 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -55,9 +55,9 @@
/* The maximum size of a message that will fit into a packet. Anything bigger
than this is sent via the system LV */
-#define MAX_INLINE_MESSAGE (MAX_CLUSTER_MESSAGE-sizeof(struct clvm_header))
+#define MAX_INLINE_MESSAGE (max_cluster_message-sizeof(struct clvm_header))
-#define ISLOCAL_CSID(c) (memcmp(c, our_csid, MAX_CSID_LEN) == 0)
+#define ISLOCAL_CSID(c) (memcmp(c, our_csid, max_csid_len) == 0)
/* Head of the fd list. Also contains
the cluster_socket details */
@@ -65,7 +65,12 @@ static struct local_client local_client_head;
static unsigned short global_xid = 0; /* Last transaction ID issued */
+static struct cluster_ops *clops = NULL;
+
static char our_csid[MAX_CSID_LEN];
+static unsigned max_csid_len;
+static unsigned max_cluster_message;
+static unsigned max_cluster_member_name_len;
/* Structure of items on the LVM thread list */
struct lvm_thread_cmd {
@@ -230,7 +235,23 @@ int main(int argc, char *argv[])
init_lvhash();
/* Start the cluster interface */
- if (init_cluster()) {
+#ifdef USE_CMAN
+ 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;
+ }
+#endif
+#ifdef USE_GULM
+ if (!clops)
+ if ((clops = init_gulm_cluster())) {
+ max_csid_len = GULM_MAX_CSID_LEN;
+ max_cluster_message = GULM_MAX_CLUSTER_MESSAGE;
+ max_cluster_member_name_len = GULM_MAX_CLUSTER_MEMBER_NAME_LEN;
+ }
+#endif
+
+ if (!clops) {
DEBUGLOG("Can't initialise cluster interface\n");
log_error("Can't initialise cluster interface\n");
child_init_signal(DFAIL_CLUSTER_IF);
@@ -239,12 +260,12 @@ int main(int argc, char *argv[])
/* Save our CSID */
uname(&nodeinfo);
- get_our_csid(our_csid);
+ clops->get_our_csid(our_csid);
/* Initialise the FD list head */
- local_client_head.fd = get_main_cluster_fd();
+ local_client_head.fd = clops->get_main_cluster_fd();
local_client_head.type = CLUSTER_MAIN_SOCK;
- local_client_head.callback = cluster_fd_callback;
+ local_client_head.callback = clops->cluster_fd_callback;
/* Add the local socket to the list */
newfd = malloc(sizeof(struct local_client));
@@ -262,13 +283,12 @@ int main(int argc, char *argv[])
DEBUGLOG("starting LVM thread\n");
pthread_create(&lvm_thread, NULL, lvm_thread_fn, nodeinfo.nodename);
-#ifndef USE_GULM
/* Tell the rest of the cluster our version number */
/* CMAN can do this immediately, gulm needs to wait until
the core initialisation has finished and the node list
has been gathered */
- send_version_message();
-#endif
+ if (clops->cluster_init_completed)
+ clops->cluster_init_completed();
DEBUGLOG("clvmd ready for work\n");
child_init_signal(SUCCESS);
@@ -417,9 +437,9 @@ static void timedout_callback(struct local_client *client, char *csid,
{
if (node_up) {
struct node_reply *reply;
- char nodename[MAX_CLUSTER_MEMBER_NAME_LEN];
+ char nodename[max_cluster_member_name_len];
- name_from_csid(csid, nodename);
+ clops->name_from_csid(csid, nodename);
DEBUGLOG("PJC: checking for a reply from %s\n", nodename);
pthread_mutex_lock(&client->bits.localsock.reply_mutex);
@@ -448,7 +468,7 @@ static void timedout_callback(struct local_client *client, char *csid,
static void request_timed_out(struct local_client *client)
{
DEBUGLOG("Request timed-out. padding\n");
- cluster_do_node_callback(client, timedout_callback);
+ clops->cluster_do_node_callback(client, timedout_callback);
if (client->bits.localsock.num_replies !=
client->bits.localsock.expected_replies) {
@@ -473,7 +493,7 @@ static void main_loop(int local_sock, int cmd_timeout)
int select_status;
struct local_client *thisfd;
struct timeval tv = { cmd_timeout, 0 };
- int quorate = is_quorate();
+ int quorate = clops->is_quorate();
/* Wait on the cluster FD and all local sockets/pipes */
FD_ZERO(&in);
@@ -488,7 +508,7 @@ static void main_loop(int local_sock, int cmd_timeout)
if ((select_status = select(FD_SETSIZE, &in, NULL, NULL, &tv)) > 0) {
struct local_client *lastfd = NULL;
char csid[MAX_CSID_LEN];
- char buf[MAX_CLUSTER_MESSAGE];
+ char buf[max_cluster_message];
for (thisfd = &local_client_head; thisfd != NULL;
thisfd = thisfd->next) {
@@ -573,7 +593,7 @@ static void main_loop(int local_sock, int cmd_timeout)
}
closedown:
- cluster_closedown();
+ clops->cluster_closedown();
close(local_sock);
}
@@ -829,7 +849,7 @@ static int read_from_local_sock(struct local_client *thisfd)
}
/* Check the node name for validity */
- if (inheader->node[0] && csid_from_name(csid, inheader->node)) {
+ if (inheader->node[0] && clops->csid_from_name(csid, inheader->node)) {
/* Error, node is not in the cluster */
struct clvm_header reply;
DEBUGLOG("Unknown node: '%s'\n", inheader->node);
@@ -961,7 +981,7 @@ static int distribute_command(struct local_client *thisfd)
/* if node is empty then do it on the whole cluster */
if (inheader->node[0] == '\0') {
thisfd->bits.localsock.expected_replies =
- get_num_nodes();
+ clops->get_num_nodes();
thisfd->bits.localsock.num_replies = 0;
thisfd->bits.localsock.sent_time = time(NULL);
thisfd->bits.localsock.in_progress = TRUE;
@@ -982,7 +1002,7 @@ static int distribute_command(struct local_client *thisfd)
/* Do it on a single node */
char csid[MAX_CSID_LEN];
- if (csid_from_name(csid, inheader->node)) {
+ if (clops->csid_from_name(csid, inheader->node)) {
/* This has already been checked so should not happen */
return 0;
} else {
@@ -992,7 +1012,7 @@ static int distribute_command(struct local_client *thisfd)
thisfd->bits.localsock.in_progress = TRUE;
/* Are we the requested node ?? */
- if (memcmp(csid, our_csid, MAX_CSID_LEN) == 0) {
+ if (memcmp(csid, our_csid, max_csid_len) == 0) {
DEBUGLOG("Doing command on local node only\n");
add_to_lvmqueue(thisfd, inheader, len, NULL);
} else {
@@ -1024,14 +1044,14 @@ void process_remote_command(struct clvm_header *msg, int msglen, int fd,
char *csid)
{
char *replyargs;
- char nodename[MAX_CLUSTER_MEMBER_NAME_LEN];
+ char nodename[max_cluster_member_name_len];
int replylen = 0;
- int buflen = MAX_CLUSTER_MESSAGE - sizeof(struct clvm_header) - 1;
+ int buflen = max_cluster_message - sizeof(struct clvm_header) - 1;
int status;
int msg_malloced = 0;
/* Get the node name as we /may/ need it later */
- name_from_csid(csid, nodename);
+ clops->name_from_csid(csid, nodename);
DEBUGLOG("process_remote_command %d for clientid 0x%x on node %s\n",
msg->cmd, msg->clientid, nodename);
@@ -1097,7 +1117,7 @@ void process_remote_command(struct clvm_header *msg, int msglen, int fd,
if (msg->cmd == CLVMD_CMD_VERSION) {
int *version_nums = (int *) msg->args;
char node[256];
- name_from_csid(csid, node);
+ clops->name_from_csid(csid, node);
DEBUGLOG("Remote node %s is version %d.%d.%d\n",
node,
ntohl(version_nums[0]),
@@ -1118,17 +1138,17 @@ void process_remote_command(struct clvm_header *msg, int msglen, int fd,
byebyemsg.flags = 0;
byebyemsg.arglen = 0;
byebyemsg.clientid = 0;
- cluster_send_message(&byebyemsg, sizeof(byebyemsg),
+ clops->cluster_send_message(&byebyemsg, sizeof(byebyemsg),
our_csid,
"Error Sending GOAWAY message");
} else {
- add_up_node(csid);
+ clops->add_up_node(csid);
}
return;
}
/* Allocate a default reply buffer */
- replyargs = malloc(MAX_CLUSTER_MESSAGE - sizeof(struct clvm_header));
+ replyargs = malloc(max_cluster_message - sizeof(struct clvm_header));
if (replyargs != NULL) {
/* Run the command */
@@ -1228,7 +1248,7 @@ static void add_reply_to_list(struct local_client *client, int status,
reply = malloc(sizeof(struct node_reply));
if (reply) {
reply->status = status;
- name_from_csid(csid, reply->node);
+ clops->name_from_csid(csid, reply->node);
DEBUGLOG("Reply from node %s: %d bytes\n", reply->node, len);
if (len > 0) {
@@ -1342,8 +1362,8 @@ static int process_local_command(struct clvm_header *msg, int msglen,
struct local_client *client,
unsigned short xid)
{
- char *replybuf = malloc(MAX_CLUSTER_MESSAGE);
- int buflen = MAX_CLUSTER_MESSAGE - sizeof(struct clvm_header) - 1;
+ char *replybuf = malloc(max_cluster_message);
+ int buflen = max_cluster_message - sizeof(struct clvm_header) - 1;
int replylen = 0;
int status;
@@ -1507,7 +1527,7 @@ static void send_version_message()
version_nums[1] = htonl(CLVMD_MINOR_VERSION);
version_nums[2] = htonl(CLVMD_PATCH_VERSION);
- cluster_send_message(message, sizeof(message), NULL,
+ clops->cluster_send_message(message, sizeof(message), NULL,
"Error Sending version number");
}
@@ -1520,7 +1540,7 @@ static int send_message(void *buf, int msglen, char *csid, int fd,
/* Send remote messages down the cluster socket */
if (csid == NULL || !ISLOCAL_CSID(csid)) {
hton_clvm((struct clvm_header *) buf); /* Byte swap if necessary */
- return cluster_send_message(buf, msglen, csid, errtext);
+ return clops->cluster_send_message(buf, msglen, csid, errtext);
} else {
int ptr = 0;
@@ -1621,7 +1641,7 @@ static int add_to_lvmqueue(struct local_client *client, struct clvm_header *msg,
cmd->xid = client->xid;
memcpy(cmd->msg, msg, msglen);
if (csid) {
- memcpy(cmd->csid, csid, MAX_CSID_LEN);
+ memcpy(cmd->csid, csid, max_csid_len);
cmd->remote = 1;
} else {
cmd->remote = 0;
@@ -1699,7 +1719,7 @@ static void check_all_callback(struct local_client *client, char *csid,
static int check_all_clvmds_running(struct local_client *client)
{
DEBUGLOG("check_all_clvmds_running\n");
- return cluster_do_node_callback(client, check_all_callback);
+ return clops->cluster_do_node_callback(client, check_all_callback);
}
/* Return a local_client struct given a client ID.
@@ -1745,3 +1765,14 @@ static void sigterm_handler(int sig)
quit = 1;
return;
}
+
+int sync_lock(const char *resource, int mode, int flags, int *lockid)
+{
+ return clops->sync_lock(resource, mode, flags, lockid);
+}
+
+int sync_unlock(const char *resource, int lockid)
+{
+ return clops->sync_unlock(resource, lockid);
+}
+
diff --git a/daemons/clvmd/clvmd.h b/daemons/clvmd/clvmd.h
index c178df87..cc25aede 100644
--- a/daemons/clvmd/clvmd.h
+++ b/daemons/clvmd/clvmd.h
@@ -93,7 +93,7 @@ struct local_client {
struct netsock_bits net;
} bits;
};
-
+#define DEBUG
#ifdef DEBUG
#define DEBUGLOG(fmt, args...) fprintf(stderr, "CLVMD[%d]: %ld ", getpid(), time(NULL) ); fprintf(stderr, fmt, ## args)
#else
@@ -116,4 +116,8 @@ extern int add_client(struct local_client *new_client);
extern void clvmd_cluster_init_completed(void);
extern void process_message(struct local_client *client, char *buf, int len, char *csid);
+
+int sync_lock(const char *resource, int mode, int flags, int *lockid);
+int sync_unlock(const char *resource, int lockid);
+
#endif
diff --git a/daemons/clvmd/cnxman-socket.h b/daemons/clvmd/cnxman-socket.h
index 1aaa0bc1..c6d5fd9f 100644
--- a/daemons/clvmd/cnxman-socket.h
+++ b/daemons/clvmd/cnxman-socket.h
@@ -63,8 +63,8 @@
/* Maximum size of a cluster message */
-#define MAX_CLUSTER_MESSAGE 1500
-#define MAX_CLUSTER_MEMBER_NAME_LEN 255
+#define CMAN_MAX_CLUSTER_MESSAGE 1500
+#define CMAN_MAX_CLUSTER_MEMBER_NAME_LEN 255
#define MAX_BARRIER_NAME_LEN 33
#define MAX_SA_ADDR_LEN 12
#define MAX_CLUSTER_NAME_LEN 16
@@ -147,7 +147,7 @@ struct cl_cluster_node {
unsigned int leave_reason;
unsigned int incarnation;
nodestate_t state;
- char name[MAX_CLUSTER_MEMBER_NAME_LEN];
+ char name[CMAN_MAX_CLUSTER_MEMBER_NAME_LEN];
unsigned char votes;
};
diff --git a/daemons/clvmd/system-lv.c b/daemons/clvmd/system-lv.c
index 5b359cdf..aa545992 100644
--- a/daemons/clvmd/system-lv.c
+++ b/daemons/clvmd/system-lv.c
@@ -42,7 +42,9 @@
#include "list.h"
#include "locking.h"
#include "system-lv.h"
+#include "clvm.h"
#include "clvmd-comms.h"
+#include "clvmd.h"
#ifdef HAVE_CCS
#include "ccs.h"
#endif
diff --git a/daemons/clvmd/tcp-comms.c b/daemons/clvmd/tcp-comms.c
index d9b011de..7c2d97e2 100644
--- a/daemons/clvmd/tcp-comms.c
+++ b/daemons/clvmd/tcp-comms.c
@@ -96,19 +96,19 @@ void tcp_remove_client(char *csid)
job of clvmd.c whch will do the job when it notices the
other end has gone. We just need to remove the client(s) from
the hash table so we don't try to use it for sending any more */
- client = hash_lookup_binary(sock_hash, csid, MAX_CSID_LEN);
+ client = hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
if (client)
{
- hash_remove_binary(sock_hash, csid, MAX_CSID_LEN);
+ hash_remove_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
}
/* Look for a mangled one too */
csid[0] ^= 0x80;
- client = hash_lookup_binary(sock_hash, csid, MAX_CSID_LEN);
+ client = hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
if (client)
{
- hash_remove_binary(sock_hash, csid, MAX_CSID_LEN);
+ hash_remove_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
}
/* Put it back as we found it */
@@ -137,7 +137,7 @@ int alloc_client(int fd, char *csid, struct local_client **new_client)
*new_client = client;
/* Add to our list of node sockets */
- if (hash_lookup_binary(sock_hash, csid, MAX_CSID_LEN))
+ if (hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN))
{
DEBUGLOG("alloc_client mangling CSID for second connection\n");
/* This is a duplicate connection but we can't close it because
@@ -150,7 +150,7 @@ int alloc_client(int fd, char *csid, struct local_client **new_client)
/* If it still exists then kill the connection as we should only
ever have one incoming connection from each node */
- if (hash_lookup_binary(sock_hash, csid, MAX_CSID_LEN))
+ if (hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN))
{
DEBUGLOG("Multiple incoming connections from node\n");
syslog(LOG_ERR, " Bogus incoming connection from %d.%d.%d.%d\n", csid[0],csid[1],csid[2],csid[3]);
@@ -160,26 +160,26 @@ int alloc_client(int fd, char *csid, struct local_client **new_client)
return -1;
}
}
- hash_insert_binary(sock_hash, csid, MAX_CSID_LEN, client);
+ hash_insert_binary(sock_hash, csid, GULM_MAX_CSID_LEN, client);
return 0;
}
-int get_main_cluster_fd()
+int get_main_gulm_cluster_fd()
{
return listen_fd;
}
/* Read on main comms (listen) socket, accept it */
-int cluster_fd_callback(struct local_client *fd, char *buf, int len, char *csid,
+int cluster_fd_gulm_callback(struct local_client *fd, char *buf, int len, char *csid,
struct local_client **new_client)
{
int newfd;
struct sockaddr_in6 addr;
socklen_t addrlen = sizeof(addr);
int status;
- char name[MAX_CLUSTER_MEMBER_NAME_LEN];
+ char name[GULM_MAX_CLUSTER_MEMBER_NAME_LEN];
DEBUGLOG("cluster_fd_callback\n");
*new_client = NULL;
@@ -196,7 +196,7 @@ int cluster_fd_callback(struct local_client *fd, char *buf, int len, char *csid,
/* Check that the client is a member of the cluster
and reject if not.
*/
- if (name_from_csid((char *)&addr.sin6_addr, name) < 0)
+ if (gulm_name_from_csid((char *)&addr.sin6_addr, name) < 0)
{
syslog(LOG_ERR, "Got connect from non-cluster node %s\n",
print_csid((char *)&addr.sin6_addr));
@@ -234,7 +234,7 @@ static int read_from_tcpsock(struct local_client *client, char *buf, int len, ch
/* Get "csid" */
getpeername(client->fd, (struct sockaddr *)&addr, &slen);
- memcpy(csid, &addr.sin6_addr, MAX_CSID_LEN);
+ memcpy(csid, &addr.sin6_addr, GULM_MAX_CSID_LEN);
status = read(client->fd, buf, len);
@@ -245,15 +245,15 @@ static int read_from_tcpsock(struct local_client *client, char *buf, int len, ch
if (status == 0 ||
(status < 0 && errno != EAGAIN && errno != EINTR))
{
- char remcsid[MAX_CSID_LEN];
+ char remcsid[GULM_MAX_CSID_LEN];
- memcpy(remcsid, csid, MAX_CSID_LEN);
+ memcpy(remcsid, csid, GULM_MAX_CSID_LEN);
close(client->fd);
/* If the csid was mangled, then make sure we remove the right entry */
if (client->bits.net.flags)
remcsid[0] ^= 0x80;
- hash_remove_binary(sock_hash, remcsid, MAX_CSID_LEN);
+ hash_remove_binary(sock_hash, remcsid, GULM_MAX_CSID_LEN);
/* Tell cluster manager layer */
add_down_node(remcsid);
@@ -281,7 +281,7 @@ static int connect_csid(char *csid, struct local_client **newclient)
}
addr.sin6_family = AF_INET6;
- memcpy(&addr.sin6_addr, csid, MAX_CSID_LEN);
+ memcpy(&addr.sin6_addr, csid, GULM_MAX_CSID_LEN);
addr.sin6_port = htons(tcp_port);
DEBUGLOG("Connecting socket %d\n", fd);
@@ -300,7 +300,7 @@ static int connect_csid(char *csid, struct local_client **newclient)
add_client(*newclient);
/* If we can connect to it, it must be running a clvmd */
- add_up_node(csid);
+ gulm_add_up_node(csid);
return status;
}
@@ -309,18 +309,18 @@ static int tcp_send_message(void *buf, int msglen, unsigned char *csid, const ch
{
int status;
struct local_client *client;
- char ourcsid[MAX_CSID_LEN];
+ char ourcsid[GULM_MAX_CSID_LEN];
assert(csid);
DEBUGLOG("tcp_send_message, csid = %s, msglen = %d\n", print_csid(csid), msglen);
/* Don't connect to ourself */
- get_our_csid(ourcsid);
- if (memcmp(csid, ourcsid, MAX_CSID_LEN) == 0)
+ get_our_gulm_csid(ourcsid);
+ if (memcmp(csid, ourcsid, GULM_MAX_CSID_LEN) == 0)
return msglen;
- client = hash_lookup_binary(sock_hash, csid, MAX_CSID_LEN);
+ client = hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
if (!client)
{
status = connect_csid(csid, &client);
@@ -333,7 +333,7 @@ static int tcp_send_message(void *buf, int msglen, unsigned char *csid, const ch
}
-int cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
+int gulm_cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
{
int status=0;
@@ -343,7 +343,7 @@ int cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
if (!csid)
{
void *context = NULL;
- char loop_csid[MAX_CSID_LEN];
+ char loop_csid[GULM_MAX_CSID_LEN];
/* Loop round all gulm-known nodes */
while (get_next_node_csid(&context, loop_csid))
@@ -377,9 +377,9 @@ static int get_our_ip_address(char *addr, int *family)
/* Public version of above for those that don't care what protocol
we're using */
-void get_our_csid(char *csid)
+void get_our_gulm_csid(char *csid)
{
- static char our_csid[MAX_CSID_LEN];
+ static char our_csid[GULM_MAX_CSID_LEN];
static int got_csid = 0;
if (!got_csid)
@@ -392,7 +392,7 @@ void get_our_csid(char *csid)
got_csid = 1;
}
}
- memcpy(csid, our_csid, MAX_CSID_LEN);
+ memcpy(csid, our_csid, GULM_MAX_CSID_LEN);
}
static void map_v4_to_v6(struct in_addr *ip4, struct in6_addr *ip6)
@@ -408,7 +408,7 @@ int get_ip_address(char *node, char *addr)
{
struct hostent *he;
- memset(addr, 0, MAX_CSID_LEN);
+ memset(addr, 0, GULM_MAX_CSID_LEN);
// TODO: what do we do about multi-homed hosts ???
// CCSs ip_interfaces solved this but some bugger removed it.
diff --git a/daemons/clvmd/tcp-comms.h b/daemons/clvmd/tcp-comms.h
index 49ac479a..ee86ee64 100644
--- a/daemons/clvmd/tcp-comms.h
+++ b/daemons/clvmd/tcp-comms.h
@@ -1,8 +1,12 @@
#include <netinet/in.h>
-#define MAX_CLUSTER_MESSAGE 1600
-#define MAX_CSID_LEN sizeof(struct in6_addr)
-#define MAX_CLUSTER_MEMBER_NAME_LEN 128
+#define GULM_MAX_CLUSTER_MESSAGE 1600
+#define GULM_MAX_CSID_LEN sizeof(struct in6_addr)
+#define GULM_MAX_CLUSTER_MEMBER_NAME_LEN 128
extern int init_comms(unsigned short);
extern char *print_csid(char *);
+int get_main_gulm_cluster_fd(void);
+int cluster_fd_gulm_callback(struct local_client *fd, char *buf, int len, char *csid, struct local_client **new_client);
+int gulm_cluster_send_message(void *buf, int msglen, char *csid, const char *errtext);
+void get_our_gulm_csid(char *csid);