block: Allow query stats for drive-mirror target
cover block: Allow query stats for drive-mirror target
This series adds an optional bool parameter "query-nodes" to query-blockstats.
By default, if omitted, the behavior is unchanged.
If set to "true", the command will iterate through all named nodes in BDS graph and report the statistics in a list, similarly. But the backing chain is not built.
This provides a way for libvirt to watch the allocation status (wr_highest_offset) of target image. Now, libvirt can start drive-mirror job specifying a node-name parameter. Thus the created target image gets a node name that can be queried with the new query-blockstats.
Fam Zheng (4):
block: Add bdrv_next_node
block: Add bdrv_get_node_name
block: Include "node-name" if present in query-blockstats
qmp: Add optional switch "query-nodes" in query-blockstats
block.c | 14 +++++++++++++- block/qapi.c | 25 ++++++++++++++++++------- hmp.c | 2 +- include/block/block.h | 2 ++ qapi/block-core.json | 9 +++++++-- qmp-commands.hx | 2 +- 6 files changed, 42 insertions(+), 12 deletions(-)
Signature · 1 line
1.9.3
PATCH 1/4 block: Add bdrv_next_node
Similar to bdrv_next, this traverses through graph_bdrv_states. Will be useful to enumerate all the named nodes.
--- block.c | 8 ++++++++ include/block/block.h | 1 + 2 files changed, 9 insertions(+)
block.c +8 -0
@@ -3775,6 +3775,14 @@ bool bdrv_chain_contains(BlockDriverState *top, BlockDriverState *base)return top !=NULL ; } +BlockDriverState *bdrv_next_node (BlockDriverState *bs) +{ +if (!bs) { +return QTAILQ_FIRST (&graph_bdrv_states); + } +return QTAILQ_NEXT (bs, node_list); +} +BlockDriverState *bdrv_next (BlockDriverState *bs) {if (!bs) {
include/block/block.h +1 -0
@@ -365,6 +365,7 @@ BlockDriverState *bdrv_lookup_bs(const char *device,const char *node_name, Error **errp);bool bdrv_chain_contains (BlockDriverState *top,BlockDriverState *base); +BlockDriverState *bdrv_next_node (BlockDriverState *bs);BlockDriverState *bdrv_next (BlockDriverState *bs);int bdrv_is_encrypted (BlockDriverState *bs);int bdrv_key_required (BlockDriverState *bs);
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 1/4] block: Add bdrv_next_node
Quoted 8 lines · Fam Zheng
Similar to
bdrv_next, this traverses throughgraph_bdrv_states. Will be useful to enumerate all the named nodes.Signed-off-by Fam Zheng <[email protected]>--- block.c | 8 ++++++++ include/block/block.h | 1 + 2 files changed, 9 insertions(+)
You could reuse this for bdrv_named_nodes_list(), but that's optional.
Re: [Qemu-devel] [PATCH 1/4] block: Add bdrv_next_node
In reply to Fam ZhengQuoted 9 lines · Fam Zheng
Similar to
bdrv_next, this traverses throughgraph_bdrv_states. Will be useful to enumerate all the named nodes.Signed-off-by Fam Zheng <[email protected]>--- block.c | 8 ++++++++ include/block/block.h | 1 + 2 files changed, 9 insertions(+)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 2/4 block: Add bdrv_get_node_name
In reply to Fam ZhengThis returns the node name of a BDS. Remove the TODO comment and expect the callers to be explicit.
--- block.c | 6 +++++- include/block/block.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)
block.c +5 -1
@@ -3791,7 +3791,11 @@ BlockDriverState *bdrv_next(BlockDriverState *bs)return QTAILQ_NEXT (bs, device_list); } -/* TODO check what callers really want: bs->node_name or blk_name() */ +const char *bdrv_get_node_name (const BlockDriverState *bs) +{ +return bs->node_name; +} +const char *bdrv_get_device_name (const BlockDriverState *bs) {return bs->blk ?blk_name (bs->blk) :"" ;
include/block/block.h +1 -0
@@ -373,6 +373,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key);int bdrv_query_missing_keys (void );void bdrv_iterate_format (void (*it)(void *opaque,const char *name),void *opaque); +const char *bdrv_get_node_name (const BlockDriverState *bs);const char *bdrv_get_device_name (const BlockDriverState *bs);int bdrv_get_flags (BlockDriverState *bs); int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 2/4] block: Add bdrv_get_node_name
Quoted 14 lines · Fam Zheng
This returns the node name of a BDS. Remove the TODO comment and expect the callers to be explicit.
Signed-off-by Fam Zheng <[email protected]>--- block.c | 6 +++++- include/block/block.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)block.c +0
-0
block.c BlockDriverState *bdrv_next(BlockDriverState *bs) · line 3794
Quoted 4 lines
block.c +0
-1@@ -3791,7 +3791,11 @@ BlockDriverState *bdrv_next(BlockDriverState *bs)return QTAILQ_NEXT (bs, device_list); } -/* TODO check what callers really want: bs->node_name or blk_name() */
Well, we still need to check this, don't we? cscope tells me there are 61 callers of bdrv_get_device_name() and not all of them look like they always query a BDS with a BB.
Max
Quoted 20 lines
block.c +5
-0+const char *bdrv_get_node_name (const BlockDriverState *bs) +{ +return bs->node_name; +} +const char *bdrv_get_device_name (const BlockDriverState *bs) {return bs->blk ?blk_name (bs->blk) :"" ;include/block/block.h +1
-0@@ -373,6 +373,7 @@ int bdrv_set_key(BlockDriverState *bs, const char *key);int bdrv_query_missing_keys (void );void bdrv_iterate_format (void (*it)(void *opaque,const char *name),void *opaque); +const char *bdrv_get_node_name (const BlockDriverState *bs);const char *bdrv_get_device_name (const BlockDriverState *bs);int bdrv_get_flags (BlockDriverState *bs); int bdrv_write_compressed(BlockDriverState *bs, int64_t sector_num,
Re: [Qemu-devel] [PATCH 2/4] block: Add bdrv_get_node_name
In reply to Fam ZhengQuoted 9 lines · Fam Zheng
This returns the node name of a BDS. Remove the TODO comment and expect the callers to be explicit.
Signed-off-by Fam Zheng <[email protected]>--- block.c | 6 +++++- include/block/block.h | 1 + 2 files changed, 6 insertions(+), 1 deletion(-)
Can still return NULL because we don't have Jeff's patches for auto-assigning a node name everywhere, right? But that doesn't matter in the context of this patch, so:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 3/4 block: Include "node-name" if present in query-blockstats
In reply to Fam ZhengNode name is a better identifier of BDS.
We will want to query statistics of a BDS node buried in the BDS graph, so reporting the node's name if there is one will do the good.
--- block/qapi.c | 5 +++++ qapi/block-core.json | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-)
block/qapi.c +5 -0
@@ -333,6 +333,11 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs) s->device =g_strdup (bdrv_get_device_name (bs)); } +if (bdrv_get_node_name (bs)[0 ]) { + s->has_node_name = true; + s->node_name =g_strdup (bdrv_get_node_name (bs)); + } + s->stats =g_malloc0 (sizeof (*s->stats)); s->stats->rd_bytes = bs->stats.nr_bytes[BLOCK_ACCT_READ ]; s->stats->wr_bytes = bs->stats.nr_bytes[BLOCK_ACCT_WRITE ];
qapi/block-core.json +4 -1
@@ -408,6 +408,8 @@ # @device: #optional If the stats are for a virtual block device, the name # corresponding to the virtual block device. # +# @device: #optional The node name of the device. (Since 2.3) +# # @stats: A @BlockDeviceStats for the device. # # @parent: #optional This describes the file block device if it has one.
@@ -418,7 +420,8 @@ # Since: 0.14.0 ## { 'type': 'BlockStats', - 'data': {'*device': 'str', 'stats': 'BlockDeviceStats', + 'data': {'*device': 'str', '*node-name': 'str', + 'stats': 'BlockDeviceStats', '*parent': 'BlockStats', '*backing': 'BlockStats'} }
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 3/4] block: Include "node-name" if present in query-blockstats
Quoted 10 lines · Fam Zheng
Node name is a better identifier of BDS.
We will want to query statistics of a BDS node buried in the BDS graph, so reporting the node's name if there is one will do the good.
Signed-off-by Fam Zheng <[email protected]>--- block/qapi.c | 5 +++++ qapi/block-core.json | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-)
Re: [Qemu-devel] [PATCH 3/4] block: Include "node-name" if present in query-blockstats
In reply to Fam ZhengQuoted 4 lines · Fam Zheng
Node name is a better identifier of BDS.
We will want to query statistics of a BDS node buried in the BDS graph, so reporting the node's name if there is one will do the good.
s/do the good/do the trick/
qapi/block-core.json line 411
Quoted 6 lines
+++
b/qapi/block-core.jsonqapi/block-core.json +1
-0@@ -408,6 +408,8 @@ # @device: #optional If the stats are for a virtual block device, the name # corresponding to the virtual block device. # +# @device: #optional The node name of the device. (Since 2.3)
Yeah, we missed soft freeze and this is a feature, so your versioning is correct.
The node-name would become non-optional once Jeff's patches auto-assign a node name, right?
qapi/block-core.json line 425
Quoted 12 lines
qapi/block-core.json +3
-1+# # @stats: A @BlockDeviceStats for the device. # # @parent: #optional This describes the file block device if it has one.@@ -418,7 +420,8 @@ # Since: 0.14.0 ## { 'type': 'BlockStats', - 'data': {'*device': 'str', 'stats': 'BlockDeviceStats', + 'data': {'*device': 'str', '*node-name': 'str', + 'stats': 'BlockDeviceStats', '*parent': 'BlockStats',
Indentation looks odd here. Fix that, and:
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH 4/4 qmp: Add optional switch "query-nodes" in query-blockstats
In reply to Fam ZhengThis bool option will allow query all the node names. It iterates all the BDSes that are assigned a name, also in this case don't query up the backing chain.
--- block/qapi.c | 20 +++++++++++++------- hmp.c | 2 +- qapi/block-core.json | 4 +++- qmp-commands.hx | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-)
block/qapi.c +13 -7
@@ -322,7 +322,8 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,qapi_free_BlockInfo (info); } -static BlockStats *bdrv_query_stats (const BlockDriverState *bs) +static BlockStats *bdrv_query_stats (const BlockDriverState *bs, +bool query_backing) {BlockStats *s;
@@ -352,12 +353,12 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)if (bs->file) { s->has_parent = true; - s->parent =bdrv_query_stats (bs->file); + s->parent =bdrv_query_stats (bs->file, query_backing); } -if (bs->backing_hd) { +if (query_backing && bs->backing_hd) { s->has_backing = true; - s->backing =bdrv_query_stats (bs->backing_hd); + s->backing =bdrv_query_stats (bs->backing_hd, query_backing); }return s;
@@ -388,17 +389,22 @@ BlockInfoList *qmp_query_block(Error **errp)return NULL ; } -BlockStatsList *qmp_query_blockstats (Error **errp) +BlockStatsList *qmp_query_blockstats (bool has_query_nodes, +bool query_nodes, +Error **errp) {BlockStatsList *head =NULL , **p_next = &head;BlockDriverState *bs =NULL ; -while ((bs =bdrv_next (bs))) { +/* Just to be safe if query_nodes is not always intialized */ + query_nodes = query_nodes && has_query_nodes; + +while ((bs = query_nodes ?bdrv_next_node (bs) :bdrv_next (bs))) {BlockStatsList *info =g_malloc0 (sizeof (*info));AioContext *ctx =bdrv_get_aio_context (bs);aio_context_acquire (ctx); - info->value =bdrv_query_stats (bs); + info->value =bdrv_query_stats (bs, !query_nodes);aio_context_release (ctx); *p_next = info;
hmp.c +1 -1
@@ -403,7 +403,7 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict) {BlockStatsList *stats_list, *stats; - stats_list =qmp_query_blockstats (NULL ); + stats_list =qmp_query_blockstats (false, false,NULL );for (stats = stats_list; stats; stats = stats->next) {if (!stats->value->has_device) {
qapi/block-core.json +3 -1
@@ -434,7 +434,9 @@ # # Since: 0.14.0 ## -{ 'command': 'query-blockstats', 'returns': ['BlockStats'] } +{ 'command': 'query-blockstats', + 'data': {'*query-nodes': 'bool' }, + 'returns': ['BlockStats'] } ## # @BlockdevOnError:
qmp-commands.hx +1 -1
@@ -2347,7 +2347,7 @@ EQMP { .name = "query-blockstats", - .args_type = "", + .args_type = "query-nodes:b?", .mhandler.cmd_new = qmp_marshal_input_query_blockstats, },
Signature · 1 line
1.9.3
Re: [Qemu-devel] [PATCH 4/4] qmp: Add optional switch "query-nodes" in query-blockstats
Quoted 30 lines · Fam Zheng
This bool option will allow query all the node names. It iterates all the BDSes that are assigned a name, also in this case don't query up the backing chain.
Signed-off-by Fam Zheng <[email protected]>--- block/qapi.c | 20 +++++++++++++------- hmp.c | 2 +- qapi/block-core.json | 4 +++- qmp-commands.hx | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-)block/qapi.c +2
-1@@ -322,7 +322,8 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,qapi_free_BlockInfo (info); } -static BlockStats *bdrv_query_stats (const BlockDriverState *bs) +static BlockStats *bdrv_query_stats (const BlockDriverState *bs, +bool query_backing) {BlockStats *s;@@ -352,12 +353,12 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)if (bs->file) { s->has_parent = true;
block/qapi.c static BlockStats *bdrv_query_stats(const BlockDriverState *bs) · line 362
Quoted 10 lines
block/qapi.c +3
-3- s->parent =bdrv_query_stats (bs->file); + s->parent =bdrv_query_stats (bs->file, query_backing); } -if (bs->backing_hd) { +if (query_backing && bs->backing_hd) { s->has_backing = true; - s->backing =bdrv_query_stats (bs->backing_hd); + s->backing =bdrv_query_stats (bs->backing_hd, query_backing); }
Is there a specific reason why you're not querying the backing chain but still recurse to bs->file?
Quoted 45 lines
block/qapi.c +8
-3return s;@@ -388,17 +389,22 @@ BlockInfoList *qmp_query_block(Error **errp)return NULL ; } -BlockStatsList *qmp_query_blockstats (Error **errp) +BlockStatsList *qmp_query_blockstats (bool has_query_nodes, +bool query_nodes, +Error **errp) {BlockStatsList *head =NULL , **p_next = &head;BlockDriverState *bs =NULL ; -while ((bs =bdrv_next (bs))) { +/* Just to be safe if query_nodes is not always intialized */ + query_nodes = query_nodes && has_query_nodes; + +while ((bs = query_nodes ?bdrv_next_node (bs) :bdrv_next (bs))) {BlockStatsList *info =g_malloc0 (sizeof (*info));AioContext *ctx =bdrv_get_aio_context (bs);aio_context_acquire (ctx); - info->value =bdrv_query_stats (bs); + info->value =bdrv_query_stats (bs, !query_nodes);aio_context_release (ctx); *p_next = info;hmp.c +1
-1@@ -403,7 +403,7 @@ void hmp_info_blockstats(Monitor *mon, const QDict *qdict) {BlockStatsList *stats_list, *stats; - stats_list =qmp_query_blockstats (NULL ); + stats_list =qmp_query_blockstats (false, false,NULL );for (stats = stats_list; stats; stats = stats->next) {if (!stats->value->has_device) {qapi/block-core.json +0
-0
qapi/block-core.json line 438
Quoted 6 lines
qapi/block-core.json +2
-1@@ -434,7 +434,9 @@ # # Since: 0.14.0 ## -{ 'command': 'query-blockstats', 'returns': ['BlockStats'] } +{ 'command': 'query-blockstats', + 'data': {'*query-nodes': 'bool' },
No space after the opening shwoopy bracket (took that from Wikipedia, I love it), but a space before the closing one.
Also, the new parameter should be documented, I think (and the documentation should include that the backing chain is not queried recursively).
Max
Quoted 17 lines
qapi/block-core.json +1
-0+ 'returns': ['BlockStats'] } ## # @BlockdevOnError:qmp-commands.hx +1
-1@@ -2347,7 +2347,7 @@ EQMP { .name = "query-blockstats", - .args_type = "", + .args_type = "query-nodes:b?", .mhandler.cmd_new = qmp_marshal_input_query_blockstats, },
Re: [Qemu-devel] [PATCH 4/4] qmp: Add optional switch "query-nodes" in query-blockstats
Quoted 32 lines · Max Reitz
Quoted 31 lines · Fam Zheng
This bool option will allow query all the node names. It iterates all the BDSes that are assigned a name, also in this case don't query up the backing chain.
Signed-off-by Fam Zheng <[email protected]>--- block/qapi.c | 20 +++++++++++++------- hmp.c | 2 +- qapi/block-core.json | 4 +++- qmp-commands.hx | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-)block/qapi.c +3
-3@@ -322,7 +322,8 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,qapi_free_BlockInfo (info); } -static BlockStats *bdrv_query_stats (const BlockDriverState *bs) +static BlockStats *bdrv_query_stats (const BlockDriverState *bs, +bool query_backing) {BlockStats *s;@@ -352,12 +353,12 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)if (bs->file) { s->has_parent = true; - s->parent =bdrv_query_stats (bs->file); + s->parent =bdrv_query_stats (bs->file, query_backing); } -if (bs->backing_hd) {
Quoted 8 lines
block/qapi.c static BlockStats *bdrv_query_stats(const BlockDriverState *bs) · line 362
Quoted 5 lines
block/qapi.c +2
-1+if (query_backing && bs->backing_hd) { s->has_backing = true; - s->backing =bdrv_query_stats (bs->backing_hd); + s->backing =bdrv_query_stats (bs->backing_hd, query_backing); }Is there a specific reason why you're not querying the backing chain but still recurse to
bs->file?
Unlike its backing, there can be some information in ->file which is interesting to the node itself, because it is ->file carries out the actual read/write on the image. Makes sense?
Fam
Re: [Qemu-devel] [PATCH 4/4] qmp: Add optional switch "query-nodes" in query-blockstats
Quoted 40 lines · Fam Zheng
Quoted 31 lines · Max Reitz
Quoted 30 lines · Fam Zheng
This bool option will allow query all the node names. It iterates all the BDSes that are assigned a name, also in this case don't query up the backing chain.
Signed-off-by Fam Zheng <[email protected]>--- block/qapi.c | 20 +++++++++++++------- hmp.c | 2 +- qapi/block-core.json | 4 +++- qmp-commands.hx | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-)block/qapi.c +3
-2@@ -322,7 +322,8 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,qapi_free_BlockInfo (info); } -static BlockStats *bdrv_query_stats (const BlockDriverState *bs) +static BlockStats *bdrv_query_stats (const BlockDriverState *bs, +bool query_backing) {BlockStats *s;@@ -352,12 +353,12 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs)if (bs->file) { s->has_parent = true; - s->parent =bdrv_query_stats (bs->file); + s->parent =bdrv_query_stats (bs->file, query_backing); }Quoted 8 lines
block/qapi.c static BlockStats *bdrv_query_stats(const BlockDriverState *bs) · line 362
Quoted 6 lines
block/qapi.c +2
-2-if (bs->backing_hd) { +if (query_backing && bs->backing_hd) { s->has_backing = true; - s->backing =bdrv_query_stats (bs->backing_hd); + s->backing =bdrv_query_stats (bs->backing_hd, query_backing); }Is there a specific reason why you're not querying the backing chain but still recurse to
bs->file?
Quoted 3 lines
Unlike its backing, there can be some information in ->file which is interesting to the node itself, because it is ->file carries out the actual read/write on the image. Makes sense?
Ah, I forgot to answer. Well, ->backing carries out reads, too. I thought you omitted it because you could give it a node-name as well and therefore you'd have some BDS appear twice; but the same applies to ->file, that's why I asked.
Max
Re: [Qemu-devel] [PATCH 4/4] qmp: Add optional switch "query-nodes" in query-blockstats
In reply to Fam ZhengQuoted 13 lines · Fam Zheng
This bool option will allow query all the node names. It iterates all the BDSes that are assigned a name, also in this case don't query up the backing chain.
Signed-off-by Fam Zheng <[email protected]>--- block/qapi.c | 20 +++++++++++++------- hmp.c | 2 +- qapi/block-core.json | 4 +++- qmp-commands.hx | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-)
block/qapi.c BlockInfoList *qmp_query_block(Error **errp) · line 399
Quoted 10 lines
block/qapi.c +4
-2-BlockStatsList *qmp_query_blockstats (Error **errp) +BlockStatsList *qmp_query_blockstats (bool has_query_nodes, +bool query_nodes, +Error **errp) {BlockStatsList *head =NULL , **p_next = &head;BlockDriverState *bs =NULL ; -while ((bs =bdrv_next (bs))) { +/* Just to be safe if query_nodes is not always intialized */
s/intialized/initialized/
Quoted 1 line
+
query_nodes=query_nodes&&has_query_nodes;
If things aren't initialized (was true a while ago, but we recently fixed that to ensure 0 initialization, although no one yet really relies on the guarantee), then valgrind could complain of a branch on an uninit memory location. Idiomatically, this is usually written:
query_nodes = has_query_nodes && query_nodes;
to pacify valgrind if we hadn't zero-initialized; although logically, the result is identical, so I don't care if you leave it.
qapi/block-core.json line 439
Quoted 9 lines
+++
b/qapi/block-core.jsonqapi/block-core.json +3
-1@@ -434,7 +434,9 @@ # # Since: 0.14.0 ## -{ 'command': 'query-blockstats', 'returns': ['BlockStats'] } +{ 'command': 'query-blockstats', + 'data': {'*query-nodes': 'bool' }, + 'returns': ['BlockStats'] }
Max correctly pointed out that this is missing documentation.
The idea looks sane; it will visit all named nodes (whether or not those nodes are also reachable from named devices), and omit any unnamed nodes (right now, libvirt would have to be taught to name nodes, or Jeff's patch to auto-name nodes will avoid that problem).
Hmm, I wonder - if we are adding an optional parameter that controls what to iterate over, should we also add an optional parameter that says to limit the output to a given input name? Then again, we don't have very many existing query-* commands that filter, and at any rate, adding such a filter should be its own patch.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH 4/4] qmp: Add optional switch "query-nodes" in query-blockstats
Quoted 27 lines · Eric Blake
Quoted 13 lines · Fam Zheng
This bool option will allow query all the node names. It iterates all the BDSes that are assigned a name, also in this case don't query up the backing chain.
Signed-off-by Fam Zheng <[email protected]>--- block/qapi.c | 20 +++++++++++++------- hmp.c | 2 +- qapi/block-core.json | 4 +++- qmp-commands.hx | 2 +- 4 files changed, 18 insertions(+), 10 deletions(-)block/qapi.c BlockInfoList *qmp_query_block(Error **errp) · line 399
Quoted 10 lines
block/qapi.c +4
-2-BlockStatsList *qmp_query_blockstats (Error **errp) +BlockStatsList *qmp_query_blockstats (bool has_query_nodes, +bool query_nodes, +Error **errp) {BlockStatsList *head =NULL , **p_next = &head;BlockDriverState *bs =NULL ; -while ((bs =bdrv_next (bs))) { +/* Just to be safe if query_nodes is not always intialized */ s/intialized/initialized/
Quoted 8 lines
Quoted 1 line
+
query_nodes=query_nodes&&has_query_nodes;If things aren't initialized (was true a while ago, but we recently fixed that to ensure 0 initialization, although no one yet really relies on the guarantee), then valgrind could complain of a branch on an uninit memory location. Idiomatically, this is usually written:
query_nodes=has_query_nodes&&query_nodes;
This does read better. Will fix.
Quoted 21 lines
to pacify valgrind if we hadn't zero-initialized; although logically, the result is identical, so I don't care if you leave it.
qapi/block-core.json line 439
Quoted 9 lines
+++
b/qapi/block-core.jsonqapi/block-core.json +3
-1@@ -434,7 +434,9 @@ # # Since: 0.14.0 ## -{ 'command': 'query-blockstats', 'returns': ['BlockStats'] } +{ 'command': 'query-blockstats', + 'data': {'*query-nodes': 'bool' }, + 'returns': ['BlockStats'] }Max correctly pointed out that this is missing documentation.
The idea looks sane; it will visit all named nodes (whether or not those nodes are also reachable from named devices), and omit any unnamed nodes (right now, libvirt would have to be taught to name nodes, or Jeff's patch to auto-name nodes will avoid that problem).
Quoted 5 lines
Hmm, I wonder - if we are adding an optional parameter that controls what to iterate over, should we also add an optional parameter that says to limit the output to a given input name? Then again, we don't have very many existing query-* commands that filter, and at any rate, adding such a filter should be its own patch.
Or separate series :)
Thanks,
Fam
Quoted 4 lines · Fam Zheng
This series adds an optional bool parameter "query-nodes" to query-blockstats.
By default, if omitted, the behavior is unchanged.
Quoted 8 lines
If set to "true", the command will iterate through all named nodes in BDS graph and report the statistics in a list, similarly. But the backing chain is not built.
This provides a way for libvirt to watch the allocation status (
wr_highest_offset) of target image. Now, libvirt can start drive-mirror job specifying a node-name parameter. Thus the created target image gets a node name that can be queried with the new query-blockstats.
Well, only if libvirt actually starts naming the node at the destination of a drive-mirror job (doesn't happen now, but this patch shifts the blame from "qemu doesn't provide access to the information" over to "libvirt hasn't yet been coded to interact with what qemu provides"), so this is a step in the right direction. The idea makes sense to me.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org