[sheepdog] [PATCH 08/10] sheep: set SD_FLAG_CMD_WRITE in sd_init_req

Liu Yuan namei.unix at gmail.com
Tue Oct 15 16:36:41 CEST 2013


It is easy to forget to set SD_FLAG_CMD_WRITE for write and create and hard
to debug, so set it directly in sd_init_req().

Signed-off-by: Liu Yuan <namei.unix at gmail.com>
---
 dog/common.c         |    1 -
 include/sheep.h      |    2 ++
 sheep/gateway.c      |    1 -
 sheep/object_cache.c |    3 ---
 sheep/store.c        |    3 ---
 5 files changed, 2 insertions(+), 8 deletions(-)

diff --git a/dog/common.c b/dog/common.c
index a2fb945..b70080e 100644
--- a/dog/common.c
+++ b/dog/common.c
@@ -100,7 +100,6 @@ int sd_write_object(uint64_t oid, uint64_t cow_oid, void *data,
 		sd_init_req(&hdr, SD_OP_WRITE_OBJ);
 
 	hdr.data_length = datalen;
-	hdr.flags = flags | SD_FLAG_CMD_WRITE;
 	if (cow_oid)
 		hdr.flags |= SD_FLAG_CMD_COW;
 	if (direct)
diff --git a/include/sheep.h b/include/sheep.h
index 293e057..f93026f 100644
--- a/include/sheep.h
+++ b/include/sheep.h
@@ -54,6 +54,8 @@ static inline void sd_init_req(struct sd_req *req, uint8_t opcode)
 	memset(req, 0, sizeof(*req));
 	req->opcode = opcode;
 	req->proto_ver = opcode < 0x80 ? SD_PROTO_VER : SD_SHEEP_PROTO_VER;
+	if (opcode == SD_OP_CREATE_AND_WRITE_OBJ || opcode == SD_OP_WRITE_OBJ)
+		req->flags = SD_FLAG_CMD_WRITE;
 }
 
 static inline int same_zone(const struct sd_vnode *v1,
diff --git a/sheep/gateway.c b/sheep/gateway.c
index e9d08c3..0f1e5ed 100644
--- a/sheep/gateway.c
+++ b/sheep/gateway.c
@@ -577,7 +577,6 @@ static int gateway_handle_cow(struct request *req)
 
 	memcpy(buf + req_hdr->obj.offset, req->data, req_hdr->data_length);
 	sd_init_req(&hdr, SD_OP_CREATE_AND_WRITE_OBJ);
-	hdr.flags = SD_FLAG_CMD_WRITE;
 	hdr.obj.oid = oid;
 	hdr.data_length = len;
 	hdr.obj.offset = 0;
diff --git a/sheep/object_cache.c b/sheep/object_cache.c
index e1968fc..5f1b4f9 100644
--- a/sheep/object_cache.c
+++ b/sheep/object_cache.c
@@ -431,9 +431,7 @@ static int write_cache_object(struct object_cache_entry *entry, void *buf,
 		sd_init_req(&hdr, SD_OP_CREATE_AND_WRITE_OBJ);
 	else
 		sd_init_req(&hdr, SD_OP_WRITE_OBJ);
-	hdr.flags =  SD_FLAG_CMD_WRITE;
 	hdr.data_length = count;
-
 	hdr.obj.oid = oid;
 	hdr.obj.offset = offset;
 
@@ -481,7 +479,6 @@ static int push_cache_object(uint32_t vid, uint32_t idx, uint64_t bmap,
 		sd_init_req(&hdr, SD_OP_CREATE_AND_WRITE_OBJ);
 	else
 		sd_init_req(&hdr, SD_OP_WRITE_OBJ);
-	hdr.flags = SD_FLAG_CMD_WRITE;
 	hdr.data_length = data_length;
 	hdr.obj.oid = oid;
 	hdr.obj.offset = offset;
diff --git a/sheep/store.c b/sheep/store.c
index b092dea..4f1c599 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -370,12 +370,9 @@ forward_write:
 		sd_init_req(&hdr, SD_OP_CREATE_AND_WRITE_OBJ);
 	else
 		sd_init_req(&hdr, SD_OP_WRITE_OBJ);
-	hdr.flags = SD_FLAG_CMD_WRITE;
 	hdr.data_length = datalen;
-
 	hdr.obj.oid = oid;
 	hdr.obj.offset = offset;
-
 	ret = exec_local_req(&hdr, data);
 	if (ret != SD_RES_SUCCESS)
 		sd_err("failed to write object %" PRIx64 ", %s", oid,
-- 
1.7.9.5




More information about the sheepdog mailing list