public inbox for cluster-cvs@sourceware.org
help / color / mirror / Atom feed
* cluster: STABLE3 - cman: More changes for the latest corosync API
@ 2009-05-11 15:07 Christine Caulfield
  0 siblings, 0 replies; only message in thread
From: Christine Caulfield @ 2009-05-11 15:07 UTC (permalink / raw)
  To: cluster-cvs-relay

Gitweb:        http://git.fedorahosted.org/git/cluster.git?p=cluster.git;a=commitdiff;h=af56607de98bb20578833a1261c5c263e9fffac7
Commit:        af56607de98bb20578833a1261c5c263e9fffac7
Parent:        7e6ec0be8f368c2991c1aabff27d39d63adb9486
Author:        Christine Caulfield <ccaulfie@redhat.com>
AuthorDate:    Mon May 11 16:06:46 2009 +0100
Committer:     Christine Caulfield <ccaulfie@redhat.com>
CommitterDate: Mon May 11 16:06:46 2009 +0100

cman: More changes for the latest corosync API

In particular honouring constness of buffers

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
---
 cman/daemon/ais.c      |   31 +++++++++++++++++--------------
 cman/daemon/commands.c |   12 ++++++++++--
 cman/daemon/commands.h |    2 +-
 cman/daemon/daemon.c   |    2 +-
 cman/daemon/daemon.h   |    2 +-
 5 files changed, 30 insertions(+), 19 deletions(-)

diff --git a/cman/daemon/ais.c b/cman/daemon/ais.c
index 3e04dd6..598bff7 100644
--- a/cman/daemon/ais.c
+++ b/cman/daemon/ais.c
@@ -90,7 +90,7 @@ static void cman_confchg_fn(enum totem_configuration_type configuration_type,
 			    const unsigned int *left_list, size_t left_list_entries,
 			    const unsigned int *joined_list, size_t joined_list_entries,
 			    const struct memb_ring_id *ring_id);
-static void cman_deliver_fn(unsigned int nodeid, const struct iovec *iovec, unsigned int iov_len,
+static void cman_deliver_fn(unsigned int nodeid, const void *msg, unsigned int msg_len,
 			    int endian_conversion_required);
 static void cman_quorum_init(struct corosync_api_v1 *api, quorum_set_quorate_fn_t report);
 
@@ -249,28 +249,31 @@ int comms_send_message(void *buf, int len,
 	return corosync->tpg_joined_mcast(group_handle, iov, 2, totem_flags);
 }
 
-// This assumes the iovec has only one element ... is it true ??
-static void cman_deliver_fn(unsigned int nodeid, const struct iovec *iovec, unsigned int iov_len,
+static void cman_deliver_fn(unsigned int nodeid, const void *msg, unsigned int msg_len,
 			    int endian_conversion_required)
 {
-	struct cl_protheader *header = iovec->iov_base;
-	char *buf = iovec->iov_base;
+	const struct cl_protheader *original_header = msg;
+	struct cl_protheader header;
+	const char *buf = msg;
 
 	P_AIS("deliver_fn source nodeid = %d, len=%d, endian_conv=%d\n",
-	      nodeid, (int)iovec->iov_len, endian_conversion_required);
+	      nodeid, msg_len, endian_conversion_required);
 
 	if (endian_conversion_required) {
-		header->srcid = swab32(header->srcid);
-		header->tgtid = swab32(header->tgtid);
-		header->flags = swab32(header->flags);
+		header.srcid = swab32(original_header->srcid);
+		header.tgtid = swab32(original_header->tgtid);
+		header.flags = swab32(original_header->flags);
+	} 
+	else {
+	        memcpy(&header, original_header, sizeof(header));
 	}
 
 	/* Only pass on messages for us or everyone */
-	if (header->tgtid == our_nodeid() ||
-	    header->tgtid == 0) {
-		send_to_userport(header->srcport, header->tgtport,
-				 header->srcid, header->tgtid,
-				 buf + sizeof(struct cl_protheader), iovec->iov_len - sizeof(struct cl_protheader),
+	if (header.tgtid == our_nodeid() ||
+	    header.tgtid == 0) {
+		send_to_userport(header.srcport, header.tgtport,
+				 header.srcid, header.tgtid,
+				 buf + sizeof(struct cl_protheader), msg_len - sizeof(struct cl_protheader),
 				 endian_conversion_required);
 	}
 }
diff --git a/cman/daemon/commands.c b/cman/daemon/commands.c
index 407e33b..11d72e6 100644
--- a/cman/daemon/commands.c
+++ b/cman/daemon/commands.c
@@ -1511,13 +1511,21 @@ int process_command(struct connection *con, int cmd, char *cmdbuf,
 
 int send_to_userport(unsigned char fromport, unsigned char toport,
 		     int nodeid, int tgtid,
-		     char *recv_buf, int len,
+		     const char *recv_buf, int len,
 		     int endian_conv)
 {
 	int ret = -1;
 
 	if (toport == 0) {
-		process_internal_message(recv_buf, nodeid, endian_conv);
+
+	  /* We need to make a private copy here so that the internal command
+	   * processors can do byteswapping.
+	   */
+	        char *newmsg = alloca(len);
+		if (!newmsg)
+		    return -1;
+		memcpy(newmsg, recv_buf, len);
+		process_internal_message(newmsg, nodeid, endian_conv);
 		ret = 0;
 	}
 	else {
diff --git a/cman/daemon/commands.h b/cman/daemon/commands.h
index 7b51309..af0b17a 100644
--- a/cman/daemon/commands.h
+++ b/cman/daemon/commands.h
@@ -5,7 +5,7 @@ extern void process_cnxman_message(char *data, char *addr, int addrlen,
 
 extern int send_to_userport(unsigned char fromport, unsigned char toport,
 			    int nodeid, int tgtnodeid,
-			    char *recv_buf, int len,
+			    const char *recv_buf, int len,
 			    int endian_conv);
 extern void clean_dead_listeners(void);
 extern void unbind_con(struct connection *con);
diff --git a/cman/daemon/daemon.c b/cman/daemon/daemon.c
index d74c454..326c828 100644
--- a/cman/daemon/daemon.c
+++ b/cman/daemon/daemon.c
@@ -425,7 +425,7 @@ int send_status_return(struct connection *con, uint32_t cmd, int status)
 	return send_reply_message(con, (struct sock_header *)&msg);
 }
 
-int send_data_reply(struct connection *con, int nodeid, int port, char *data, int len)
+int send_data_reply(struct connection *con, int nodeid, int port, const char *data, int len)
 {
 	char buf[len + sizeof(struct sock_data_header)];
 	struct sock_data_header *msg = (struct sock_data_header *)buf;
diff --git a/cman/daemon/daemon.h b/cman/daemon/daemon.h
index 6907de3..4c202ef 100644
--- a/cman/daemon/daemon.h
+++ b/cman/daemon/daemon.h
@@ -1,5 +1,5 @@
 extern int send_status_return(struct connection *con, uint32_t cmd, int status);
-extern int send_data_reply(struct connection *con, int nodeid, int port, char *data, int len);
+extern int send_data_reply(struct connection *con, int nodeid, int port, const char *data, int len);
 extern void set_cman_timeout(int secs);
 extern void notify_listeners(struct connection *con, int reason, int arg);
 extern int num_listeners(void);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-05-11 15:07 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-11 15:07 cluster: STABLE3 - cman: More changes for the latest corosync API Christine Caulfield

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).