Patchwork [v2,2/2] sheepdog: support 'qemu-img snapshot -a'

login
register
mail settings
Submitter namei.unix@gmail.com
Date June 7, 2013, 2:15 p.m.
Message ID <1370614552-4288-3-git-send-email-namei.unix@gmail.com>
Download mbox | patch
Permalink /patch/249733/
State New
Headers show

Comments

namei.unix@gmail.com - June 7, 2013, 2:15 p.m.
Just call sd_create_branch() to rollback the image is good enough

Cc: qemu-devel@nongnu.org
Cc: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp>
Cc: Kevin Wolf <kwolf@redhat.com>
Cc: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Liu Yuan <namei.unix@gmail.com>
---
 block/sheepdog.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

Patch

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;