[sheepdog] [PATCH 3/3] sheep: don't allow get_obj_copy_number to return more than nr_zones

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Sat Aug 25 19:21:41 CEST 2012


This is necessary to recover objects when we have less zones available
than the desired redundancy.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 sheep/ops.c         |    5 +++--
 sheep/plain_store.c |    2 +-
 sheep/recovery.c    |    4 ++--
 sheep/sheep_priv.h  |    2 +-
 sheep/vdi.c         |    9 +++++----
 5 files changed, 12 insertions(+), 10 deletions(-)

diff --git a/sheep/ops.c b/sheep/ops.c
index 5d6c80b..c6a4f3b 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -655,7 +655,7 @@ static int read_copy_from_replica(struct vnode_info *vnodes, uint32_t epoch,
 	char name[128];
 	int rounded_rand, local = -1;
 
-	nr_copies = get_obj_copy_number(oid);
+	nr_copies = get_obj_copy_number(oid, vnodes->nr_zones);
 	oid_to_vnodes(vnodes->vnodes, vnodes->nr_vnodes, oid,
 		      nr_copies, obj_vnodes);
 
@@ -765,7 +765,8 @@ int peer_read_obj(struct request *req)
 	if (hdr->obj.copies)
 		rsp->obj.copies = hdr->obj.copies;
 	else
-		rsp->obj.copies = get_obj_copy_number(hdr->obj.oid);
+		rsp->obj.copies = get_obj_copy_number(hdr->obj.oid,
+						      req->vinfo->nr_zones);
 out:
 	return ret;
 }
diff --git a/sheep/plain_store.c b/sheep/plain_store.c
index fe2ced9..9eb2fb6 100644
--- a/sheep/plain_store.c
+++ b/sheep/plain_store.c
@@ -307,7 +307,7 @@ static bool oid_stale(uint64_t oid)
 	struct sd_vnode *obj_vnodes[SD_MAX_COPIES];
 
 	vinfo = get_vnode_info();
-	nr_copies = get_obj_copy_number(oid);
+	nr_copies = get_obj_copy_number(oid, vinfo->nr_zones);
 	if (!nr_copies) {
 		ret = false;
 		goto out;
diff --git a/sheep/recovery.c b/sheep/recovery.c
index 325f3a5..72c90cd 100644
--- a/sheep/recovery.c
+++ b/sheep/recovery.c
@@ -172,7 +172,7 @@ again:
 		oid, tgt_epoch);
 
 	/* Let's do a breadth-first search */
-	nr_copies = get_obj_copy_number(oid);
+	nr_copies = get_obj_copy_number(oid, old->nr_zones);
 	for (i = 0; i < nr_copies; i++) {
 		struct sd_vnode *tgt_vnode = oid_to_vnode(old->vnodes,
 							  old->nr_vnodes,
@@ -516,7 +516,7 @@ static void screen_object_list(struct recovery_work *rw,
 	int i, j;
 
 	for (i = 0; i < nr_oids; i++) {
-		nr_objs = get_obj_copy_number(oids[i]);
+		nr_objs = get_obj_copy_number(oids[i], rw->cur_vinfo->nr_zones);
 		if (!nr_objs) {
 			dprintf("can not find copy number for object %" PRIx64
 				"\n", oids[i]);
diff --git a/sheep/sheep_priv.h b/sheep/sheep_priv.h
index df30f57..224be51 100644
--- a/sheep/sheep_priv.h
+++ b/sheep/sheep_priv.h
@@ -215,7 +215,7 @@ int init_base_path(const char *dir);
 
 int fill_vdi_copy_list(void *data);
 int get_vdi_copy_number(uint32_t vid);
-int get_obj_copy_number(uint64_t oid);
+int get_obj_copy_number(uint64_t oid, int nr_zones);
 int get_max_copy_number(void);
 int get_req_copy_number(struct request *req);
 int add_vdi_copy_number(uint32_t vid, int nr_copies);
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 80ec4b2..97d9f4e 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -86,7 +86,7 @@ int get_vdi_copy_number(uint32_t vid)
 	return entry->nr_copies;
 }
 
-int get_obj_copy_number(uint64_t oid)
+int get_obj_copy_number(uint64_t oid, int nr_zones)
 {
 	uint32_t vid;
 	if (is_vdi_attr_obj(oid))
@@ -94,16 +94,17 @@ int get_obj_copy_number(uint64_t oid)
 	else
 		vid = oid_to_vid(oid);
 
-	return get_vdi_copy_number(vid);
+	return min(get_vdi_copy_number(vid), nr_zones);
 }
 
 int get_req_copy_number(struct request *req)
 {
 	int nr_copies;
 
-	nr_copies = req->rq.obj.copies;
+	nr_copies = min((int)req->rq.obj.copies, req->vinfo->nr_zones);
 	if (!nr_copies)
-		nr_copies = get_obj_copy_number(req->rq.obj.oid);
+		nr_copies = get_obj_copy_number(req->rq.obj.oid,
+						req->vinfo->nr_zones);
 
 	return nr_copies;
 }
-- 
1.7.2.5




More information about the sheepdog mailing list