[Sheepdog] [PATCH 1/7] distinguish different kinds of objects

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Thu Apr 7 02:56:17 CEST 2011


Sheepdog has four kinds of objects:

  vdi object      - contains metadata of vdi
  data object     - contains actual data of vdi
  vmstate object  - contains vmstate data which is used for live snapshot
  vdi attr object - contains vdi attributes

This patch distinguishes these objects and makes codes easy to maintain.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 include/sheepdog_proto.h |   18 +++++++++++++++++-
 sheep/group.c            |    2 +-
 sheep/store.c            |   28 +++++++++++++++++-----------
 3 files changed, 35 insertions(+), 13 deletions(-)

diff --git a/include/sheepdog_proto.h b/include/sheepdog_proto.h
index 954d276..1614bb7 100644
--- a/include/sheepdog_proto.h
+++ b/include/sheepdog_proto.h
@@ -208,9 +208,25 @@ static inline int is_data_obj_writeable(struct sheepdog_inode *inode, int idx)
 	return inode->vdi_id == inode->data_vdi_id[idx];
 }
 
+static inline int is_vdi_obj(uint64_t oid)
+{
+	return !!(oid & VDI_BIT);
+}
+
+static inline int is_vmstate_obj(uint64_t oid)
+{
+	return !!(oid & VMSTATE_BIT);
+}
+
+static inline int is_vdi_attr_obj(uint64_t oid)
+{
+	return !!(oid & VDI_ATTR_BIT);
+}
+
 static inline int is_data_obj(uint64_t oid)
 {
-	return !(VDI_BIT & oid);
+	return !is_vdi_obj(oid) && !is_vmstate_obj(oid) &&
+		!is_vdi_attr_obj(oid);
 }
 
 static inline uint64_t data_oid_to_idx(uint64_t oid)
diff --git a/sheep/group.c b/sheep/group.c
index b67ca4e..ae7b385 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -1355,7 +1355,7 @@ do_retry:
 				struct data_object_bmap *bmap;
 
 				req->check_consistency = 1;
-				if (is_data_obj(hdr->oid)) {
+				if (!is_vdi_obj(hdr->oid)) {
 					list_for_each_entry(bmap, &sys->consistent_obj_list, list) {
 						if (bmap->vdi_id == vdi_id) {
 							if (test_bit(data_oid_to_idx(hdr->oid), bmap->dobjs))
diff --git a/sheep/store.c b/sheep/store.c
index 21b4425..e5a04a0 100644
--- a/sheep/store.c
+++ b/sheep/store.c
@@ -688,7 +688,7 @@ static int store_queue_request_local(struct request *req, uint32_t epoch)
 		if (hdr->flags & SD_FLAG_CMD_TRUNCATE)
 			ftruncate(fd, hdr->offset + hdr->data_length);
 
-		if (!is_data_obj(oid)) {
+		if (is_vdi_obj(oid)) {
 			jd.jdf_epoch = epoch;
 			jd.jdf_oid = oid;
 			jd.jdf_target_fd = fd;
@@ -746,10 +746,12 @@ static int fix_object_consistency(struct request *req, int idx)
 	void *data = req->data, *buf;
 	uint64_t oid = hdr->oid;
 
-	if (is_data_obj(hdr->oid))
-		data_length = SD_DATA_OBJ_SIZE;
-	else
+	if (is_vdi_obj(hdr->oid))
 		data_length = sizeof(struct sheepdog_inode);
+	else if (is_vdi_attr_obj(hdr->oid))
+		data_length = SD_MAX_VDI_ATTR_VALUE_LEN;
+	else
+		data_length = SD_DATA_OBJ_SIZE;
 
 	buf = zalloc(data_length);
 	if (buf == NULL) {
@@ -1188,10 +1190,12 @@ next:
 		return -1;
 	}
 
-	if (is_data_obj(oid))
-		rlen = SD_DATA_OBJ_SIZE;
-	else
+	if (is_vdi_obj(oid))
 		rlen = sizeof(struct sheepdog_inode);
+	else if (is_vdi_attr_obj(oid))
+		rlen = SD_MAX_VDI_ATTR_VALUE_LEN;
+	else
+		rlen = SD_DATA_OBJ_SIZE;
 
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.opcode = SD_OP_READ_OBJ;
@@ -1316,10 +1320,12 @@ static void recover_one(struct work *work, int idx)
 		goto out;
 	}
 
-	if (is_data_obj(oid))
-		buf = malloc(SD_DATA_OBJ_SIZE);
-	else
+	if (is_vdi_obj(oid))
 		buf = malloc(sizeof(struct sheepdog_inode));
+	else if (is_vdi_attr_obj(oid))
+		buf = malloc(SD_MAX_VDI_ATTR_VALUE_LEN);
+	else
+		buf = malloc(SD_DATA_OBJ_SIZE);
 
 	cur_nr_nodes = epoch_log_read(epoch, (char *)cur_nodes, sizeof(cur_nodes));
 	if (cur_nr_nodes <= 0) {
@@ -1843,7 +1849,7 @@ static int init_epoch_path(const char *base_path)
 
 		oid = strtoull(dent->d_name, NULL, 16);
 
-		if (is_data_obj(oid))
+		if (!is_vdi_obj(oid))
 			continue;
 
 		vprintf(SDOG_DEBUG "found the vdi obj, %" PRIx64 "\n", oid);
-- 
1.5.6.5




More information about the sheepdog mailing list