summaryrefslogtreecommitdiffstats
path: root/qemu-img.c
Commit message (Collapse)AuthorAgeFilesLines
* Use glib memory allocation and free functionsAnthony Liguori2011-08-201-9/+9
| | | | | | qemu_malloc/qemu_free no longer exist after this commit. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
* block: add bdrv_get_allocated_file_size() operationFam Zheng2011-07-191-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>
* qemu-img: Add cache command line optionFederico Simoncelli2011-07-051-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>
* qemu-img: Don't prepend qemu-img to error messages twice.Markus Armbruster2011-06-241-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>
* Strip trailing '\n' from error_report()'s first argumentMarkus Armbruster2011-06-241-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>
* qemu_img: is_not_zero() optimizationDmitry Konishchev2011-05-181-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>
* qemu-img.c: Remove superfluous parenthesisJes Sorensen2011-05-181-3/+3
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-img resize: Fix option parsingKevin Wolf2011-05-031-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>
* qemu-img: allow rebase to a NULL backing file when unsafeAnthony Liguori2011-04-271-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>
* qemu-img rebase: Fix segfault if backing file can't be openedKevin Wolf2011-04-071-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>
* qemu-img: Initial progress printing supportJes Sorensen2011-04-071-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>
* qemu-img: Improve error messages for failed bdrv_openKevin Wolf2011-02-101-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>
* Make strtosz() return int64_t instead of ssize_tJes Sorensen2011-01-241-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>
* qemu-img snapshot: Use writeback cachingKevin Wolf2011-01-241-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>
* Remove NULL checks for bdrv_new return valueKevin Wolf2010-12-171-4/+1
| | | | | | It's an indirect call to qemu_malloc, which never returns an error. Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu.img.c: Use error_report() instead of own error() implementationJes Sorensen2010-12-171-65/+62
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* qemu-img.c: Re-factor img_create()Jes Sorensen2010-12-171-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>
* qemu-img: Call error_set_prognameKevin Wolf2010-12-171-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>
* qemu-img.c: Clean up handling of image size in img_create()Jes Sorensen2010-12-171-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>
* qemu-img: Fail creation if backing format is invalidStefan Hajnoczi2010-12-141-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>
* qemu-img: Free option parameter lists in img_create()Stefan Hajnoczi2010-12-141-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>
* qemu-img: Deprecate obsolete -6 and -e optionsJes Sorensen2010-12-141-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>
* Make error handling more consistent in img_create() and img_resize()Jes Sorensen2010-12-141-6/+12
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Fail if detecting an unknown optionJes Sorensen2010-12-141-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>
* Fix formatting and missing braces in qemu-img.cJes Sorensen2010-12-141-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>
* Consolidate printing of block driver optionsJes Sorensen2010-12-141-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>
* img_convert(): Only try to free bs[] entries if bs is valid.Jes Sorensen2010-12-141-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>
* Use qemu_mallocz() instead of calloc() in img_convert()Jes Sorensen2010-12-141-6/+2
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
* Move qemu_gettimeofday() to OS specific filesJes Sorensen2010-10-301-0/+1
| | | | | Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* qemu-img: Fix qemu-img convert -obacking_fileKevin Wolf2010-10-221-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>
* Copy snapshots out of QCOW2 diskedison2010-10-221-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>
* Use GCC_FMT_ATTR (format checking)Stefan Weil2010-10-031-1/+1
| | | | | Signed-off-by: Stefan Weil <weil@mail.berlios.de> Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* qemu-img convert: Use cache=unsafe for output imageKevin Wolf2010-09-081-1/+2
| | | | | | | 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>
* qemu-img rebase: Open new backing file read-onlyKevin Wolf2010-08-301-1/+1
| | | | | | | 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>
* qemu-img check: Distinguish different kinds of errorsKevin Wolf2010-07-061-15/+48
| | | | | | | | 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>
* qemu-img: avoid calling exit(1) to release resources properlyMORITA Kazutaka2010-07-021-52/+185
| | | | | | | | | | | | 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>
* add support for protocol driver create_optionsMORITA Kazutaka2010-05-281-15/+34
| | | | | | | | | 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>
* Fix %lld or %llx printf format useBlue Swirl2010-05-221-5/+5
| | | | Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
* qemu-img rebase: Fix output image corruptionKevin Wolf2010-05-031-3/+3
| | | | | | | | | 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>
* qemu-img: Add 'resize' command to grow/shrink disk imagesStefan Hajnoczi2010-05-031-0/+92
| | | | | | | | | 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>
* block: bdrv_has_zero_initKevin Wolf2010-05-031-2/+4
| | | | | | | | | 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>
* qemu-img: Fix BRDV_O_FLAGS typoStefan Hajnoczi2010-04-231-10/+10
| | | | | | | 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>
* qemu-img: Eliminate bdrv_new_open() code duplicationStefan Hajnoczi2010-04-231-73/+10
| | | | | | | | | | | | 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>
* Replace calls of old bdrv_openKevin Wolf2010-04-231-8/+8
| | | | | | | | | 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>
* block: print errno on errorJuan Quintela2010-03-091-2/+2
| | | | | | | 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>
* qemu-img rebase: Add -f optionKevin Wolf2010-03-091-4/+16
| | | | | | | 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>
* qemu-img: Fix error messageKevin Wolf2010-02-191-1/+1
| | | | | | | | | 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>
* qemu-img: Fix segfault during rebaseKevin Wolf2010-02-191-1/+1
| | | | | | | | 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>
* qemu-img: use the heap instead of the huge stack array for win32TeLeMan2010-02-101-3/+11
| | | | | | | | | | | 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>
* qemu-img: Fix qemu-img can't create qcow image based on read-only imageSheng Yang2010-02-101-5/+10
| | | | | | | | | | 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>
OpenPOWER on IntegriCloud