block/qapi: Use blk_enable_write_cache()
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> Reviewed-by: Max Reitz <mreitz@redhat.com>
This commit is contained in:
parent
bfd18d1e0b
commit
c83f9fba2a
2
block.c
2
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;
|
||||
|
@ -34,7 +34,8 @@
|
||||
#include "sysemu/block-backend.h"
|
||||
#include "qemu/cutils.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;
|
||||
@ -48,7 +49,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),
|
||||
};
|
||||
@ -343,7 +344,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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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
|
||||
|
@ -39,14 +39,17 @@ 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
|
||||
|
||||
cache.direct=on on backing
|
||||
Cache mode: writeback
|
||||
Cache mode: writeback
|
||||
Cache mode: writeback
|
||||
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,14 +85,17 @@ 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
|
||||
|
||||
cache.no-flush=on on backing
|
||||
Cache mode: writeback
|
||||
Cache mode: writeback
|
||||
Cache mode: writeback
|
||||
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,14 +237,17 @@ 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
|
||||
|
||||
cache.no-flush=on on backing
|
||||
Cache mode: writeback, direct
|
||||
Cache mode: writeback, direct
|
||||
Cache mode: writeback, direct
|
||||
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,14 +313,17 @@ 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
|
||||
|
||||
cache.no-flush=on on backing
|
||||
Cache mode: writeback, direct
|
||||
Cache mode: writeback, direct
|
||||
Cache mode: writeback, direct
|
||||
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,20 +672,24 @@ 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
|
||||
|
||||
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
|
||||
@ -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
|
||||
|
||||
@ -681,24 +714,28 @@ 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
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user