[sheepdog] [PATCH 1/3] simplify exec_req

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Oct 18 02:49:53 CEST 2012


We can know how many bytes should be read and written from sd_req
header, so we don't need to pass the size with rlen and wlen.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/cluster.c     |   28 +++++++---------------------
 collie/collie.c      |    6 ++----
 collie/common.c      |   19 +++++++------------
 collie/debug.c       |    7 +++----
 collie/node.c        |    7 ++-----
 collie/vdi.c         |   50 +++++++++++++++++---------------------------------
 include/net.h        |    5 ++---
 lib/net.c            |   34 +++++++++++++++++++++++-----------
 sheep/gateway.c      |    8 ++------
 sheep/group.c        |    5 ++---
 sheep/recovery.c     |   13 ++++---------
 sheep/sheep_priv.h   |    2 +-
 sheep/sockfd_cache.c |    4 ++--
 sheep/store.c        |    7 ++-----
 sheepfs/volume.c     |   15 +++++----------
 15 files changed, 81 insertions(+), 129 deletions(-)

diff --git a/collie/cluster.c b/collie/cluster.c
index ace5254..b81ec00 100644
--- a/collie/cluster.c
+++ b/collie/cluster.c
@@ -44,20 +44,16 @@ static int list_store(void)
 	int fd, ret;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	unsigned rlen, wlen;
 	char buf[512] = { 0 };
 
 	fd = connect_to(sdhost, sdport);
 	if (fd < 0)
 		return EXIT_SYSFAIL;
 
-	wlen = 0;
-	rlen = 512;
-
 	sd_init_req(&hdr, SD_OP_GET_STORE_LIST);
-	hdr.data_length = rlen;
+	hdr.data_length = 512;
 
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, buf, NULL);
 	close(fd);
 
 	if (ret) {
@@ -82,7 +78,6 @@ static int cluster_format(int argc, char **argv)
 	int fd, ret;
 	struct sd_so_req hdr;
 	struct sd_so_rsp *rsp = (struct sd_so_rsp *)&hdr;
-	unsigned rlen, wlen;
 	struct timeval tv;
 	char store_name[STORE_LEN];
 
@@ -108,11 +103,8 @@ static int cluster_format(int argc, char **argv)
 	hdr.data_length = strlen(store_name) + 1;
 	hdr.flags |= SD_FLAG_CMD_WRITE;
 
-	wlen = hdr.data_length;
-	rlen = 0;
-
 	printf("using backend %s store\n", store_name);
-	ret = exec_req(fd, (struct sd_req *)&hdr, store_name, &wlen, &rlen);
+	ret = exec_req(fd, (struct sd_req *)&hdr, store_name, NULL);
 	close(fd);
 
 	if (ret) {
@@ -137,7 +129,6 @@ static int cluster_info(int argc, char **argv)
 	int i, fd, ret;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	unsigned rlen, wlen;
 	struct epoch_log *logs;
 	int nr_logs, log_length;
 	time_t ti, ct;
@@ -163,9 +154,7 @@ again:
 	sd_init_req(&hdr, SD_OP_STAT_CLUSTER);
 	hdr.data_length = log_length;
 
-	rlen = hdr.data_length;
-	wlen = 0;
-	ret = exec_req(fd, &hdr, logs, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, logs, NULL);
 	close(fd);
 
 	if (ret != 0)
@@ -269,7 +258,7 @@ static int list_snap(void)
 	int fd, ret = EXIT_SYSFAIL;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	unsigned rlen, wlen;
+	unsigned rlen;
 	void *buf;
 
 	buf = malloc(SD_DATA_OBJ_SIZE);
@@ -280,13 +269,10 @@ static int list_snap(void)
 	if (fd < 0)
 		goto out;
 
-	wlen = 0;
-	rlen = SD_DATA_OBJ_SIZE;
-
 	sd_init_req(&hdr, SD_OP_GET_SNAP_FILE);
-	hdr.data_length = rlen;
+	hdr.data_length = SD_DATA_OBJ_SIZE;
 
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, buf, &rlen);
 	close(fd);
 
 	if (ret) {
diff --git a/collie/collie.c b/collie/collie.c
index 18c3cf2..04567b4 100644
--- a/collie/collie.c
+++ b/collie/collie.c
@@ -47,7 +47,7 @@ unsigned master_idx;
 static int update_node_list(int max_nodes, uint32_t epoch)
 {
 	int fd, ret;
-	unsigned int size, wlen;
+	unsigned int size;
 	char *buf = NULL;
 	struct sd_node *ent;
 	struct sd_node_req hdr;
@@ -69,9 +69,7 @@ static int update_node_list(int max_nodes, uint32_t epoch)
 
 	hdr.data_length = size;
 
-	wlen = 0;
-
-	ret = exec_req(fd, (struct sd_req *)&hdr, buf, &wlen, &size);
+	ret = exec_req(fd, (struct sd_req *)&hdr, buf, &size);
 	if (ret) {
 		ret = -1;
 		goto out;
diff --git a/collie/common.c b/collie/common.c
index bca213b..227b045 100644
--- a/collie/common.c
+++ b/collie/common.c
@@ -48,7 +48,6 @@ int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int fd, ret;
-	unsigned wlen = 0, rlen = datalen;
 
 	fd = connect_to(sdhost, sdport);
 	if (fd < 0) {
@@ -57,14 +56,14 @@ int sd_read_object(uint64_t oid, void *data, unsigned int datalen,
 	}
 
 	sd_init_req(&hdr, SD_OP_READ_OBJ);
-	hdr.data_length = rlen;
+	hdr.data_length = datalen;
 
 	hdr.obj.oid = oid;
 	hdr.obj.offset = offset;
 	if (direct)
 		hdr.flags |= SD_FLAG_CMD_DIRECT;
 
-	ret = exec_req(fd, &hdr, data, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, data, NULL);
 	close(fd);
 
 	if (ret) {
@@ -90,7 +89,6 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int fd, ret;
-	unsigned wlen = datalen, rlen = 0;
 
 	fd = connect_to(sdhost, sdport);
 	if (fd < 0) {
@@ -103,7 +101,7 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
 	else
 		sd_init_req(&hdr, SD_OP_WRITE_OBJ);
 
-	hdr.data_length = wlen;
+	hdr.data_length = datalen;
 	hdr.flags = flags | SD_FLAG_CMD_WRITE;
 	if (cow_oid)
 		hdr.flags |= SD_FLAG_CMD_COW;
@@ -115,7 +113,7 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
 	hdr.obj.cow_oid = cow_oid;
 	hdr.obj.offset = offset;
 
-	ret = exec_req(fd, &hdr, data, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, data, NULL);
 	close(fd);
 
 	if (ret) {
@@ -139,7 +137,7 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 	static struct sheepdog_inode i;
 	struct sd_req req;
 	struct sd_rsp *rsp = (struct sd_rsp *)&req;
-	unsigned int wlen = 0, rlen = SD_DATA_OBJ_SIZE; /* FIXME */
+	unsigned int rlen = SD_DATA_OBJ_SIZE; /* FIXME */
 
 	vc = zalloc(rlen);
 	if (!vc) {
@@ -157,7 +155,7 @@ int parse_vdi(vdi_parser_func_t func, size_t size, void *data)
 	sd_init_req(&req, SD_OP_GET_VDI_COPIES);
 	req.data_length = rlen;
 
-	ret = exec_req(fd, &req, (char *)vc, &wlen, &rlen);
+	ret = exec_req(fd, &req, (char *)vc, NULL);
 	if (ret < 0) {
 		fprintf(stderr, "Failed to read VDIs from %s:%d\n",
 			sdhost, sdport);
@@ -209,15 +207,12 @@ int send_light_req_get_response(struct sd_req *hdr, const char *host, int port)
 {
 	int fd, ret;
 	struct sd_rsp *rsp = (struct sd_rsp *)hdr;
-	unsigned rlen, wlen;
 
 	fd = connect_to(host, port);
 	if (fd < 0)
 		return -1;
 
-	rlen = 0;
-	wlen = 0;
-	ret = exec_req(fd, hdr, NULL, &wlen, &rlen);
+	ret = exec_req(fd, hdr, NULL, NULL);
 	close(fd);
 	if (ret) {
 		fprintf(stderr, "failed to connect to  %s:%d\n",
diff --git a/collie/debug.c b/collie/debug.c
index b2d63d9..8221539 100644
--- a/collie/debug.c
+++ b/collie/debug.c
@@ -77,7 +77,7 @@ static int trace_read_buffer(void)
 	int fd, ret, tfd;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	unsigned rlen, wlen;
+	unsigned rlen;
 #define TRACE_BUF_LEN      (1024 * 1024 * 20)
 	char *buf = xzalloc(TRACE_BUF_LEN);
 
@@ -93,11 +93,10 @@ static int trace_read_buffer(void)
 
 read_buffer:
 	sd_init_req(&hdr, SD_OP_TRACE_READ_BUF);
-	hdr.data_length = rlen = TRACE_BUF_LEN;
+	hdr.data_length = TRACE_BUF_LEN;
 	hdr.epoch = sd_epoch;
 
-	wlen = 0;
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, buf, &rlen);
 
 	if (ret) {
 		fprintf(stderr, "Failed to connect\n");
diff --git a/collie/node.c b/collie/node.c
index b5aeec1..68fe2e2 100644
--- a/collie/node.c
+++ b/collie/node.c
@@ -145,7 +145,6 @@ static int node_cache(int argc, char **argv)
 	char *p;
 	int fd, ret;
 	uint32_t cache_size;
-	unsigned int wlen, rlen = 0;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 
@@ -159,13 +158,11 @@ static int node_cache(int argc, char **argv)
 	if (fd < 0)
 		return EXIT_FAILURE;
 
-	wlen = sizeof(cache_size);
-
 	sd_init_req(&hdr, SD_OP_SET_CACHE_SIZE);
 	hdr.flags = SD_FLAG_CMD_WRITE;
-	hdr.data_length = wlen;
+	hdr.data_length = sizeof(cache_size);
 
-	ret = exec_req(fd, &hdr, (void *)&cache_size, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, (void *)&cache_size, NULL);
 	close(fd);
 
 	if (ret) {
diff --git a/collie/vdi.c b/collie/vdi.c
index b352294..f6ba21b 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -290,7 +290,7 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne
 	}
 
 	for (i = 0; i < sd_nodes_nr; i++) {
-		unsigned wlen = 0, rlen = size;
+		unsigned rlen;
 		struct sd_req hdr;
 		struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 
@@ -301,13 +301,13 @@ static void parse_objs(uint64_t oid, obj_parser_func_t func, void *data, unsigne
 			break;
 
 		sd_init_req(&hdr, SD_OP_READ_PEER);
-		hdr.data_length = rlen;
+		hdr.data_length = size;
 		hdr.flags = 0;
 		hdr.epoch = sd_epoch;
 
 		hdr.obj.oid = oid;
 
-		ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+		ret = exec_req(fd, &hdr, buf, &rlen);
 		close(fd);
 
 		sprintf(name + strlen(name), ":%d", sd_nodes[i].nid.port);
@@ -379,7 +379,6 @@ static int find_vdi_name(char *vdiname, uint32_t snapid, const char *tag,
 	int ret, fd;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	unsigned int wlen, rlen = 0;
 	char buf[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
 
 	fd = connect_to(sdhost, sdport);
@@ -394,12 +393,11 @@ static int find_vdi_name(char *vdiname, uint32_t snapid, const char *tag,
 		sd_init_req(&hdr, SD_OP_GET_VDI_INFO);
 	else
 		sd_init_req(&hdr, SD_OP_LOCK_VDI);
-	wlen = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN;
-	hdr.data_length = wlen;
+	hdr.data_length = SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN;
 	hdr.flags = SD_FLAG_CMD_WRITE;
 	hdr.vdi.snapid = snapid;
 
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, buf, NULL);
 	if (ret) {
 		ret = -1;
 		goto out;
@@ -458,7 +456,6 @@ static int do_vdi_create(char *vdiname, int64_t vdi_size, uint32_t base_vid,
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int fd, ret;
-	unsigned int wlen, rlen = 0;
 	char buf[SD_MAX_VDI_LEN];
 
 	fd = connect_to(sdhost, sdport);
@@ -470,18 +467,16 @@ static int do_vdi_create(char *vdiname, int64_t vdi_size, uint32_t base_vid,
 	memset(buf, 0, sizeof(buf));
 	strncpy(buf, vdiname, SD_MAX_VDI_LEN);
 
-	wlen = SD_MAX_VDI_LEN;
-
 	sd_init_req(&hdr, SD_OP_NEW_VDI);
 	hdr.flags = SD_FLAG_CMD_WRITE;
-	hdr.data_length = wlen;
+	hdr.data_length = SD_MAX_VDI_LEN;
 
 	hdr.vdi.base_vdi_id = base_vid;
 	hdr.vdi.snapid = snapshot ? 1 : 0;
 	hdr.vdi.vdi_size = roundup(vdi_size, 512);
 	hdr.vdi.copies = nr_copies;
 
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, buf, NULL);
 
 	close(fd);
 
@@ -730,26 +725,22 @@ static int do_vdi_delete(const char *vdiname, int snap_id, const char *snap_tag)
 	int fd, ret;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	unsigned rlen, wlen;
 	char data[SD_MAX_VDI_LEN + SD_MAX_VDI_TAG_LEN];
 
 	fd = connect_to(sdhost, sdport);
 	if (fd < 0)
 		return EXIT_SYSFAIL;
 
-	rlen = 0;
-	wlen = sizeof(data);
-
 	sd_init_req(&hdr, SD_OP_DEL_VDI);
 	hdr.flags = SD_FLAG_CMD_WRITE;
-	hdr.data_length = wlen;
+	hdr.data_length = sizeof(data);
 	hdr.vdi.snapid = snap_id;
 	memset(data, 0, sizeof(data));
 	strncpy(data, vdiname, SD_MAX_VDI_LEN);
 	if (snap_tag)
 		strncpy(data + SD_MAX_VDI_LEN, snap_tag, SD_MAX_VDI_TAG_LEN);
 
-	ret = exec_req(fd, &hdr, data, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, data, NULL);
 	close(fd);
 
 	if (ret) {
@@ -867,7 +858,6 @@ static int print_obj_epoch(uint64_t oid)
 	int i, j, fd, ret;
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	unsigned rlen, wlen;
 	struct sd_vnode vnodes[SD_MAX_VNODES];
 	struct sd_vnode *vnode_buf[SD_MAX_COPIES];
 	struct epoch_log *logs;
@@ -894,9 +884,7 @@ again:
 	hdr.epoch = sd_epoch;
 	hdr.data_length = log_length;
 
-	rlen = hdr.data_length;
-	wlen = 0;
-	ret = exec_req(fd, &hdr, logs, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, logs, NULL);
 	close(fd);
 
 	if (ret != 0)
@@ -993,7 +981,6 @@ static int find_vdi_attr_oid(char *vdiname, char *tag, uint32_t snapid,
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int fd, ret;
-	unsigned int wlen, rlen;
 	struct sheepdog_vdi_attr vattr;
 
 	memset(&vattr, 0, sizeof(vattr));
@@ -1013,10 +1000,8 @@ static int find_vdi_attr_oid(char *vdiname, char *tag, uint32_t snapid,
 	}
 
 	sd_init_req(&hdr, SD_OP_GET_VDI_ATTR);
-	wlen = SD_ATTR_OBJ_SIZE;
-	rlen = 0;
 	hdr.flags = SD_FLAG_CMD_WRITE;
-	hdr.data_length = wlen;
+	hdr.data_length = SD_ATTR_OBJ_SIZE;
 	hdr.vdi.snapid = vdi_cmd_data.snapshot_id;
 
 	if (create)
@@ -1026,7 +1011,7 @@ static int find_vdi_attr_oid(char *vdiname, char *tag, uint32_t snapid,
 	if (delete)
 		hdr.flags |= SD_FLAG_CMD_DEL;
 
-	ret = exec_req(fd, &hdr, &vattr, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, &vattr, NULL);
 	if (ret) {
 		ret = SD_RES_EIO;
 		goto out;
@@ -1363,7 +1348,7 @@ static void *read_object_from(struct sd_vnode *vnode, uint64_t oid)
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int fd, ret;
-	unsigned wlen = 0, rlen = SD_DATA_OBJ_SIZE;
+	unsigned rlen;
 	char name[128];
 	void *buf;
 
@@ -1384,11 +1369,11 @@ static void *read_object_from(struct sd_vnode *vnode, uint64_t oid)
 	sd_init_req(&hdr, SD_OP_READ_PEER);
 	hdr.epoch = sd_epoch;
 	hdr.flags = 0;
-	hdr.data_length = rlen;
+	hdr.data_length = SD_DATA_OBJ_SIZE;
 
 	hdr.obj.oid = oid;
 
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, buf, &rlen);
 	close(fd);
 
 	if (ret) {
@@ -1412,7 +1397,6 @@ static void write_object_to(struct sd_vnode *vnode, uint64_t oid, void *buf)
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int fd, ret;
-	unsigned wlen = SD_DATA_OBJ_SIZE, rlen = 0;
 	char name[128];
 
 	addr_to_str(name, sizeof(name), vnode->nid.addr, 0);
@@ -1426,11 +1410,11 @@ static void write_object_to(struct sd_vnode *vnode, uint64_t oid, void *buf)
 	sd_init_req(&hdr, SD_OP_WRITE_PEER);
 	hdr.epoch = sd_epoch;
 	hdr.flags = SD_FLAG_CMD_WRITE;
-	hdr.data_length = wlen;
+	hdr.data_length = SD_DATA_OBJ_SIZE;
 
 	hdr.obj.oid = oid;
 
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, buf, NULL);
 	close(fd);
 
 	if (ret) {
diff --git a/include/net.h b/include/net.h
index 7fd9f46..2966b2d 100644
--- a/include/net.h
+++ b/include/net.h
@@ -41,9 +41,8 @@ int do_read(int sockfd, void *buf, int len);
 int rx(struct connection *conn, enum conn_state next_state);
 int tx(struct connection *conn, enum conn_state next_state, int flags);
 int connect_to(const char *name, int port);
-int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int *wlen);
-int exec_req(int sockfd, struct sd_req *hdr, void *data,
-	     unsigned int *wlen, unsigned int *rlen);
+int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int wlen);
+int exec_req(int sockfd, struct sd_req *hdr, void *data, unsigned int *len);
 int create_listen_ports(char *bindaddr, int port,
 			int (*callback)(int fd, void *), void *data);
 
diff --git a/lib/net.c b/lib/net.c
index 1c6a632..4b32fe7 100644
--- a/lib/net.c
+++ b/lib/net.c
@@ -320,7 +320,7 @@ rewrite:
 	return 0;
 }
 
-int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int *wlen)
+int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int wlen)
 {
 	int ret;
 	struct msghdr msg;
@@ -334,27 +334,36 @@ int send_req(int sockfd, struct sd_req *hdr, void *data, unsigned int *wlen)
 	iov[0].iov_base = hdr;
 	iov[0].iov_len = sizeof(*hdr);
 
-	if (*wlen) {
+	if (wlen) {
 		msg.msg_iovlen++;
 		iov[1].iov_base = data;
-		iov[1].iov_len = *wlen;
+		iov[1].iov_len = wlen;
 	}
 
-	ret = do_write(sockfd, &msg, sizeof(*hdr) + *wlen);
+	ret = do_write(sockfd, &msg, sizeof(*hdr) + wlen);
 	if (ret) {
 		eprintf("failed to send request %x, %d: %m\n", hdr->opcode,
-			*wlen);
+			wlen);
 		ret = -1;
 	}
 
 	return ret;
 }
 
-int exec_req(int sockfd, struct sd_req *hdr, void *data,
-	     unsigned int *wlen, unsigned int *rlen)
+/* when len is not NULL, this function sets *len to the received data size */
+int exec_req(int sockfd, struct sd_req *hdr, void *data, unsigned int *len)
 {
 	int ret;
 	struct sd_rsp *rsp = (struct sd_rsp *)hdr;
+	unsigned int wlen, rlen;
+
+	if (hdr->flags & SD_FLAG_CMD_WRITE) {
+		wlen = hdr->data_length;
+		rlen = 0;
+	} else {
+		wlen = 0;
+		rlen = hdr->data_length;
+	}
 
 	if (send_req(sockfd, hdr, data, wlen))
 		return 1;
@@ -365,17 +374,20 @@ int exec_req(int sockfd, struct sd_req *hdr, void *data,
 		return 1;
 	}
 
-	if (*rlen > rsp->data_length)
-		*rlen = rsp->data_length;
+	if (rlen > rsp->data_length)
+		rlen = rsp->data_length;
 
-	if (*rlen) {
-		ret = do_read(sockfd, data, *rlen);
+	if (rlen) {
+		ret = do_read(sockfd, data, rlen);
 		if (ret) {
 			eprintf("failed to read the response data\n");
 			return 1;
 		}
 	}
 
+	if (len)
+		*len = rlen;
+
 	return 0;
 }
 
diff --git a/sheep/gateway.c b/sheep/gateway.c
index f9419ec..1f25850 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -31,7 +31,6 @@ static inline void gateway_init_fwd_hdr(struct sd_req *fwd, struct sd_req *hdr)
 int gateway_read_obj(struct request *req)
 {
 	int i, ret = SD_RES_SUCCESS;
-	unsigned wlen, rlen;
 	struct sd_req fwd_hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&fwd_hdr;
 	struct sd_vnode *v;
@@ -76,10 +75,7 @@ int gateway_read_obj(struct request *req)
 		 * structure.
 		 */
 		gateway_init_fwd_hdr(&fwd_hdr, &req->rq);
-		wlen = 0;
-		rlen = fwd_hdr.data_length;
-		ret = sheep_exec_req(&v->nid, &fwd_hdr, req->data, &wlen,
-				     &rlen);
+		ret = sheep_exec_req(&v->nid, &fwd_hdr, req->data, NULL);
 		if (ret != SD_RES_SUCCESS)
 			continue;
 
@@ -288,7 +284,7 @@ static int gateway_forward_request(struct request *req, bool all_node)
 			break;
 		}
 
-		ret = send_req(sfd->fd, &hdr, req->data, &wlen);
+		ret = send_req(sfd->fd, &hdr, req->data, wlen);
 		if (ret) {
 			sheep_del_sockfd(nid, sfd);
 			err_ret = SD_RES_NETWORK_ERROR;
diff --git a/sheep/group.c b/sheep/group.c
index ebb6192..62e32a6 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -607,7 +607,7 @@ static int get_vdis_from(struct sd_node *node)
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	struct vdi_copy *vc = NULL;
 	int i, ret = SD_RES_SUCCESS;
-	unsigned int rlen, wlen;
+	unsigned int rlen;
 	int count;
 
 	if (node_is_local(node))
@@ -624,8 +624,7 @@ static int get_vdis_from(struct sd_node *node)
 	sd_init_req(&hdr, SD_OP_GET_VDI_COPIES);
 	hdr.epoch = sys->epoch;
 	hdr.data_length = rlen;
-	wlen = 0;
-	ret = sheep_exec_req(&node->nid, &hdr, (char *)vc, &wlen, &rlen);
+	ret = sheep_exec_req(&node->nid, &hdr, (char *)vc, NULL);
 	if (ret != SD_RES_SUCCESS)
 		goto out;
 
diff --git a/sheep/recovery.c b/sheep/recovery.c
index f455a2b..3c58231 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -65,7 +65,7 @@ static int recover_object_from_replica(uint64_t oid, struct sd_vnode *vnode,
 {
 	struct sd_req hdr;
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-	unsigned wlen = 0, rlen;
+	unsigned rlen;
 	int ret = SD_RES_NO_MEM;
 	void *buf = NULL;
 	struct siocb iocb = { 0 };
@@ -91,7 +91,7 @@ static int recover_object_from_replica(uint64_t oid, struct sd_vnode *vnode,
 	hdr.obj.oid = oid;
 	hdr.obj.tgt_epoch = tgt_epoch;
 
-	ret = sheep_exec_req(&vnode->nid, &hdr, buf, &wlen, &rlen);
+	ret = sheep_exec_req(&vnode->nid, &hdr, buf, &rlen);
 	if (ret != SD_RES_SUCCESS)
 		goto out;
 	iocb.epoch = epoch;
@@ -507,7 +507,6 @@ static void finish_object_list(struct work *work)
 static int fetch_object_list(struct sd_node *e, uint32_t epoch,
 			     uint8_t *buf, size_t buf_size)
 {
-	unsigned wlen, rlen;
 	char name[128];
 	struct sd_list_req hdr;
 	struct sd_list_rsp *rsp = (struct sd_list_rsp *)&hdr;
@@ -517,15 +516,11 @@ static int fetch_object_list(struct sd_node *e, uint32_t epoch,
 
 	dprintf("%s %"PRIu32"\n", name, e->nid.port);
 
-	wlen = 0;
-	rlen = buf_size;
-
 	sd_init_req((struct sd_req *)&hdr, SD_OP_GET_OBJ_LIST);
 	hdr.tgt_epoch = epoch - 1;
-	hdr.flags = 0;
-	hdr.data_length = rlen;
+	hdr.data_length = buf_size;
 
-	ret = sheep_exec_req(&e->nid, (struct sd_req *)&hdr, buf, &wlen, &rlen);
+	ret = sheep_exec_req(&e->nid, (struct sd_req *)&hdr, buf, NULL);
 
 	if (ret != SD_RES_SUCCESS)
 		return -1;
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index d308751..d0f6f00 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -405,7 +405,7 @@ struct sockfd *sheep_get_sockfd(struct node_id *);
 void sheep_put_sockfd(struct node_id *, struct sockfd *);
 void sheep_del_sockfd(struct node_id *, struct sockfd *);
 int sheep_exec_req(struct node_id *nid, struct sd_req *hdr, void *data,
-		   unsigned int *wlen, unsigned int *rlen);
+		   unsigned int *rlen);
 
 static inline bool is_object_cache_enabled(void)
 {
diff --git a/sheep/sockfd_cache.c b/sheep/sockfd_cache.c
index ac1c9ce..6f3da08 100644
--- a/sheep/sockfd_cache.c
+++ b/sheep/sockfd_cache.c
@@ -464,7 +464,7 @@ void sheep_del_sockfd(struct node_id *nid, struct sockfd *sfd)
 }
 
 int sheep_exec_req(struct node_id *nid, struct sd_req *hdr, void *buf,
-		   unsigned int *wlen, unsigned int *rlen)
+		   unsigned int *rlen)
 {
 	struct sd_rsp *rsp = (struct sd_rsp *)hdr;
 	struct sockfd *sfd;
@@ -474,7 +474,7 @@ int sheep_exec_req(struct node_id *nid, struct sd_req *hdr, void *buf,
 	if (!sfd)
 		return SD_RES_NETWORK_ERROR;
 
-	ret = exec_req(sfd->fd, hdr, buf, wlen, rlen);
+	ret = exec_req(sfd->fd, hdr, buf, rlen);
 	if (ret) {
 		dprintf("remote node might have gone away\n");
 		sheep_del_sockfd(nid, sfd);
diff --git a/sheep/store.c b/sheep/store.c
index e3c95bd..64c9e5d 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -92,17 +92,14 @@ int epoch_log_read_remote(uint32_t epoch, struct sd_node *nodes, int len)
 	for (i = 0; i < nr; i++) {
 		struct sd_req hdr;
 		struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
-		unsigned int rlen, wlen;
 
 		if (node_is_local(&local_nodes[i]))
 			continue;
 
 		sd_init_req(&hdr, SD_OP_GET_EPOCH);
-		hdr.data_length = rlen = len;
+		hdr.data_length = len;
 		hdr.obj.tgt_epoch = epoch;
-		wlen = 0;
-		ret = sheep_exec_req(&local_nodes[i].nid, &hdr, nodes, &wlen,
-				     &rlen);
+		ret = sheep_exec_req(&local_nodes[i].nid, &hdr, nodes, NULL);
 		if (ret != SD_RES_SUCCESS)
 			continue;
 
diff --git a/sheepfs/volume.c b/sheepfs/volume.c
index 20cf029..80492b6 100644
--- a/sheepfs/volume.c
+++ b/sheepfs/volume.c
@@ -140,7 +140,6 @@ static int volume_rw_object(char *buf, uint64_t oid, size_t size,
 	struct sd_req hdr = { 0 };
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int ret, fd, sock_idx;
-	unsigned wlen = 0, rlen = 0;
 	bool create = false;
 	uint32_t vid = oid_to_vid(oid);
 	struct vdi_inode *vdi;
@@ -182,11 +181,9 @@ static int volume_rw_object(char *buf, uint64_t oid, size_t size,
 		}
 	}
 
-	if (rw == VOLUME_READ) {
-		rlen = size;
+	if (rw == VOLUME_READ)
 		hdr.opcode = SD_OP_READ_OBJ;
-	} else {
-		wlen = size;
+	else {
 		hdr.opcode = create ?
 			SD_OP_CREATE_AND_WRITE_OBJ : SD_OP_WRITE_OBJ;
 		hdr.flags |= SD_FLAG_CMD_WRITE;
@@ -200,7 +197,7 @@ static int volume_rw_object(char *buf, uint64_t oid, size_t size,
 		hdr.flags |= SD_FLAG_CMD_CACHE;
 
 	fd = get_socket_fd(vdi, &sock_idx);
-	ret = exec_req(fd, &hdr, buf, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, buf, NULL);
 	put_socket_fd(vdi, sock_idx);
 
 	if (ret || rsp->result != SD_RES_SUCCESS) {
@@ -296,7 +293,6 @@ static int volume_do_sync(uint32_t vid)
 	struct sd_req hdr = { 0 };
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int ret, fd, idx;
-	unsigned wlen = 0, rlen = 0;
 	struct vdi_inode *vdi;
 
 	pthread_rwlock_rdlock(&vdi_inode_tree_lock);
@@ -307,7 +303,7 @@ static int volume_do_sync(uint32_t vid)
 	hdr.obj.oid = vid_to_vdi_oid(vid);
 
 	fd = get_socket_fd(vdi, &idx);
-	ret = exec_req(fd, &hdr, NULL, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, NULL, NULL);
 	put_socket_fd(vdi, idx);
 
 	if (ret || rsp->result != SD_RES_SUCCESS) {
@@ -484,7 +480,6 @@ static int volume_sync_and_delete(uint32_t vid)
 	struct sd_req hdr = { 0 };
 	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;
 	int ret, fd, idx;
-	unsigned wlen = 0, rlen = 0;
 	struct vdi_inode *vdi;
 
 	pthread_rwlock_rdlock(&vdi_inode_tree_lock);
@@ -495,7 +490,7 @@ static int volume_sync_and_delete(uint32_t vid)
 	hdr.obj.oid = vid_to_vdi_oid(vid);
 
 	fd = get_socket_fd(vdi, &idx);
-	ret = exec_req(fd, &hdr, NULL, &wlen, &rlen);
+	ret = exec_req(fd, &hdr, NULL, NULL);
 	put_socket_fd(vdi, idx);
 
 	if (ret || rsp->result != SD_RES_SUCCESS) {
-- 
1.7.2.5




More information about the sheepdog mailing list