summaryrefslogtreecommitdiff
path: root/qemu-img.c
AgeCommit message (Collapse)AuthorFilesLines
2012-06-15block: Replace bdrv_get_format() by bdrv_get_format_name()Markus Armbruster1-3/+2
So callers don't need to know anything about maximum name length. Returning a pointer is safe, because the name string lives as long as the block driver it names, and block drivers don't die. Requested by Peter Maydell. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-06-15qemu-img check: Print fixed clusters and recheckKevin Wolf1-0/+10
When any inconsistencies have been fixed, print the statistics and run another check to make sure everything is correct now. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-06-15qemu-img check -r for repairing imagesKevin Wolf1-3/+22
The QED block driver already provides the functionality to not only detect inconsistencies in images, but also fix them. However, this functionality cannot be manually invoked with qemu-img, but the check happens only automatically during bdrv_open(). This adds a -r switch to qemu-img check that allows manual invocation of an image repair. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-05-14qemu-img: Fix segmentation faultCharles Arnold1-1/+3
The following command generates a segmentation fault. qemu-img convert -O vpc -o ? test test2 This is because the 'goto out;' statement calls qemu_progress_end before qemu_progress_init is called resulting in a NULL pointer invocation. Signed-off-by: Charles Arnold <carnold@suse.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-05-10qemu-img: make "info" backing file output correct and easier to usePaolo Bonzini1-5/+7
qemu-img info should use the same logic as qemu when printing the backing file path, or debugging becomes quite tricky. We can also simplify the output in case the backing file has an absolute path or a protocol. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-20qemu-img: let 'qemu-img convert' flush dataLiu Yuan1-2/+2
The 'qemu-img convert -h' advertise that the default cache mode is 'writeback', while in fact it is 'unsafe'. This patch 1) fix the help manual and 2) let bdrv_close() call bdrv_flush() 2) is needed because some backend storage doesn't have a self-flush mechanism(for e.g., sheepdog), so we need to call bdrv_flush() to make sure the image is really writen to the storage instead of hanging around writeback cache forever. Signed-off-by: Liu Yuan <tailai.ly@taobao.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05qemu-img: add dirty flag statusDong Xu Wang1-0/+3
Some block drivers can verify their image files are clean or not. So we can show it while using "qemu-img info". Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-04-05qemu-img: add image fragmentation statisticsDong Xu Wang1-1/+8
Discussion can be found at: http://patchwork.ozlabs.org/patch/128730/ This patch add image fragmentation statistics while using qemu-img check. Signed-off-by: Dong Xu Wang <wdongxu@linux.vnet.ibm.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-03-12qcow2: Add error messages in qcow2_truncateKevin Wolf1-1/+1
qemu-img resize has some limitations with qcow2, but the user is only told that "this image format does not support resize". Quite confusing, so add some more detailed error_report() calls and change "this image format" into "this image". Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-02-29qemu-img: fix segment fault when the image format is qedZhi Yong Wu1-0/+2
[root@f15 qemu]# qemu-img info /home/zwu/work/misc/rh6.img image: /home/zwu/work/misc/rh6.img file format: qed virtual size: 4.0G (4294967296 bytes) disk size: 1.2G cluster_size: 65536 Segmentation fault (core dumped) Today when i were fixing another issue, i found this issue; After simple investigation, i found that the required clock vm_clock is not created for qemu tool. Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2012-02-09cutils: extract buffer_is_zero() from qemu-img.cStefan Hajnoczi1-39/+7
The qemu-img.c:is_not_zero() function checks if a buffer contains all zeroes. This function will come in handy for zero-detection in the block layer, so clean it up and move it to cutils.c. Note that the function now returns true if the buffer is all zeroes. This avoids the double-negatives (i.e. !is_not_zero()) that the old function can cause in callers. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-12-15qemu-img rebase: Fix for undersized backing filesKevin Wolf1-9/+33
Backing files may be smaller than the corresponding COW file. When reading directly from the backing file, qemu-img rebase must consider this and assume zero sectors after the end of backing files. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-11-28qemu-img: Tighten parsing of size argumentsMarkus Armbruster1-4/+6
strtosz_suffix() fails unless the size is followed by 0, whitespace or ','. Useless here, because we need to fail for any junk following the size, even if it starts with whitespace or ','. Check manually. Things like "qemu-img create xxx 1024," and "qemu-img convert -S '1024 junk'" are now caught. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-10-21qemu-img: Don't allow preallocation and compression at the same timeKevin Wolf1-0/+11
Only qcow and qcow2 can do compression at all, and they require unallocated clusters when writing the compressed data. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-08-29qemu-img: Require larger zero areas for sparse handlingKevin Wolf1-2/+59
By default, require 4k of consecutive zero bytes for qemu-img to make the output file sparse by not issuing a write request for the zeroed parts. Add an -S option to allow users to tune this setting. This helps to avoid situations where a lot of zero sectors and data sectors are mixed and qemu-img tended to issue many tiny 512 byte writes. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-23qemu-img: print error codes when convert failsStefan Hajnoczi1-5/+8
Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-23qemu-img: Use qemu_blockalignKevin Wolf1-6/+6
Now that you can use cache=none for the output file in qemu-img, we should properly align our buffers so that raw-posix doesn't have to use its (smaller) bounce buffer. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-08-23block: add cache=directsync parameter to -driveStefan Hajnoczi1-1/+2
This patch adds -drive cache=directsync for O_DIRECT | O_SYNC host file I/O with no disk write cache presented to the guest. This mode is useful when guests may not be sending flushes when appropriate and therefore leave data at risk in case of power failure. When cache=directsync is used, write operations are only completed to the guest when data is safely on disk. This new mode is like cache=writethrough but it bypasses the host page cache. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-23block: parse cache mode flags in a single placeStefan Hajnoczi1-24/+3
This patch introduces bdrv_parse_cache_flags() which sets open flags given a cache mode. Previously this was duplicated in blockdev.c and qemu-img.c. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-08-20Use glib memory allocation and free functionsAnthony Liguori1-9/+9
qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2011-07-19block: add bdrv_get_allocated_file_size() operationFam Zheng1-30/+1
qemu-img.c wants to count allocated file size of image. Previously it counts a single bs->file by 'stat' or Window API. As VMDK introduces multiple file support, the operation becomes format specific with platform specific meanwhile. The functions are moved to block/raw-{posix,win32}.c and qemu-img.c calls bdrv_get_allocated_file_size to count the bs. And also added VMDK code to count his own extents. Signed-off-by: Fam Zheng <famcool@gmail.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-07-05qemu-img: Add cache command line optionFederico Simoncelli1-13/+67
qemu-img currently writes disk images using writeback and filling up the cache buffers which are then flushed by the kernel preventing other processes from accessing the storage. This is particularly bad in cluster environments where time-based algorithms might be in place and accessing the storage within certain timeouts is critical. This patch adds the option to choose a cache method when writing disk images. Signed-off-by: Federico Simoncelli <fsimonce@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-06-24qemu-img: Don't prepend qemu-img to error messages twice.Markus Armbruster1-4/+4
error_report() prepends the location already. Example: $ qemu-img convert -6 qemu-img: qemu-img: option -6 is deprecated, please use '-o compat6' instead! Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-06-24Strip trailing '\n' from error_report()'s first argumentMarkus Armbruster1-2/+2
error_report() prepends location, and appends a newline. The message constructed from the arguments should not contain a newline. Fix the obvious offenders. Signed-off-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-05-18qemu_img: is_not_zero() optimizationDmitry Konishchev1-3/+26
I run qemu-img under profiler and realized, that most of CPU time is consumed by is_not_zero() function. I had made a couple of optimizations on it and got the following output for `time qemu-img convert -O qcow2 volume.qcow2 snapshot.qcow2`: Original qemu-img: real 0m56.159s user 0m34.670s sys 0m12.079s Patched qemu-img: real 0m34.805s user 0m18.445s sys 0m12.552s Signed-off-by: Dmitry Konishchev <konishchev@gmail.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-05-18qemu-img.c: Remove superfluous parenthesisJes Sorensen1-3/+3
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-05-03qemu-img resize: Fix option parsingKevin Wolf1-2/+11
For shrinking images, you're supposed to use a negative size. However, the leading minus makes getopt think that it's an option and so you get the help text if you don't use -- like in 'qemu-img resize test.img -- -1G'. This patch handles the size first and removes it from the argument list so that getopt won't even try to interpret it and you don't need -- any more. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-04-27qemu-img: allow rebase to a NULL backing file when unsafeAnthony Liguori1-1/+1
QEMU can drop a backing file so that an image file no longer depends on the backing file, but this feature has not been exposed in qemu-img. This is useful in an image streaming usecase or when an image file has been fully allocated and no reads can hit the backing file anymore. Since the dropping the backing file can make the image unusable, only allow this when the unsafe flag has been set. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-04-07qemu-img rebase: Fix segfault if backing file can't be openedKevin Wolf1-2/+6
bdrv_delete must not be called for a NULL BlockDriverState. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2011-04-07qemu-img: Initial progress printing supportJes Sorensen1-2/+36
This adds the basic infrastructure for supporting progress output on the command line, as well as progress support for qemu-img commands 'rebase' and 'convert'. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-02-10qemu-img: Improve error messages for failed bdrv_openKevin Wolf1-3/+7
Output the error message string of the bdrv_open return code. Also set a non-empty device name for the images because the unknown feature error message includes it. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com>
2011-01-24Make strtosz() return int64_t instead of ssize_tJes Sorensen1-1/+1
strtosz() needs to return a 64 bit type even on 32 bit architectures. Otherwise qemu-img will fail to create disk images >= 2GB Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2011-01-24qemu-img snapshot: Use writeback cachingKevin Wolf1-1/+1
None of the other qemu-img subcommands uses writethrough, and there's no reason why snapshot should be special. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2010-12-17Remove NULL checks for bdrv_new return valueKevin Wolf1-4/+1
It's an indirect call to qemu_malloc, which never returns an error. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-17qemu.img.c: Use error_report() instead of own error() implementationJes Sorensen1-65/+62
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-17qemu-img.c: Re-factor img_create()Jes Sorensen1-106/+2
This patch re-factors img_create() moving the code doing the actual work into block.c where it can be shared with QEMU. This is needed to be able to create images from QEMU to be used for live snapshots. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-17qemu-img: Call error_set_prognameKevin Wolf1-0/+3
Call error_set_progname during the qemu-img initialization, so that error messages printed with error_report() use the right prefix. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-17qemu-img.c: Clean up handling of image size in img_create()Jes Sorensen1-6/+17
This cleans up the handling of image size in img_create() by parsing the value early, and then only setting it once if a value has been added as the last argument to the command line. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14qemu-img: Fail creation if backing format is invalidStefan Hajnoczi1-10/+12
The qemu-img create command should check the backing format to ensure only image files with valid backing formats are created. By checking in qemu-img.c we can print a useful error message. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14qemu-img: Free option parameter lists in img_create()Stefan Hajnoczi1-2/+2
Free option parameter lists in the img_create() error return path. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14qemu-img: Deprecate obsolete -6 and -e optionsJes Sorensen1-31/+22
If -6 or -e is specified, an error message is printed and we exit. It does not print help() to avoid the error message getting lost in the noise. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14Make error handling more consistent in img_create() and img_resize()Jes Sorensen1-6/+12
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14Fail if detecting an unknown optionJes Sorensen1-0/+8
This patch changes qemu-img to exit if an unknown option is detected, instead of trying to continue with a set of arguments which may be incorrect. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14Fix formatting and missing braces in qemu-img.cJes Sorensen1-26/+51
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14Consolidate printing of block driver optionsJes Sorensen1-9/+37
This consolidates the printing of block driver options in print_block_option_help() which is called from both img_create() and img_convert(). This allows for the "?" detection to be done just after the parsing of options and the filename, instead of half way down the codepath of these functions. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14img_convert(): Only try to free bs[] entries if bs is valid.Jes Sorensen1-5/+8
This allows for jumping to 'out:' consistently for error exit. Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14Use qemu_mallocz() instead of calloc() in img_convert()Jes Sorensen1-6/+2
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-10-30Move qemu_gettimeofday() to OS specific filesJes Sorensen1-0/+1
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-10-22qemu-img: Fix qemu-img convert -obacking_fileKevin Wolf1-0/+7
The old -B option caused a backing file to be used for the converted image and to avoid copying clusters from the old backing file. When replaced with -obacking_file, qemu-img convert does assign the backing file to the new image, but it doesn't realize that it should avoid copying clusters from the backing file. This patch checks the -o options for a backing_file and applies the same logic as for -B in this case. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-10-22Copy snapshots out of QCOW2 diskedison1-1/+18
In order to backup snapshots, created from QCOW2 iamge, we want to copy snapshots out of QCOW2 disk to a seperate storage. The following patch adds a new option in "qemu-img": qemu-img convert -f qcow2 -O qcow2 -s snapshot_name src_img bck_img. Right now, it only supports to copy the full snapshot, delta snapshot is on the way. Changes from V1: all the comments from Kevin are addressed: Add read-only checking Fix coding style Change the name from bdrv_snapshot_load to bdrv_snapshot_load_tmp Signed-off-by: Disheng Su <edison@cloud.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>