[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 27/93] block: Allow block devices without files
From: |
Kevin Wolf |
Subject: |
[Qemu-devel] [PULL 27/93] block: Allow block devices without files |
Date: |
Fri, 24 Jan 2014 18:21:10 +0100 |
From: Max Reitz <address@hidden>
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>
Signed-off-by: Kevin Wolf <address@hidden>
---
block.c | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
diff --git a/block.c b/block.c
index bef4f82..7464fb2 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 */
@@ -1165,7 +1168,13 @@ int bdrv_open(BlockDriverState *bs, const char
*filename, QDict *options,
}
if (!drv) {
- ret = find_image_format(file, filename, &drv, &local_err);
+ if (file) {
+ ret = find_image_format(file, filename, &drv, &local_err);
+ } else {
+ error_setg(errp, "Must specify either driver or file");
+ ret = -EINVAL;
+ goto unlink_and_fail;
+ }
}
if (!drv) {
@@ -1178,7 +1187,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename,
QDict *options,
goto unlink_and_fail;
}
- if (bs->file != file) {
+ if (file && (bs->file != file)) {
bdrv_unref(file);
file = NULL;
}
--
1.8.1.4
- [Qemu-devel] [PULL 17/93] qemu-io: add command completion, (continued)
- [Qemu-devel] [PULL 17/93] qemu-io: add command completion, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 18/93] blkdebug: Use errp for read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 19/93] blkdebug: Don't require sophisticated filename, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 20/93] qdict: Add qdict_array_split(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 21/93] qapi: extend qdict_flatten() for QLists, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 22/93] qemu-option: Add qemu_config_parse_qdict(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 23/93] blkdebug: Always call read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 24/93] blkdebug: Use command-line in read_config(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 25/93] block: Allow reference for bdrv_file_open(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 26/93] block: Pass reference to bdrv_file_open(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 27/93] block: Allow block devices without files,
Kevin Wolf <=
- [Qemu-devel] [PULL 29/93] block: Use bdrv_open_image() in bdrv_open(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 30/93] block: Allow recursive "file"s, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 28/93] block: Add bdrv_open_image(), Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 32/93] blkdebug: Allow command-line file configuration, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 31/93] blockdev: Move "file" to legacy_opts, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 34/93] blkverify: Don't require protocol filename, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 35/93] qapi: Add "errno" to the list of polluted words, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 33/93] blkverify: Allow command-line configuration, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 36/93] qapi: QMP interface for blkdebug and blkverify, Kevin Wolf, 2014/01/24
- [Qemu-devel] [PULL 37/93] qemu-io: Make filename optional, Kevin Wolf, 2014/01/24