[sheepdog] [PATCH 2/3] allow creating snapshot when there is no current image

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Tue Oct 16 20:04:26 CEST 2012


This fixes vdi_rollback and vdi_restore.

Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
---
 collie/vdi.c |    4 ++--
 sheep/vdi.c  |    9 ++++-----
 2 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/collie/vdi.c b/collie/vdi.c
index 9dc15e1..b352294 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -803,7 +803,7 @@ static int vdi_rollback(int argc, char **argv)
 	}
 
 	return do_vdi_create(vdiname, inode->vdi_size, base_vid, NULL,
-			     true, vdi_cmd_data.nr_copies);
+			     false, vdi_cmd_data.nr_copies);
 }
 
 static int vdi_object(int argc, char **argv)
@@ -1754,7 +1754,7 @@ static uint32_t do_restore(char *vdiname, int snapid, const char *tag)
 		goto out;
 
 	ret = do_vdi_create(vdiname, inode->vdi_size, inode->vdi_id, &vid,
-			    true, inode->nr_copies);
+			    false, inode->nr_copies);
 	if (ret != EXIT_SUCCESS) {
 		fprintf(stderr, "Failed to read VDI\n");
 		goto out;
diff --git a/sheep/vdi.c b/sheep/vdi.c
index 3ac0f12..0893a02 100644
--- a/sheep/vdi.c
+++ b/sheep/vdi.c
@@ -346,8 +346,10 @@ static int find_first_vdi(unsigned long start, unsigned long end, char *name,
 		}
 
 		if (!strncmp(inode->name, name, strlen(inode->name))) {
+			*next_snap = inode->snap_id + 1;
+
 			if (!(tag && tag[0]) && !snapid && inode->snap_ctime)
-				continue;
+				break;
 
 			vdi_found = true;
 			if (tag && tag[0] &&
@@ -356,7 +358,6 @@ static int find_first_vdi(unsigned long start, unsigned long end, char *name,
 			if (snapid && snapid != inode->snap_id)
 				continue;
 
-			*next_snap = inode->snap_id + 1;
 			*vid = inode->vdi_id;
 			*inode_nr_copies = inode->nr_copies;
 			if (create_time)
@@ -438,7 +439,7 @@ int lookup_vdi(char *name, char *tag, uint32_t *vid, uint32_t snapid,
 int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
 {
 	uint32_t cur_vid = 0;
-	uint32_t next_snapid;
+	uint32_t next_snapid = 1;
 	unsigned long nr, deleted_nr = SD_NR_VDIS, right_nr = SD_NR_VDIS;
 	unsigned int dummy;
 	int ret;
@@ -472,8 +473,6 @@ int add_vdi(struct vdi_iocb *iocb, uint32_t *new_vid)
 			nr = right_nr;
 		else
 			nr = deleted_nr; /* we can recycle a deleted VDI */
-
-		next_snapid = 1;
 	}
 
 	*new_vid = nr;
-- 
1.7.2.5




More information about the sheepdog mailing list