Received: from eggs.gnu.org ([2001:4830:134:3::10]:41674) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUALF-0005Wm-70 for qemu-devel@nongnu.org; Thu, 10 Oct 2013 03:07:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VUAL9-0006jj-6O for qemu-devel@nongnu.org; Thu, 10 Oct 2013 03:07:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VUAL8-0006ja-T1 for qemu-devel@nongnu.org; Thu, 10 Oct 2013 03:07:19 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r9A778Dm017106 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 10 Oct 2013 03:07:08 -0400 From: Fam Zheng Date: Thu, 10 Oct 2013 15:07:04 +0800 Message-Id: <1381388824-14999-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH] vmdk: implment bdrv_get_info and bdrv_get_specific_info List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, famz@redhat.com, stefanha@redhat.com .bdrv_get_info reports cluster_size if it's a monolithic image. .bdrv_get_specific_info reports the image version (if applicable) and extent file name list. Signed-off-by: Fam Zheng --- block/vmdk.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ qapi-schema.json | 14 +++++++++++++- 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/block/vmdk.c b/block/vmdk.c index 5d56e31..ff9bdac 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -1814,6 +1814,48 @@ static int vmdk_has_zero_init(BlockDriverState *bs) return 1; } +static int vmdk_get_info(BlockDriverState *bs, BlockDriverInfo *bdi) +{ + BDRVVmdkState *s = bs->opaque; + /* Normally the cluster sizes for all the extents in a vmdk image are the + * same, but we don't bother to check for this here and only report the + * value for the monolithic case. */ + if (s->num_extents == 1 && !s->extents[0].flat) { + bdi->cluster_size = s->extents[0].cluster_sectors * 512; + } + return 0; +} + +static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs) +{ + int i; + BDRVVmdkState *s = bs->opaque; + ImageInfoSpecific *spec_info = g_new(ImageInfoSpecific, 1); + strList **next; + + *spec_info = (ImageInfoSpecific){ + .kind = IMAGE_INFO_SPECIFIC_KIND_VMDK, + .vmdk = g_new(ImageInfoSpecificVmdk, 1), + }; + + next = &spec_info->vmdk->extents; + for (i = 0; i < s->num_extents; i++) { + *next = g_new(strList, 1); + **next = (strList){ + .value = g_strdup(s->extents[i].file->filename), + .next = NULL, + }; + next = &(*next)->next; + } + + if (s->num_extents == 1) { + spec_info->vmdk->version = s->extents[0].version; + spec_info->vmdk->has_version = true; + } + + return spec_info; +} + static QEMUOptionParameter vmdk_create_options[] = { { .name = BLOCK_OPT_SIZE, @@ -1866,6 +1908,8 @@ static BlockDriver bdrv_vmdk = { .bdrv_co_get_block_status = vmdk_co_get_block_status, .bdrv_get_allocated_file_size = vmdk_get_allocated_file_size, .bdrv_has_zero_init = vmdk_has_zero_init, + .bdrv_get_info = vmdk_get_info, + .bdrv_get_specific_info = vmdk_get_specific_info, .create_options = vmdk_create_options, }; diff --git a/qapi-schema.json b/qapi-schema.json index a1a81a4..b1e74b3 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -225,6 +225,17 @@ } } ## +# @ImageInfoSpecificVmdk: +# +# Since: 1.7 +## +{ 'type': 'ImageInfoSpecificVmdk', + 'data': { + '*version': 'int', + 'extents': ['str'] + } } + +## # @ImageInfoSpecific: # # A discriminated record of image format specific information structures. @@ -234,7 +245,8 @@ { 'union': 'ImageInfoSpecific', 'data': { - 'qcow2': 'ImageInfoSpecificQCow2' + 'qcow2': 'ImageInfoSpecificQCow2', + 'vmdk': 'ImageInfoSpecificVmdk' } } ## -- 1.8.3.1