[sheepdog] [PATCH 1/2] collie: add command 'collie vdi rollback'
levin li
levin108 at gmail.com
Fri Aug 31 11:09:22 CEST 2012
On 08/31/2012 04:25 PM, MORITA Kazutaka wrote:
> 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",
>
With your patch I got the following result:
$ collie/collie vdi list
Name Id Size Used Shared Creation time VDI id Copies Tag
s base 1 20 MB 20 MB 0.0 MB 2012-08-31 16:58 54c278 3 tag
s base 2 20 MB 0.0 MB 20 MB 2012-08-31 16:58 54c279 3
base 3 20 MB 0.0 MB 20 MB 2012-08-31 16:59 54c27a 3
c clone 1 20 MB 0.0 MB 20 MB 2012-08-31 16:58 72a1e2 3
$ collie/collie vdi tree
base---[2012-08-31 16:58]---[2012-08-31 16:58]---(you are here)
clone---(you are here)
$ collie/collie vdi rollback -s 2 base
$ collie/collie vdi tree
base---[2012-08-31 16:58]---[2012-08-31 16:58]-+-[2012-08-31 16:59]
`-(you are here)
clone---(you are here)
$ collie/collie vdi rollback -s 1 base
$ collie/collie vdi tree
base---[2012-08-31 16:58]-+-[2012-08-31 16:58]-+-[2012-08-31 16:59]
| `-[2012-08-31 17:00]
`-(you are here)
I still don't understand what's the use of your rollback of a snapshot, it seems
it just move the current VDI to the specified snapshot VDI and created a new one,
but what's the use of the current VDI ?
In my scenario, we clone a VDI from a snapshot, and the cloned VDI is modified after
VM running, but we want to reset the VDI back to the initial state, I think this is
useful for me and many users, but I don't quite understand the use of your rollback
scenario, maybe I can go back to rename the command as *'reset'* to just reset a cloned
VDI, what do you think about it?
thanks,
levin
More information about the sheepdog
mailing list