]> xenbits.xensource.com Git - qemu-upstream-4.5-testing.git/commitdiff
block: Fail if requested driver is not available
authorKevin Wolf <kwolf@redhat.com>
Thu, 8 Aug 2013 15:44:52 +0000 (17:44 +0200)
committerKevin Wolf <kwolf@redhat.com>
Fri, 15 Nov 2013 12:37:48 +0000 (13:37 +0100)
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 <kwolf@redhat.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
block.c
tests/qemu-iotests/051
tests/qemu-iotests/051.out

diff --git a/block.c b/block.c
index 38078f7cd548dda2dc34b611cb0d13a124145811..382ea71f4b8c28550d4a798377fd1e6c4bae04ae 100644 (file)
--- a/block.c
+++ b/block.c
@@ -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) {
index 0a4971d4375f89f068f23e4e50f27170a4fa4c41..3a75bda5ebf0840ffea1ff3b631578858c5711a4 100755 (executable)
@@ -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
index d351935383096bac2c82827038a95e2f0c18de74..8769c8e66e71812f0dadf1bbe574dd05bef0226e 100644 (file)
@@ -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