x-blockdev-reopen requires that the 'backing' parameter is specified
when an image has a backing file attached or when there is a default
backing file in the image metadata.

The latter can be checked by reading bs->auto_backing_file, but
bdrv_reopen_prepare() is using bs->backing_file.

This bug should be detected by iotest 245, but unfortunately the test
expectation is wrong so it must be corrected as well.

Signed-off-by: Alberto Garcia <be...@igalia.com>
Reported-by: Max Reitz <mre...@redhat.com>
---
 block.c                | 3 ++-
 tests/qemu-iotests/245 | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/block.c b/block.c
index 16615bc876..e496999e2f 100644
--- a/block.c
+++ b/block.c
@@ -3634,7 +3634,8 @@ int bdrv_reopen_prepare(BDRVReopenState *reopen_state, 
BlockReopenQueue *queue,
      * its metadata. Otherwise the 'backing' option can be omitted.
      */
     if (drv->supports_backing && reopen_state->backing_missing &&
-        (backing_bs(reopen_state->bs) || reopen_state->bs->backing_file[0])) {
+        (backing_bs(reopen_state->bs) ||
+         reopen_state->bs->auto_backing_file[0])) {
         error_setg(errp, "backing is missing for '%s'",
                    reopen_state->bs->node_name);
         ret = -EINVAL;
diff --git a/tests/qemu-iotests/245 b/tests/qemu-iotests/245
index 7891a210c1..9784ca3ced 100644
--- a/tests/qemu-iotests/245
+++ b/tests/qemu-iotests/245
@@ -716,7 +716,7 @@ class TestBlockdevReopen(iotests.QMPTestCase):
 
         # Detach hd2 from hd0.
         self.reopen(opts, {'backing': None})
-        self.reopen(opts, {}, "backing is missing for 'hd0'")
+        self.reopen(opts)
 
         # Remove both hd0 and hd2
         result = self.vm.qmp('blockdev-del', conv_keys = True, node_name = 
'hd0')
-- 
2.11.0


Reply via email to