[Sheepdog] [PATCH] sheep: use hash value for vdi attribute object id

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Aug 2 07:46:17 CEST 2011


The vdi id can change if we get the snapshot, so there is a problem
that vdi attributes vanish after taking snapshots.  This patch uses
the hash value for the vdi attribute object id instead of the vdi id.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
Hi Chris,

Thank you for your testing.  I've implemented another approach.
Could you try again?


Thanks,

Kazutaka


 sheep/group.c      |    7 ++++++-
 sheep/sheep_priv.h |    2 +-
 sheep/vdi.c        |   15 +++------------
 3 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/sheep/group.c b/sheep/group.c
index 9e039e7..957daf1 100644
--- a/sheep/group.c
+++ b/sheep/group.c
@@ -686,8 +686,13 @@ static void vdi_op(struct vdi_op_message *msg)
 				 &vid, hdr->snapid, &nr_copies);
 		if (ret != SD_RES_SUCCESS)
 			break;
+		/* the curernt vdi id can change if we take the snapshot,
+		   so we use the hash value of the vdi name as the vdi id */
+		vid = fnv_64a_buf(data, strlen(data), FNV1A_64_INIT);
+		vid &= SD_NR_VDIS - 1;
 		ret = get_vdi_attr(hdr->epoch, data, hdr->data_length, vid,
-				   &attrid, hdr->flags & SD_FLAG_CMD_CREAT,
+				   &attrid, nr_copies,
+				   hdr->flags & SD_FLAG_CMD_CREAT,
 				   hdr->flags & SD_FLAG_CMD_EXCL);
 		break;
 	case SD_OP_RELEASE_VDI:
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index e0be2cc..06edfc7 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -160,7 +160,7 @@ int lookup_vdi(uint32_t epoch, char *data, int data_len, uint32_t *vid,
 int read_vdis(char *data, int len, unsigned int *rsp_len);
 
 int get_vdi_attr(uint32_t epoch, char *data, int data_len, uint32_t vid,
-		 uint32_t *attrid, int creat, int excl);
+		 uint32_t *attrid, int copies, int creat, int excl);
 
 int get_ordered_sd_node_list(struct sheepdog_node_list_entry *entries);
 void setup_ordered_sd_vnode_list(struct request *req);
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 9518085..9f8ce01 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -538,28 +538,19 @@ int start_deletion(uint32_t vid, uint32_t epoch)
 }
 
 int get_vdi_attr(uint32_t epoch, char *data, int data_len, uint32_t vid,
-		 uint32_t *attrid, int creat, int excl)
+		 uint32_t *attrid, int copies, int creat, int excl)
 {
 	struct sheepdog_vnode_list_entry entries[SD_MAX_VNODES];
-	char attr_buf[SD_ATTR_HEADER_SIZE], inode_buf[SD_INODE_HEADER_SIZE];
+	char attr_buf[SD_ATTR_HEADER_SIZE];
 	uint64_t oid;
 	uint32_t end;
-	int ret, nr_nodes, nr_vnodes, copies;
+	int ret, nr_nodes, nr_vnodes;
 
 	if (data_len != SD_ATTR_HEADER_SIZE)
 		return SD_RES_INVALID_PARMS;
 
 	get_ordered_sd_vnode_list(entries, &nr_vnodes, &nr_nodes);
 
-	ret = read_object(entries, nr_vnodes, nr_nodes, epoch, vid_to_vdi_oid(vid),
-			  inode_buf, sizeof(inode_buf), 0, sys->nr_sobjs);
-	if (ret != SD_INODE_HEADER_SIZE) {
-		eprintf("failed to read vdi object, %"PRIx32"\n", vid);
-		return -ret;
-	}
-
-	copies = ((struct sheepdog_inode *)inode_buf)->nr_copies;
-
 	*attrid = fnv_64a_buf(data, data_len, FNV1A_64_INIT);
 	*attrid &= (UINT64_C(1) << VDI_SPACE_SHIFT) - 1;
 
-- 
1.7.2.5




More information about the sheepdog mailing list