qemu-img: Implement 'diff' operation.
PATCH 1/1 qemu-img: Implement 'diff' operation.
From: "Richard W.M. Jones" <[email protected]>
This produces a qcow2 file which is the different between two disk images. ie, if:
original.img - is a disk image (in any format) modified.img - is a modified version of original.img
then:
qemu-img diff -b original.img modified.img diff.qcow2
creates 'diff.qcow2' which contains just the differences. Note that 'diff.qcow2' has 'original.img' set as the backing file.
--- qemu-img-cmds.hx | 6 +++ qemu-img.c | 150 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-img.texi | 17 +++++++ 3 files changed, 173 insertions(+)
qemu-img-cmds.hx +6 -0
@@ -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 fmt] [-F backing_fmt] [-O output_fmt] -b backing_file filename output_filename") +STEXI +@item rebase [-f @var{fmt}] [-F @var{backing_fmt}] [-O @var{output_fmt}] -b @var{backing_file} @var{filename} @var{output_filename} +ETEXI + DEF("info", img_info, "info [-f fmt] filename") STEXI
qemu-img.c +150 -0
156 lines not on this page · raw message
qemu-img.texi +17 -0
@@ -114,6 +114,23 @@ 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{fmt}] [-F @var{backing_fmt}] [-O @var{output_fmt}] -b @var{backing_file} @var{filename} @var{output_filename} + +Create a new file (@var{output_filename}) which contains the +differences between @var{backing_file} and @var{filename}. + +The @var{backing_file} and @var{filename} must have the same +virtual disk size, but may be in different formats. + +@var{output_file} will have @var{backing_file} set as its backing +file. The format of @var{output_file} must be one that supports +backing files (currently @code{qcow2} is the default and only +permitted output format). + +Typical usage is: + +@code{qemu-img diff -b original.img modified.img diff.qcow2} + @item info [-f @var{fmt}] @var{filename} Give information about the disk image @var{filename}. Use it in
Signature · 1 line
1.7.10
Quoted 8 lines · Richard W.M. Jones
From: "Richard W.M. Jones" <[email protected]>
This produces a qcow2 file which is the different between two disk images. ie, if:
original.img - is a disk image (in any format) modified.img - is a modified version of original.img
Quoted 6 lines
then:
qemu-img diff -b original.img modified.img diff.qcow2
creates 'diff.qcow2' which contains just the differences. Note that 'diff.qcow2' has 'original.img' set as the backing file.
Any chance of some more detailed explanation in the docs patch about what this actually means and why it's useful? I spent several minutes going "huh, does it even mean anything to calculate the difference between two binary disk images?" before realising that it's the presence of the backing file that makes it actually make sense...
(maybe I'm just dense :-))
-- PMM
Quoted 16 lines · Peter Maydell
Quoted 8 lines · Richard W.M. Jones
From: "Richard W.M. Jones" <[email protected]>
This produces a qcow2 file which is the different between two disk images. ie, if:
original.img - is a disk image (in any format) modified.img - is a modified version of original.img
Quoted 6 lines
then:
qemu-img diff -b original.img modified.img diff.qcow2
creates 'diff.qcow2' which contains just the differences. Note that 'diff.qcow2' has 'original.img' set as the backing file.
Quoted 6 lines
Any chance of some more detailed explanation in the docs patch about what this actually means and why it's useful? I spent several minutes going "huh, does it even mean anything to calculate the difference between two binary disk images?" before realising that it's the presence of the backing file that makes it actually make sense...
Even something as simple as:
Useful for converting a monolithic image back into a thin image on top of a common base.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 16 lines · Peter Maydell
Quoted 8 lines · Richard W.M. Jones
From: "Richard W.M. Jones" <[email protected]>
This produces a qcow2 file which is the different between two disk images. ie, if:
original.img - is a disk image (in any format) modified.img - is a modified version of original.img
Quoted 6 lines
then:
qemu-img diff -b original.img modified.img diff.qcow2
creates 'diff.qcow2' which contains just the differences. Note that 'diff.qcow2' has 'original.img' set as the backing file.
Quoted 6 lines
Any chance of some more detailed explanation in the docs patch about what this actually means and why it's useful? I spent several minutes going "huh, does it even mean anything to calculate the difference between two binary disk images?" before realising that it's the presence of the backing file that makes it actually make sense...
Well I'll say first of all that I was asked to implement this by a colleague. Personally, I'm far more organized than this, and I always use snapshots and backing files if I want to create an efficient COW from a base template :-)
However my colleague has got himself into a situation where he has copied (ie. "cp" or equivalent) a guest several times from a template, and these guests have been running independently. He now wants to conserve disk space by turning this situation back into one where he has one backing file + several COW copies.
To do this, he can (with this patch) do:
qemu-img diff -b base.img the_copied_guest.img guest.qcow2 rm the_copied_guest.img
'guest.qcow2' will (in theory at least) be much smaller than the copied guests he has right now.
Does that make sense?
[BTW I'm still working on this. There are a few spelling mistakes and it needs a lot more testing. This patch is just for comment at the moment.]
Rich.
Signature · 3 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Quoted 8 lines · Richard W.M. Jones
From: "Richard W.M. Jones" <[email protected]>
This produces a qcow2 file which is the different between two disk images. ie, if:
original.img - is a disk image (in any format) modified.img - is a modified version of original.img
Quoted 6 lines
then:
qemu-img diff -b original.img modified.img diff.qcow2
creates 'diff.qcow2' which contains just the differences. Note that 'diff.qcow2' has 'original.img' set as the backing file.
Sounds useful!
qemu-img-cmds.hx STEXI · line 37
Quoted 3 lines
qemu-img-cmds.hx +2
-0+DEF("diff", img_diff, + "diff [-f fmt] [-F backing_fmt] [-O output_fmt] -b backing_file filename output_filename")
Just so I'm clear: -f is for filename (the file with the modifications being extracted), -F is for backing_file (the file that serves as the base of the diff), and -O is for output_filename.
Quoted 2 lines
+STEXI
+@item rebase [-f @var{fmt}] [-F @var{backing_fmt}] [-O @var{output_fmt}] -b @var{backing_file} @var{filename} @var{output_filename}
s/rebase/diff/
We also need to support -o options for the output_filename, so that we can expose other qcow2 attributes while creating the diff. For example, encryption, cluster_size, and preacllocation all come to mind.
qemu-img.c out: · line 1608
Quoted 7 lines
qemu-img.c +7
-0+ +bdrv_get_geometry (bs_original, &num_sectors); +bdrv_get_geometry (bs_modified, &modified_num_sectors); +if (num_sectors != modified_num_sectors) { +error_report ("Number of sectors in backing and source must be the same" ); + goto out2; + }
Why are you requiring equality? I can see the usefulness of doing a diff where the modified file is larger than the original (basically, the diff was created by extending the original file to something larger). Prohibiting a modified file smaller than the original makes sense, so I think this should be >, not !=.
qemu-img.c out: · line 1617
Quoted 9 lines
qemu-img.c +9
-0+ +/* Output image. */ +if (fmt_out ==NULL || fmt_out[0 ] =='\0' ) { + fmt_out ="qcow2" ; + } + ret =bdrv_img_create (out, fmt_out, +/* original file becomes the new backing file */ + original, fmt_original, +NULL , num_sectors *BDRV_SECTOR_SIZE ,BDRV_O_FLAGS );
If you allow a modified larger than backing, then this should be modified_num_sectors, not num_sectors.
qemu-img.texi created as a copy on write image of the specified base image; the · line 123
Quoted 12 lines
+++ b/qemu-img.texi
qemu-img.texi +7
-0@@ -114,6 +114,23 @@ 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{fmt}] [-F @var{backing_fmt}] [-O @var{output_fmt}] -b @var{backing_file} @var{filename} @var{output_filename} + +Create a new file (@var{output_filename}) which contains the +differences between @var{backing_file} and @var{filename}. + +The @var{backing_file} and @var{filename} must have the same +virtual disk size, but may be in different formats.
Again, I think this is overly tight.
qemu-img.texi created as a copy on write image of the specified base image; the · line 128
Quoted 5 lines
qemu-img.texi +5
-0+ +@var{output_file} will have @var{backing_file} set as its backing +file. The format of @var{output_file} must be one that supports +backing files (currently @code{qcow2} is the default and only +permitted output format).
Why doesn't qed just work out of the box?
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
On Thu, May 17, 2012 at 07:57:31AM -0600, Eric Blake wrote:
[...]
I just posted a v2 patch which fixes everything you mentioned except the case of resizing the disk, which I need to think about a bit more.
Rich.
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v