This adds a new command 'vdi rollback': Usage: collie vdi rollback [-s snapshot] [-a address] [-p port] [-h] <vdiname> Options: -s, --snapshot specify a snapshot id or tag name -a, --address specify the daemon address (default: localhost) -p, --port specify the daemon port -h, --help display this help and exit
This makes the current vdi a new snapshot, rollbacks to the requested snapshot, and branches a new vdi as a new current one. Removing the previous current vdi is a future work. Signed-off-by: MORITA Kazutaka <[email protected]> --- collie/vdi.c | 34 ++++++++++++++++++++++++++++++++++ 1 files changed, 34 insertions(+), 0 deletions(-) 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", -- 1.7.2.5 -- sheepdog mailing list [email protected] http://lists.wpkg.org/mailman/listinfo/sheepdog
