diff mbox

block: don't add 'driver' to options when refering to backing via node name

Message ID bdbb9d79839f3149db9cf2ff11a2cc04977e0a64.1507817548.git.pkrempa@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Krempa Oct. 12, 2017, 2:14 p.m. UTC
When refering to a backing file of an image via node name
bdrv_open_backing_file would add the 'driver' option to the option list
filling it with the backing format driver. This breaks construction of
the backing chain via -blockdev, as bdrv_open_inherit reports an error
if both 'reference' and 'options' are provided.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 block.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Kevin Wolf Oct. 17, 2017, 2:41 p.m. UTC | #1
Am 12.10.2017 um 16:14 hat Peter Krempa geschrieben:
> When refering to a backing file of an image via node name
> bdrv_open_backing_file would add the 'driver' option to the option list
> filling it with the backing format driver. This breaks construction of
> the backing chain via -blockdev, as bdrv_open_inherit reports an error
> if both 'reference' and 'options' are provided.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>

If you don't mind, I'd add a specific example to the commit message:

$ qemu-img create -f raw /tmp/backing.raw 64M
$ qemu-img create -f qcow2 -F raw -b /tmp/backing.raw /tmp/test.qcow2
$ qemu-system-x86_64 \
  -blockdev driver=file,filename=/tmp/backing.raw,node-name=backing \
  -blockdev driver=qcow2,file.driver=file,file.filename=/tmp/test.qcow2,node-name=root,backing=backing
qemu-system-x86_64: -blockdev driver=qcow2,file.driver=file,file.filename=/tmp/test.qcow2,node-name=root,backing=backing: Could not open backing file: Cannot reference an existing block device with additional options or a new filename

> diff --git a/block.c b/block.c
> index 46eb1728da..684cb018da 100644
> --- a/block.c
> +++ b/block.c
> @@ -2245,7 +2245,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
>          goto free_exit;
>      }
> 
> -    if (bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
> +    if (!reference &&
> +        bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
>          qdict_put_str(options, "driver", bs->backing_format);
>      }

Looks good to me.

Kevin
Peter Krempa Oct. 17, 2017, 2:44 p.m. UTC | #2
On Tue, Oct 17, 2017 at 16:41:00 +0200, Kevin Wolf wrote:
> Am 12.10.2017 um 16:14 hat Peter Krempa geschrieben:
> > When refering to a backing file of an image via node name
> > bdrv_open_backing_file would add the 'driver' option to the option list
> > filling it with the backing format driver. This breaks construction of
> > the backing chain via -blockdev, as bdrv_open_inherit reports an error
> > if both 'reference' and 'options' are provided.
> > 
> > Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> 
> If you don't mind, I'd add a specific example to the commit message:

I certainly don't mind. I was frustrated after some attempts to find
bugs in my code using it before looking into qemu so I forgot to add
the info. (Also it would take me some time to figure out that I have the
backing format specified in the overlay image).

> 
> $ qemu-img create -f raw /tmp/backing.raw 64M
> $ qemu-img create -f qcow2 -F raw -b /tmp/backing.raw /tmp/test.qcow2
> $ qemu-system-x86_64 \
>   -blockdev driver=file,filename=/tmp/backing.raw,node-name=backing \
>   -blockdev driver=qcow2,file.driver=file,file.filename=/tmp/test.qcow2,node-name=root,backing=backing
> qemu-system-x86_64: -blockdev driver=qcow2,file.driver=file,file.filename=/tmp/test.qcow2,node-name=root,backing=backing: Could not open backing file: Cannot reference an existing block device with additional options or a new filename
> 
> > diff --git a/block.c b/block.c
> > index 46eb1728da..684cb018da 100644
> > --- a/block.c
> > +++ b/block.c
> > @@ -2245,7 +2245,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
> >          goto free_exit;
> >      }
> > 
> > -    if (bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
> > +    if (!reference &&
> > +        bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
> >          qdict_put_str(options, "driver", bs->backing_format);
> >      }
> 
> Looks good to me.

Thanks.
Eric Blake Oct. 17, 2017, 9:41 p.m. UTC | #3
On 10/12/2017 09:14 AM, Peter Krempa wrote:
> When refering to a backing file of an image via node name

s/refering/referring/ (here and in the subject)

> bdrv_open_backing_file would add the 'driver' option to the option list
> filling it with the backing format driver. This breaks construction of
> the backing chain via -blockdev, as bdrv_open_inherit reports an error
> if both 'reference' and 'options' are provided.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  block.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/block.c b/block.c
index 46eb1728da..684cb018da 100644
--- a/block.c
+++ b/block.c
@@ -2245,7 +2245,8 @@  int bdrv_open_backing_file(BlockDriverState *bs, QDict *parent_options,
         goto free_exit;
     }

-    if (bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
+    if (!reference &&
+        bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
         qdict_put_str(options, "driver", bs->backing_format);
     }