[Qemu-kvm] qemu-img fail to create qcow image

Bug #706766 reported by xudong
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
QEMU
Fix Released
Undecided
Unassigned

Bug Description

On qemu-kvm tree 6f32e3d09d990fd50008756fcb446b55e0c0af79, complier it. Then try to create a qcow image with a exist raw image, create fail.

reproduce steps:
1) build qemu-kvm
2) ./qemu-img create -b ./ia32e_fc10.img -f qcow2 ./qcow.img
3) Fail to create qcow image, it show error "qemu-img: Could not open './qcow.img' "

Revision history for this message
xudong (xudong-hao) wrote :

The latest qemu tree e10990c3f0c39e92ab5f74004b89a24fcc36fa14 also has this issue.

Changed in qemu:
status: New → Confirmed
Revision history for this message
Stefan Hajnoczi (stefanha) wrote : [PATCH] block: Use backing format driver during image creation

The backing format should be honored during image creation. For some
reason we currently use the image format to open the backing file. This
fails when the backing file has a different format than the image being
created. Keep the image and backing format drivers completely separate.

Also print the backing filename if there is an error opening the backing
file instead of the image filename.

Signed-off-by: Stefan Hajnoczi <email address hidden>
---
 block.c | 8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/block.c b/block.c
index ff2795b..7ad3ddf 100644
--- a/block.c
+++ b/block.c
@@ -2778,6 +2778,7 @@ int bdrv_img_create(const char *filename, const char *fmt,
     QEMUOptionParameter *backing_fmt, *backing_file;
     BlockDriverState *bs = NULL;
     BlockDriver *drv, *proto_drv;
+ BlockDriver *backing_drv = NULL;
     int ret = 0;

     /* Find driver and parse its options */
@@ -2846,7 +2847,8 @@ int bdrv_img_create(const char *filename, const char *fmt,

     backing_fmt = get_option_parameter(param, BLOCK_OPT_BACKING_FMT);
     if (backing_fmt && backing_fmt->value.s) {
- if (!bdrv_find_format(backing_fmt->value.s)) {
+ backing_drv = bdrv_find_format(backing_fmt->value.s);
+ if (!backing_drv) {
             error_report("Unknown backing file format '%s'",
                          backing_fmt->value.s);
             ret = -EINVAL;
@@ -2863,9 +2865,9 @@ int bdrv_img_create(const char *filename, const char *fmt,

             bs = bdrv_new("");

- ret = bdrv_open(bs, backing_file->value.s, flags, drv);
+ ret = bdrv_open(bs, backing_file->value.s, flags, backing_drv);
             if (ret < 0) {
- error_report("Could not open '%s'", filename);
+ error_report("Could not open '%s'", backing_file->value.s);
                 goto out;
             }
             bdrv_get_geometry(bs, &size);
--
1.7.2.3

Revision history for this message
Jes Sorensen (jes-sorensen) wrote :

On 01/24/11 10:32, Stefan Hajnoczi wrote:
> The backing format should be honored during image creation. For some
> reason we currently use the image format to open the backing file. This
> fails when the backing file has a different format than the image being
> created. Keep the image and backing format drivers completely separate.
>
> Also print the backing filename if there is an error opening the backing
> file instead of the image filename.
>
> Signed-off-by: Stefan Hajnoczi <email address hidden>
> ---
> block.c | 8 +++++---
> 1 files changed, 5 insertions(+), 3 deletions(-)
>

Looks good!

Acked-by: Jes Sorensen <email address hidden>

Revision history for this message
xudong (xudong-hao) wrote :

Patch worked with testing.

Revision history for this message
xudong (xudong-hao) wrote :

Fixed patch in qemu-kvm: 96df67d1c3928704cd76d0b2e76372ef18658e85, close this bug.

Changed in qemu:
status: Confirmed → Fix Committed
Aurelien Jarno (aurel32)
Changed in qemu:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.