Skip to contentSkip to conversation

fix 'qemu-img snapshot -a' operation for sheepdog

PATCH Superseded Liu Yuan 1 participant 3 messages Jun 7, 2013 Block layer

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Liu Yuan

author
#0 lore raw

v2 cover fix 'qemu-img snapshot -a' operation for sheepdog

v2:
- add the comment to make things more clear
- call sd_create_branch() after s->is_snapshot = true because after calling sd_create_branch, it is not snapshot anymore.

Nothing big, just two simple patches to enable this commind for sheepdog.

Cc MORITA Kazutaka <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>

Liu Yuan (2):
sheepdog: fix snapshot tag initialization
sheepdog: support 'qemu-img snapshot -a'

 block/sheepdog.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
Signature · 1 line
1.7.9.5
author
#1 lore raw

PATCH v2 1/2 sheepdog: fix snapshot tag initialization

This is an old and obvious bug. We should pass snapshot_id to the tag. Or simple command like 'qemu-img snapshot -a tag sheepdog:image' will fail

---
 block/sheepdog.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
block/sheepdog.c +1 -1
index 21a4edf..94218ac 100644
@@ -2063,7 +2063,7 @@ static int sd_snapshot_goto(BlockDriverState *bs, const char *snapshot_id)
     if (snapid) {
         tag[0] = 0;
     } else {
-        pstrcpy(tag, sizeof(tag), s->name);
+        pstrcpy(tag, sizeof(tag), snapshot_id);
     }
 
     ret = reload_inode(s, snapid, tag);
Signature · 1 line
1.7.9.5
author
#2 lore raw

PATCH v2 2/2 sheepdog: support 'qemu-img snapshot -a'

In reply to Liu Yuan

Just call sd_create_branch() to rollback the image is good enough

Cc MORITA Kazutaka <[email protected]>
Cc Kevin Wolf <[email protected]>
Cc Stefan Hajnoczi <[email protected]>
---
 block/sheepdog.c |   17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
block/sheepdog.c +12 -5
index 94218ac..c128b37 100644
@@ -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;
Signature · 1 line
1.7.9.5