qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 11/20] block/qapi: Use blk_enable_write_cache()
Date: Fri, 18 Mar 2016 19:21:20 +0100	[thread overview]
Message-ID: <1458325289-17848-12-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1458325289-17848-1-git-send-email-kwolf@redhat.com>

Now that WCE is handled on the BlockBackend level, the flag is
meaningless for BDSes. As the schema requires us to fill the field,
we return an enabled write cache for them.

Note that this means that querying the BlockBackend name may return
writethrough as the cache information, whereas querying the node-name of
the root of that same BlockBackend will return writeback.

This may appear odd at first, but it actually makes sense because it
correctly repesents the layer that implements the WCE handling. This
becomes more apparent when you consider nodes that are the root node of
multiple BlockBackends, where each BB can have its own WCE setting.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block.c                    |  2 +-
 block/qapi.c               |  7 +++---
 include/block/qapi.h       |  3 ++-
 tests/qemu-iotests/142     |  7 +++++-
 tests/qemu-iotests/142.out | 57 ++++++++++++++++++++++++++++++++++++++--------
 5 files changed, 60 insertions(+), 16 deletions(-)

diff --git a/block.c b/block.c
index 9271dbb..4e95d01 100644
--- a/block.c
+++ b/block.c
@@ -2917,7 +2917,7 @@ BlockDeviceInfoList *bdrv_named_nodes_list(Error **errp)
 
     list = NULL;
     QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) {
-        BlockDeviceInfo *info = bdrv_block_device_info(bs, errp);
+        BlockDeviceInfo *info = bdrv_block_device_info(NULL, bs, errp);
         if (!info) {
             qapi_free_BlockDeviceInfoList(list);
             return NULL;
diff --git a/block/qapi.c b/block/qapi.c
index 6a4869a..f01894a 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -33,7 +33,8 @@
 #include "qapi/qmp/types.h"
 #include "sysemu/block-backend.h"
 
-BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp)
+BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
+                                        BlockDriverState *bs, Error **errp)
 {
     ImageInfo **p_image_info;
     BlockDriverState *bs0;
@@ -47,7 +48,7 @@ BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp)
 
     info->cache = g_new(BlockdevCacheInfo, 1);
     *info->cache = (BlockdevCacheInfo) {
-        .writeback      = bdrv_enable_write_cache(bs),
+        .writeback      = blk ? blk_enable_write_cache(blk) : true,
         .direct         = !!(bs->open_flags & BDRV_O_NOCACHE),
         .no_flush       = !!(bs->open_flags & BDRV_O_NO_FLUSH),
     };
@@ -342,7 +343,7 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
 
     if (bs && bs->drv) {
         info->has_inserted = true;
-        info->inserted = bdrv_block_device_info(bs, errp);
+        info->inserted = bdrv_block_device_info(blk, bs, errp);
         if (info->inserted == NULL) {
             goto err;
         }
diff --git a/include/block/qapi.h b/include/block/qapi.h
index 327549d..82ba4b6 100644
--- a/include/block/qapi.h
+++ b/include/block/qapi.h
@@ -29,7 +29,8 @@
 #include "block/block.h"
 #include "block/snapshot.h"
 
-BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs, Error **errp);
+BlockDeviceInfo *bdrv_block_device_info(BlockBackend *blk,
+                                        BlockDriverState *bs, Error **errp);
 int bdrv_query_snapshot_info_list(BlockDriverState *bs,
                                   SnapshotInfoList **p_list,
                                   Error **errp);
diff --git a/tests/qemu-iotests/142 b/tests/qemu-iotests/142
index 517fb30..8bbbfde 100755
--- a/tests/qemu-iotests/142
+++ b/tests/qemu-iotests/142
@@ -134,7 +134,8 @@ echo
 
 # First check the inherited cache mode after opening the image.
 
-hmp_cmds="info block image
+hmp_cmds="info block none0
+info block image
 info block file
 info block backing
 info block backing-file"
@@ -164,6 +165,7 @@ echo
 # new cache mode is specified in the flags, not as an option.
 
 hmp_cmds='qemu-io none0 "reopen -c none"
+info block none0
 info block image
 info block file
 info block backing
@@ -179,6 +181,7 @@ echo
 # new cache mode is specified as an option, not in the flags.
 
 hmp_cmds='qemu-io none0 "reopen -o cache.direct=on"
+info block none0
 info block image
 info block file
 info block backing
@@ -214,6 +217,7 @@ echo
 # options from its parent node.
 
 hmp_cmds="qemu-io none0 \"reopen -o cache.writeback=off,cache.direct=on,cache.no-flush=on\"
+info block none0
 info block image
 info block blkdebug
 info block file"
@@ -321,6 +325,7 @@ echo "--- Basic reopen ---"
 echo
 
 hmp_cmds='qemu-io none0 "reopen -o backing.cache.direct=on"
+info block none0
 info block image
 info block file
 info block backing
diff --git a/tests/qemu-iotests/142.out b/tests/qemu-iotests/142.out
index 32dc802..c922490 100644
--- a/tests/qemu-iotests/142.out
+++ b/tests/qemu-iotests/142.out
@@ -39,9 +39,11 @@ cache.direct=on on none0
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.direct=on on file
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct
     Cache mode:       writeback
     Cache mode:       writeback
@@ -49,6 +51,7 @@ cache.direct=on on file
 cache.direct=on on backing
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
 
@@ -56,6 +59,7 @@ cache.direct=on on backing-file
     Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct
 
 
@@ -64,6 +68,7 @@ cache.writeback=off on none0
     Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
 
 cache.writeback=off on file
 QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root
@@ -80,9 +85,11 @@ cache.no-flush=on on none0
     Cache mode:       writeback, ignore flushes
     Cache mode:       writeback, ignore flushes
     Cache mode:       writeback, ignore flushes
+    Cache mode:       writeback, ignore flushes
 
 cache.no-flush=on on file
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, ignore flushes
     Cache mode:       writeback
     Cache mode:       writeback
@@ -90,6 +97,7 @@ cache.no-flush=on on file
 cache.no-flush=on on backing
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, ignore flushes
     Cache mode:       writeback, ignore flushes
 
@@ -97,6 +105,7 @@ cache.no-flush=on on backing-file
     Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, ignore flushes
 
 --- Cache modes after reopen (live snapshot) ---
@@ -182,24 +191,28 @@ cache.direct=on on none0
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.direct=on on file
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.direct=on on backing
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.direct=on on backing-file
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 
 cache.writeback=off on none0
@@ -207,6 +220,7 @@ cache.writeback=off on none0
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.writeback=off on file
 QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root
@@ -223,9 +237,11 @@ cache.no-flush=on on none0
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.no-flush=on on file
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
     Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
@@ -233,6 +249,7 @@ cache.no-flush=on on file
 cache.no-flush=on on backing
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
     Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, direct, ignore flushes
 
@@ -240,6 +257,7 @@ cache.no-flush=on on backing-file
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
     Cache mode:       writeback, direct, ignore flushes
 
 --- Change cache modes with reopen (qemu-io command, options) ---
@@ -249,24 +267,28 @@ cache.direct=on on none0
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.direct=on on file
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.direct=on on backing
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.direct=on on backing-file
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 
 cache.writeback=off on none0
@@ -274,6 +296,7 @@ cache.writeback=off on none0
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.writeback=off on file
 QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t.qcow2.base,node-name=image,backing.node-name=backing,backing.file.node-name=backing-file,file.node-name=file,file.cache.writeback=off: Can't set writethrough mode except for the root
@@ -290,9 +313,11 @@ cache.no-flush=on on none0
     Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, direct, ignore flushes
+    Cache mode:       writeback, direct, ignore flushes
 
 cache.no-flush=on on file
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
     Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
@@ -300,6 +325,7 @@ cache.no-flush=on on file
 cache.no-flush=on on backing
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
     Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, direct, ignore flushes
 
@@ -307,6 +333,7 @@ cache.no-flush=on on backing-file
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
     Cache mode:       writeback, direct, ignore flushes
 
 --- Change cache modes after snapshot ---
@@ -389,6 +416,7 @@ cache.no-flush=on on backing-file
 
     Cache mode:       writethrough, direct, ignore flushes
     Cache mode:       writeback, direct, ignore flushes
+    Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, ignore flushes
 
 === Check that referenced BDSes don't inherit ===
@@ -422,28 +450,28 @@ cache.direct=on on backing-file
 
 
 cache.writeback=off on blk
-    Cache mode:       writethrough
+    Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
 
 cache.writeback=off on file
     Cache mode:       writeback
-    Cache mode:       writethrough
+    Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
 
 cache.writeback=off on backing
     Cache mode:       writeback
     Cache mode:       writeback
-    Cache mode:       writethrough
+    Cache mode:       writeback
     Cache mode:       writeback
 
 cache.writeback=off on backing-file
     Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
-    Cache mode:       writethrough
+    Cache mode:       writeback
 
 
 cache.no-flush=on on blk
@@ -511,7 +539,7 @@ cache.writeback=off on blk
 cache.writeback=off on file
     Cache mode:       writeback
     Cache mode:       writeback
-    Cache mode:       writethrough
+    Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
 
@@ -519,7 +547,7 @@ cache.writeback=off on backing
     Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
-    Cache mode:       writethrough
+    Cache mode:       writeback
     Cache mode:       writeback
 
 cache.writeback=off on backing-file
@@ -527,7 +555,7 @@ cache.writeback=off on backing-file
     Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
-    Cache mode:       writethrough
+    Cache mode:       writeback
 
 
 cache.no-flush=on on blk
@@ -593,21 +621,21 @@ cache.writeback=off on blk
 
 cache.writeback=off on file
     Cache mode:       writeback, direct
-    Cache mode:       writethrough
+    Cache mode:       writeback
     Cache mode:       writeback
     Cache mode:       writeback
 
 cache.writeback=off on backing
     Cache mode:       writeback, direct
     Cache mode:       writeback
-    Cache mode:       writethrough
+    Cache mode:       writeback
     Cache mode:       writeback
 
 cache.writeback=off on backing-file
     Cache mode:       writeback, direct
     Cache mode:       writeback
     Cache mode:       writeback
-    Cache mode:       writethrough
+    Cache mode:       writeback
 
 
 cache.no-flush=on on blk
@@ -644,9 +672,11 @@ cache.direct=on on none0
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
+    Cache mode:       writeback, direct
 
 cache.direct=on on file
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
@@ -654,12 +684,14 @@ cache.direct=on on file
 cache.direct=on on backing
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
 
 cache.direct=on on backing-file
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
 
@@ -667,6 +699,7 @@ cache.direct=on on backing-file
 cache.writeback=off on none0
     Cache mode:       writethrough
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
 
@@ -683,11 +716,13 @@ QEMU_PROG: -drive if=none,file=TEST_DIR/t.qcow2,backing.file.filename=TEST_DIR/t
 cache.no-flush=on on none0
     Cache mode:       writeback, ignore flushes
     Cache mode:       writeback, ignore flushes
+    Cache mode:       writeback, ignore flushes
     Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, direct, ignore flushes
 
 cache.no-flush=on on file
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, ignore flushes
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct
@@ -695,12 +730,14 @@ cache.no-flush=on on file
 cache.no-flush=on on backing
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct, ignore flushes
     Cache mode:       writeback, direct, ignore flushes
 
 cache.no-flush=on on backing-file
     Cache mode:       writeback
     Cache mode:       writeback
+    Cache mode:       writeback
     Cache mode:       writeback, direct
     Cache mode:       writeback, direct, ignore flushes
 
-- 
1.8.3.1

  parent reply	other threads:[~2016-03-18 18:22 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-18 18:21 [Qemu-devel] [PATCH 00/20] block: Implement writethrough in BlockBackend Kevin Wolf
2016-03-18 18:21 ` [Qemu-devel] [PATCH 01/20] block: Add bdrv_parse_cache_mode() Kevin Wolf
2016-03-26 17:05   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 02/20] qemu-nbd: Call blk_set_enable_write_cache() explicitly Kevin Wolf
2016-03-26 17:09   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 03/20] qemu-io: " Kevin Wolf
2016-03-26 17:18   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 04/20] qemu-img: Expand all BDRV_O_FLAGS uses Kevin Wolf
2016-03-26 17:34   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 05/20] qemu-img: Call blk_set_enable_write_cache() explicitly Kevin Wolf
2016-03-26 17:54   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 06/20] xen_disk: " Kevin Wolf
2016-03-22 11:08   ` Stefano Stabellini
2016-03-26 17:59   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 07/20] block: blockdev_init(): " Kevin Wolf
2016-03-26 18:13   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 08/20] block: Always set writeback mode in blk_new_open() Kevin Wolf
2016-03-26 18:36   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 09/20] block: Handle flush error in bdrv_pwrite_sync() Kevin Wolf
2016-03-26 18:46   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 10/20] block: Move enable_write_cache to BB level Kevin Wolf
2016-03-26 19:54   ` Max Reitz
2016-03-18 18:21 ` Kevin Wolf [this message]
2016-03-26 20:14   ` [Qemu-devel] [PATCH 11/20] block/qapi: Use blk_enable_write_cache() Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 12/20] block: Introduce bdrv_co_writev_flags() Kevin Wolf
2016-03-26 20:24   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 13/20] iscsi: Support BDRV_REQ_FUA Kevin Wolf
2016-03-26 20:33   ` Max Reitz
2016-03-26 20:44   ` Max Reitz
2016-03-29 11:02     ` Kevin Wolf
2016-03-18 18:21 ` [Qemu-devel] [PATCH 14/20] nbd: " Kevin Wolf
2016-03-26 20:46   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 15/20] raw: " Kevin Wolf
2016-03-26 20:49   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 16/20] block: Use bdrv_parse_cache_mode() in drive_init() Kevin Wolf
2016-03-26 20:53   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 17/20] qemu-io: Use bdrv_parse_cache_mode() in reopen_f() Kevin Wolf
2016-03-26 21:05   ` Max Reitz
2016-03-29 10:16     ` Kevin Wolf
2016-03-18 18:21 ` [Qemu-devel] [PATCH 18/20] block: Remove bdrv_parse_cache_flags() Kevin Wolf
2016-03-26 21:06   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 19/20] block: Remove BDRV_O_CACHE_WB Kevin Wolf
2016-03-26 21:23   ` Max Reitz
2016-03-18 18:21 ` [Qemu-devel] [PATCH 20/20] block: Remove bdrv_(set_)enable_write_cache() Kevin Wolf
2016-03-26 21:25   ` Max Reitz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1458325289-17848-12-git-send-email-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).