[Sheepdog] [PATCH 3/3] sheep: fix nr_copies in vdi.c

Liu Yuan namei.unix at gmail.com
Mon Apr 30 10:53:47 CEST 2012


From: Liu Yuan <tailai.ly at taobao.com>

- for vdi create operation, if we have less available nodes for
  desired redundancy, simply fail-returen. So no need to change
  copies into nr_zones.
- for delete_one, let's keep its origin logic as before commit:
  ad8c5cf6495

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/vdi.c |   37 +++++++++++++------------------------
 1 files changed, 13 insertions(+), 24 deletions(-)

diff --git a/sheep/vdi.c b/sheep/vdi.c
index 0788f26..c9fbb69 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -27,7 +27,6 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 	struct timeval tv;
 	int ret = SD_RES_NO_MEM;
 	unsigned long block_size = SD_DATA_OBJ_SIZE;
-	int nr_copies;
 
 	new = zalloc(sizeof(*new));
 	if (!new) {
@@ -53,14 +52,10 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 
 	vnode_info = get_vnode_info();
 
-	nr_copies = get_nr_copies(vnode_info);
-	if (nr_copies > copies)
-		nr_copies = copies;
-
 	if (base_vid) {
 		ret = read_object(vnode_info, epoch,
 				  vid_to_vdi_oid(base_vid), (char *)base,
-				  sizeof(*base), 0, nr_copies);
+				  sizeof(*base), 0, copies);
 		if (ret != SD_RES_SUCCESS) {
 			ret = SD_RES_BASE_VDI_READ;
 			goto out_put_vnode_info;
@@ -76,7 +71,7 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 
 			ret = read_object(vnode_info, epoch,
 					  vid_to_vdi_oid(cur_vid), (char *)cur,
-					  SD_INODE_HEADER_SIZE, 0, nr_copies);
+					  SD_INODE_HEADER_SIZE, 0, copies);
 			if (ret != SD_RES_SUCCESS) {
 				vprintf(SDOG_ERR, "failed\n");
 				ret = SD_RES_BASE_VDI_READ;
@@ -119,7 +114,7 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 	if (is_snapshot && cur_vid != base_vid) {
 		ret = write_object(vnode_info, epoch,
 				   vid_to_vdi_oid(cur_vid), (char *)cur,
-				   SD_INODE_HEADER_SIZE, 0, 0, nr_copies, 0);
+				   SD_INODE_HEADER_SIZE, 0, 0, copies, 0);
 		if (ret != 0) {
 			vprintf(SDOG_ERR, "failed\n");
 			ret = SD_RES_BASE_VDI_READ;
@@ -130,7 +125,7 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 	if (base_vid) {
 		ret = write_object(vnode_info, epoch,
 				   vid_to_vdi_oid(base_vid), (char *)base,
-				   SD_INODE_HEADER_SIZE, 0, 0, nr_copies, 0);
+				   SD_INODE_HEADER_SIZE, 0, 0, copies, 0);
 		if (ret != 0) {
 			vprintf(SDOG_ERR, "failed\n");
 			ret = SD_RES_BASE_VDI_WRITE;
@@ -140,7 +135,7 @@ static int create_vdi_obj(uint32_t epoch, char *name, uint32_t new_vid, uint64_t
 
 	ret = write_object(vnode_info, epoch,
 			   vid_to_vdi_oid(new_vid), (char *)new, sizeof(*new),
-			   0, 0, nr_copies, 1);
+			   0, 0, copies, 1);
 	if (ret != 0)
 		ret = SD_RES_VDI_WRITE;
 
@@ -428,7 +423,7 @@ static int delete_inode(struct deletion_work *dw)
 
 	ret = write_object(dw->vnodes, dw->epoch, vid_to_vdi_oid(dw->vid),
 			   (char *)inode, SD_INODE_HEADER_SIZE, 0, 0,
-			   nr_copies, 0);
+			   inode->nr_copies, 0);
 	if (ret != 0) {
 		ret = SD_RES_EIO;
 		goto out;
@@ -481,7 +476,7 @@ static void delete_one(struct work *work)
 
 		ret = remove_object(dw->vnodes, dw->epoch,
 			      vid_to_data_oid(inode->data_vdi_id[i], i),
-			      nr_copies);
+			      inode->nr_copies);
 
 		if (ret != SD_RES_SUCCESS)
 			dw->delete_error = 1;
@@ -491,7 +486,7 @@ static void delete_one(struct work *work)
 
 	if (dw->delete_error) {
 		write_object(dw->vnodes, dw->epoch, vid_to_vdi_oid(vdi_id),
-			     (void *)inode, sizeof(*inode), 0, 0, nr_copies, 0);
+			     (void *)inode, sizeof(*inode), 0, 0, inode->nr_copies, 0);
 	}
 
 out:
@@ -577,7 +572,6 @@ static uint64_t get_vdi_root(struct vnode_info *vnode_info, uint32_t epoch,
 {
 	int ret;
 	struct sheepdog_inode *inode = NULL;
-	int nr_copies = get_nr_copies(vnode_info);
 
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
@@ -587,7 +581,7 @@ static uint64_t get_vdi_root(struct vnode_info *vnode_info, uint32_t epoch,
 	}
 next:
 	ret = read_object(vnode_info, epoch, vid_to_vdi_oid(vid), (char *)inode,
-			  SD_INODE_HEADER_SIZE, 0, nr_copies);
+			  SD_INODE_HEADER_SIZE, 0, sys->nr_copies);
 
 	if (vid == inode->vdi_id && inode->snap_id == 1
 			&& inode->parent_vdi_id != 0
@@ -686,17 +680,12 @@ int get_vdi_attr(uint32_t epoch, struct sheepdog_vdi_attr *vattr, int data_len,
 	struct sheepdog_vdi_attr tmp_attr;
 	uint64_t oid, hval;
 	uint32_t end;
-	int nr_copies;
 	int ret;
 
 	vattr->ctime = ctime;
 
 	vnode_info = get_vnode_info();
 
-	nr_copies = get_nr_copies(vnode_info);
-	if (nr_copies > copies)
-		nr_copies = copies;
-
 	/* we cannot include value_len for calculating the hash value */
 	hval = fnv_64a_buf(vattr->name, sizeof(vattr->name), FNV1A_64_INIT);
 	hval = fnv_64a_buf(vattr->tag, sizeof(vattr->tag), hval);
@@ -708,12 +697,12 @@ int get_vdi_attr(uint32_t epoch, struct sheepdog_vdi_attr *vattr, int data_len,
 	while (*attrid != end) {
 		oid = vid_to_attr_oid(vid, *attrid);
 		ret = read_object(vnode_info, epoch, oid, (char *)&tmp_attr,
-				  sizeof(tmp_attr), 0, nr_copies);
+				  sizeof(tmp_attr), 0, copies);
 
 		if (ret == SD_RES_NO_OBJ && wr) {
 			ret = write_object(vnode_info, epoch, oid,
 					   (char *)vattr, data_len, 0, 0,
-					   nr_copies, 1);
+					   copies, 1);
 			if (ret)
 				ret = SD_RES_EIO;
 			else
@@ -735,7 +724,7 @@ int get_vdi_attr(uint32_t epoch, struct sheepdog_vdi_attr *vattr, int data_len,
 				ret = write_object(vnode_info,
 						   epoch, oid, (char *)"", 1,
 						   offsetof(struct sheepdog_vdi_attr, name),
-						   0, nr_copies, 0);
+						   0, copies, 0);
 				if (ret)
 					ret = SD_RES_EIO;
 				else
@@ -744,7 +733,7 @@ int get_vdi_attr(uint32_t epoch, struct sheepdog_vdi_attr *vattr, int data_len,
 				ret = write_object(vnode_info,
 						   epoch, oid, (char *)vattr,
 						   SD_ATTR_OBJ_SIZE, 0, 0,
-						   nr_copies, 0);
+						   copies, 0);
 
 				if (ret)
 					ret = SD_RES_EIO;
-- 
1.7.8.2




More information about the sheepdog mailing list