aboutsummaryrefslogtreecommitdiff
path: root/qemu-img.c
AgeCommit message (Collapse)Author
2010-12-17Remove NULL checks for bdrv_new return valueKevin Wolf
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 Sorensen
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 Sorensen
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 Wolf
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 Sorensen
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 Hajnoczi
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 Hajnoczi
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 Sorensen
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 Sorensen
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 Sorensen
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 Sorensen
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 Sorensen
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 Sorensen
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 Sorensen
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 Sorensen
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 Wolf
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 diskedison
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>
2010-10-03Use GCC_FMT_ATTR (format checking)Stefan Weil
Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-09-08qemu-img convert: Use cache=unsafe for output imageKevin Wolf
If qemu-img crashes during the conversion, the user will throw away the broken output file anyway and start over. So no need to be too cautious. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-08-30qemu-img rebase: Open new backing file read-onlyKevin Wolf
We never write to a backing file, so opening rw is useless. It just means that you can't rebase on top of a file for which you don't have write permissions. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-07-06qemu-img check: Distinguish different kinds of errorsKevin Wolf
People think that their images are corrupted when in fact there are just some leaked clusters. Differentiating several error cases should make the messages more comprehensible. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-07-02qemu-img: avoid calling exit(1) to release resources properlyMORITA Kazutaka
This patch removes exit(1) from error(), and properly releases resources such as a block driver and an allocated memory. For testing the Sheepdog block driver with qemu-iotests, it is necessary to call bdrv_delete() before the program exits. Because the driver releases the lock of VM images in the close handler. Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-05-28add support for protocol driver create_optionsMORITA Kazutaka
This patch enables protocol drivers to use their create options which are not supported by the format. For example, protcol drivers can use a backing_file option with raw format. Signed-off-by: MORITA Kazutaka <morita.kazutaka@lab.ntt.co.jp> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-05-22Fix %lld or %llx printf format useBlue Swirl
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-05-03qemu-img rebase: Fix output image corruptionKevin Wolf
qemu-img rebase must always give clusters in the COW file priority over those in the backing file. As it failed to use number of non-allocated clusters but assumed the maximum, it was possible that allocated clusters were taken from the backing file instead, leading to a corrupted output image. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-05-03qemu-img: Add 'resize' command to grow/shrink disk imagesStefan Hajnoczi
This patch adds a 'resize' command to grow/shrink disk images. This allows changing the size of disk images without copying to a new image file. Currently only raw files support resize. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-05-03block: bdrv_has_zero_initKevin Wolf
This fixes the problem that qemu-img's use of no_zero_init only considered the no_zero_init flag of the format driver, but not of the underlying protocols. Between the raw/file split and this fix, converting to host devices is broken. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-04-23qemu-img: Fix BRDV_O_FLAGS typoStefan Hajnoczi
It should be BDRV_O_FLAGS instead of BRDV_O_FLAGS. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-04-23qemu-img: Eliminate bdrv_new_open() code duplicationStefan Hajnoczi
Several commands have code to create a BlockDriverState and open a file. The bdrv_new_open() function can be used to perform these steps. This patch converts the qemu-img commands to actually use bdrv_new_open(). Replaced the bdrv_new_open() 'readonly' argument with bdrv_open()-style flags to support generic flags like BDRV_O_NO_BACKING. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-04-23Replace calls of old bdrv_openKevin Wolf
What is known today as bdrv_open2 becomes the new bdrv_open. All remaining callers of the old function are converted to the new one. In some places they even know the right format, so they should have used bdrv_open2 from the beginning. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-03-09block: print errno on errorJuan Quintela
Now that we changed all create calls to return errno, just print it. Signed-off-by: Juan Quintela <quintela@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-03-09qemu-img rebase: Add -f optionKevin Wolf
Allow the user to specify the format of the image to rebase. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19qemu-img: Fix error messageKevin Wolf
When qemu-img can't open the new backing file for a rebase, it prints an error message which contains the file name of the old backing file. This is wrong, obviously. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-19qemu-img: Fix segfault during rebaseKevin Wolf
This fixes a possible read beyond the end of the temporary buffers used for comparing data in the old and the new backing file. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10qemu-img: use the heap instead of the huge stack array for win32TeLeMan
The default stack size of PE is 1MB on win32 and IO_BUF_SIZE in img_convert() & img_rebase() is 2MB, so qemu-img will crash when doing "convert" & "rebase" on win32. Although we can improve the stack size of PE to resolve it, I think we should avoid using the huge stack variables. Signed-off-by: TeLeMan <geleman@gmail.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-10qemu-img: Fix qemu-img can't create qcow image based on read-only imageSheng Yang
Commit 03cbdac7 "Disable fall-back to read-only when cannot open drive's file for read-write" result in read-only image can't be used as backed image in qemu-img. Cc: Naphtali Sprei <nsprei@redhat.com> Signed-off-by: Sheng Yang <sheng@linux.intel.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-02-08qemu-img: avoid preprocessor directives in a printf callPaolo Bonzini
Other choices include using "(printf)", but this one is not bad in terms of readability. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: malc <av1474@comtv.ru>
2010-02-08Revert "On some systems printf is a macro"malc
This reverts commit bc5b6004588ad17370e0416e40b4aa9cf977023b.
2010-02-07On some systems printf is a macromalc
Signed-off-by: malc <av1474@comtv.ru>
2010-01-26Ask for read-write permissions when opening filesNaphtali Sprei
Found some places that seems needs this explicitly, now that read-write is not the default. Signed-off-by: Naphtali Sprei <nsprei@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-20Clean-up a little bit the RW related bits of BDRV_O_FLAGS. BDRV_O_RDONLY ↵Naphtali Sprei
gone (and so is BDRV_O_ACCESS). Default value for bdrv_flags (0/zero) is READ-ONLY. Need to explicitly request READ-WRITE. Instead of using the field 'readonly' of the BlockDriverState struct for passing the request, pass the request in the flags parameter to the function. Signed-off-by: Naphtali Sprei <nsprei@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-13qemu-img rebaseKevin Wolf
This adds a rebase subcommand to qemu-img which allows to change the backing file of an image. In default mode, both the current and the new backing file need to exist, and after the rebase, the COW image is guaranteed to have the same guest visible content as before. To achieve this, old and new backing file are compared and, if necessary, data is copied from the old backing file into the COW image. With -u an unsafe mode is enabled that doesn't require the backing files to exist. It merely changes the backing file reference in the COW image. This is useful for renaming or moving the backing file. The user is responsible to make sure that the new backing file has no changes compared to the old one, or corruption may occur. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2010-01-13block: Introduce BDRV_O_NO_BACKINGKevin Wolf
If an image references a backing file that doesn't exist, qemu-img info fails to open this image. Exactly in this case the info would be valuable, though: the user might want to find out which file is missing. This patch introduces a BDRV_O_NO_BACKING flag to ignore the backing file when opening the image. qemu-img info is the first user and provides info now even if the backing file is invalid. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03qemu-img: Fix memory leakKevin Wolf
Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03Fix description of size parameter in qemu-img's help textPierre Riteau
Valid description taken from qemu-img.texi, although it would be better to have this information recorded in only one place. Signed-off-by: Pierre Riteau <Pierre.Riteau@irisa.fr> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03qemu-img: There is more than one host device driverKevin Wolf
I haven't heard yet of anyone using qemu-img to copy an image to a real floppy, but it's a valid use case. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-11-09Documentation: Don't mention old qemu-img optionsKevin Wolf
The old options are still supported for compatibility, but they are inconsistent (for example create -b vs. convert -B for backing files) and incomplete (-F only exists for create) which tends to confuse people. Remove all references to the old options from the documentation to guide users to the more consistent -o options. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-11-09qemu-img: Allow creating zero sized imagesKevin Wolf
A size of 0 should be valid and cannot be treated as "missing value". Use -1 for this purpose instead. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-05qcow2: Increase maximum cluster size to 2 MBKevin Wolf
This patch increases the maximum qcow2 cluster size to 2 MB. Starting with 128k clusters, L2 tables span 2 GB or more of virtual disk space, causing 32 bit truncation and wraparound of signed integers. Therefore some variables need to use a larger data type. While being at reviewing data types, change some integers that are used for array indices to unsigned. In some places they were checked against some upper limit but not for negative values. This could avoid potential segfaults with corrupted qcow2 images. Signed-off-by: Kevin Wolf <kwolf@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-01Revert "Get rid of _t suffix"Anthony Liguori
In the very least, a change like this requires discussion on the list. The naming convention is goofy and it causes a massive merge problem. Something like this _must_ be presented on the list first so people can provide input and cope with it. This reverts commit 99a0949b720a0936da2052cb9a46db04ffc6db29. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>