Skip to content

Commit

Permalink
block: Fail if requested driver is not available
Browse files Browse the repository at this point in the history
If an explicit driver option is present, but doesn't specify a valid
driver, then bdrv_open() should fail instead of probing the format.

Signed-off-by: Kevin Wolf <[email protected]>
Reviewed-by: Jeff Cody <[email protected]>
Reviewed-by: Stefan Hajnoczi <[email protected]>
  • Loading branch information
kevmw committed Nov 15, 2013
1 parent f05b328 commit 06d22aa
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions block.c
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,11 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
if (drvname) {
drv = bdrv_find_format(drvname);
qdict_del(options, "driver");
if (!drv) {
error_setg(errp, "Invalid driver: '%s'", drvname);
ret = -EINVAL;
goto unlink_and_fail;
}
}

if (!drv) {
Expand Down
7 changes: 7 additions & 0 deletions tests/qemu-iotests/051
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ 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 === Invalid format ===
echo

run_qemu -drive file="$TEST_IMG",format=foo
run_qemu -drive file="$TEST_IMG",driver=foo

echo
echo === Overriding backing file ===
echo
Expand Down
9 changes: 9 additions & 0 deletions tests/qemu-iotests/051.out
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ 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'


=== Invalid format ===

Testing: -drive file=TEST_DIR/t.qcow2,format=foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,format=foo: 'foo' invalid format

Testing: -drive file=TEST_DIR/t.qcow2,driver=foo
QEMU_PROG: -drive file=TEST_DIR/t.qcow2,driver=foo: could not open disk image TEST_DIR/t.qcow2: Invalid driver: 'foo'


=== Overriding backing file ===

Testing: -drive file=TEST_DIR/t.qcow2,driver=qcow2,backing.file.filename=TEST_DIR/t.qcow2.orig -nodefaults
Expand Down

0 comments on commit 06d22aa

Please sign in to comment.