[sheepdog] [PATCH 2/6] sheep: remove nr_copies parameter

Liu Yuan namei.unix at gmail.com
Mon Apr 22 17:34:11 CEST 2013


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

We have a vdi_copy tree and we can get the vdi copy information for the tree
on the fly, no need to get it from inode.

Signed-off-by: Liu Yuan <tailai.ly at taobao.com>
---
 sheep/ops.c        |   25 +++++++++----------------
 sheep/sheep_priv.h |    4 ++--
 sheep/vdi.c        |   31 ++++++++++++-------------------
 3 files changed, 23 insertions(+), 37 deletions(-)

diff --git a/sheep/ops.c b/sheep/ops.c
index 96b25eb..c266a9f 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -130,17 +130,10 @@ static int post_cluster_new_vdi(const struct sd_req *req, struct sd_rsp *rsp,
 static int cluster_del_vdi(struct request *req)
 {
 	const struct sd_req *hdr = &req->rq;
-	struct sd_rsp *rsp = &req->rp;
-	uint32_t vid = 0, nr_copies = sys->nr_copies;
-	int ret;
-
-	ret = del_vdi(req, req->data, hdr->data_length,
-		      &vid, hdr->vdi.snapid, &nr_copies);
-
-	rsp->vdi.vdi_id = vid;
-	rsp->vdi.copies = nr_copies;
+	uint32_t vid;
 
-	return ret;
+	return del_vdi(req, req->data, hdr->data_length,
+		       &vid, hdr->vdi.snapid);
 }
 
 struct cache_deletion_work {
@@ -188,7 +181,7 @@ static int local_get_vdi_info(struct request *req)
 {
 	const struct sd_req *hdr = &req->rq;
 	struct sd_rsp *rsp = &req->rp;
-	uint32_t vid = 0, nr_copies = sys->nr_copies;
+	uint32_t vid;
 	void *tag;
 	int ret;
 
@@ -200,12 +193,12 @@ static int local_get_vdi_info(struct request *req)
 		return SD_RES_INVALID_PARMS;
 
 	ret = lookup_vdi(req->data, tag, &vid,
-			 hdr->vdi.snapid, &nr_copies, NULL);
+			 hdr->vdi.snapid, NULL);
 	if (ret != SD_RES_SUCCESS)
 		return ret;
 
 	rsp->vdi.vdi_id = vid;
-	rsp->vdi.copies = nr_copies;
+	rsp->vdi.copies = get_vdi_copy_number(vid);
 
 	return ret;
 }
@@ -308,14 +301,14 @@ static int cluster_get_vdi_attr(struct request *req)
 {
 	const struct sd_req *hdr = &req->rq;
 	struct sd_rsp *rsp = &req->rp;
-	uint32_t vid = 0, attrid = 0, nr_copies = sys->nr_copies;
+	uint32_t vid = 0, attrid = 0;
 	uint64_t created_time = 0;
 	int ret;
 	struct sheepdog_vdi_attr *vattr;
 
 	vattr = req->data;
 	ret = lookup_vdi(vattr->name, vattr->tag, &vid,
-			 hdr->vdi.snapid, &nr_copies, &created_time);
+			 hdr->vdi.snapid, &created_time);
 	if (ret != SD_RES_SUCCESS)
 		return ret;
 
@@ -333,7 +326,7 @@ static int cluster_get_vdi_attr(struct request *req)
 
 	rsp->vdi.vdi_id = vid;
 	rsp->vdi.attr_id = attrid;
-	rsp->vdi.copies = nr_copies;
+	rsp->vdi.copies = get_vdi_copy_number(vid);
 
 	return ret;
 }
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index 6434acf..3586f68 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -253,10 +253,10 @@ int vdi_exist(uint32_t vid);
 int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid);
 
 int del_vdi(struct request *req, char *data, int data_len, uint32_t *vid,
-	    uint32_t snapid, unsigned int *nr_copies);
+	    uint32_t snapid);
 
 int lookup_vdi(const char *name, const char *tag, uint32_t *vid,
-	       uint32_t snapid, unsigned int *nr_copies, uint64_t *ctime);
+	       uint32_t snapid, uint64_t *ctime);
 
 int read_vdis(char *data, int len, unsigned int *rsp_len);
 
diff --git a/sheep/vdi.c b/sheep/vdi.c
index e4d3c9e..b637f50 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -302,8 +302,7 @@ out:
 static int find_first_vdi(unsigned long start, unsigned long end,
 			  const char *name, const char *tag, uint32_t snapid,
 			  uint32_t *vid, unsigned long *deleted_nr,
-			  uint32_t *next_snap, unsigned int *inode_nr_copies,
-			  uint64_t *create_time)
+			  uint32_t *next_snap, uint64_t *create_time)
 {
 	struct sheepdog_inode *inode = NULL;
 	unsigned long i;
@@ -349,7 +348,6 @@ static int find_first_vdi(unsigned long start, unsigned long end,
 			}
 
 			*vid = inode->vdi_id;
-			*inode_nr_copies = inode->nr_copies;
 			if (create_time)
 				*create_time = inode->create_time;
 			ret = SD_RES_SUCCESS;
@@ -370,8 +368,7 @@ out_free_inode:
 static int do_lookup_vdi(const char *name, int namelen, uint32_t *vid,
 			 const char *tag, uint32_t snapid,
 			 uint32_t *next_snapid, unsigned long *right_nr,
-			 unsigned long *deleted_nr, unsigned int *nr_copies,
-			 uint64_t *create_time)
+			 unsigned long *deleted_nr, uint64_t *create_time)
 {
 	int ret;
 	unsigned long nr, start_nr;
@@ -388,9 +385,8 @@ static int do_lookup_vdi(const char *name, int namelen, uint32_t *vid,
 	} else if (nr < SD_NR_VDIS) {
 right_side:
 		/* look up on the right side of the hash point */
-		ret = find_first_vdi(nr - 1, start_nr, name,
-				     tag, snapid, vid, deleted_nr, next_snapid,
-				     nr_copies, create_time);
+		ret = find_first_vdi(nr - 1, start_nr, name, tag, snapid, vid,
+				     deleted_nr, next_snapid, create_time);
 		return ret;
 	} else {
 		/* round up... bitmap search from the head of the bitmap */
@@ -400,9 +396,8 @@ right_side:
 			return SD_RES_FULL_VDI;
 		else if (nr) {
 			/* look up on the left side of the hash point */
-			ret = find_first_vdi(nr - 1, 0, name,
-					     tag, snapid, vid, deleted_nr,
-					     next_snapid, nr_copies,
+			ret = find_first_vdi(nr - 1, 0, name, tag, snapid, vid,
+					     deleted_nr, next_snapid,
 					     create_time);
 			if (ret == SD_RES_NO_VDI)
 				; /* we need to go to the right side */
@@ -416,14 +411,13 @@ right_side:
 }
 
 int lookup_vdi(const char *name, const char *tag, uint32_t *vid,
-	       uint32_t snapid, unsigned int *nr_copies, uint64_t *create_time)
+	       uint32_t snapid, uint64_t *create_time)
 {
 	uint32_t dummy0;
 	unsigned long dummy1, dummy2;
 
-	return do_lookup_vdi(name, strlen(name), vid, tag,
-			     snapid, &dummy0, &dummy1, &dummy2, nr_copies,
-			     create_time);
+	return do_lookup_vdi(name, strlen(name), vid, tag, snapid, &dummy0,
+			     &dummy1, &dummy2, create_time);
 }
 
 static int notify_vdi_add(uint32_t vdi_id, uint32_t nr_copies)
@@ -455,7 +449,6 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
 	uint32_t cur_vid = 0;
 	uint32_t next_snapid = 1;
 	unsigned long nr, deleted_nr = SD_NR_VDIS, right_nr = SD_NR_VDIS;
-	unsigned int dummy;
 	int ret;
 	const char *name;
 
@@ -466,7 +459,7 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
 
 	ret = do_lookup_vdi(name, strlen(name), &cur_vid,
 			    NULL, 0, &next_snapid, &right_nr, &deleted_nr,
-			    &dummy, NULL);
+			    NULL);
 
 	if (iocb->create_snapshot) {
 		if (ret != SD_RES_SUCCESS) {
@@ -505,7 +498,7 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
 static int start_deletion(struct request *req, uint32_t vid);
 
 int del_vdi(struct request *req, char *data, int data_len,
-	    uint32_t *vid, uint32_t snapid, unsigned int *nr_copies)
+	    uint32_t *vid, uint32_t snapid)
 {
 	const char *name = data, *tag;
 	uint32_t dummy0;
@@ -523,7 +516,7 @@ int del_vdi(struct request *req, char *data, int data_len,
 
 	ret = do_lookup_vdi(name, strlen(name), vid, tag,
 			    snapid, &dummy0, &dummy1, &dummy2,
-			    nr_copies, NULL);
+			    NULL);
 	if (ret != SD_RES_SUCCESS)
 		goto out;
 
-- 
1.7.9.5




More information about the sheepdog mailing list