All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open()
@ 2015-02-02 17:08 Max Reitz
  2015-02-02 17:08 ` [Qemu-devel] [PATCH 1/2] " Max Reitz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Max Reitz @ 2015-02-02 17:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz

BDRV_O_PROTOCOL is an internal qemu flag which a user should be able to
override by explicitly specifying a block driver. This series implements
this and adds two iotests (one for NBD, one for file) to test it.

For the NBD test to succeed, this series relies on
"iotests: Specify format for qemu-nbd".

Also, the second patch's "group" file modifying hunk relies on
"qemu-iotests: add 116 invalid QED input file tests".


Max Reitz (2):
  block: driver should override flags in bdrv_open()
  iotests: Add tests for overriding BDRV_O_PROTOCOL

 block.c                    | 49 +++++++++++++++++++++-------------
 tests/qemu-iotests/051     |  1 -
 tests/qemu-iotests/051.out |  3 ---
 tests/qemu-iotests/119     | 60 ++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/119.out | 11 ++++++++
 tests/qemu-iotests/120     | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/120.out | 15 +++++++++++
 tests/qemu-iotests/group   |  2 ++
 8 files changed, 184 insertions(+), 22 deletions(-)
 create mode 100755 tests/qemu-iotests/119
 create mode 100644 tests/qemu-iotests/119.out
 create mode 100755 tests/qemu-iotests/120
 create mode 100644 tests/qemu-iotests/120.out

-- 
2.1.0

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 1/2] block: driver should override flags in bdrv_open()
  2015-02-02 17:08 [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open() Max Reitz
@ 2015-02-02 17:08 ` Max Reitz
  2015-02-02 17:08 ` [Qemu-devel] [PATCH 2/2] iotests: Add tests for overriding BDRV_O_PROTOCOL Max Reitz
  2015-02-27 22:28 ` [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open() Max Reitz
  2 siblings, 0 replies; 4+ messages in thread
From: Max Reitz @ 2015-02-02 17:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz

The BDRV_O_PROTOCOL flag should have an impact only if no driver is
specified explicitly. Therefore, if bdrv_open() is called with an
explicit block driver argument (either through the options QDict or
through the drv parameter) and that block driver is a protocol block
driver, BDRV_O_PROTOCOL should be set; if it is a format block driver,
BDRV_O_PROTOCOL should be unset.

While there was code to unset the flag in case a format block driver
has been selected, it only followed the bdrv_fill_options() function
call whereas the flag in fact needs to be adjusted before it is used
there.

With that change, BDRV_O_PROTOCOL will always be set if the BDS should
be a protocol driver; if the driver has been specified explicitly, the
new code will set it; and bdrv_fill_options() will only "probe" a
protocol driver if BDRV_O_PROTOCOL is set. The probing after
bdrv_fill_options() cannot select a protocol driver.

Thus, bdrv_open_image() to open BDS.file is never called if a protocol
BDS is about to be created. With that change in turn it is impossible to
call bdrv_open_common() with a protocol drv and file != NULL, which
allows us to remove the bdrv_swap() call.

This change breaks a test case in qemu-iotest 051:
"-drive file=t.qcow2,file.driver=qcow2" now works because the explicitly
specified "qcow2" overrides the BDRV_O_PROTOCOL which is automatically
set for the "file" BDS (and the filename is just passed down).
Therefore, this patch removes that test case.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 block.c                    | 49 +++++++++++++++++++++++++++++-----------------
 tests/qemu-iotests/051     |  1 -
 tests/qemu-iotests/051.out |  3 ---
 3 files changed, 31 insertions(+), 22 deletions(-)

diff --git a/block.c b/block.c
index d45e4dd..f2d07bf 100644
--- a/block.c
+++ b/block.c
@@ -956,14 +956,6 @@ static int bdrv_open_common(BlockDriverState *bs, BlockDriverState *file,
     }
     qdict_del(options, "node-name");
 
-    /* bdrv_open() with directly using a protocol as drv. This layer is already
-     * opened, so assign it to bs (while file becomes a closed BlockDriverState)
-     * and return immediately. */
-    if (file != NULL && drv->bdrv_file_open) {
-        bdrv_swap(file, bs);
-        return 0;
-    }
-
     bs->open_flags = flags;
     bs->guest_block_size = 512;
     bs->request_alignment = 512;
@@ -1085,14 +1077,17 @@ static QDict *parse_json_filename(const char *filename, Error **errp)
 /*
  * Fills in default options for opening images and converts the legacy
  * filename/flags pair to option QDict entries.
+ * The BDRV_O_PROTOCOL flag in *flags will be set or cleared accordingly if a
+ * block driver has been specified explicitly.
  */
-static int bdrv_fill_options(QDict **options, const char **pfilename, int flags,
-                             BlockDriver *drv, Error **errp)
+static int bdrv_fill_options(QDict **options, const char **pfilename,
+                             int *flags, BlockDriver *drv, Error **errp)
 {
     const char *filename = *pfilename;
     const char *drvname;
-    bool protocol = flags & BDRV_O_PROTOCOL;
+    bool protocol = *flags & BDRV_O_PROTOCOL;
     bool parse_filename = false;
+    BlockDriver *tmp_drv;
     Error *local_err = NULL;
 
     /* Parse json: pseudo-protocol */
@@ -1110,6 +1105,24 @@ static int bdrv_fill_options(QDict **options, const char **pfilename, int flags,
         *pfilename = filename = NULL;
     }
 
+    drvname = qdict_get_try_str(*options, "driver");
+
+    /* If the user has explicitly specified the driver, this choice should
+     * override the BDRV_O_PROTOCOL flag */
+    tmp_drv = drv;
+    if (!tmp_drv && drvname) {
+        tmp_drv = bdrv_find_format(drvname);
+    }
+    if (tmp_drv) {
+        protocol = tmp_drv->bdrv_file_open;
+    }
+
+    if (protocol) {
+        *flags |= BDRV_O_PROTOCOL;
+    } else {
+        *flags &= ~BDRV_O_PROTOCOL;
+    }
+
     /* Fetch the file name from the options QDict if necessary */
     if (protocol && filename) {
         if (!qdict_haskey(*options, "filename")) {
@@ -1124,7 +1137,6 @@ static int bdrv_fill_options(QDict **options, const char **pfilename, int flags,
 
     /* Find the right block driver */
     filename = qdict_get_try_str(*options, "filename");
-    drvname = qdict_get_try_str(*options, "driver");
 
     if (drv) {
         if (drvname) {
@@ -1461,7 +1473,7 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         options = qdict_new();
     }
 
-    ret = bdrv_fill_options(&options, &filename, flags, drv, &local_err);
+    ret = bdrv_fill_options(&options, &filename, &flags, drv, &local_err);
     if (local_err) {
         goto fail;
     }
@@ -1480,11 +1492,6 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
     }
 
     assert(drvname || !(flags & BDRV_O_PROTOCOL));
-    if (drv && !drv->bdrv_file_open) {
-        /* If the user explicitly wants a format driver here, we'll need to add
-         * another layer for the protocol in bs->file */
-        flags &= ~BDRV_O_PROTOCOL;
-    }
 
     bs->options = options;
     options = qdict_clone_shallow(options);
@@ -1521,6 +1528,12 @@ int bdrv_open(BlockDriverState **pbs, const char *filename,
         goto fail;
     }
 
+    /* BDRV_O_PROTOCOL must be set iff a protocol BDS is about to be created */
+    assert(!!(flags & BDRV_O_PROTOCOL) == !!drv->bdrv_file_open);
+    /* file must be NULL if a protocol BDS is about to be created
+     * (the inverse results in an error message from bdrv_open_common()) */
+    assert(!(flags & BDRV_O_PROTOCOL) || !file);
+
     /* Open the image */
     ret = bdrv_open_common(bs, file, options, flags, drv, &local_err);
     if (ret < 0) {
diff --git a/tests/qemu-iotests/051 b/tests/qemu-iotests/051
index 11c858f..a2aa620 100755
--- a/tests/qemu-iotests/051
+++ b/tests/qemu-iotests/051
@@ -184,7 +184,6 @@ echo === Specifying the protocol layer ===
 echo
 
 run_qemu -drive file="$TEST_IMG",file.driver=file
-run_qemu -drive file="$TEST_IMG",file.driver=qcow2
 
 echo
 echo === Leaving out required options ===
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
index f497c57..ff9a252 100644
--- a/tests/qemu-iotests/051.out
+++ b/tests/qemu-iotests/051.out
@@ -247,9 +247,6 @@ Testing: -drive file=TEST_DIR/t.qcow2,file.driver=file
 QEMU X.Y.Z monitor - type 'help' for more information
 (qemu) q^[[K^[[Dqu^[[K^[[D^[[Dqui^[[K^[[D^[[D^[[Dquit^[[K
 
-Testing: -drive file=TEST_DIR/t.qcow2,file.driver=qcow2
-QEMU_PROG: -drive file=TEST_DIR/t.qcow2,file.driver=qcow2: could not open disk image TEST_DIR/t.qcow2: Block format 'qcow2' used by device '' doesn't support the option 'filename'
-
 
 === Leaving out required options ===
 
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH 2/2] iotests: Add tests for overriding BDRV_O_PROTOCOL
  2015-02-02 17:08 [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open() Max Reitz
  2015-02-02 17:08 ` [Qemu-devel] [PATCH 1/2] " Max Reitz
@ 2015-02-02 17:08 ` Max Reitz
  2015-02-27 22:28 ` [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open() Max Reitz
  2 siblings, 0 replies; 4+ messages in thread
From: Max Reitz @ 2015-02-02 17:08 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz

This adds tests for overriding the qemu-internal BDRV_O_PROTOCOL flag by
explicitly specifying a block driver. As one test must be run over the
NBD protocol while the other must not, this patch adds two separate
iotests.

Signed-off-by: Max Reitz <mreitz@redhat.com>
---
 tests/qemu-iotests/119     | 60 ++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/119.out | 11 ++++++++
 tests/qemu-iotests/120     | 65 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/120.out | 15 +++++++++++
 tests/qemu-iotests/group   |  2 ++
 5 files changed, 153 insertions(+)
 create mode 100755 tests/qemu-iotests/119
 create mode 100644 tests/qemu-iotests/119.out
 create mode 100755 tests/qemu-iotests/120
 create mode 100644 tests/qemu-iotests/120.out

diff --git a/tests/qemu-iotests/119 b/tests/qemu-iotests/119
new file mode 100755
index 0000000..9a11f1b
--- /dev/null
+++ b/tests/qemu-iotests/119
@@ -0,0 +1,60 @@
+#!/bin/bash
+#
+# NBD test case for overriding BDRV_O_PROTOCOL by explicitly specifying
+# a driver
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# creator
+owner=mreitz@redhat.com
+
+seq="$(basename $0)"
+echo "QA output created by $seq"
+
+here="$PWD"
+tmp=/tmp/$$
+status=1	# failure is the default!
+
+_cleanup()
+{
+	_cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_supported_fmt raw
+_supported_proto nbd
+_supported_os Linux
+
+_make_test_img 64M
+# This should not crash
+echo "{'execute': 'qmp_capabilities'}
+      {'execute': 'human-monitor-command',
+       'arguments': {'command-line': 'qemu-io drv \"read -P 0 0 64k\"'}}
+      {'execute': 'quit'}" \
+    | $QEMU -drive id=drv,if=none,file="$TEST_IMG",driver=nbd \
+            -qmp stdio -nodefaults \
+    | _filter_qmp | _filter_qemu_io
+
+# success, all done
+echo
+echo '*** done'
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/119.out b/tests/qemu-iotests/119.out
new file mode 100644
index 0000000..58e7114
--- /dev/null
+++ b/tests/qemu-iotests/119.out
@@ -0,0 +1,11 @@
+QA output created by 119
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+QMP_VERSION
+{"return": {}}
+read 65536/65536 bytes at offset 0
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+{"return": ""}
+{"return": {}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN"}
+
+*** done
diff --git a/tests/qemu-iotests/120 b/tests/qemu-iotests/120
new file mode 100755
index 0000000..9f13078
--- /dev/null
+++ b/tests/qemu-iotests/120
@@ -0,0 +1,65 @@
+#!/bin/bash
+#
+# Non-NBD test cases for overriding BDRV_O_PROTOCOL by explicitly
+# specifying a driver
+#
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+
+# creator
+owner=mreitz@redhat.com
+
+seq="$(basename $0)"
+echo "QA output created by $seq"
+
+here="$PWD"
+tmp=/tmp/$$
+status=1	# failure is the default!
+
+_cleanup()
+{
+	_cleanup_test_img
+}
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+. ./common.rc
+. ./common.filter
+
+_supported_fmt generic
+_supported_proto file
+_supported_os Linux
+
+_make_test_img 64M
+
+echo "{'execute': 'qmp_capabilities'}
+      {'execute': 'human-monitor-command',
+       'arguments': {'command-line': 'qemu-io drv \"write -P 42 0 64k\"'}}
+      {'execute': 'quit'}" \
+    | $QEMU -qmp stdio -nodefaults \
+            -drive id=drv,if=none,file="$TEST_IMG",driver=raw,file.driver=$IMGFMT \
+    | _filter_qmp | _filter_qemu_io
+$QEMU_IO -c 'read -P 42 0 64k' "$TEST_IMG" | _filter_qemu_io
+
+$QEMU_IO_PROG -c 'read -P 42 0 64k' \
+    "json:{'driver': 'raw', 'file': {'driver': '$IMGFMT', 'file': {'filename': '$TEST_IMG'}}}" \
+    | _filter_qemu_io
+
+# success, all done
+echo
+echo '*** done'
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/120.out b/tests/qemu-iotests/120.out
new file mode 100644
index 0000000..9131b1b
--- /dev/null
+++ b/tests/qemu-iotests/120.out
@@ -0,0 +1,15 @@
+QA output created by 120
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
+QMP_VERSION
+{"return": {}}
+wrote 65536/65536 bytes at offset 0
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+{"return": ""}
+{"return": {}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN"}
+read 65536/65536 bytes at offset 0
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+read 65536/65536 bytes at offset 0
+64 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+*** done
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 4b2b93b..acc8016 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -117,3 +117,5 @@
 113 rw auto quick
 114 rw auto quick
 116 rw auto quick
+119 rw auto quick
+120 rw auto quick
-- 
2.1.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open()
  2015-02-02 17:08 [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open() Max Reitz
  2015-02-02 17:08 ` [Qemu-devel] [PATCH 1/2] " Max Reitz
  2015-02-02 17:08 ` [Qemu-devel] [PATCH 2/2] iotests: Add tests for overriding BDRV_O_PROTOCOL Max Reitz
@ 2015-02-27 22:28 ` Max Reitz
  2 siblings, 0 replies; 4+ messages in thread
From: Max Reitz @ 2015-02-27 22:28 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi

Ping

On 2015-02-02 at 12:08, Max Reitz wrote:
> BDRV_O_PROTOCOL is an internal qemu flag which a user should be able to
> override by explicitly specifying a block driver. This series implements
> this and adds two iotests (one for NBD, one for file) to test it.
>
> For the NBD test to succeed, this series relies on
> "iotests: Specify format for qemu-nbd".
>
> Also, the second patch's "group" file modifying hunk relies on
> "qemu-iotests: add 116 invalid QED input file tests".
>
>
> Max Reitz (2):
>    block: driver should override flags in bdrv_open()
>    iotests: Add tests for overriding BDRV_O_PROTOCOL
>
>   block.c                    | 49 +++++++++++++++++++++-------------
>   tests/qemu-iotests/051     |  1 -
>   tests/qemu-iotests/051.out |  3 ---
>   tests/qemu-iotests/119     | 60 ++++++++++++++++++++++++++++++++++++++++++
>   tests/qemu-iotests/119.out | 11 ++++++++
>   tests/qemu-iotests/120     | 65 ++++++++++++++++++++++++++++++++++++++++++++++
>   tests/qemu-iotests/120.out | 15 +++++++++++
>   tests/qemu-iotests/group   |  2 ++
>   8 files changed, 184 insertions(+), 22 deletions(-)
>   create mode 100755 tests/qemu-iotests/119
>   create mode 100644 tests/qemu-iotests/119.out
>   create mode 100755 tests/qemu-iotests/120
>   create mode 100644 tests/qemu-iotests/120.out

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-02-27 22:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-02 17:08 [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open() Max Reitz
2015-02-02 17:08 ` [Qemu-devel] [PATCH 1/2] " Max Reitz
2015-02-02 17:08 ` [Qemu-devel] [PATCH 2/2] iotests: Add tests for overriding BDRV_O_PROTOCOL Max Reitz
2015-02-27 22:28 ` [Qemu-devel] [PATCH 0/2] block: driver should override flags in bdrv_open() Max Reitz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.