[sheepdog] [PATCH 2/3] add a helper function to calculate the max size of objects

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sun Jul 8 09:33:01 CEST 2012


This prepares for the next patch.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/sheepdog_proto.h |   11 +++++++++++
 sheep/ops.c              |   10 +---------
 sheep/recovery.c         |    7 +------
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index d31db57..e06d830 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -239,6 +239,17 @@ static inline int is_data_obj(uint64_t oid)
 		!is_vdi_attr_obj(oid);
 }
 
+static inline size_t get_objsize(uint64_t oid)
+{
+	if (is_vdi_obj(oid))
+		return SD_INODE_SIZE;
+
+	if (is_vdi_attr_obj(oid))
+		return SD_ATTR_OBJ_SIZE;
+
+	return SD_DATA_OBJ_SIZE;
+}
+
 static inline uint64_t data_oid_to_idx(uint64_t oid)
 {
 	return oid & (MAX_DATA_OBJS - 1);
diff --git a/sheep/ops.c b/sheep/ops.c
index 0da1bbd..ecf4f2e 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -714,20 +714,12 @@ int peer_create_and_write_obj(struct request *req)
 	uint64_t oid = hdr->obj.oid;
 	char *buf = NULL;
 	struct siocb iocb;
-	unsigned data_length;
 	int ret = SD_RES_SUCCESS;
 
-	if (is_vdi_obj(oid))
-		data_length = SD_INODE_SIZE;
-	else if (is_vdi_attr_obj(oid))
-		data_length = SD_ATTR_OBJ_SIZE;
-	else
-		data_length = SD_DATA_OBJ_SIZE;
-
 	memset(&iocb, 0, sizeof(iocb));
 	iocb.epoch = epoch;
 	iocb.flags = hdr->flags;
-	iocb.length = data_length;
+	iocb.length = get_objsize(oid);
 	if (hdr->flags & SD_FLAG_CMD_COW) {
 		dprintf("%" PRIx64 ", %" PRIx64 "\n", oid, hdr->obj.cow_oid);
 
diff --git a/sheep/recovery.c b/sheep/recovery.c
index a6e98b4..3a609da 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -67,12 +67,7 @@ static int recover_object_from_replica(uint64_t oid,
 	void *buf;
 	struct siocb iocb = { 0 };
 
-	if (is_vdi_obj(oid))
-		rlen = SD_INODE_SIZE;
-	else if (is_vdi_attr_obj(oid))
-		rlen = SD_ATTR_OBJ_SIZE;
-	else
-		rlen = SD_DATA_OBJ_SIZE;
+	rlen = get_objsize(oid);
 
 	buf = valloc(rlen);
 	if (!buf) {
-- 
1.7.9.5




More information about the sheepdog mailing list