From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41707) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkxTq-0006f7-IX for qemu-devel@nongnu.org; Fri, 07 Jun 2013 10:17:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UkxTp-0002Sd-6c for qemu-devel@nongnu.org; Fri, 07 Jun 2013 10:17:26 -0400 Received: from mail-pb0-x22f.google.com ([2607:f8b0:400e:c01::22f]:53630) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UkxTp-0002SI-0Z for qemu-devel@nongnu.org; Fri, 07 Jun 2013 10:17:25 -0400 Received: by mail-pb0-f47.google.com with SMTP id rr13so2083639pbb.20 for ; Fri, 07 Jun 2013 07:17:24 -0700 (PDT) From: Liu Yuan Date: Fri, 7 Jun 2013 22:15:51 +0800 Message-Id: <1370614552-4288-3-git-send-email-namei.unix@gmail.com> In-Reply-To: <1370614552-4288-1-git-send-email-namei.unix@gmail.com> References: <1370614552-4288-1-git-send-email-namei.unix@gmail.com> Subject: [Qemu-devel] [PATCH v2 2/2] sheepdog: support 'qemu-img snapshot -a' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: sheepdog@lists.wpkg.org Cc: Kevin Wolf , Stefan Hajnoczi , qemu-devel@nongnu.org, MORITA Kazutaka Just call sd_create_branch() to rollback the image is good enough Cc: qemu-devel@nongnu.org Cc: MORITA Kazutaka Cc: Kevin Wolf Cc: Stefan Hajnoczi Signed-off-by: Liu Yuan --- 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