qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix handling of disk-only snapshots
@ 2008-12-08 15:00 Kevin Wolf
  2008-12-11 21:06 ` Anthony Liguori
  0 siblings, 1 reply; 2+ messages in thread
From: Kevin Wolf @ 2008-12-08 15:00 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 976 bytes --]

When creating a snapshot with multiple qcow2 disks attached, the current
behaviour is that qemu creates a disk snapshot on all of them and
chooses one to write the VM state to.

Despite having the state only in one image, loadvm tries to restore the
VM state from the middle of nowhere if you run qemu a second time with
only one of the other images attached. In the lucky case it will fail
because there simply is no state, but it also can happen that it loads
the state of a different snapshot (the one this new one is based upon).

The fix is to write a zero VM state size to the images which don't
contain the state, and check this in loadvm.

I agree that you probably have to provoke such things intentionally to
get in a state like this with qemu itself. However, with my second patch
that adds snapshot support to qemu-img it could become a reasonable use
case to have snapshots with and without VM states on the same image.

Signed-off-by: Kevin Wolf <kwolf@suse.de>

[-- Attachment #2: snapshot-without-vmstate.patch --]
[-- Type: text/x-patch, Size: 1670 bytes --]

Index: qemu-svn/savevm.c
===================================================================
--- qemu-svn.orig/savevm.c
+++ qemu-svn/savevm.c
@@ -1020,6 +1020,7 @@ void do_savevm(const char *name)
     BlockDriverInfo bdi1, *bdi = &bdi1;
     QEMUFile *f;
     int saved_vm_running;
+    uint32_t vm_state_size;
 #ifdef _WIN32
     struct _timeb tb;
 #else
@@ -1079,7 +1080,7 @@ void do_savevm(const char *name)
         goto the_end;
     }
     ret = qemu_savevm_state(f);
-    sn->vm_state_size = qemu_ftell(f);
+    vm_state_size = qemu_ftell(f);
     qemu_fclose(f);
     if (ret < 0) {
         term_printf("Error %d while writing VM\n", ret);
@@ -1098,6 +1099,8 @@ void do_savevm(const char *name)
                                 bdrv_get_device_name(bs1));
                 }
             }
+            /* Write VM state size only to the image that contains the state */
+            sn->vm_state_size = (bs == bs1 ? vm_state_size : 0);
             ret = bdrv_snapshot_create(bs1, sn);
             if (ret < 0) {
                 term_printf("Error while creating snapshot on '%s'\n",
@@ -1115,6 +1118,7 @@ void do_loadvm(const char *name)
 {
     BlockDriverState *bs, *bs1;
     BlockDriverInfo bdi1, *bdi = &bdi1;
+    QEMUSnapshotInfo sn;
     QEMUFile *f;
     int i, ret;
     int saved_vm_running;
@@ -1165,6 +1169,11 @@ void do_loadvm(const char *name)
         return;
     }
 
+    /* Don't even try to load empty VM states */
+    ret = bdrv_snapshot_find(bs, &sn, name);
+    if ((ret >= 0) && (sn.vm_state_size == 0))
+        goto the_end;
+
     /* restore the VM state */
     f = qemu_fopen_bdrv(bs, bdi->vm_state_offset, 0);
     if (!f) {

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix handling of disk-only snapshots
  2008-12-08 15:00 [Qemu-devel] [PATCH] Fix handling of disk-only snapshots Kevin Wolf
@ 2008-12-11 21:06 ` Anthony Liguori
  0 siblings, 0 replies; 2+ messages in thread
From: Anthony Liguori @ 2008-12-11 21:06 UTC (permalink / raw)
  To: qemu-devel

Kevin Wolf wrote:
> When creating a snapshot with multiple qcow2 disks attached, the current
> behaviour is that qemu creates a disk snapshot on all of them and
> chooses one to write the VM state to.
>
> Despite having the state only in one image, loadvm tries to restore the
> VM state from the middle of nowhere if you run qemu a second time with
> only one of the other images attached. In the lucky case it will fail
> because there simply is no state, but it also can happen that it loads
> the state of a different snapshot (the one this new one is based upon).
>
> The fix is to write a zero VM state size to the images which don't
> contain the state, and check this in loadvm.
>
> I agree that you probably have to provoke such things intentionally to
> get in a state like this with qemu itself. However, with my second patch
> that adds snapshot support to qemu-img it could become a reasonable use
> case to have snapshots with and without VM states on the same image.
>
> Signed-off-by: Kevin Wolf <kwolf@suse.de>
>   

Applied.  Thanks.

Regards,

Anthony Liguori

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-12-11 21:07 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-08 15:00 [Qemu-devel] [PATCH] Fix handling of disk-only snapshots Kevin Wolf
2008-12-11 21:06 ` Anthony Liguori

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).