summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick Caulfield <pcaulfie@redhat.com>2007-05-02 12:22:40 +0000
committerPatrick Caulfield <pcaulfie@redhat.com>2007-05-02 12:22:40 +0000
commite1cd6dbc07d41bda93caa5a388470c2fd7e6e5dd (patch)
tree98de41d46ed242561acfeb3f502efa777d777654
parentf46af53ea36216d1784a6cbc2139fcc70878bd04 (diff)
downloadlvm2-e1cd6dbc07d41bda93caa5a388470c2fd7e6e5dd.tar.gz
lvm2-e1cd6dbc07d41bda93caa5a388470c2fd7e6e5dd.tar.xz
lvm2-e1cd6dbc07d41bda93caa5a388470c2fd7e6e5dd.zip
Misc clvmd cleanups from Jim Meyering
-rw-r--r--WHATS_NEW1
-rw-r--r--daemons/clvmd/clvmd-cman.c30
-rw-r--r--daemons/clvmd/clvmd-command.c25
-rw-r--r--daemons/clvmd/clvmd-comms.h22
-rw-r--r--daemons/clvmd/clvmd.c41
-rw-r--r--daemons/clvmd/clvmd.h6
-rw-r--r--daemons/clvmd/tcp-comms.c48
-rw-r--r--daemons/clvmd/tcp-comms.h4
8 files changed, 97 insertions, 80 deletions
diff --git a/WHATS_NEW b/WHATS_NEW
index 5211c6fc..ab4119d6 100644
--- a/WHATS_NEW
+++ b/WHATS_NEW
@@ -1,6 +1,7 @@
Version 2.02.26 -
=================================
Add some more debuglogs to clvmd startup.
+ Misc clvmd cleanups
Version 2.02.25 - 27th April 2007
=================================
diff --git a/daemons/clvmd/clvmd-cman.c b/daemons/clvmd/clvmd-cman.c
index 846b9a96..697305dc 100644
--- a/daemons/clvmd/clvmd-cman.c
+++ b/daemons/clvmd/clvmd-cman.c
@@ -58,7 +58,7 @@ 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 nodeid_from_csid(const 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,
@@ -131,7 +131,8 @@ static int _get_num_nodes()
}
/* send_message with the fd check removed */
-static int _cluster_send_message(void *buf, int msglen, char *csid, const char *errtext)
+static int _cluster_send_message(const void *buf, int msglen, const char *csid,
+ const char *errtext)
{
int nodeid = 0;
@@ -140,7 +141,7 @@ static int _cluster_send_message(void *buf, int msglen, char *csid, const char *
if (cman_send_data(c_handle, buf, msglen, 0, CLUSTER_PORT_CLVMD, nodeid) <= 0)
{
- log_error(errtext);
+ log_error("%s", errtext);
}
return msglen;
}
@@ -155,7 +156,8 @@ static void _get_our_csid(char *csid)
/* Call a callback routine for each node is that known (down means not running a clvmd) */
static int _cluster_do_node_callback(struct local_client *client,
- void (*callback) (struct local_client *, char *,
+ void (*callback) (struct local_client *,
+ const char *,
int))
{
int i;
@@ -208,7 +210,8 @@ static void event_callback(cman_handle_t handle, void *private, int reason, int
}
static struct local_client *cman_client;
-static int _cluster_fd_callback(struct local_client *fd, char *buf, int len, char *csid,
+static int _cluster_fd_callback(struct local_client *fd, char *buf, int len,
+ const char *csid,
struct local_client **new_client)
{
@@ -231,7 +234,7 @@ static void data_callback(cman_handle_t handle, void *private,
process_message(cman_client, buf, len, (char *)&nodeid);
}
-static void _add_up_node(char *csid)
+static void _add_up_node(const char *csid)
{
/* It's up ! */
int nodeid = nodeid_from_csid(csid);
@@ -323,17 +326,16 @@ static void get_members()
}
if (node_updown == NULL) {
- node_updown =
- (int *) malloc(sizeof(int) *
- max(num_nodes, max_updown_nodes));
- memset(node_updown, 0,
- sizeof(int) * max(num_nodes, max_updown_nodes));
+ size_t buf_len = sizeof(int) * max(num_nodes, max_updown_nodes);
+ node_updown = malloc(buf_len);
+ if (node_updown)
+ memset(node_updown, 0, buf_len);
}
}
/* Convert a node name to a CSID */
-static int _csid_from_name(char *csid, char *name)
+static int _csid_from_name(char *csid, const char *name)
{
int i;
@@ -347,7 +349,7 @@ static int _csid_from_name(char *csid, char *name)
}
/* Convert a CSID to a node name */
-static int _name_from_csid(char *csid, char *name)
+static int _name_from_csid(const char *csid, char *name)
{
int i;
@@ -379,7 +381,7 @@ static int name_from_nodeid(int nodeid, char *name)
}
/* Convert a CSID to a node ID */
-static int nodeid_from_csid(char *csid)
+static int nodeid_from_csid(const char *csid)
{
int nodeid;
diff --git a/daemons/clvmd/clvmd-command.c b/daemons/clvmd/clvmd-command.c
index 0623c3a7..157e351a 100644
--- a/daemons/clvmd/clvmd-command.c
+++ b/daemons/clvmd/clvmd-command.c
@@ -95,13 +95,22 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
/* Just a test message */
case CLVMD_CMD_TEST:
if (arglen > buflen) {
+ char *new_buf;
buflen = arglen + 200;
- *buf = realloc(*buf, buflen);
+ new_buf = realloc(*buf, buflen);
+ if (new_buf == NULL) {
+ status = errno;
+ free (*buf);
+ }
+ *buf = new_buf;
+ }
+ if (*buf) {
+ uname(&nodeinfo);
+ *retlen = 1 + snprintf(*buf, buflen,
+ "TEST from %s: %s v%s",
+ nodeinfo.nodename, args,
+ nodeinfo.release);
}
- uname(&nodeinfo);
- *retlen = 1 + snprintf(*buf, buflen, "TEST from %s: %s v%s",
- nodeinfo.nodename, args,
- nodeinfo.release);
break;
case CLVMD_CMD_LOCK_VG:
@@ -118,7 +127,7 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
/* Replace EIO with something less scary */
if (status == EIO) {
*retlen =
- 1 + snprintf(*buf, buflen,
+ 1 + snprintf(*buf, buflen, "%s",
get_last_lvm_error());
return EIO;
}
@@ -131,7 +140,7 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
case CLVMD_CMD_GET_CLUSTERNAME:
status = clops->get_cluster_name(*buf, buflen);
if (!status)
- *retlen = strlen(*buf);
+ *retlen = strlen(*buf)+1;
break;
default:
@@ -141,7 +150,7 @@ int do_command(struct local_client *client, struct clvm_header *msg, int msglen,
/* Check the status of the command and return the error text */
if (status) {
- *retlen = 1 + snprintf(*buf, buflen, strerror(status));
+ *retlen = 1 + snprintf(*buf, buflen, "%s", strerror(status));
}
return status;
diff --git a/daemons/clvmd/clvmd-comms.h b/daemons/clvmd/clvmd-comms.h
index 6bfcd562..4cd177ab 100644
--- a/daemons/clvmd/clvmd-comms.h
+++ b/daemons/clvmd/clvmd-comms.h
@@ -25,27 +25,31 @@ struct local_client;
struct cluster_ops {
void (*cluster_init_completed) (void);
- int (*cluster_send_message) (void *buf, int msglen, char *csid,
- const char *errtext);
- int (*name_from_csid) (char *csid, char *name);
- int (*csid_from_name) (char *csid, char *name);
+ int (*cluster_send_message) (const void *buf, int msglen,
+ const char *csid,
+ const char *errtext);
+ int (*name_from_csid) (const char *csid, char *name);
+ int (*csid_from_name) (char *csid, const 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);
+ const char *csid,
+ struct local_client **new_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));
+ void (*callback) (struct local_client *,
+ const char *csid,
+ int node_up));
int (*is_quorate) (void);
void (*get_our_csid) (char *csid);
- void (*add_up_node) (char *csid);
+ void (*add_up_node) (const char *csid);
void (*reread_config) (void);
void (*cluster_closedown) (void);
int (*get_cluster_name)(char *buf, int buflen);
- int (*sync_lock) (const char *resource, int mode, int flags, int *lockid);
+ int (*sync_lock) (const char *resource, int mode,
+ int flags, int *lockid);
int (*sync_unlock) (const char *resource, int lockid);
};
diff --git a/daemons/clvmd/clvmd.c b/daemons/clvmd/clvmd.c
index 752bbbd7..3feabaf6 100644
--- a/daemons/clvmd/clvmd.c
+++ b/daemons/clvmd/clvmd.c
@@ -115,31 +115,32 @@ static void send_local_reply(struct local_client *client, int status,
static void free_reply(struct local_client *client);
static void send_version_message(void);
static void *pre_and_post_thread(void *arg);
-static int send_message(void *buf, int msglen, char *csid, int fd,
+static int send_message(void *buf, int msglen, const char *csid, int fd,
const char *errtext);
static int read_from_local_sock(struct local_client *thisfd);
static int process_local_command(struct clvm_header *msg, int msglen,
struct local_client *client,
unsigned short xid);
static void process_remote_command(struct clvm_header *msg, int msglen, int fd,
- char *csid);
-static int process_reply(struct clvm_header *msg, int msglen, char *csid);
+ const char *csid);
+static int process_reply(const struct clvm_header *msg, int msglen,
+ const char *csid);
static int open_local_sock(void);
static struct local_client *find_client(int clientid);
static void main_loop(int local_sock, int cmd_timeout);
static void be_daemon(int start_timeout);
static int check_all_clvmds_running(struct local_client *client);
static int local_rendezvous_callback(struct local_client *thisfd, char *buf,
- int len, char *csid,
+ int len, const char *csid,
struct local_client **new_client);
static void *lvm_thread_fn(void *);
static int add_to_lvmqueue(struct local_client *client, struct clvm_header *msg,
- int msglen, char *csid);
+ int msglen, const char *csid);
static int distribute_command(struct local_client *thisfd);
static void hton_clvm(struct clvm_header *hdr);
static void ntoh_clvm(struct clvm_header *hdr);
static void add_reply_to_list(struct local_client *client, int status,
- char *csid, const char *buf, int len);
+ const char *csid, const char *buf, int len);
static void usage(char *prog, FILE *file)
{
@@ -359,7 +360,8 @@ void clvmd_cluster_init_completed()
/* Data on a connected socket */
static int local_sock_callback(struct local_client *thisfd, char *buf, int len,
- char *csid, struct local_client **new_client)
+ const char *csid,
+ struct local_client **new_client)
{
*new_client = NULL;
return read_from_local_sock(thisfd);
@@ -367,7 +369,7 @@ static int local_sock_callback(struct local_client *thisfd, char *buf, int len,
/* Data on a connected socket */
static int local_rendezvous_callback(struct local_client *thisfd, char *buf,
- int len, char *csid,
+ int len, const char *csid,
struct local_client **new_client)
{
/* Someone connected to our local socket, accept it. */
@@ -408,7 +410,7 @@ static int local_rendezvous_callback(struct local_client *thisfd, char *buf,
}
static int local_pipe_callback(struct local_client *thisfd, char *buf,
- int maxlen, char *csid,
+ int maxlen, const char *csid,
struct local_client **new_client)
{
int len;
@@ -484,7 +486,7 @@ static int local_pipe_callback(struct local_client *thisfd, char *buf,
add one with "ETIMEDOUT".
NOTE: This won't race with real replies because they happen in the same thread.
*/
-static void timedout_callback(struct local_client *client, char *csid,
+static void timedout_callback(struct local_client *client, const char *csid,
int node_up)
{
if (node_up) {
@@ -1152,7 +1154,7 @@ static int distribute_command(struct local_client *thisfd)
/* Process a command from a remote node and return the result */
static void process_remote_command(struct clvm_header *msg, int msglen, int fd,
- char *csid)
+ const char *csid)
{
char *replyargs;
char nodename[max_cluster_member_name_len];
@@ -1352,7 +1354,7 @@ static void process_remote_command(struct clvm_header *msg, int msglen, int fd,
If we have got a full set then send them to the waiting client down the local
socket */
static void add_reply_to_list(struct local_client *client, int status,
- char *csid, const char *buf, int len)
+ const char *csid, const char *buf, int len)
{
struct node_reply *reply;
@@ -1529,7 +1531,7 @@ static int process_local_command(struct clvm_header *msg, int msglen,
return status;
}
-static int process_reply(struct clvm_header *msg, int msglen, char *csid)
+static int process_reply(const struct clvm_header *msg, int msglen, const char *csid)
{
struct local_client *client = NULL;
@@ -1679,7 +1681,7 @@ static void send_version_message()
}
/* Send a message to either a local client or another server */
-static int send_message(void *buf, int msglen, char *csid, int fd,
+static int send_message(void *buf, int msglen, const char *csid, int fd,
const char *errtext)
{
int len;
@@ -1701,7 +1703,7 @@ static int send_message(void *buf, int msglen, char *csid, int fd,
if (retry_cnt > MAX_RETRIES)
{
errno = saved_errno;
- log_error(errtext);
+ log_error("%s", errtext);
errno = saved_errno;
break;
}
@@ -1725,7 +1727,7 @@ static int send_message(void *buf, int msglen, char *csid, int fd,
continue;
}
- log_error(errtext);
+ log_error("%s", errtext);
break;
}
ptr += len;
@@ -1811,7 +1813,7 @@ static __attribute__ ((noreturn)) void *lvm_thread_fn(void *arg)
/* Pass down some work to the LVM thread */
static int add_to_lvmqueue(struct local_client *client, struct clvm_header *msg,
- int msglen, char *csid)
+ int msglen, const char *csid)
{
struct lvm_thread_cmd *cmd;
@@ -1889,7 +1891,8 @@ static int open_local_sock()
return local_socket;
}
-void process_message(struct local_client *client, char *buf, int len, char *csid)
+void process_message(struct local_client *client, const char *buf, int len,
+ const char *csid)
{
struct clvm_header *inheader;
@@ -1902,7 +1905,7 @@ void process_message(struct local_client *client, char *buf, int len, char *csid
}
-static void check_all_callback(struct local_client *client, char *csid,
+static void check_all_callback(struct local_client *client, const char *csid,
int node_up)
{
if (!node_up)
diff --git a/daemons/clvmd/clvmd.h b/daemons/clvmd/clvmd.h
index 65eaa530..8842936b 100644
--- a/daemons/clvmd/clvmd.h
+++ b/daemons/clvmd/clvmd.h
@@ -76,7 +76,8 @@ struct netsock_bits {
};
typedef int (*fd_callback_t) (struct local_client * fd, char *buf, int len,
- char *csid, struct local_client ** new_client);
+ const char *csid,
+ struct local_client ** new_client);
/* One of these for each fd we are listening on */
struct local_client {
@@ -112,7 +113,8 @@ extern void cmd_client_cleanup(struct local_client *client);
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);
+extern void process_message(struct local_client *client, const char *buf,
+ int len, const char *csid);
extern void debuglog(const char *fmt, ... );
int sync_lock(const char *resource, int mode, int flags, int *lockid);
diff --git a/daemons/clvmd/tcp-comms.c b/daemons/clvmd/tcp-comms.c
index ffbfe92d..4c7f5b16 100644
--- a/daemons/clvmd/tcp-comms.c
+++ b/daemons/clvmd/tcp-comms.c
@@ -92,41 +92,37 @@ int init_comms(unsigned short port)
return 0;
}
-void tcp_remove_client(char *csid)
- {
+void tcp_remove_client(const char *c_csid)
+{
struct local_client *client;
+ char csid[GULM_MAX_CSID_LEN];
+ unsigned int i;
+ memcpy(csid, c_csid, sizeof csid);
DEBUGLOG("tcp_remove_client\n");
/* Don't actually close the socket here - that's the
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 = dm_hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
- if (client)
+ for (i = 0; i < 2; i++)
{
- dm_hash_remove_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
- client->removeme = 1;
- close(client->fd);
- }
-
- /* Look for a mangled one too */
- csid[0] ^= 0x80;
-
- client = dm_hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
- if (client)
- {
- dm_hash_remove_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
- client->removeme = 1;
- close(client->fd);
+ client = dm_hash_lookup_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
+ if (client)
+ {
+ dm_hash_remove_binary(sock_hash, csid, GULM_MAX_CSID_LEN);
+ client->removeme = 1;
+ close(client->fd);
+ }
+ /* Look for a mangled one too, on the 2nd iteration. */
+ csid[0] ^= 0x80;
}
-
- /* Put it back as we found it */
- csid[0] ^= 0x80;
}
-int alloc_client(int fd, char *csid, struct local_client **new_client)
+int alloc_client(int fd, const char *c_csid, struct local_client **new_client)
{
struct local_client *client;
+ char csid[GULM_MAX_CSID_LEN];
+ memcpy(csid, c_csid, sizeof csid);
DEBUGLOG("alloc_client %d csid = %s\n", fd, print_csid(csid));
@@ -315,7 +311,7 @@ static int read_from_tcpsock(struct local_client *client, char *buf, int len, ch
return status;
}
-int gulm_connect_csid(char *csid, struct local_client **newclient)
+int gulm_connect_csid(const char *csid, struct local_client **newclient)
{
int fd;
struct sockaddr_in6 addr;
@@ -366,7 +362,7 @@ int gulm_connect_csid(char *csid, struct local_client **newclient)
}
/* Send a message to a known CSID */
-static int tcp_send_message(void *buf, int msglen, unsigned char *csid, const char *errtext)
+static int tcp_send_message(void *buf, int msglen, const char *csid, const char *errtext)
{
int status;
struct local_client *client;
@@ -465,7 +461,7 @@ static void map_v4_to_v6(struct in_addr *ip4, struct in6_addr *ip6)
}
/* Get someone else's IP address from DNS */
-int get_ip_address(char *node, char *addr)
+int get_ip_address(const char *node, char *addr)
{
struct hostent *he;
@@ -493,7 +489,7 @@ int get_ip_address(char *node, char *addr)
return 0;
}
-char *print_csid(char *csid)
+char *print_csid(const char *csid)
{
static char buf[128];
int *icsid = (int *)csid;
diff --git a/daemons/clvmd/tcp-comms.h b/daemons/clvmd/tcp-comms.h
index 75828a1a..d0ef29d5 100644
--- a/daemons/clvmd/tcp-comms.h
+++ b/daemons/clvmd/tcp-comms.h
@@ -5,9 +5,9 @@
#define GULM_MAX_CLUSTER_MEMBER_NAME_LEN 128
extern int init_comms(unsigned short);
-extern char *print_csid(char *);
+extern char *print_csid(const 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);
-int gulm_connect_csid(char *csid, struct local_client **newclient);
+int gulm_connect_csid(const char *csid, struct local_client **newclient);