[sheepdog] [PATCH 1/2] collie: add command 'collie vdi rollback'

MORITA Kazutaka morita.kazutaka at lab.ntt.co.jp
Fri Aug 31 10:25:51 CEST 2012


At Fri, 31 Aug 2012 15:23:01 +0800,
levin li wrote:
> 
> OK, I got the point of CURRENT VDI, but there's another problem, I never thought of
> rolling back a snapshot to its parent or other, take think of this:
> 
> snap1 is the root snapshot, then we start snap1 with QEMU and it creates another snapshot
> snap2 which creates its own object A, and A is not included in snap1, then user may clones
> a new VDI clone1 from snap2, it derives from snap2 together with object A, but now if we
> rollback snap2 to snap1 and the object A is lost, how can clone1 find this object, is it right?

The rollback operation shouldn't delete snap2.

Here is a draft patch which implements my example but doesn't support
resetting clone vdis.  I hope it would help you.

==
commit 138511431d4f87642572b0e2a51d869240b5ac83
Author: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>
Date:   Fri Aug 31 17:21:38 2012 +0900

    [tmp] collie: add vdi rollback support
    
    Signed-off-by: MORITA Kazutaka <morita.kazutaka at lab.ntt.co.jp>

diff --git a/collie/vdi.c b/collie/vdi.c
index 966fb9f..39e04a7 100644
--- a/collie/vdi.c
+++ b/collie/vdi.c
@@ -752,6 +752,37 @@ static int vdi_delete(int argc, char **argv)
 	return EXIT_SUCCESS;
 }
 
+static int vdi_rollback(int argc, char **argv)
+{
+	char *vdiname = argv[optind++];
+	uint32_t base_vid;
+	int ret;
+	char buf[SD_INODE_HEADER_SIZE];
+	struct sheepdog_inode *inode = (struct sheepdog_inode *)buf;
+
+	if (!vdi_cmd_data.snapshot_id && !vdi_cmd_data.snapshot_tag[0]) {
+		fprintf(stderr, "Please specify the '-s' option\n");
+		return EXIT_USAGE;
+	}
+
+	ret = find_vdi_name(vdiname, vdi_cmd_data.snapshot_id,
+			    vdi_cmd_data.snapshot_tag, &base_vid, 0);
+	if (ret < 0) {
+		fprintf(stderr, "Failed to open VDI %s\n", vdiname);
+		return EXIT_FAILURE;
+	}
+
+	inode = xmalloc(sizeof(*inode));
+	ret = sd_read_object(vid_to_vdi_oid(base_vid), inode, SD_INODE_SIZE, 0);
+	if (ret != SD_RES_SUCCESS) {
+		fprintf(stderr, "Failed to read an inode\n");
+		return EXIT_FAILURE;
+	}
+
+	return do_vdi_create(vdiname, inode->vdi_size, base_vid, NULL,
+			     inode->snap_id, vdi_cmd_data.nr_copies);
+}
+
 static int vdi_object(int argc, char **argv)
 {
 	char *vdiname = argv[optind];
@@ -1537,6 +1568,9 @@ static struct subcommand vdi_cmd[] = {
 	{"delete", "<vdiname>", "saph", "delete an image",
 	 NULL, SUBCMD_FLAG_NEED_THIRD_ARG,
 	 vdi_delete, vdi_options},
+	{"rollback", "<vdiname>", "saph", "rollback to a snapshot",
+	 NULL, SUBCMD_FLAG_NEED_THIRD_ARG,
+	 vdi_rollback, vdi_options},
 	{"list", "[vdiname]", "aprh", "list images",
 	 NULL, 0, vdi_list, vdi_options},
 	{"tree", NULL, "aph", "show images in tree view format",



More information about the sheepdog mailing list