From: Kevin Wolf <kwolf@redhat.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH 2/6] block: Add optional device argument to query-block
Date: Tue, 16 Sep 2014 17:36:32 +0200 [thread overview]
Message-ID: <1410881796-18452-3-git-send-email-kwolf@redhat.com> (raw)
In-Reply-To: <1410881796-18452-1-git-send-email-kwolf@redhat.com>
This allows querying one specific BlockDriverState instead of a list of
all drives.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/qapi.c | 15 +++++++++++++--
hmp.c | 6 +++---
qapi/block-core.json | 8 ++++++--
3 files changed, 22 insertions(+), 7 deletions(-)
diff --git a/block/qapi.c b/block/qapi.c
index 6b43bc3..2a060d3 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -367,13 +367,24 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)
return s;
}
-BlockInfoList *qmp_query_block(Error **errp)
+BlockInfoList *qmp_query_block(bool has_device, const char *device,
+ Error **errp)
{
BlockInfoList *head = NULL, **p_next = &head;
BlockDriverState *bs = NULL;
Error *local_err = NULL;
- while ((bs = bdrv_next(bs))) {
+ if (has_device) {
+ bs = bdrv_find(device);
+ if (bs == NULL) {
+ error_setg(errp, "Device not found");
+ goto err;
+ }
+ } else {
+ bs = bdrv_next(NULL);
+ }
+
+ for (; bs; (bs = has_device ? NULL : bdrv_next(bs))) {
BlockInfoList *info = g_malloc0(sizeof(*info));
bdrv_query_info(bs, &info->value, &local_err);
if (local_err) {
diff --git a/hmp.c b/hmp.c
index c3846b8..02eee80 100644
--- a/hmp.c
+++ b/hmp.c
@@ -298,7 +298,7 @@ void hmp_info_block(Monitor *mon, const QDict *qdict)
const char *device = qdict_get_try_str(qdict, "device");
bool verbose = qdict_get_try_bool(qdict, "verbose", 0);
- block_list = qmp_query_block(NULL);
+ block_list = qmp_query_block(false, NULL, NULL);
for (info = block_list; info; info = info->next) {
if (device && strcmp(device, info->value->device)) {
@@ -847,7 +847,7 @@ void hmp_cont(Monitor *mon, const QDict *qdict)
BlockInfoList *bdev_list, *bdev;
Error *err = NULL;
- bdev_list = qmp_query_block(NULL);
+ bdev_list = qmp_query_block(false, NULL, NULL);
for (bdev = bdev_list; bdev; bdev = bdev->next) {
if (key_is_missing(bdev->value)) {
monitor_read_block_device_key(mon, bdev->value->device,
@@ -1588,7 +1588,7 @@ void hmp_nbd_server_start(Monitor *mon, const QDict *qdict)
/* Then try adding all block devices. If one fails, close all and
* exit.
*/
- block_list = qmp_query_block(NULL);
+ block_list = qmp_query_block(false, NULL, NULL);
for (info = block_list; info; info = info->next) {
if (!info->value->has_inserted) {
diff --git a/qapi/block-core.json b/qapi/block-core.json
index c53b587..ddc3fe0 100644
--- a/qapi/block-core.json
+++ b/qapi/block-core.json
@@ -354,13 +354,17 @@
##
# @query-block:
#
-# Get a list of BlockInfo for all virtual block devices.
+# Get a list of BlockInfo for all or one specific virtual block device.
+#
+# @device: #optional The id of the block device to inspect. (Since 2.2)
#
# Returns: a list of @BlockInfo describing each virtual block device
#
# Since: 0.14.0
##
-{ 'command': 'query-block', 'returns': ['BlockInfo'] }
+{ 'command': 'query-block',
+ 'data': { '*device': 'str' },
+ 'returns': ['BlockInfo'] }
##
# @BlockDeviceStats:
--
1.8.3.1
next prev parent reply other threads:[~2014-09-16 15:37 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-16 15:36 [Qemu-devel] [PATCH 0/6] block: Single-device query-block(-node) and cache info Kevin Wolf
2014-09-16 15:36 ` [Qemu-devel] [PATCH 1/6] block/qapi: Add cache information to query-block Kevin Wolf
2014-09-18 11:04 ` Markus Armbruster
2014-09-18 11:38 ` Markus Armbruster
2014-09-18 11:53 ` Kevin Wolf
2014-09-18 12:46 ` Markus Armbruster
2014-09-18 12:49 ` Eric Blake
2014-09-16 15:36 ` Kevin Wolf [this message]
2014-09-18 11:53 ` [Qemu-devel] [PATCH 2/6] block: Add optional device argument " Markus Armbruster
2014-09-16 15:36 ` [Qemu-devel] [PATCH 3/6] block: Introduce query-block-node Kevin Wolf
2014-09-18 11:59 ` Markus Armbruster
2014-09-16 15:36 ` [Qemu-devel] [PATCH 4/6] block/hmp: Factor out print_block_info() Kevin Wolf
2014-09-16 15:36 ` [Qemu-devel] [PATCH 5/6] block/hmp: Allow info = NULL in print_block_info() Kevin Wolf
2014-09-16 15:36 ` [Qemu-devel] [PATCH 6/6] block: Allow node-name in HMP 'info block' Kevin Wolf
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=1410881796-18452-3-git-send-email-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/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).