Skip to contentSkip to conversation

block: fix backing file overriding

PATCH Applied Fam Zheng 2 participants 4 messages Sep 22, 2013 – Sep 23, 2013

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

cover block: fix backing file overriding

The backing.file.filename option is not working as expected: if there's also a backing file name from the format driver, adding this option fails bdrv_open; if there's no backing file name info in the image, "info block" doesn't show the overrided file name.

A test case is updated to catch these issues.

Fam Zheng (2):
block: fix backing file overriding
qemu-iotests: add test for backing file overriding

 block.c                    |  7 +++++--
 tests/qemu-iotests/051     | 17 ++++++++++++++++-
 tests/qemu-iotests/051.out | 11 +++++++++++
 3 files changed, 32 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.3.1
author
#1 lore raw

PATCH 1/2 block: fix backing file overriding

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

    $ x86_64-softmmu/qemu-system-x86_64 -drive \
        file=/tmp/child.qcow2,backing.file.filename=/tmp/fake.qcow2

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

With

    $ 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".

---
 block.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
block.c +5 -2
index e176c6f..a2ea39a 100644
@@ -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) {
         QDECREF(options);
         return 0;
+    } else {
+        bdrv_get_full_backing_filename(bs, backing_filename,
+                                       sizeof(backing_filename));
     }
 
     bs->backing_hd = bdrv_new("");
-    bdrv_get_full_backing_filename(bs, backing_filename,
-                                   sizeof(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),
+            bs->backing_hd->file->filename);
     if (ret < 0) {
         bdrv_unref(bs->backing_hd);
         bs->backing_hd = NULL;
Signature · 1 line
1.8.3.1
author
#2 lore raw

PATCH 2/2 qemu-iotests: add test for backing file overriding

In reply to Fam Zheng

Test that backing.file.filename option can be parsed and override the backing file from image (backing file reflected with "info block").

---
 tests/qemu-iotests/051     | 17 ++++++++++++++++-
 tests/qemu-iotests/051.out | 11 +++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)
tests/qemu-iotests/051 +16 -1
index 1f39c6a..78e1182 100755
@@ -45,7 +45,14 @@ _supported_os Linux
 function do_run_qemu()
 {
     echo Testing: "$@"
-    echo quit | $QEMU -nographic -monitor stdio -serial none "$@"
+    (
+        if ! test -t 0; then
+            while read cmd; do
+                echo $cmd
+            done
+        fi
+        echo quit
+    ) | $QEMU -nographic -monitor stdio -serial none "$@"
     echo
 }
 
@@ -57,6 +64,9 @@ function run_qemu()
 size=128M
 
 _make_test_img $size
+cp $TEST_IMG $TEST_IMG.orig
+mv $TEST_IMG $TEST_IMG.base
+_make_test_img -b $TEST_IMG.base $size
 
 echo
 echo === Unknown option ===
@@ -67,6 +77,11 @@ run_qemu -drive file=$TEST_IMG,format=qcow2,unknown_opt=on
 run_qemu -drive file=$TEST_IMG,format=qcow2,unknown_opt=1234
 run_qemu -drive file=$TEST_IMG,format=qcow2,unknown_opt=foo
 
+echo
+echo === Overriding backing file ===
+echo
+
+echo "info block" | run_qemu -drive file=$TEST_IMG,driver=qcow2,backing.file.filename=$TEST_IMG.orig -nodefaults
 
 echo
 echo === Enable and disable lazy refcounting on the command line, plus some invalid values ===
tests/qemu-iotests/051.out +11 -0
index 88e8fa7..335fbe3 100644
@@ -1,5 +1,6 @@
 QA output created by 051
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 backing_file='TEST_DIR/t.IMGFMT.base' 
 
 === Unknown option ===
 
@@ -16,6 +17,16 @@ Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=foo
 QEMU_PROG: -drive file=TEST_DIR/t.qcow2,format=qcow2,unknown_opt=foo: could not open disk image TEST_DIR/t.qcow2: Block format 'qcow2' used by device 'ide0-hd0' doesn't support the option 'unknown_opt'
 
 
+=== Overriding backing file ===
+
+Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,backing.file.filename=TEST_DIR/t.qcow2.orig -nodefaults
+QEMU X.Y.Z monitor - type 'help' for more information
+(qemu) iininfinfoinfo info binfo blinfo bloinfo blocinfo block
+ide0-hd0: TEST_DIR/t.qcow2 (qcow2)
+    Backing file:     TEST_DIR/t.qcow2.orig (chain depth: 1)
+ [not inserted](qemu) qququiquit
+
+
 === Enable and disable lazy refcounting on the command line, plus some invalid values ===
 
 Testing: -drive file=TEST_DIR/t.qcow2,format=qcow2,lazy-refcounts=on
Signature · 1 line
1.8.3.1
Applied
#3 lore raw
In reply to Fam Zheng

Am 22.09.2013 um 14:05 hat Fam Zheng geschrieben:

Quoted 6 lines

The backing.file.filename option is not working as expected: if there's also a backing file name from the format driver, adding this option fails bdrv_open; if there's no backing file name info in the image, "info block" doesn't show the overrided file name.

A test case is updated to catch these issues.

Thanks, applied to the block branch.

Kevin