aboutsummaryrefslogtreecommitdiff
path: root/block/qapi.c
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2017-02-13 10:16:23 +0000
committerPeter Maydell <peter.maydell@linaro.org>2017-02-13 10:16:23 +0000
commit0b4384d0bb98f0016ba671b1c9cc75c2f31cd057 (patch)
treedb1dee0698068c944569f72e325dc816065cc86d /block/qapi.c
parented3d90df7c75203d9d4bae135f0a3c75be209f78 (diff)
parent10d6eda1926804a09aa0710ca62933087813de0b (diff)
downloadqemu-0b4384d0bb98f0016ba671b1c9cc75c2f31cd057.zip
qemu-0b4384d0bb98f0016ba671b1c9cc75c2f31cd057.tar.gz
qemu-0b4384d0bb98f0016ba671b1c9cc75c2f31cd057.tar.bz2
Merge remote-tracking branch 'remotes/maxreitz/tags/pull-block-2017-02-12' into staging
Block patches # gpg: Signature made Sun 12 Feb 2017 01:26:20 GMT # gpg: using RSA key 0xF407DB0061D5CF40 # gpg: Good signature from "Max Reitz <mreitz@redhat.com>" # Primary key fingerprint: 91BE B60A 30DB 3E88 57D1 1829 F407 DB00 61D5 CF40 * remotes/maxreitz/tags/pull-block-2017-02-12: (21 commits) qemu-img: Avoid setting ret to unused value in img_convert() qemu-img: Use qemu_strtoul() rather than raw strtoul() qemu-io: don't allow I/O operations larger than BDRV_REQUEST_MAX_BYTES qcow2: Optimize the refcount-block overlap check qemu-io: Add failure regression tests qemu-iotests: Add _unsupported_fmt helper qemu-io: Return non-zero exit code on failure block/nfs: fix naming of runtime opts block/nfs: fix NULL pointer dereference in URI parsing block: bdrv_invalidate_cache: invalidate children first block/qapi: reduce the execution time of qmp_query_blockstats block/qapi: reduce the coupling between the bdrv_query_stats and bdrv_query_bds_stats qemu-iotest: test to lookup protocol-based image with relative backing qemu-iotests: Don't create fifos / pidfiles with protocol paths block: check full backing filename when searching protocol filenames block/vmdk: Fix the endian problem of buf_len and lba iotests: record separate timings per format,protocol pair iotests: Fix reference output for 059 qapi: Tweak error message of bdrv_query_image_info qemu-img: Improve commit invalid base message ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'block/qapi.c')
-rw-r--r--block/qapi.c99
1 files changed, 43 insertions, 56 deletions
diff --git a/block/qapi.c b/block/qapi.c
index a62e862..ac480aa 100644
--- a/block/qapi.c
+++ b/block/qapi.c
@@ -237,8 +237,8 @@ void bdrv_query_image_info(BlockDriverState *bs,
size = bdrv_getlength(bs);
if (size < 0) {
- error_setg_errno(errp, -size, "Can't get size of device '%s'",
- bdrv_get_device_name(bs));
+ error_setg_errno(errp, -size, "Can't get image size '%s'",
+ bs->exact_filename);
goto out;
}
@@ -357,10 +357,6 @@ static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info,
qapi_free_BlockInfo(info);
}
-static BlockStats *bdrv_query_stats(BlockBackend *blk,
- const BlockDriverState *bs,
- bool query_backing);
-
static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
{
BlockAcctStats *stats = blk_get_stats(blk);
@@ -428,9 +424,18 @@ static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
}
}
-static void bdrv_query_bds_stats(BlockStats *s, const BlockDriverState *bs,
+static BlockStats *bdrv_query_bds_stats(const BlockDriverState *bs,
bool query_backing)
{
+ BlockStats *s = NULL;
+
+ s = g_malloc0(sizeof(*s));
+ s->stats = g_malloc0(sizeof(*s->stats));
+
+ if (!bs) {
+ return s;
+ }
+
if (bdrv_get_node_name(bs)[0]) {
s->has_node_name = true;
s->node_name = g_strdup(bdrv_get_node_name(bs));
@@ -440,32 +445,12 @@ static void bdrv_query_bds_stats(BlockStats *s, const BlockDriverState *bs,
if (bs->file) {
s->has_parent = true;
- s->parent = bdrv_query_stats(NULL, bs->file->bs, query_backing);
+ s->parent = bdrv_query_bds_stats(bs->file->bs, query_backing);
}
if (query_backing && bs->backing) {
s->has_backing = true;
- s->backing = bdrv_query_stats(NULL, bs->backing->bs, query_backing);
- }
-
-}
-
-static BlockStats *bdrv_query_stats(BlockBackend *blk,
- const BlockDriverState *bs,
- bool query_backing)
-{
- BlockStats *s;
-
- s = g_malloc0(sizeof(*s));
- s->stats = g_malloc0(sizeof(*s->stats));
-
- if (blk) {
- s->has_device = true;
- s->device = g_strdup(blk_name(blk));
- bdrv_query_blk_stats(s->stats, blk);
- }
- if (bs) {
- bdrv_query_bds_stats(s, bs, query_backing);
+ s->backing = bdrv_query_bds_stats(bs->backing->bs, query_backing);
}
return s;
@@ -494,42 +479,44 @@ BlockInfoList *qmp_query_block(Error **errp)
return head;
}
-static bool next_query_bds(BlockBackend **blk, BlockDriverState **bs,
- bool query_nodes)
-{
- if (query_nodes) {
- *bs = bdrv_next_node(*bs);
- return !!*bs;
- }
-
- *blk = blk_next(*blk);
- *bs = *blk ? blk_bs(*blk) : NULL;
-
- return !!*blk;
-}
-
BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
bool query_nodes,
Error **errp)
{
BlockStatsList *head = NULL, **p_next = &head;
- BlockBackend *blk = NULL;
- BlockDriverState *bs = NULL;
+ BlockBackend *blk;
+ BlockDriverState *bs;
/* Just to be safe if query_nodes is not always initialized */
- query_nodes = has_query_nodes && query_nodes;
-
- while (next_query_bds(&blk, &bs, query_nodes)) {
- BlockStatsList *info = g_malloc0(sizeof(*info));
- AioContext *ctx = blk ? blk_get_aio_context(blk)
- : bdrv_get_aio_context(bs);
+ if (has_query_nodes && query_nodes) {
+ for (bs = bdrv_next_node(NULL); bs; bs = bdrv_next_node(bs)) {
+ BlockStatsList *info = g_malloc0(sizeof(*info));
+ AioContext *ctx = bdrv_get_aio_context(bs);
- aio_context_acquire(ctx);
- info->value = bdrv_query_stats(blk, bs, !query_nodes);
- aio_context_release(ctx);
+ aio_context_acquire(ctx);
+ info->value = bdrv_query_bds_stats(bs, false);
+ aio_context_release(ctx);
- *p_next = info;
- p_next = &info->next;
+ *p_next = info;
+ p_next = &info->next;
+ }
+ } else {
+ for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
+ BlockStatsList *info = g_malloc0(sizeof(*info));
+ AioContext *ctx = blk_get_aio_context(blk);
+ BlockStats *s;
+
+ aio_context_acquire(ctx);
+ s = bdrv_query_bds_stats(blk_bs(blk), true);
+ s->has_device = true;
+ s->device = g_strdup(blk_name(blk));
+ bdrv_query_blk_stats(s->stats, blk);
+ aio_context_release(ctx);
+
+ info->value = s;
+ *p_next = info;
+ p_next = &info->next;
+ }
}
return head;