Just call sd_create_branch() to rollback the image is good enough Cc: qemu-devel@nongnu.org Cc: MORITA Kazutaka <morita.kazut...@lab.ntt.co.jp> Cc: Kevin Wolf <kw...@redhat.com> Cc: Stefan Hajnoczi <stefa...@redhat.com> Signed-off-by: Liu Yuan <namei.u...@gmail.com> --- block/sheepdog.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
diff --git a/block/sheepdog.c b/block/sheepdog.c index 94218ac..c128b37 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2071,14 +2071,21 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) goto out; } + s->is_snapshot = true; + if (!s->inode.vm_state_size) { - error_report("Invalid snapshot"); - ret = -ENOENT; - goto out; + /* + * qemu-img asks us to rollback, we can't rely on the write to create + * the branch, so do it right now. We can call sd_create_branch() right + * here only when vm_state_size == 0 because it changes vdi_id + * internally, otherwise we will read the wrong vmstate if any. + */ + ret = sd_create_branch(s); + if (ret) { + goto out; + } } - s->is_snapshot = true; - g_free(old_s); return 0; -- 1.7.9.5