Fix query-blockstats with -blockdev
cover Fix query-blockstats with -blockdev
Kevin Wolf (3):
block/qapi: Add 'qdev' field to query-blockstats result block/qapi: Include anonymous BBs in query-blockstats
qemu-iotests: Test query-blockstats with -drive and -blockdev
qapi/block-core.json | 5 ++- block/qapi.c | 16 ++++++- tests/qemu-iotests/227 | 101 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/227.out | 42 +++++++++++++++++++ tests/qemu-iotests/group | 1 + 5 files changed, 163 insertions(+), 2 deletions(-) create mode 100755 tests/qemu-iotests/227 create mode 100644 tests/qemu-iotests/227.out
Signature · 1 line
2.13.6
PATCH 1/3 block/qapi: Add 'qdev' field to query-blockstats result
Like for query-block, the client needs to identify which BlockBackend the returned data is for. Anonymous BlockBackends are identified by the device model they are attached to. Add a 'qdev' field that contains the qdev ID or QOM path of the attached device model.
--- qapi/block-core.json | 5 ++++- block/qapi.c | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-)
qapi/block-core.json +4 -1
@@ -866,6 +866,9 @@ # # @node-name: The node name of the device. (Since 2.3) # +# @qdev: The qdev ID, or if no ID is assigned, the QOM path of the block +# device. (since 3.0) +# # @stats: A @BlockDeviceStats for the device. # # @parent: This describes the file block device if it has one.
@@ -879,7 +882,7 @@ # Since: 0.14.0 ## { 'struct': 'BlockStats', - 'data': {'*device': 'str', '*node-name': 'str', + 'data': {'*device': 'str', '*qdev': 'str', '*node-name': 'str', 'stats': 'BlockDeviceStats', '*parent': 'BlockStats', '*backing': 'BlockStats'} }
block/qapi.c +10 -0
@@ -597,11 +597,21 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes,BlockStatsList *info =g_malloc0 (sizeof (*info));AioContext *ctx =blk_get_aio_context (blk);BlockStats *s; +char *qdev;aio_context_acquire (ctx); s =bdrv_query_bds_stats (blk_bs (blk), true); s->has_device = true; s->device =g_strdup (blk_name (blk)); + + qdev =blk_get_attached_dev_id (blk); +if (qdev && *qdev) { + s->has_qdev = true; + s->qdev = qdev; + }else { +g_free (qdev); + } +bdrv_query_blk_stats (s->stats, blk);aio_context_release (ctx);
Signature · 1 line
2.13.6
PATCH 2/3 block/qapi: Include anonymous BBs in query-blockstats
In reply to Kevin WolfConsistent with query-block, query-blockstats should not only include named BlockBackends, but also those that are anonmyous, but belong to a device model.
--- block/qapi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
block/qapi.c +5 -1
@@ -593,12 +593,16 @@ BlockStatsList *qmp_query_blockstats(bool has_query_nodes, p_next = &info->next; } }else { -for (blk =blk_next (NULL ); blk; blk =blk_next (blk)) { +for (blk =blk_all_next (NULL ); blk; blk =blk_all_next (blk)) {BlockStatsList *info =g_malloc0 (sizeof (*info));AioContext *ctx =blk_get_aio_context (blk);BlockStats *s;char *qdev; +if (!*blk_name (blk) && !blk_get_attached_dev (blk)) { +continue ; + } +aio_context_acquire (ctx); s =bdrv_query_bds_stats (blk_bs (blk), true); s->has_device = true;
Signature · 1 line
2.13.6
PATCH 3/3 qemu-iotests: Test query-blockstats with -drive and -blockdev
In reply to Kevin WolfMake sure that query-blockstats returns information for every BlockBackend that is named or attached to a device model (or both).
--- tests/qemu-iotests/227 | 101 +++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/227.out | 42 +++++++++++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 144 insertions(+) create mode 100755 tests/qemu-iotests/227 create mode 100644 tests/qemu-iotests/227.out
tests/qemu-iotests/227 new file +101 -0
@@ -0,0 +1,101 @@ +#!/bin/bash +# +# Test query-blockstats with different ways to create a BB +# +# Copyright (C) 2018 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 [email protected] + +seq=$(basename $0) +echo "QA output created by $seq" + +here=$PWD +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 + +function do_run_qemu() +{ + echo Testing: "$@" + $QEMU -nographic -qmp stdio -serial none "$@" + echo +} + +function run_qemu() +{ + do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \ + | _filter_qemu | _filter_imgfmt \ + | _filter_generated_node_ids +} + +echo +echo '=== blockstats with -drive if=virtio ===' +echo + +run_qemu -drive driver=null-co,if=virtio <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "query-blockstats"} +{ "execute": "quit" } +EOF + +echo +echo '=== blockstats with -drive if=none ===' +echo + +run_qemu -drive driver=null-co,if=none <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "query-blockstats"} +{ "execute": "quit" } +EOF + +echo +echo '=== blockstats with -blockdev ===' +echo + +run_qemu -blockdev driver=null-co,node-name=null <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "query-blockstats"} +{ "execute": "quit" } +EOF + +echo +echo '=== blockstats with -blockdev and -device ===' +echo + +run_qemu -blockdev driver=null-co,node-name=null -device virtio-blk,drive=null,id=virtio0 <<EOF +{ "execute": "qmp_capabilities" } +{ "execute": "query-blockstats"} +{ "execute": "quit" } +EOF + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/227.out new file +42 -0
42 lines not on this page · raw message
tests/qemu-iotests/group +1 -0
@@ -224,3 +224,4 @@ 223 rw auto quick 225 rw auto quick 226 auto quick +227 auto quick
Signature · 1 line
2.13.6
Re: [Qemu-devel] [PATCH for-3.0 1/3] block/qapi: Add 'qdev' field to query-blockstats result
In reply to Kevin WolfQuoted 9 lines · Kevin Wolf
Like for query-block, the client needs to identify which BlockBackend the returned data is for. Anonymous BlockBackends are identified by the device model they are attached to. Add a 'qdev' field that contains the qdev ID or QOM path of the attached device model.
Signed-off-by Kevin Wolf <[email protected]>---
qapi/block-core.json line 888
Quoted 8 lines
qapi/block-core.json +1
-1@@ -879,7 +882,7 @@ # Since: 0.14.0 ## { 'struct': 'BlockStats', - 'data': {'*device': 'str', '*node-name': 'str', + 'data': {'*device': 'str', '*qdev': 'str', '*node-name': 'str', 'stats': 'BlockDeviceStats', '*parent': 'BlockStats', '*backing': 'BlockStats'} }
Can we also update the example under query-blockstats a few lines later to show the added field?
At any rate, it looks helpful. Although this is borderline new feature, it resolves a need identified in libvirt using -blockdev, and so I can live with it as a 3.0 bugfix.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH for-3.0 2/3] block/qapi: Include anonymous BBs in query-blockstats
In reply to Kevin WolfQuoted 2 lines · Kevin Wolf
Consistent with query-block, query-blockstats should not only include named BlockBackends, but also those that are anonmyous, but belong to a
s/anonmyous/anonymous/
Quoted 7 lines
device model.
Signed-off-by Kevin Wolf <[email protected]>--- block/qapi.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH for-3.0 3/3] qemu-iotests: Test query-blockstats with -drive and -blockdev
In reply to Kevin WolfQuoted 2 lines · Kevin Wolf
Make sure that query-blockstats returns information for every BlockBackend that is named or attached to a device model (or both).
Needed for libvirt switching over to -blockdev, so even though we're rather late in the 3.0 cycle, I can understand it going in now.
Quoted 3 lines
Signed-off-by Kevin Wolf <[email protected]>---
tests/qemu-iotests/227.out line 8
Quoted 10 lines
+++ b/tests/qemu-iotests/227.out
tests/qemu-iotests/227.out new file +8
-0@@ -0,0 +1,42 @@ +QA output created by 227 + +=== blockstats with -drive if=virtio === + +Testing: -drive driver=null-co,if=virtio +QMP_VERSION +{"return": {}} +{"return": [{"device": "virtio0", "stats": {"flush_total_time_ns": 0, "wr_highest_offset": 0, "wr_total_time_ns": 0, "failed_wr_operations": 0, "failed_rd_operations": 0, "wr_merged": 0, "wr_bytes": 0, "timed_stats": [], "failed_flush_operations": 0, "account_invalid": true, "rd_total_time_ns": 0, "flush_operations": 0, "wr_operations": 0, "rd_merged": 0, "rd_bytes": 0, "invalid_flush_operations": 0, "account_failed": true, "rd_operations": 0, "invalid_wr_operations": 0, "invalid_rd_operations": 0}, "node-name": "NODE_NAME", "qdev": "/machine/peripheral-anon/device[0]/virtio-backend"}]}
Long lines. Would it be worth writing the test to use QMP pretty mode?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH for-3.0 1/3] block/qapi: Add 'qdev' field to query-blockstats result
In reply to Eric BlakeAm 27.07.2018 um 17:07 hat Eric Blake geschrieben:
Quoted 9 lines · Kevin Wolf
Quoted 7 lines
Like for query-block, the client needs to identify which BlockBackend the returned data is for. Anonymous BlockBackends are identified by the device model they are attached to. Add a 'qdev' field that contains the qdev ID or QOM path of the attached device model.
Signed-off-by Kevin Wolf <[email protected]>---
Quoted 12 lines
qapi/block-core.json line 888
Quoted 9 lines
qapi/block-core.json +1
-1@@ -879,7 +882,7 @@ # Since: 0.14.0 ## { 'struct': 'BlockStats', - 'data': {'*device': 'str', '*node-name': 'str', + 'data': {'*device': 'str', '*qdev': 'str', '*node-name': 'str', 'stats': 'BlockDeviceStats', '*parent': 'BlockStats', '*backing': 'BlockStats'} }Can we also update the example under query-blockstats a few lines later to show the added field?
I'll add the qdev field, but the example is hopelessly outdated anyway. Sounds like something for another patch.
Quoted 5 lines
At any rate, it looks helpful. Although this is borderline new feature, it resolves a need identified in libvirt using -blockdev, and so I can live with it as a 3.0 bugfix.
Reviewed-by Eric Blake <[email protected]>
Thanks.
Kevin
Re: [Qemu-devel] [PATCH for-3.0 3/3] qemu-iotests: Test query-blockstats with -drive and -blockdev
In reply to Eric BlakeAm 27.07.2018 um 17:12 hat Eric Blake geschrieben:
Quoted 13 lines · Kevin Wolf
Quoted 2 lines
Make sure that query-blockstats returns information for every BlockBackend that is named or attached to a device model (or both).
Needed for libvirt switching over to -blockdev, so even though we're rather late in the 3.0 cycle, I can understand it going in now.
Quoted 3 lines
Signed-off-by Kevin Wolf <[email protected]>---
Reviewed-by Eric Blake <[email protected]>
Quoted 12 lines
tests/qemu-iotests/227.out line 8
Quoted 10 lines
+++ b/tests/qemu-iotests/227.out
tests/qemu-iotests/227.out new file +8
-0@@ -0,0 +1,42 @@ +QA output created by 227 + +=== blockstats with -drive if=virtio === + +Testing: -drive driver=null-co,if=virtio +QMP_VERSION +{"return": {}} +{"return": [{"device": "virtio0", "stats": {"flush_total_time_ns": 0, "wr_highest_offset": 0, "wr_total_time_ns": 0, "failed_wr_operations": 0, "failed_rd_operations": 0, "wr_merged": 0, "wr_bytes": 0, "timed_stats": [], "failed_flush_operations": 0, "account_invalid": true, "rd_total_time_ns": 0, "flush_operations": 0, "wr_operations": 0, "rd_merged": 0, "rd_bytes": 0, "invalid_flush_operations": 0, "account_failed": true, "rd_operations": 0, "invalid_wr_operations": 0, "invalid_rd_operations": 0}, "node-name": "NODE_NAME", "qdev": "/machine/peripheral-anon/device[0]/virtio-backend"}]}Long lines. Would it be worth writing the test to use QMP pretty mode?
Good idea. I'll do that before applying the patches.
Kevin
Re: [Qemu-devel] [PATCH for-3.0 1/3] block/qapi: Add 'qdev' field to query-blockstats result
In reply to Kevin WolfQuoted 23 lines · Kevin Wolf
Am 27.07.2018 um 17:07 hat Eric Blake geschrieben:
Quoted 9 lines · Kevin Wolf
Quoted 7 lines
Like for query-block, the client needs to identify which BlockBackend the returned data is for. Anonymous BlockBackends are identified by the device model they are attached to. Add a 'qdev' field that contains the qdev ID or QOM path of the attached device model.
Signed-off-by Kevin Wolf <[email protected]>---
Quoted 12 lines
qapi/block-core.json line 888
Quoted 9 lines
qapi/block-core.json +1
-1@@ -879,7 +882,7 @@ # Since: 0.14.0 ## { 'struct': 'BlockStats', - 'data': {'*device': 'str', '*node-name': 'str', + 'data': {'*device': 'str', '*qdev': 'str', '*node-name': 'str', 'stats': 'BlockDeviceStats', '*parent': 'BlockStats', '*backing': 'BlockStats'} }Can we also update the example under query-blockstats a few lines later to show the added field?
Quoted 2 lines
I'll add the qdev field, but the example is hopelessly outdated anyway. Sounds like something for another patch.
When doing further cleanups it would be worth also noting that the 'query-nodes' argument of 'query-blockstats' does not return correct information.
Right now it creates a false impression that it just changes the output from nested to linear and includes filter nodes, but in fact the data is not correct in that mode.