qemu-img: Implement 'diff' operation.
PATCH v2 1/1 qemu-img: Implement 'diff' operation.
From: "Richard W.M. Jones" <[email protected]>
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.
--- qemu-img-cmds.hx | 6 ++ qemu-img.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ qemu-img.texi | 22 ++++++++ 3 files changed, 190 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 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
qemu-img.c +162 -0
168 lines not on this page · raw message
qemu-img.texi +22 -0
@@ -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
Signature · 1 line
1.7.10
Quoted 19 lines · Richard W.M. Jones
From: "Richard W.M. Jones" <[email protected]>
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 modifiedthen:
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.
+++ b/qemu-img-cmds.hx
qemu-img-cmds.hx STEXI · line 39
Quoted 7 lines
qemu-img-cmds.hx +4
-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 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}
Why the difference in ordering between -o and -O?
qemu-img.c out: · line 1592
Quoted 4 lines
qemu-img.c +4
-0+ +if (argc - optind !=2 ) { +error_report ("The input and output filenames must be supplied" ); +return 1 ;
Error is misleading if argc > optind+2.
qemu-img.c out: · line 1599
Quoted 4 lines
qemu-img.c +4
-0+ +if (fmt_out ==NULL || fmt_out[0 ] =='\0' ) { + fmt_out ="qcow2" ; + }
So output defaults to qcow2, and input (both base and modified) default to probing. Works for me.
qemu-img.c out: · line 1622
Quoted 7 lines
qemu-img.c +7
-0+ +bdrv_get_geometry (bs_base, &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; + }
I can live with an initial implementation that is strict, where a later patch relaxes things to allow a modified image that has been enlarged.
qemu-img.c out: · line 1629
Quoted 7 lines
qemu-img.c +7
-0+ +/* Output image. */ + ret =bdrv_img_create (out, fmt_out, +/* base file becomes the new backing file */ + base, fmt_base, + options, + num_sectors *BDRV_SECTOR_SIZE ,BDRV_O_FLAGS );
I still think this should be modified_num_sectors - for now, the two values are equal, but if we relax the error check up above, then you really do want to go with the output file the same size as the modified file.
It looks like you did indeed address most of my comments on v1.
Signature · 2 lines
Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 7 lines · Eric Blake
qemu-img-cmds.hx STEXI · line 39
Quoted 4 lines · Richard W.M. Jones
qemu-img-cmds.hx +4
-0+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}Why the difference in ordering between -o and -O?
I though it looked more logical, but I can swap them around too if you think it's better.
Quoted 6 lines
qemu-img.c out: · line 1592
Quoted 4 lines
qemu-img.c +4
-0+ +if (argc - optind !=2 ) { +error_report ("The input and output filenames must be supplied" ); +return 1 ;Error is misleading if argc > optind+2.
OK will fix.
I'll rework the num_sectors thing in v3.
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