Skip to contentSkip to conversation

LVM2 ./WHATS_NEW daemons/clvmd/clvmd-cman.c da ...

PATCH [email protected] 1 participant 1 message May 2, 2007

lore
Share & tools
lore
#0 lore raw

CVSROOT: /cvs/lvm2
Module name: LVM2
Changes by: pcaulfield at sourceware.org 2007-05-02 12:22:41

Modified files:
. : WHATS_NEW
daemons/clvmd : clvmd-cman.c clvmd-command.c clvmd-comms.h
clvmd.c clvmd.h tcp-comms.c tcp-comms.h

Log message:
Misc clvmd cleanups from Jim Meyering

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/WHATS_NEW.diff?cvsroot=lvm2&r1=1.614&r2=1.615
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvmd-cman.c.diff?cvsroot=lvm2&r1=1.19&r2=1.20
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvmd-command.c.diff?cvsroot=lvm2&r1=1.15&r2=1.16
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvmd-comms.h.diff?cvsroot=lvm2&r1=1.6&r2=1.7
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvmd.c.diff?cvsroot=lvm2&r1=1.35&r2=1.36
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/clvmd.h.diff?cvsroot=lvm2&r1=1.8&r2=1.9
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/tcp-comms.c.diff?cvsroot=lvm2&r1=1.16&r2=1.17
http://sourceware.org/cgi-bin/cvsweb.cgi/LVM2/daemons/clvmd/tcp-comms.h.diff?cvsroot=lvm2&r1=1.4&r2=1.5

WHATS_NEW +1 -0
@@ -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
 =================================
daemons/clvmd/clvmd-cman.c +16 -14
@@ -58,7 +58,7 @@
 
 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 @@
 }
 
 /* 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 @@
 
 	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 @@
 
 /* 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 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 @@
 	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 @@
 	}
 
 	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 @@
 }
 
 /* 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 @@
 }
 
 /* Convert a CSID to a node ID */
-static int nodeid_from_csid(char *csid)
+static int nodeid_from_csid(const char *csid)
 {
         int nodeid;
 
daemons/clvmd/clvmd-command.c +17 -8
@@ -95,13 +95,22 @@
 		/* 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 @@
 		/* 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 @@
 	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 @@
 
 	/* 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;
daemons/clvmd/clvmd-comms.h +13 -9
@@ -25,27 +25,31 @@
 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);
 
 };
daemons/clvmd/clvmd.c +22 -19

144 lines not on this page · raw message

daemons/clvmd/clvmd.h +4 -2
@@ -76,7 +76,8 @@
 };
 
 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 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);
daemons/clvmd/tcp-comms.c +22 -26

91 lines not on this page · raw message

daemons/clvmd/tcp-comms.h +2 -2
@@ -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);