Commit dbecebdd authored by Fam Zheng's avatar Fam Zheng Committed by Kevin Wolf

block: fix backing file overriding

Providing backing.file.filename doesn't override backing file as expected:

    $ x86_64-softmmu/qemu-system-x86_64 -drive \

    qemu-system-x86_64: -drive \
        file=/tmp/child.qcow2,backing.file.filename=/tmp/fake.qcow2: could not
        open disk image /tmp/child.qcow2: Can't specify 'file' and 'filename'
        options at the same time


    $ qemu-img info /tmp/child.qcow2
    image: /tmp/child.qcow2
    file format: qcow2
    virtual size: 1.0G (1073741824 bytes)
    disk size: 196K
    cluster_size: 65536
    backing file: /tmp/fake.qcow2

This fixes it by calling bdrv_get_full_backing_filename only if
backing.file.filename is not provided. Also save the backing file name
to bs->backing_file so the information is correct with HMP "info block".
Signed-off-by: default avatarFam Zheng <>
Signed-off-by: default avatarKevin Wolf <>
parent f828a4c8
......@@ -978,11 +978,12 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
} else if (bs->backing_file[0] == '\0' && qdict_size(options) == 0) {
return 0;
} else {
bdrv_get_full_backing_filename(bs, backing_filename,
bs->backing_hd = bdrv_new("");
bdrv_get_full_backing_filename(bs, backing_filename,
if (bs->backing_format[0] != '\0') {
back_drv = bdrv_find_format(bs->backing_format);
......@@ -994,6 +995,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
ret = bdrv_open(bs->backing_hd,
*backing_filename ? backing_filename : NULL, options,
back_flags, back_drv, &local_err);
pstrcpy(bs->backing_file, sizeof(bs->backing_file),
if (ret < 0) {
bs->backing_hd = NULL;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment