[sheepdog] [PATCH] dog: check existence of specified snapshot in vdi_restore()
Liu Yuan
namei.unix at gmail.com
Mon Oct 28 07:51:28 CET 2013
On Mon, Oct 28, 2013 at 03:32:12PM +0900, Hitoshi Mitake wrote:
> Current "dog vdi restore" doesn't check existence of specified
> snapshot. So if users specify invalid snapshot ID or tag, the parent
> VDI is simply deleted. This behavior causes serious problem. This
> patch adds the existence check for preventing it.
>
> Signed-off-by: Hitoshi Mitake <mitake.hitoshi at lab.ntt.co.jp>
> ---
> dog/vdi.c | 13 +++++++++++++
> 1 file changed, 13 insertions(+)
>
> diff --git a/dog/vdi.c b/dog/vdi.c
> index 6d00d36..84e2ce3 100644
> --- a/dog/vdi.c
> +++ b/dog/vdi.c
> @@ -1981,6 +1981,7 @@ static int vdi_restore(int argc, char **argv)
> const char *vdiname = argv[optind++];
> int ret;
> char buf[SD_INODE_HEADER_SIZE] = {0};
> + struct sd_inode *inode_for_check = xzalloc(sizeof(*inode_for_check));
> struct sd_inode *current_inode = xzalloc(sizeof(*current_inode));
> struct sd_inode *parent_inode = (struct sd_inode *)buf;
> bool need_current_recovery = false;
> @@ -1992,6 +1993,17 @@ static int vdi_restore(int argc, char **argv)
> goto out;
> }
>
> + ret = read_vdi_obj(vdiname, vdi_cmd_data.snapshot_id,
> + vdi_cmd_data.snapshot_tag, NULL, inode_for_check,
> + SD_INODE_SIZE);
> + if (ret != SD_RES_SUCCESS) {
> + sd_err("You would've specified invalid snapshot"
"Snapshot ID xxx or tag xxx doesn't exist" is more descriptive.
Thanks
Yuan
More information about the sheepdog
mailing list