[sheepdog] [PATCH] sheep: fix vid wrap around

fukumoto.yoshifumi at lab.ntt.co.jp fukumoto.yoshifumi at lab.ntt.co.jp
Mon Feb 2 06:36:23 CET 2015


From: FUKUMOTO Yoshifumi <fukumoto.yoshifumi at lab.ntt.co.jp>

If a vid of a vdi reaches the max number of vid space, creating the snapshot of
the vdi fails.

Example:
$ dog vdi create 00471718 1G
$ dog vdi snapshot 00471718   (repeat 7 times)
failed to read a response
Failed to create snapshot for 00471718: I/O error

This patch fixes the problem.

Signed-off-by: FUKUMOTO Yoshifumi <fukumoto.yoshifumi at lab.ntt.co.jp>
---
 sheep/vdi.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/sheep/vdi.c b/sheep/vdi.c
index 2889df6..4113a4f 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -1398,15 +1398,20 @@ static int fill_vdi_info_range(uint32_t left, uint32_t right,
 	uint32_t i;
 	const char *name = iocb->name;
 
+	if (!right)
+		return SD_RES_NO_VDI;
 	inode = malloc(SD_INODE_HEADER_SIZE);
 	if (!inode) {
 		sd_err("failed to allocate memory");
 		ret = SD_RES_NO_MEM;
 		goto out;
 	}
-	for (i = right - 1; i && i >= left; i--) {
-		if (!test_bit(i, sys->vdi_inuse))
+	for (i = right - 1; i >= left; i--) {
+		if (!test_bit(i, sys->vdi_inuse)) {
+			if (!i)
+				break;
 			continue;
+		}
 
 		ret = sd_read_object(vid_to_vdi_oid(i), (char *)inode,
 				     SD_INODE_HEADER_SIZE, 0);
@@ -1420,9 +1425,13 @@ static int fill_vdi_info_range(uint32_t left, uint32_t right,
 				/* Read, delete, clone on snapshots */
 				if (!vdi_is_snapshot(inode)) {
 					vdi_found = true;
+					if (!i)
+						break;
 					continue;
 				}
 				if (!vdi_tag_match(iocb, inode))
+					if (!i)
+						break;
 					continue;
 			} else {
 				/*
@@ -1438,6 +1447,8 @@ static int fill_vdi_info_range(uint32_t left, uint32_t right,
 			info->vid = inode->vdi_id;
 			goto out;
 		}
+		if (!i)
+			break;
 	}
 	ret = vdi_found ? SD_RES_NO_TAG : SD_RES_NO_VDI;
 out:
@@ -1458,7 +1469,7 @@ static int fill_vdi_info(unsigned long left, unsigned long right,
 	switch (ret) {
 	case SD_RES_NO_VDI:
 	case SD_RES_NO_TAG:
-		ret = fill_vdi_info_range(left, SD_NR_VDIS - 1, iocb, info);
+		ret = fill_vdi_info_range(left, SD_NR_VDIS, iocb, info);
 		break;
 	default:
 		break;
-- 
1.9.1





More information about the sheepdog mailing list