Commit Graph

103 Commits

Author SHA1 Message Date
Jes Sorensen 2a81998a1a Make error handling more consistent in img_create() and img_resize()
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14 15:44:21 +01:00
Jes Sorensen ef87394c08 Fail if detecting an unknown option
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-14 15:44:21 +01:00
Jes Sorensen b8fb60da2d Fix formatting and missing braces in qemu-img.c
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-14 15:44:21 +01:00
Jes Sorensen 4ac8aacd95 Consolidate printing of block driver options
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-14 15:44:21 +01:00
Jes Sorensen 31ca34b8cc img_convert(): Only try to free bs[] entries if bs is valid.
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-14 15:44:21 +01:00
Jes Sorensen 5bdf61fdd7 Use qemu_mallocz() instead of calloc() in img_convert()
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2010-12-14 15:44:21 +01:00
Jes Sorensen dc786bc910 Move qemu_gettimeofday() to OS specific files
Signed-off-by: Jes Sorensen <Jes.Sorensen@redhat.com>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-10-30 08:02:38 +00:00
Kevin Wolf a18953fbe7 qemu-img: Fix qemu-img convert -obacking_file
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-22 14:49:35 +02:00
edison 51ef67270b Copy snapshots out of QCOW2 disk
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-22 14:49:35 +02:00
Stefan Weil 8b7968f7c4 Use GCC_FMT_ATTR (format checking)
Signed-off-by: Stefan Weil <weil@mail.berlios.de>
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-10-03 06:34:51 +00:00
Kevin Wolf 1bd8e17558 qemu-img convert: Use cache=unsafe for output image
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-09-08 12:39:20 +02:00
Kevin Wolf cdbae85169 qemu-img rebase: Open new backing file read-only
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-08-30 18:29:22 +02:00
Kevin Wolf e076f3383b qemu-img check: Distinguish different kinds of errors
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-06 17:05:48 +02:00
MORITA Kazutaka c2abccecd9 qemu-img: avoid calling exit(1) to release resources properly
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-07-02 13:18:02 +02:00
MORITA Kazutaka b50cbabc1b add support for protocol driver create_options
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-28 13:14:25 +02:00
Blue Swirl 0bfcd599e3 Fix %lld or %llx printf format use
Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
2010-05-22 08:02:12 +00:00
Kevin Wolf cc60e327c0 qemu-img rebase: Fix output image corruption
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-03 10:07:32 +02:00
Stefan Hajnoczi ae6b0ed6d4 qemu-img: Add 'resize' command to grow/shrink disk images
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-03 10:07:32 +02:00
Kevin Wolf f2feebbd93 block: bdrv_has_zero_init
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-05-03 10:07:30 +02:00
Stefan Hajnoczi adfe078e4b qemu-img: Fix BRDV_O_FLAGS typo
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-23 16:21:57 +02:00
Stefan Hajnoczi f163d0736c qemu-img: Eliminate bdrv_new_open() code duplication
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-23 16:21:57 +02:00
Kevin Wolf d6e9098e10 Replace calls of old bdrv_open
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-04-23 16:08:46 +02:00
Juan Quintela 3e7896dec4 block: print errno on error
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-09 11:23:00 -06:00
Kevin Wolf e53dbee05d qemu-img rebase: Add -f option
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-03-09 09:04:17 -06:00
Kevin Wolf 584771e6b6 qemu-img: Fix error message
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-19 15:53:54 -06:00
Kevin Wolf 60b1bd4fc5 qemu-img: Fix segfault during rebase
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-19 15:53:54 -06:00
TeLeMan d6771bfa52 qemu-img: use the heap instead of the huge stack array for win32
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-10 14:00:53 -06:00
Sheng Yang 9bc378c143 qemu-img: Fix qemu-img can't create qcow image based on read-only image
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-10 11:56:56 -06:00
Paolo Bonzini e00291c008 qemu-img: avoid preprocessor directives in a printf call
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-08 12:12:40 +03:00
malc 3f020d7024 Revert "On some systems printf is a macro"
This reverts commit bc5b600458.
2010-02-08 12:12:40 +03:00
malc bc5b600458 On some systems printf is a macro
Signed-off-by: malc <av1474@comtv.ru>
2010-02-07 02:04:28 +03:00
Naphtali Sprei 058fc8c768 Ask for read-write permissions when opening files
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-26 15:42:01 -06:00
Naphtali Sprei f5edb014ed Clean-up a little bit the RW related bits of BDRV_O_FLAGS. BDRV_O_RDONLY 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-20 08:25:22 -06:00
Kevin Wolf 3e85c6fd71 qemu-img rebase
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-13 17:14:15 -06:00
Kevin Wolf b783e409bf block: Introduce BDRV_O_NO_BACKING
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>
2010-01-13 17:14:15 -06:00
Kevin Wolf 7078dead94 qemu-img: Fix memory leak
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-12-03 15:26:00 -06:00
Pierre Riteau 21eb3a2ba3 Fix description of size parameter in qemu-img's help text
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-03 15:25:58 -06:00
Kevin Wolf 12c09b8ce2 qemu-img: There is more than one host device driver
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-12-03 11:45:50 -06:00
Kevin Wolf 8063d0fe3b Documentation: Don't mention old qemu-img options
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-09 08:43:12 -06:00
Kevin Wolf 9f56640c85 qemu-img: Allow creating zero sized images
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-11-09 08:43:03 -06:00
Kevin Wolf 80ee15a6b2 qcow2: Increase maximum cluster size to 2 MB
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-05 09:32:52 -05:00
Anthony Liguori c227f0995e Revert "Get rid of _t suffix"
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 99a0949b72.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-10-01 16:12:16 -05:00
malc 99a0949b72 Get rid of _t suffix
Some not so obvious bits, slirp and Xen were left alone for the time
being.

Signed-off-by: malc <av1474@comtv.ru>
2009-10-01 22:45:02 +04:00
Akkarit Sangpetch d032044fb9 qmu-img: fix qemu-img convert to generate a valid image when the source referenced a backing file
Make 'qemu-img convert' copies unallocated parts of the source image
when -B option was not specified.

Signed-off-by: Akkarit Sangpetch <asangpet@andrew.cmu.edu>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-07-22 10:58:47 -05:00
Stuart Brady 153859be1a Use hxtool for qemu-img command list
Use hxtool to generate the 'command syntax' section of qemu-img's help
message, and the corresponding section of the texinfo documentation.

This has the side-effect of adding 'check' to this list of commands in
the texinfo documentation.

Signed-off-by: Stuart Brady <stuart.brady@gmail.com>
2009-06-07 09:59:47 +03:00
Kevin Wolf eff442662d Document changes in qemu-img interface
Update the documentation to reflect the introduction of format specific options
with -o. Don't advertise -e or -6 any more, they exist only for compatibility
reasons and can be replaced by the corresponding -o options.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2009-06-06 18:39:02 +03:00
Kevin Wolf db08adf526 qemu-img: Print available options with -o ?
This patch adds a small help text to each of the options in the block drivers
which can be displayed by using qemu-img create -f fmt -o ?

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
2009-06-06 18:38:57 +03:00
Kevin Wolf efa84d43cc Convert qemu-img convert to new bdrv_create
This is part two of the qemu-img conversion. This really works the same as the
previous conversion of qemu-img create: It introduces a new -o option for the
generic approach and adds the old-style options to this option set.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22 10:50:32 -05:00
Kevin Wolf 9ea2ea7146 Convert qemu-img create to new bdrv_create
This patch changes qemu-img to actually use the new bdrv_create interface. It
translates the old-style qemu-img options which have been bdrv_create2
parameters or flags so far to option structures. As the generic approach, it
introduces an -o option which accepts any parameter the driver knows.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22 10:50:31 -05:00
Kevin Wolf 0e7e1989f7 Convert all block drivers to new bdrv_create
Now we can make use of the newly introduced option structures. Instead of
having bdrv_create carry more and more parameters (which are format specific in
most cases), just pass a option structure as defined by the driver itself.

bdrv_create2() contains an emulation of the old interface to simplify the
transition.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2009-05-22 10:50:31 -05:00