blkdebug and blkverify will, in order to retain compatibility, not
support the field "file" implicitly through bdrv_open(). In order to be
able to use those drivers without giving a filename anyway, it is
necessary to be able to have block devices without files implicitly
opened by bdrv_open(). This is the case, if there was neither a file
name, a reference to an existing block device to use as a file nor
options specific to the file.
Signed-off-by: Max Reitz <address@hidden>
---
block.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/block.c b/block.c
index bef4f82..9659eb5 100644
--- a/block.c
+++ b/block.c
@@ -1145,11 +1145,14 @@ int bdrv_open(BlockDriverState *bs, const char
*filename, QDict *options,
qdict_extract_subqdict(options, &file_options, "file.");
file_reference = qdict_get_try_str(options, "file");
- ret = bdrv_file_open(&file, filename, file_reference, file_options,
- bdrv_open_flags(bs, flags | BDRV_O_UNMAP),
&local_err);
- qdict_del(options, "file");
- if (ret < 0) {
- goto fail;
+ if (filename || file_reference || qdict_size(file_options)) {
+ ret = bdrv_file_open(&file, filename, file_reference, file_options,
+ bdrv_open_flags(bs, flags | BDRV_O_UNMAP),
+ &local_err);
+ qdict_del(options, "file");
+ if (ret < 0) {
+ goto fail;
+ }
}
/* Find the right image format driver */
@@ -1178,7 +1181,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
QDict *options,