[sheepdog] [PATCH] sheep: check zone availability when creating new VDI

Hitoshi Mitake mitake.hitoshi at gmail.com
Sun Feb 24 11:17:10 CET 2013


As reported by Valerio Pachera [1], current sheep allows creating vdis
which have copy numbers larger than provided zones. This patch adds a
check for protecting the invalid behaviour.

Could you test this patch, Valerio?

[1] http://lists.wpkg.org/pipermail/sheepdog-users/2013-February/000548.html

Cc: Valerio Pachera <sirio81 at gmail.com>
Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
---
 sheep/ops.c |   18 ++++++++++++++++++
 1 files changed, 18 insertions(+), 0 deletions(-)

diff --git a/sheep/ops.c b/sheep/ops.c
index c1940c8..9fd8f28 100644
--- a/sheep/ops.c
+++ b/sheep/ops.c
@@ -112,6 +112,22 @@ static int cluster_new_vdi(struct request *req)
 	struct vdi_iocb iocb;
 	int ret;
 
+	struct vnode_info *current;
+	int required_zones;
+
+	current = get_vnode_info();
+	required_zones = sys->flags & SD_FLAG_QUORUM ?
+		hdr->vdi.copies / 2 + 1 : hdr->vdi.copies;
+
+	if (current->nr_zones < required_zones) {
+		sd_eprintf("too large copy number of newly created VDI: %d, "
+			"max copy number of current cluster is %d\n",
+			required_zones, current->nr_zones);
+		ret = SD_RES_INVALID_PARMS;
+
+		goto end;
+	}
+
 	iocb.name = req->data;
 	iocb.data_len = hdr->data_length;
 	iocb.size = hdr->vdi.vdi_size;
@@ -127,6 +143,8 @@ static int cluster_new_vdi(struct request *req)
 	rsp->vdi.vdi_id = vid;
 	rsp->vdi.copies = iocb.nr_copies;
 
+end:
+	put_vnode_info(current);
 	return ret;
 }
 
-- 
1.7.5.1




More information about the sheepdog mailing list