[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH V5 05/13] block: add image info query function b
From: |
Kevin Wolf |
Subject: |
Re: [Qemu-devel] [PATCH V5 05/13] block: add image info query function bdrv_query_image_info() |
Date: |
Tue, 29 Jan 2013 13:55:58 +0100 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120605 Thunderbird/13.0 |
Am 24.01.2013 03:57, schrieb Wenchao Xia:
> This patch add function bdrv_query_image_info(), which will return
> image info in qmp object format. The implementation code are mostly
> copied from qemu-img.c, but use block layer function to get snapshot
> info.
Don't copy code, reuse it.
Can you move the existing qemu-img code to block.c and make qemu-img use
it from there?
> A check with bdrv_can_read_snapshot(), was done before collecting
> snapshot info.
>
> Signed-off-by: Wenchao Xia <address@hidden>
> Reviewed-by: Eric Blake <address@hidden>
> ---
> block.c | 73
> +++++++++++++++++++++++++++++++++++++++++++++++++
> include/block/block.h | 1 +
> 2 files changed, 74 insertions(+), 0 deletions(-)
>
> diff --git a/block.c b/block.c
> index 7cdb6c6..14bf653 100644
> --- a/block.c
> +++ b/block.c
> @@ -2902,6 +2902,79 @@ SnapshotInfoList
> *bdrv_query_snapshot_infolist(BlockDriverState *bs,
> return head;
> }
>
> +/* collect all internal snapshot info in a image for ImageInfo */
> +static void collect_snapshots_info(BlockDriverState *bs,
> + ImageInfo *info,
> + Error **errp)
> +{
> + SnapshotInfoList *info_list;
> +
> + if (!bdrv_can_read_snapshot(bs)) {
> + return;
> + }
> + info_list = bdrv_query_snapshot_infolist(bs, NULL, NULL, errp);
> + if (info_list != NULL) {
> + info->has_snapshots = true;
> + info->snapshots = info_list;
> + }
> +}
> +
> +static void collect_image_info(BlockDriverState *bs,
> + ImageInfo *info)
> +{
> + uint64_t total_sectors;
> + char backing_filename[1024];
> + char backing_filename2[1024];
> + BlockDriverInfo bdi;
> + const char *filename;
> +
> + filename = bdrv_get_filename(bs);
> + bdrv_get_geometry(bs, &total_sectors);
> +
> + info->filename = g_strdup(filename);
> + info->format = g_strdup(bdrv_get_format_name(bs));
> + info->virtual_size = total_sectors * 512;
> + info->actual_size = bdrv_get_allocated_file_size(bs);
> + info->has_actual_size = info->actual_size >= 0;
> + if (bdrv_is_encrypted(bs)) {
> + info->encrypted = true;
> + info->has_encrypted = true;
> + }
> + if (bdrv_get_info(bs, &bdi) >= 0) {
> + if (bdi.cluster_size != 0) {
> + info->cluster_size = bdi.cluster_size;
> + info->has_cluster_size = true;
> + }
> + info->dirty_flag = bdi.is_dirty;
> + info->has_dirty_flag = true;
> + }
> + bdrv_get_backing_filename(bs, backing_filename,
> sizeof(backing_filename));
No need to copy this, you can directly access bs->backing_file.
Kevin
- Re: [Qemu-devel] [PATCH V5 02/13] block: add bdrv_get_filename() function, (continued)
- [Qemu-devel] [PATCH V5 04/13] block: add snapshot info query function bdrv_query_snapshot_infolist(), Wenchao Xia, 2013/01/23
- [Qemu-devel] [PATCH V5 05/13] block: add image info query function bdrv_query_image_info(), Wenchao Xia, 2013/01/23
- Re: [Qemu-devel] [PATCH V5 05/13] block: add image info query function bdrv_query_image_info(),
Kevin Wolf <=
- [Qemu-devel] [PATCH V5 06/13] qemu-img: switch image retrieving function, Wenchao Xia, 2013/01/23
- [Qemu-devel] [PATCH V5 07/13] block: rename bdrv_query_info to bdrv_query_block_info, Wenchao Xia, 2013/01/23
[Qemu-devel] [PATCH V5 09/13] block: export function bdrv_find_snapshot(), Wenchao Xia, 2013/01/23