From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42906) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTuoJ-0006Ih-8m for qemu-devel@nongnu.org; Tue, 16 Sep 2014 11:37:01 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTuoB-00029R-Kz for qemu-devel@nongnu.org; Tue, 16 Sep 2014 11:36:55 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59083) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTuoB-00028m-EK for qemu-devel@nongnu.org; Tue, 16 Sep 2014 11:36:47 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8GFahPo024185 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 16 Sep 2014 11:36:44 -0400 From: Kevin Wolf Date: Tue, 16 Sep 2014 17:36:32 +0200 Message-Id: <1410881796-18452-3-git-send-email-kwolf@redhat.com> In-Reply-To: <1410881796-18452-1-git-send-email-kwolf@redhat.com> References: <1410881796-18452-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 2/6] block: Add optional device argument to query-block List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com This allows querying one specific BlockDriverState instead of a list of all drives. Signed-off-by: Kevin Wolf --- 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