diff options
Diffstat (limited to 'block/qapi.c')
-rw-r--r-- | block/qapi.c | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/block/qapi.c b/block/qapi.c index f44f6b401..a87a34a8b 100644 --- a/block/qapi.c +++ b/block/qapi.c @@ -28,6 +28,7 @@ #include "qapi-visit.h" #include "qapi/qmp-output-visitor.h" #include "qapi/qmp/types.h" +#include "sysemu/block-backend.h" BlockDeviceInfo *bdrv_block_device_info(BlockDriverState *bs) { @@ -165,19 +166,25 @@ void bdrv_query_image_info(BlockDriverState *bs, ImageInfo **p_info, Error **errp) { - uint64_t total_sectors; + int64_t size; const char *backing_filename; char backing_filename2[1024]; BlockDriverInfo bdi; int ret; Error *err = NULL; - ImageInfo *info = g_new0(ImageInfo, 1); + ImageInfo *info; - bdrv_get_geometry(bs, &total_sectors); + size = bdrv_getlength(bs); + if (size < 0) { + error_setg_errno(errp, -size, "Can't get size of device '%s'", + bdrv_get_device_name(bs)); + return; + } + info = g_new0(ImageInfo, 1); info->filename = g_strdup(bs->filename); info->format = g_strdup(bdrv_get_format_name(bs)); - info->virtual_size = total_sectors * 512; + info->virtual_size = size; info->actual_size = bdrv_get_allocated_file_size(bs); info->has_actual_size = info->actual_size >= 0; if (bdrv_is_encrypted(bs)) { @@ -236,22 +243,22 @@ void bdrv_query_image_info(BlockDriverState *bs, } /* @p_info will be set only on success. */ -void bdrv_query_info(BlockDriverState *bs, - BlockInfo **p_info, - Error **errp) +static void bdrv_query_info(BlockBackend *blk, BlockInfo **p_info, + Error **errp) { BlockInfo *info = g_malloc0(sizeof(*info)); + BlockDriverState *bs = blk_bs(blk); BlockDriverState *bs0; ImageInfo **p_image_info; Error *local_err = NULL; - info->device = g_strdup(bs->device_name); + info->device = g_strdup(blk_name(blk)); info->type = g_strdup("unknown"); - info->locked = bdrv_dev_is_medium_locked(bs); - info->removable = bdrv_dev_has_removable_media(bs); + info->locked = blk_dev_is_medium_locked(blk); + info->removable = blk_dev_has_removable_media(blk); - if (bdrv_dev_has_removable_media(bs)) { + if (blk_dev_has_removable_media(blk)) { info->has_tray_open = true; - info->tray_open = bdrv_dev_is_tray_open(bs); + info->tray_open = blk_dev_is_tray_open(blk); } if (bdrv_iostatus_is_enabled(bs)) { @@ -299,21 +306,22 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs) s = g_malloc0(sizeof(*s)); - if (bs->device_name[0]) { + if (bdrv_get_device_name(bs)[0]) { s->has_device = true; - s->device = g_strdup(bs->device_name); + s->device = g_strdup(bdrv_get_device_name(bs)); } s->stats = g_malloc0(sizeof(*s->stats)); - s->stats->rd_bytes = bs->nr_bytes[BDRV_ACCT_READ]; - s->stats->wr_bytes = bs->nr_bytes[BDRV_ACCT_WRITE]; - s->stats->rd_operations = bs->nr_ops[BDRV_ACCT_READ]; - s->stats->wr_operations = bs->nr_ops[BDRV_ACCT_WRITE]; - s->stats->wr_highest_offset = bs->wr_highest_sector * BDRV_SECTOR_SIZE; - s->stats->flush_operations = bs->nr_ops[BDRV_ACCT_FLUSH]; - s->stats->wr_total_time_ns = bs->total_time_ns[BDRV_ACCT_WRITE]; - s->stats->rd_total_time_ns = bs->total_time_ns[BDRV_ACCT_READ]; - s->stats->flush_total_time_ns = bs->total_time_ns[BDRV_ACCT_FLUSH]; + s->stats->rd_bytes = bs->stats.nr_bytes[BLOCK_ACCT_READ]; + s->stats->wr_bytes = bs->stats.nr_bytes[BLOCK_ACCT_WRITE]; + s->stats->rd_operations = bs->stats.nr_ops[BLOCK_ACCT_READ]; + s->stats->wr_operations = bs->stats.nr_ops[BLOCK_ACCT_WRITE]; + s->stats->wr_highest_offset = + bs->stats.wr_highest_sector * BDRV_SECTOR_SIZE; + s->stats->flush_operations = bs->stats.nr_ops[BLOCK_ACCT_FLUSH]; + s->stats->wr_total_time_ns = bs->stats.total_time_ns[BLOCK_ACCT_WRITE]; + s->stats->rd_total_time_ns = bs->stats.total_time_ns[BLOCK_ACCT_READ]; + s->stats->flush_total_time_ns = bs->stats.total_time_ns[BLOCK_ACCT_FLUSH]; if (bs->file) { s->has_parent = true; @@ -331,12 +339,12 @@ static BlockStats *bdrv_query_stats(const BlockDriverState *bs) BlockInfoList *qmp_query_block(Error **errp) { BlockInfoList *head = NULL, **p_next = &head; - BlockDriverState *bs = NULL; + BlockBackend *blk; Error *local_err = NULL; - while ((bs = bdrv_next(bs))) { + for (blk = blk_next(NULL); blk; blk = blk_next(blk)) { BlockInfoList *info = g_malloc0(sizeof(*info)); - bdrv_query_info(bs, &info->value, &local_err); + bdrv_query_info(blk, &info->value, &local_err); if (local_err) { error_propagate(errp, local_err); goto err; |