All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation.
@ 2012-05-17 15:34 Richard W.M. Jones
  2012-05-17 15:49 ` Eric Blake
  2012-05-21 13:29 ` Kevin Wolf
  0 siblings, 2 replies; 7+ messages in thread
From: Richard W.M. Jones @ 2012-05-17 15:34 UTC (permalink / raw)
  To: qemu-devel

From: "Richard W.M. Jones" <rjones@redhat.com>

This produces a qcow2 file which is the difference between
two disk images.  ie, if:

  base.img     - is a disk image (in any format)
  modified.img - is base.img, copied and modified

then:

  qemu-img diff -b base.img modified.img diff.qcow2

creates 'diff.qcow2' which contains the differences between 'base.img'
and 'modified.img'.  Note that 'diff.qcow2' has 'base.img' as its
backing file.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Cc: Matthew Booth <mbooth@redhat.com>
Cc: Pablo Iranzo Gómez <Pablo.Iranzo@redhat.com>
Cc: Tomas Von Veschler <tvvcox@redhat.com>
---
 qemu-img-cmds.hx |    6 ++
 qemu-img.c       |  166 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 qemu-img.texi    |   22 ++++++++
 3 files changed, 194 insertions(+)

diff --git a/qemu-img-cmds.hx b/qemu-img-cmds.hx
index 49dce7c..00eef96 100644
--- a/qemu-img-cmds.hx
+++ b/qemu-img-cmds.hx
@@ -33,6 +33,12 @@ STEXI
 @item convert [-c] [-p] [-f @var{fmt}] [-t @var{cache}] [-O @var{output_fmt}] [-o @var{options}] [-s @var{snapshot_name}] [-S @var{sparse_size}] @var{filename} [@var{filename2} [...]] @var{output_filename}
 ETEXI
 
+DEF("diff", img_diff,
+    "diff [-F backing_fmt] -b backing_file [-f fmt] [-O output_fmt] [-o options] filename output_filename")
+STEXI
+@item diff [-F @var{backing_fmt}] -b @var{backing_file} [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] @var{filename} @var{output_filename}
+ETEXI
+
 DEF("info", img_info,
     "info [-f fmt] filename")
 STEXI
diff --git a/qemu-img.c b/qemu-img.c
index c8a70ff..af12c29 100644
--- a/qemu-img.c
+++ b/qemu-img.c
@@ -1533,6 +1533,172 @@ out:
     return 0;
 }
 
+static int img_diff(int argc, char **argv)
+{
+    /* qemu-img diff -b base modified out */
+    BlockDriverState *bs_base, *bs_modified, *bs_out;
+    const char *fmt_base, *base,
+        *fmt_modified, *modified,
+        *fmt_out, *out;
+    char *options;
+    int c, ret = 0;
+    uint64_t num_sectors_base, num_sectors_modified;
+    uint64_t sector;
+    int n;
+    uint8_t *buf_base;
+    uint8_t *buf_modified;
+
+    /* Parse commandline parameters */
+    fmt_base = NULL;
+    fmt_modified = NULL;
+    fmt_out = NULL;
+    base = NULL;
+    options = NULL;
+    for(;;) {
+        c = getopt(argc, argv, "b:hf:F:O:o:");
+        if (c == -1) {
+            break;
+        }
+        switch(c) {
+        case '?':
+        case 'h':
+            help();
+            return 0;
+        case 'f':
+            fmt_modified = optarg;
+            break;
+        case 'F':
+            fmt_base = optarg;
+            break;
+        case 'b':
+            base = optarg;
+            break;
+        case 'O':
+            fmt_out = optarg;
+            break;
+        case 'o':
+            options = optarg;
+            break;
+        }
+    }
+
+    if (base == NULL) {
+        error_report("The -b (backing filename) option must be supplied");
+        return 1;
+    }
+
+    if (argc - optind != 2) {
+        error_report("Exactly two filenames (source and destination) must be supplied");
+        return 1;
+    }
+    modified = argv[optind++];
+    out = argv[optind++];
+
+    if (fmt_out == NULL || fmt_out[0] == '\0') {
+        fmt_out = "qcow2";
+    }
+
+    if (options && !strcmp(options, "?")) {
+        ret = print_block_option_help(out, fmt_out);
+        return 1;
+    }
+
+    /* Open the input images. */
+    bs_base = bdrv_new_open(base, fmt_base, BDRV_O_FLAGS);
+    if (!bs_base) {
+        return 1;
+    }
+
+    bs_modified = bdrv_new_open(modified, fmt_modified, BDRV_O_FLAGS);
+    if (!bs_modified) {
+        return 1;
+    }
+
+    bdrv_get_geometry(bs_base, &num_sectors_base);
+    bdrv_get_geometry(bs_modified, &num_sectors_modified);
+    /* NB: It is possible to relax this constraint so that
+     * num_sectors_base <= num_sectors_modified, ie. the modified disk
+     * has been expanded.  That requires changes to the loop below.
+     */
+    if (num_sectors_base != num_sectors_modified) {
+        error_report("Number of sectors in backing and source must be the same");
+        goto out2;
+    }
+
+    /* Output image. */
+    ret = bdrv_img_create(out, fmt_out,
+                          /* base file becomes the new backing file */
+                          base, fmt_base,
+                          options, num_sectors_modified * BDRV_SECTOR_SIZE,
+                          BDRV_O_FLAGS);
+    if (ret != 0) {
+        goto out2;
+    }
+    bs_out = bdrv_new_open(out, fmt_out, BDRV_O_RDWR);
+
+    buf_base = qemu_blockalign(bs_base, IO_BUF_SIZE);
+    buf_modified = qemu_blockalign(bs_modified, IO_BUF_SIZE);
+
+    for (sector = 0; sector < num_sectors_modified; sector += n) {
+        /* How many sectors can we handle with the next read? */
+        if (sector + (IO_BUF_SIZE / BDRV_SECTOR_SIZE) <= num_sectors_modified) {
+            n = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
+        } else {
+            n = num_sectors_modified - sector;
+        }
+
+        /* Read input files and compare. */
+        ret = bdrv_read(bs_base, sector, buf_base, n);
+        if (ret < 0) {
+            error_report("error while reading from backing file");
+            goto out;
+        }
+
+        ret = bdrv_read(bs_modified, sector, buf_modified, n);
+        if (ret < 0) {
+            error_report("error while reading from input file");
+            goto out;
+        }
+
+        /* If they differ, we need to write to the differences file. */
+        uint64_t written = 0;
+
+        while (written < n) {
+            int pnum;
+
+            if (compare_sectors(buf_base + written * BDRV_SECTOR_SIZE,
+                                buf_modified + written * BDRV_SECTOR_SIZE,
+                                n - written, &pnum)) {
+                ret = bdrv_write(bs_out, sector + written,
+                                 buf_modified + written * BDRV_SECTOR_SIZE,
+                                 pnum);
+                if (ret < 0) {
+                    error_report("Error while writing to output file: %s",
+                                 strerror(-ret));
+                    goto out;
+                }
+            }
+
+            written += pnum;
+        }
+    }
+
+    qemu_vfree(buf_base);
+    qemu_vfree(buf_modified);
+
+ out:
+    /* Cleanup */
+    bdrv_delete(bs_out);
+ out2:
+    bdrv_delete(bs_base);
+    bdrv_delete(bs_modified);
+
+    if (ret) {
+        return 1;
+    }
+    return 0;
+}
+
 static int img_resize(int argc, char **argv)
 {
     int c, ret, relative;
diff --git a/qemu-img.texi b/qemu-img.texi
index b2ca3a5..718d302 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -114,6 +114,28 @@ created as a copy on write image of the specified base image; the
 @var{backing_file} should have the same content as the input's base image,
 however the path, image format, etc may differ.
 
+@item diff [-F @var{backing_fmt}] -b @var{backing_file} [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] @var{filename} @var{output_filename}
+
+Create a new disk image (@var{output_filename}) which contains
+the differences between @var{backing_file} and @var{filename}.
+This is useful if you have cloned a disk image by copying it,
+and you want to get back to a thin image on top of a common base.
+
+Typical usage is:
+
+@code{qemu-img diff -b base.img modified.img diff.qcow2}
+
+The @var{backing_file} and @var{filename} must have the same
+virtual disk size, but may be in different formats.
+
+The format of @var{output_file} must be one that supports backing
+files (@code{qcow2} or @code{qed}).  If not specified,
+@var{output_fmt} defaults to @code{qcow2}.
+@var{options} can be used to specify options for the output file.
+
+@var{output_file} will have @var{backing_file} set as its backing
+file.
+
 @item info [-f @var{fmt}] @var{filename}
 
 Give information about the disk image @var{filename}. Use it in
-- 
1.7.10

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

* Re: [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation.
  2012-05-17 15:34 [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation Richard W.M. Jones
@ 2012-05-17 15:49 ` Eric Blake
  2012-05-21 13:29 ` Kevin Wolf
  1 sibling, 0 replies; 7+ messages in thread
From: Eric Blake @ 2012-05-17 15:49 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: qemu-devel

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

On 05/17/2012 09:34 AM, Richard W.M. Jones wrote:
> From: "Richard W.M. Jones" <rjones@redhat.com>
> 
> This produces a qcow2 file which is the difference between
> two disk images.  ie, if:
> 
>   base.img     - is a disk image (in any format)
>   modified.img - is base.img, copied and modified
> 
> then:
> 
>   qemu-img diff -b base.img modified.img diff.qcow2
> 
> creates 'diff.qcow2' which contains the differences between 'base.img'
> and 'modified.img'.  Note that 'diff.qcow2' has 'base.img' as its
> backing file.
> 
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> Cc: Matthew Booth <mbooth@redhat.com>
> Cc: Pablo Iranzo Gómez <Pablo.Iranzo@redhat.com>
> Cc: Tomas Von Veschler <tvvcox@redhat.com>

Regarding the documentation and command overview:

Reviewed-by: Eric Blake <eblake@redhat.com>

Regarding the actual logic used in computing the diff, I did not closely
look at that, and you would be wise to get a review from someone more
familiar with block dev operations.

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

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

* Re: [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation.
  2012-05-17 15:34 [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation Richard W.M. Jones
  2012-05-17 15:49 ` Eric Blake
@ 2012-05-21 13:29 ` Kevin Wolf
  2012-05-21 13:59   ` Richard W.M. Jones
  1 sibling, 1 reply; 7+ messages in thread
From: Kevin Wolf @ 2012-05-21 13:29 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: qemu-devel

Am 17.05.2012 17:34, schrieb Richard W.M. Jones:
> From: "Richard W.M. Jones" <rjones@redhat.com>
> 
> This produces a qcow2 file which is the difference between
> two disk images.  ie, if:
> 
>   base.img     - is a disk image (in any format)
>   modified.img - is base.img, copied and modified
> 
> then:
> 
>   qemu-img diff -b base.img modified.img diff.qcow2
> 
> creates 'diff.qcow2' which contains the differences between 'base.img'
> and 'modified.img'.  Note that 'diff.qcow2' has 'base.img' as its
> backing file.
> 
> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> Cc: Matthew Booth <mbooth@redhat.com>
> Cc: Pablo Iranzo Gómez <Pablo.Iranzo@redhat.com>
> Cc: Tomas Von Veschler <tvvcox@redhat.com>

Hm, I'm wondering... If I have a command line like this:

  qemu-img diff -b base.img modified.img diff.qcow2

Would this be equivalent to this sequence?

  qemu-img create -f qcow2 -b modified.img diff.qcow2
  qemu-img rebase -b base.img diff.qcow2

Or is there some detail that I'm missing? If it is equivalent, this
would suggest that either the new command isn't necessary at all or at
least that it should reuse the qemu-img rebase code.

> +    /* NB: It is possible to relax this constraint so that
> +     * num_sectors_base <= num_sectors_modified, ie. the modified disk
> +     * has been expanded.  That requires changes to the loop below.
> +     */
> +    if (num_sectors_base != num_sectors_modified) {
> +        error_report("Number of sectors in backing and source must be the same");
> +        goto out2;
> +    }

Just to confirm what Eric said, all other places in qemu can (or are
supposed to) deal with backing files that are smaller than the overlay
image.

> +
> +    /* Output image. */
> +    ret = bdrv_img_create(out, fmt_out,
> +                          /* base file becomes the new backing file */
> +                          base, fmt_base,
> +                          options, num_sectors_modified * BDRV_SECTOR_SIZE,
> +                          BDRV_O_FLAGS);
> +    if (ret != 0) {
> +        goto out2;
> +    }
> +    bs_out = bdrv_new_open(out, fmt_out, BDRV_O_RDWR);
> +
> +    buf_base = qemu_blockalign(bs_base, IO_BUF_SIZE);
> +    buf_modified = qemu_blockalign(bs_modified, IO_BUF_SIZE);
> +
> +    for (sector = 0; sector < num_sectors_modified; sector += n) {
> +        /* How many sectors can we handle with the next read? */
> +        if (sector + (IO_BUF_SIZE / BDRV_SECTOR_SIZE) <= num_sectors_modified) {
> +            n = IO_BUF_SIZE / BDRV_SECTOR_SIZE;
> +        } else {
> +            n = num_sectors_modified - sector;
> +        }
> +
> +        /* Read input files and compare. */
> +        ret = bdrv_read(bs_base, sector, buf_base, n);
> +        if (ret < 0) {
> +            error_report("error while reading from backing file");
> +            goto out;

buf_base/modified are leaked here.

> +        }
> +
> +        ret = bdrv_read(bs_modified, sector, buf_modified, n);
> +        if (ret < 0) {
> +            error_report("error while reading from input file");
> +            goto out;

And here.

> +        }
> +
> +        /* If they differ, we need to write to the differences file. */
> +        uint64_t written = 0;
> +
> +        while (written < n) {
> +            int pnum;
> +
> +            if (compare_sectors(buf_base + written * BDRV_SECTOR_SIZE,
> +                                buf_modified + written * BDRV_SECTOR_SIZE,
> +                                n - written, &pnum)) {
> +                ret = bdrv_write(bs_out, sector + written,
> +                                 buf_modified + written * BDRV_SECTOR_SIZE,
> +                                 pnum);
> +                if (ret < 0) {
> +                    error_report("Error while writing to output file: %s",
> +                                 strerror(-ret));
> +                    goto out;

And here.

> +                }
> +            }
> +
> +            written += pnum;
> +        }
> +    }
> +
> +    qemu_vfree(buf_base);
> +    qemu_vfree(buf_modified);
> +
> + out:
> +    /* Cleanup */
> +    bdrv_delete(bs_out);
> + out2:
> +    bdrv_delete(bs_base);
> +    bdrv_delete(bs_modified);
> +
> +    if (ret) {
> +        return 1;
> +    }
> +    return 0;
> +}
> +
>  static int img_resize(int argc, char **argv)
>  {
>      int c, ret, relative;
> diff --git a/qemu-img.texi b/qemu-img.texi
> index b2ca3a5..718d302 100644
> --- a/qemu-img.texi
> +++ b/qemu-img.texi
> @@ -114,6 +114,28 @@ created as a copy on write image of the specified base image; the
>  @var{backing_file} should have the same content as the input's base image,
>  however the path, image format, etc may differ.
>  
> +@item diff [-F @var{backing_fmt}] -b @var{backing_file} [-f @var{fmt}] [-O @var{output_fmt}] [-o @var{options}] @var{filename} @var{output_filename}
> +
> +Create a new disk image (@var{output_filename}) which contains
> +the differences between @var{backing_file} and @var{filename}.
> +This is useful if you have cloned a disk image by copying it,
> +and you want to get back to a thin image on top of a common base.
> +
> +Typical usage is:
> +
> +@code{qemu-img diff -b base.img modified.img diff.qcow2}
> +
> +The @var{backing_file} and @var{filename} must have the same
> +virtual disk size, but may be in different formats.
> +
> +The format of @var{output_file} must be one that supports backing
> +files (@code{qcow2} or @code{qed}).

Just don't mention any specific image formats. qcow1, VMDK and COW are
other formats that support backing files and should work just as well.
And if another one is added, nobody will remember to update the qemu-img
documentation.

Kevin

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

* Re: [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation.
  2012-05-21 13:29 ` Kevin Wolf
@ 2012-05-21 13:59   ` Richard W.M. Jones
  2012-05-21 14:06     ` Kevin Wolf
  2012-05-21 15:30     ` Eric Blake
  0 siblings, 2 replies; 7+ messages in thread
From: Richard W.M. Jones @ 2012-05-21 13:59 UTC (permalink / raw)
  To: Kevin Wolf; +Cc: qemu-devel

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

On Mon, May 21, 2012 at 03:29:22PM +0200, Kevin Wolf wrote:
> Am 17.05.2012 17:34, schrieb Richard W.M. Jones:
> > From: "Richard W.M. Jones" <rjones@redhat.com>
> > 
> > This produces a qcow2 file which is the difference between
> > two disk images.  ie, if:
> > 
> >   base.img     - is a disk image (in any format)
> >   modified.img - is base.img, copied and modified
> > 
> > then:
> > 
> >   qemu-img diff -b base.img modified.img diff.qcow2
> > 
> > creates 'diff.qcow2' which contains the differences between 'base.img'
> > and 'modified.img'.  Note that 'diff.qcow2' has 'base.img' as its
> > backing file.
> > 
> > Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
> > Cc: Matthew Booth <mbooth@redhat.com>
> > Cc: Pablo Iranzo Gómez <Pablo.Iranzo@redhat.com>
> > Cc: Tomas Von Veschler <tvvcox@redhat.com>
> 
> Hm, I'm wondering... If I have a command line like this:
> 
>   qemu-img diff -b base.img modified.img diff.qcow2
> 
> Would this be equivalent to this sequence?
> 
>   qemu-img create -f qcow2 -b modified.img diff.qcow2
>   qemu-img rebase -b base.img diff.qcow2
> 
> Or is there some detail that I'm missing? If it is equivalent, this
> would suggest that either the new command isn't necessary at all or at
> least that it should reuse the qemu-img rebase code.

Yes.  I tried for a while to work out the sequence of commands that
could make a diff using 'qemu-img rebase', but it wasn't obvious and I
gave up.  It should at least be documented.  How about the attached
patch?

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming blog: http://rwmj.wordpress.com
Fedora now supports 80 OCaml packages (the OPEN alternative to F#)
http://cocan.org/getting_started_with_ocaml_on_red_hat_and_fedora

[-- Attachment #2: 0001-qemu-img-Explain-how-rebase-operation-can-be-used-to.patch --]
[-- Type: text/plain, Size: 1556 bytes --]

>From eec7fa864298b5619c52ada1e8fbd32c00b302d9 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Mon, 21 May 2012 14:58:05 +0100
Subject: [PATCH] qemu-img: Explain how rebase operation can be used to
 perform a 'diff' operation.

Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
---
 qemu-img.texi |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/qemu-img.texi b/qemu-img.texi
index b2ca3a5..6fc3c28 100644
--- a/qemu-img.texi
+++ b/qemu-img.texi
@@ -159,6 +159,24 @@ It can be used without an accessible old backing file, i.e. you can use it to
 fix an image whose backing file has already been moved/renamed.
 @end table
 
+You can use @code{rebase} to perform a ``diff'' operation on two
+disk images.  This can be useful when you have copied or cloned
+a guest, and you want to get back to a thin image on top of a
+template or base image.
+
+Say that @code{base.img} has been cloned as @code{modified.img} by
+copying it, and that the @code{modified.img} guest has run so there
+are now some changes compared to @code{base.img}.  To construct a thin
+image called @code{diff.qcow2} that contains just the differences, do:
+
+@example
+qemu-img create -f qcow2 -b modified.img diff.qcow2
+qemu-img rebase -b base.img diff.qcow2
+@end example
+
+At this point, @code{modified.img} can be discarded, since
+@code{base.img + diff.qcow2} contains the same information.
+
 @item resize @var{filename} [+ | -]@var{size}
 
 Change the disk image as if it had been created with @var{size}.
-- 
1.7.10


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

* Re: [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation.
  2012-05-21 13:59   ` Richard W.M. Jones
@ 2012-05-21 14:06     ` Kevin Wolf
  2012-05-21 15:30     ` Eric Blake
  1 sibling, 0 replies; 7+ messages in thread
From: Kevin Wolf @ 2012-05-21 14:06 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: qemu-devel

Am 21.05.2012 15:59, schrieb Richard W.M. Jones:
> On Mon, May 21, 2012 at 03:29:22PM +0200, Kevin Wolf wrote:
>> Am 17.05.2012 17:34, schrieb Richard W.M. Jones:
>>> From: "Richard W.M. Jones" <rjones@redhat.com>
>>>
>>> This produces a qcow2 file which is the difference between
>>> two disk images.  ie, if:
>>>
>>>   base.img     - is a disk image (in any format)
>>>   modified.img - is base.img, copied and modified
>>>
>>> then:
>>>
>>>   qemu-img diff -b base.img modified.img diff.qcow2
>>>
>>> creates 'diff.qcow2' which contains the differences between 'base.img'
>>> and 'modified.img'.  Note that 'diff.qcow2' has 'base.img' as its
>>> backing file.
>>>
>>> Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
>>> Cc: Matthew Booth <mbooth@redhat.com>
>>> Cc: Pablo Iranzo Gómez <Pablo.Iranzo@redhat.com>
>>> Cc: Tomas Von Veschler <tvvcox@redhat.com>
>>
>> Hm, I'm wondering... If I have a command line like this:
>>
>>   qemu-img diff -b base.img modified.img diff.qcow2
>>
>> Would this be equivalent to this sequence?
>>
>>   qemu-img create -f qcow2 -b modified.img diff.qcow2
>>   qemu-img rebase -b base.img diff.qcow2
>>
>> Or is there some detail that I'm missing? If it is equivalent, this
>> would suggest that either the new command isn't necessary at all or at
>> least that it should reuse the qemu-img rebase code.
> 
> Yes.  I tried for a while to work out the sequence of commands that
> could make a diff using 'qemu-img rebase', but it wasn't obvious and I
> gave up.  It should at least be documented.  How about the attached
> patch?

Looks good to me. As it already has a SoB, I've applied it to the block
branch. Let me know if I should dequeue it again.

Kevin

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

* Re: [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation.
  2012-05-21 13:59   ` Richard W.M. Jones
  2012-05-21 14:06     ` Kevin Wolf
@ 2012-05-21 15:30     ` Eric Blake
  2012-05-21 15:40       ` Kevin Wolf
  1 sibling, 1 reply; 7+ messages in thread
From: Eric Blake @ 2012-05-21 15:30 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: Kevin Wolf, qemu-devel

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

On 05/21/2012 07:59 AM, Richard W.M. Jones wrote:

>>
>> Hm, I'm wondering... If I have a command line like this:
>>
>>   qemu-img diff -b base.img modified.img diff.qcow2
>>
>> Would this be equivalent to this sequence?
>>
>>   qemu-img create -f qcow2 -b modified.img diff.qcow2
>>   qemu-img rebase -b base.img diff.qcow2

So 'qemu-img rebase' is able to rebase to any other image, even if
base.img is nowhere in the backing chain of modified.img?  That means it
is more powerful than runtime 'block-stream' monitor command under qemu,
which can only do a block pull from an earlier point in the backing chain.

> Yes.  I tried for a while to work out the sequence of commands that
> could make a diff using 'qemu-img rebase', but it wasn't obvious and I
> gave up.  It should at least be documented.  How about the attached
> patch?

Seems reasonable to me.  A two-command sequence of qemu-img to
manipulate offline images isn't all that bad; it's different from the
case of a disk image in active use by qemu.

-- 
Eric Blake   eblake@redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 620 bytes --]

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

* Re: [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation.
  2012-05-21 15:30     ` Eric Blake
@ 2012-05-21 15:40       ` Kevin Wolf
  0 siblings, 0 replies; 7+ messages in thread
From: Kevin Wolf @ 2012-05-21 15:40 UTC (permalink / raw)
  To: Eric Blake; +Cc: Richard W.M. Jones, qemu-devel

Am 21.05.2012 17:30, schrieb Eric Blake:
> On 05/21/2012 07:59 AM, Richard W.M. Jones wrote:
> 
>>>
>>> Hm, I'm wondering... If I have a command line like this:
>>>
>>>   qemu-img diff -b base.img modified.img diff.qcow2
>>>
>>> Would this be equivalent to this sequence?
>>>
>>>   qemu-img create -f qcow2 -b modified.img diff.qcow2
>>>   qemu-img rebase -b base.img diff.qcow2
> 
> So 'qemu-img rebase' is able to rebase to any other image, even if
> base.img is nowhere in the backing chain of modified.img?  That means it
> is more powerful than runtime 'block-stream' monitor command under qemu,
> which can only do a block pull from an earlier point in the backing chain.

Correct. 'qemu-img rebase' compares the old and the new backing file for
each unallocated cluster of the overlay, and if they differ, it copies
the data from the old backing file into the overlay.

Not sure if there would be any real use for a real live rebase, but even
if there was, implementing it probably wouldn't be a priority for most
of us.

>> Yes.  I tried for a while to work out the sequence of commands that
>> could make a diff using 'qemu-img rebase', but it wasn't obvious and I
>> gave up.  It should at least be documented.  How about the attached
>> patch?
> 
> Seems reasonable to me.  A two-command sequence of qemu-img to
> manipulate offline images isn't all that bad; it's different from the
> case of a disk image in active use by qemu.

Even there you use a two-command sequence when you do an external
'qemu-img create' and then use the 'existing' mode of snapshots or
mirroring. :-)

Kevin

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

end of thread, other threads:[~2012-05-21 15:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-17 15:34 [Qemu-devel] [PATCH v3] qemu-img: Implement 'diff' operation Richard W.M. Jones
2012-05-17 15:49 ` Eric Blake
2012-05-21 13:29 ` Kevin Wolf
2012-05-21 13:59   ` Richard W.M. Jones
2012-05-21 14:06     ` Kevin Wolf
2012-05-21 15:30     ` Eric Blake
2012-05-21 15:40       ` Kevin Wolf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.