Skip to content

Commit

Permalink
block: Allow block devices without files
Browse files Browse the repository at this point in the history
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 <mreitz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
  • Loading branch information
XanClic authored and kevmw committed Jan 22, 2014
1 parent 2258e3f commit 2a05cbe
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions block.c
Expand Up @@ -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 */
Expand All @@ -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) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 2a05cbe

Please sign in to comment.