From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36449) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul0Ln-0002lj-HO for qemu-devel@nongnu.org; Fri, 07 Jun 2013 13:21:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ul0Lk-0005Oa-En for qemu-devel@nongnu.org; Fri, 07 Jun 2013 13:21:19 -0400 Received: from mail-pa0-x230.google.com ([2607:f8b0:400e:c03::230]:54282) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul0Lk-0005OM-74 for qemu-devel@nongnu.org; Fri, 07 Jun 2013 13:21:16 -0400 Received: by mail-pa0-f48.google.com with SMTP id kp12so1086836pab.7 for ; Fri, 07 Jun 2013 10:21:15 -0700 (PDT) From: Liu Yuan Date: Sat, 8 Jun 2013 01:20:40 +0800 Message-Id: <1370625640-5469-3-git-send-email-namei.unix@gmail.com> In-Reply-To: <1370625640-5469-1-git-send-email-namei.unix@gmail.com> References: <1370625640-5469-1-git-send-email-namei.unix@gmail.com> Subject: [Qemu-devel] [PATCH v3 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() in the snapshot_goto to rollback the image is good enough. With this patch, 'loadvm' process for sheepdog is modified: Suppose we have a snapshot chain A --> B --> C, we do 'loadvm A' so as to get a new chain, A --> B | V C1 in the old code: 1 reload inode of A (in snapshot_goto) 2 read vmstate via A's vdi_id (loadvm_state) 3 delete C and create C1, reload inode of C1 (sd_create_branch on write) with this patch applied: 1 reload inode of A, delete C and create C1 (in snapshot_goto) 2 read vmstate via C1's parent, that is A's vdi_id (loadvm_state) This will fix the possible bug that QEMU exit between 2 and 3 in the old code Cc: qemu-devel@nongnu.org Cc: MORITA Kazutaka Cc: Kevin Wolf Cc: Stefan Hajnoczi Signed-off-by: Liu Yuan --- block/sheepdog.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/block/sheepdog.c b/block/sheepdog.c index 94218ac..6d2cb9f 100644 --- a/block/sheepdog.c +++ b/block/sheepdog.c @@ -2071,14 +2071,11 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id) goto out; } - if (!s->inode.vm_state_size) { - error_report("Invalid snapshot"); - ret = -ENOENT; + ret = sd_create_branch(s); + if (ret) { goto out; } - s->is_snapshot = true; - g_free(old_s); return 0; @@ -2210,7 +2207,7 @@ static int do_load_save_vmstate(BDRVSheepdogState *s, uint8_t *data, data_len = MIN(remaining, SD_DATA_OBJ_SIZE - offset); - vmstate_oid = vid_to_vmstate_oid(s->inode.vdi_id, vdi_index); + vmstate_oid = vid_to_vmstate_oid(s->inode.parent_vdi_id, vdi_index); create = (offset == 0); if (load) { -- 1.7.9.5