238
238
size = bdrv_getlength(bs);
240
error_setg_errno(errp, -size, "Can't get size of device '%s'",
241
bdrv_get_device_name(bs));
240
error_setg_errno(errp, -size, "Can't get image size '%s'",
357
357
qapi_free_BlockInfo(info);
360
static BlockStats *bdrv_query_stats(BlockBackend *blk,
361
const BlockDriverState *bs,
364
360
static void bdrv_query_blk_stats(BlockDeviceStats *ds, BlockBackend *blk)
366
362
BlockAcctStats *stats = blk_get_stats(blk);
431
static void bdrv_query_bds_stats(BlockStats *s, const BlockDriverState *bs,
427
static BlockStats *bdrv_query_bds_stats(const BlockDriverState *bs,
432
428
bool query_backing)
430
BlockStats *s = NULL;
432
s = g_malloc0(sizeof(*s));
433
s->stats = g_malloc0(sizeof(*s->stats));
434
439
if (bdrv_get_node_name(bs)[0]) {
435
440
s->has_node_name = true;
436
441
s->node_name = g_strdup(bdrv_get_node_name(bs));
442
447
s->has_parent = true;
443
s->parent = bdrv_query_stats(NULL, bs->file->bs, query_backing);
448
s->parent = bdrv_query_bds_stats(bs->file->bs, query_backing);
446
451
if (query_backing && bs->backing) {
447
452
s->has_backing = true;
448
s->backing = bdrv_query_stats(NULL, bs->backing->bs, query_backing);
453
static BlockStats *bdrv_query_stats(BlockBackend *blk,
454
const BlockDriverState *bs,
459
s = g_malloc0(sizeof(*s));
460
s->stats = g_malloc0(sizeof(*s->stats));
463
s->has_device = true;
464
s->device = g_strdup(blk_name(blk));
465
bdrv_query_blk_stats(s->stats, blk);
468
bdrv_query_bds_stats(s, bs, query_backing);
453
s->backing = bdrv_query_bds_stats(bs->backing->bs, query_backing);
497
static bool next_query_bds(BlockBackend **blk, BlockDriverState **bs,
501
*bs = bdrv_next_node(*bs);
505
*blk = blk_next(*blk);
506
*bs = *blk ? blk_bs(*blk) : NULL;
511
482
BlockStatsList *qmp_query_blockstats(bool has_query_nodes,
512
483
bool query_nodes,
515
486
BlockStatsList *head = NULL, **p_next = &head;
516
BlockBackend *blk = NULL;
517
BlockDriverState *bs = NULL;
488
BlockDriverState *bs;
519
490
/* Just to be safe if query_nodes is not always initialized */
520
query_nodes = has_query_nodes && query_nodes;
522
while (next_query_bds(&blk, &bs, query_nodes)) {
523
BlockStatsList *info = g_malloc0(sizeof(*info));
524
AioContext *ctx = blk ? blk_get_aio_context(blk)
525
: bdrv_get_aio_context(bs);
527
aio_context_acquire(ctx);
528
info->value = bdrv_query_stats(blk, bs, !query_nodes);
529
aio_context_release(ctx);
532
p_next = &info->next;
491
if (has_query_nodes && query_nodes) {
492
for (bs = bdrv_next_node(NULL); bs; bs = bdrv_next_node(bs)) {
493
BlockStatsList *info = g_malloc0(sizeof(*info));
494
AioContext *ctx = bdrv_get_aio_context(bs);
496
aio_context_acquire(ctx);
497
info->value = bdrv_query_bds_stats(bs, false);
498
aio_context_release(ctx);
501
p_next = &info->next;
504
for (blk = blk_next(NULL); blk; blk = blk_next(blk)) {
505
BlockStatsList *info = g_malloc0(sizeof(*info));
506
AioContext *ctx = blk_get_aio_context(blk);
509
aio_context_acquire(ctx);
510
s = bdrv_query_bds_stats(blk_bs(blk), true);
511
s->has_device = true;
512
s->device = g_strdup(blk_name(blk));
513
bdrv_query_blk_stats(s->stats, blk);
514
aio_context_release(ctx);
518
p_next = &info->next;
696
683
visit_type_ImageInfoSpecific(v, NULL, &info_spec, &error_abort);
697
684
visit_complete(v, &obj);
698
assert(qobject_type(obj) == QTYPE_QDICT);
699
685
data = qdict_get(qobject_to_qdict(obj), "data");
700
686
dump_qobject(func_fprintf, f, 1, data);
701
687
qobject_decref(obj);