qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] QCOW2 multiple disk (not VM) snapshots
@ 2008-11-19 19:23 Mike Sun
  2008-11-24 14:16 ` Kevin Wolf
  0 siblings, 1 reply; 6+ messages in thread
From: Mike Sun @ 2008-11-19 19:23 UTC (permalink / raw)
  To: qemu-devel

Hi,

For a research project, we've been doing a bit of hacking with Xen and
utilize QCOW disk images as our VBDs. One intriguing thing about the
QCOW2 format was support for multiple disk snapshots. Unfortunately,
it seems from what I've been able to glean that support for multiple
snapshots within a QCOW2 image is really only supported by QEMU's VM
snapshot feature. Since I'm using Xen and only use QCOW2 disk images,
I was wondering if there was any way from a tool such as 'qemu-img' to
take snapshots of the QCOW2 disk image only and not through the
general QEMU VM snapshot?

Originally, I had thought that the CoW functionality provided by QCOW
disks could be used to implement snapshots, but I learned that this
wasn't achievable since QCOW disks cannot recursively back themselves.

Thanks,
Mike

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

* Re: [Qemu-devel] QCOW2 multiple disk (not VM) snapshots
  2008-11-19 19:23 [Qemu-devel] QCOW2 multiple disk (not VM) snapshots Mike Sun
@ 2008-11-24 14:16 ` Kevin Wolf
  2008-11-24 20:46   ` Anthony Liguori
  2008-11-24 20:51   ` [Qemu-devel] " Charles Duffy
  0 siblings, 2 replies; 6+ messages in thread
From: Kevin Wolf @ 2008-11-24 14:16 UTC (permalink / raw)
  To: msun; +Cc: qemu-devel

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

Hi Mike,

Mike Sun schrieb:
> For a research project, we've been doing a bit of hacking with Xen and
> utilize QCOW disk images as our VBDs. One intriguing thing about the
> QCOW2 format was support for multiple disk snapshots. Unfortunately,
> it seems from what I've been able to glean that support for multiple
> snapshots within a QCOW2 image is really only supported by QEMU's VM
> snapshot feature. Since I'm using Xen and only use QCOW2 disk images,
> I was wondering if there was any way from a tool such as 'qemu-img' to
> take snapshots of the QCOW2 disk image only and not through the
> general QEMU VM snapshot?

You can try the attached patch to qemu-img. I had it already for list,
delete and apply (as that's what I've needed so far), and I just added
create to it to make it complete. However, I didn't test it more than
making sure that it compiles and a new snapshot is listed afterwards.

If you're interested in having real snapshots with Xen, i.e. basically a
combination of xm save/restore and qemu-img snapshot, I also have some
patches to do that. They have quite a few dependencies, though, so they
are not yet upstream.

Kevin

[-- Attachment #2: qemu-img-snapshots.patch --]
[-- Type: text/x-patch, Size: 3788 bytes --]

Index: qemu-svn/qemu-img.c
===================================================================
--- qemu-svn.orig/qemu-img.c
+++ qemu-svn/qemu-img.c
@@ -57,6 +57,7 @@ static void help(void)
            "  commit [-f fmt] filename\n"
            "  convert [-c] [-e] [-6] [-f fmt] [-O output_fmt] [-B output_base_image] filename [filename2 [...]] output_filename\n"
            "  info [-f fmt] filename\n"
+           "  snapshot [-l|-a snapshot|-c snapshot|-d snapshot] filename\n"
            "\n"
            "Command parameters:\n"
            "  'filename' is a disk image filename\n"
@@ -729,6 +730,121 @@ static int img_info(int argc, char **arg
     return 0;
 }
 
+#define SNAPSHOT_LIST   1
+#define SNAPSHOT_CREATE 2
+#define SNAPSHOT_APPLY  3
+#define SNAPSHOT_DELETE 4
+
+static void img_snapshot(int argc, char **argv)
+{
+    BlockDriverState *bs;
+    QEMUSnapshotInfo sn;
+    char *filename, *snapshot_name = NULL;
+    char c;
+    int ret;
+    int action = 0;
+#ifdef _WIN32
+    struct _timeb tb;
+#else
+    struct timeval tv;
+#endif
+
+    /* Parse commandline parameters */
+    for(;;) {
+        c = getopt(argc, argv, "la:c:d:h");
+        if (c == -1)
+            break;
+        switch(c) {
+        case 'h':
+            help();
+            return;
+        case 'l':
+            if (action) {
+                help();
+                return;
+            }
+            action = SNAPSHOT_LIST;
+            break;
+        case 'a':
+            if (action) {
+                help();
+                return;
+            }
+            action = SNAPSHOT_APPLY;
+            snapshot_name = optarg;
+            break;
+        case 'c':
+            if (action) {
+                help();
+                return;
+            }
+            action = SNAPSHOT_CREATE;
+            snapshot_name = optarg;
+            break;
+        case 'd':
+            if (action) {
+                help();
+                return;
+            }
+            action = SNAPSHOT_DELETE;
+            snapshot_name = optarg;
+            break;
+        }
+    }
+
+    if (optind >= argc)
+        help();
+    filename = argv[optind++];
+
+    /* Open the image */
+    bs = bdrv_new("");
+    if (!bs)
+        error("Not enough memory");
+
+    if (bdrv_open2(bs, filename, 0, NULL) < 0) {
+        error("Could not open '%s'", filename);
+    }
+
+    /* Perform the requested action */
+    switch(action) {
+    case SNAPSHOT_LIST:
+        dump_snapshots(bs);
+        break;
+
+    case SNAPSHOT_CREATE:
+        memset(&sn, 0, sizeof(sn));
+        pstrcpy(sn.name, sizeof(sn.name), snapshot_name);
+#ifdef _WIN32
+        _ftime(&tb);
+        sn.date_sec = tb.time;
+        sn.date_nsec = tb.millitm * 1000000;
+#else
+        gettimeofday(&tv, NULL);
+        sn.date_sec = tv.tv_sec;
+        sn.date_nsec = tv.tv_usec * 1000;
+#endif
+        ret = bdrv_snapshot_create(bs, &sn);
+        break;
+
+    case SNAPSHOT_APPLY:
+        ret = bdrv_snapshot_goto(bs, snapshot_name);
+        if (ret)
+            error("Could not apply snapshot '%s': %d (%s)",
+                snapshot_name, strerror(ret), ret);
+        break;
+
+    case SNAPSHOT_DELETE:
+        ret = bdrv_snapshot_delete(bs, snapshot_name);
+        if (ret)
+            error("Could not delete snapshot '%s': %d (%s)",
+                snapshot_name, strerror(ret), ret);
+        break;
+    }
+
+    /* Cleanup */
+    bdrv_delete(bs);
+}
+
 int main(int argc, char **argv)
 {
     const char *cmd;
@@ -746,6 +862,8 @@ int main(int argc, char **argv)
         img_convert(argc, argv);
     } else if (!strcmp(cmd, "info")) {
         img_info(argc, argv);
+    } else if (!strcmp(cmd, "snapshot")) {
+        img_snapshot(argc, argv);
     } else {
         help();
     }

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

* Re: [Qemu-devel] QCOW2 multiple disk (not VM) snapshots
  2008-11-24 14:16 ` Kevin Wolf
@ 2008-11-24 20:46   ` Anthony Liguori
  2008-11-25  9:07     ` Kevin Wolf
  2008-11-24 20:51   ` [Qemu-devel] " Charles Duffy
  1 sibling, 1 reply; 6+ messages in thread
From: Anthony Liguori @ 2008-11-24 20:46 UTC (permalink / raw)
  To: qemu-devel; +Cc: msun

Kevin Wolf wrote:
> Hi Mike,
>
> Mike Sun schrieb:
>   
>> For a research project, we've been doing a bit of hacking with Xen and
>> utilize QCOW disk images as our VBDs. One intriguing thing about the
>> QCOW2 format was support for multiple disk snapshots. Unfortunately,
>> it seems from what I've been able to glean that support for multiple
>> snapshots within a QCOW2 image is really only supported by QEMU's VM
>> snapshot feature. Since I'm using Xen and only use QCOW2 disk images,
>> I was wondering if there was any way from a tool such as 'qemu-img' to
>> take snapshots of the QCOW2 disk image only and not through the
>> general QEMU VM snapshot?
>>     
>
> You can try the attached patch to qemu-img. I had it already for list,
> delete and apply (as that's what I've needed so far), and I just added
> create to it to make it complete. However, I didn't test it more than
> making sure that it compiles and a new snapshot is listed afterwards.
>
> If you're interested in having real snapshots with Xen, i.e. basically a
> combination of xm save/restore and qemu-img snapshot, I also have some
> patches to do that. They have quite a few dependencies, though, so they
> are not yet upstream.
>   

Care to resubmit with a proper Signed-off-by line?  Seems like a useful 
feature.

Regards,

Anthony Liguori

> Kevin
>   

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

* [Qemu-devel] Re: QCOW2 multiple disk (not VM) snapshots
  2008-11-24 14:16 ` Kevin Wolf
  2008-11-24 20:46   ` Anthony Liguori
@ 2008-11-24 20:51   ` Charles Duffy
  1 sibling, 0 replies; 6+ messages in thread
From: Charles Duffy @ 2008-11-24 20:51 UTC (permalink / raw)
  To: kwolf; +Cc: qemu-devel

Hey --

That's quite a shiny piece of functionality, and a very readable 
implementation. Any chance you might have plans to submit it for 
inclusion in qemu proper?

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

* Re: [Qemu-devel] QCOW2 multiple disk (not VM) snapshots
  2008-11-24 20:46   ` Anthony Liguori
@ 2008-11-25  9:07     ` Kevin Wolf
  2008-11-25 15:33       ` Kevin Wolf
  0 siblings, 1 reply; 6+ messages in thread
From: Kevin Wolf @ 2008-11-25  9:07 UTC (permalink / raw)
  To: qemu-devel

Anthony Liguori schrieb:
>> You can try the attached patch to qemu-img. I had it already for list,
>> delete and apply (as that's what I've needed so far), and I just added
>> create to it to make it complete. However, I didn't test it more than
>> making sure that it compiles and a new snapshot is listed afterwards.
>>
>> If you're interested in having real snapshots with Xen, i.e. basically a
>> combination of xm save/restore and qemu-img snapshot, I also have some
>> patches to do that. They have quite a few dependencies, though, so they
>> are not yet upstream.
>>   
> 
> Care to resubmit with a proper Signed-off-by line?  Seems like a useful
> feature.

Sure, that's what I wanted to do anyway. I just want to do at least a
bit more than only compile testing before.

Kevin

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

* Re: [Qemu-devel] QCOW2 multiple disk (not VM) snapshots
  2008-11-25  9:07     ` Kevin Wolf
@ 2008-11-25 15:33       ` Kevin Wolf
  0 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2008-11-25 15:33 UTC (permalink / raw)
  To: qemu-devel

Kevin Wolf schrieb:
> Anthony Liguori schrieb:
>> Care to resubmit with a proper Signed-off-by line?  Seems like a useful
>> feature.
> 
> Sure, that's what I wanted to do anyway. I just want to do at least a
> bit more than only compile testing before.

Well, creating the disk snapshot seems to work. It's just that qemu
seems to be confused to get a snapshot without VM state when you try to
loadvm the snapshot in a VM. However, the same seems to apply if you use
savevm with two qcow2 images and later try to loadvm from the second
image where no VM state is written to.

So it's not only broken because of qemu snapshot -c but a more general
problem. If "then don't do that" is enough for now, I can submit my
current patch for inclusion.

Kevin

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

end of thread, other threads:[~2008-11-25 15:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-19 19:23 [Qemu-devel] QCOW2 multiple disk (not VM) snapshots Mike Sun
2008-11-24 14:16 ` Kevin Wolf
2008-11-24 20:46   ` Anthony Liguori
2008-11-25  9:07     ` Kevin Wolf
2008-11-25 15:33       ` Kevin Wolf
2008-11-24 20:51   ` [Qemu-devel] " Charles Duffy

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).