Re: [Qemu-devel] [PATCH v3 2/2] vmdk: Implment bdrv_get_specific_info

2013-10-17 Thread Stefan Hajnoczi
On Fri, Oct 11, 2013 at 08:08:35PM +0800, Fam Zheng wrote:
 @@ -814,6 +821,7 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int 
 flags,
  ret = -ENOTSUP;
  goto exit;
  }
 +s-create_type = g_strdup(ct);

Where is this freed if opening the file fails?



[Qemu-devel] [PATCH v3 2/2] vmdk: Implment bdrv_get_specific_info

2013-10-11 Thread Fam Zheng
Implement .bdrv_get_specific_info to return the extent information.

Signed-off-by: Fam Zheng f...@redhat.com
---
 block/vmdk.c   | 57 +-
 qapi-schema.json   | 24 ++-
 tests/qemu-iotests/059 |  2 +-
 tests/qemu-iotests/059.out |  5 ++--
 4 files changed, 82 insertions(+), 6 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index 709aa3d..047b4b3 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -106,17 +106,20 @@ typedef struct VmdkExtent {
 uint32_t l2_cache_counts[L2_CACHE_SIZE];
 
 int64_t cluster_sectors;
+char *type;
 } VmdkExtent;
 
 typedef struct BDRVVmdkState {
 CoMutex lock;
 uint64_t desc_offset;
 bool cid_updated;
+uint32_t cid;
 uint32_t parent_cid;
 int num_extents;
 /* Extent array with num_extents entries, ascend ordered by address */
 VmdkExtent *extents;
 Error *migration_blocker;
+char *create_type;
 } BDRVVmdkState;
 
 typedef struct VmdkMetaData {
@@ -215,6 +218,7 @@ static void vmdk_free_extents(BlockDriverState *bs)
 g_free(e-l1_table);
 g_free(e-l2_cache);
 g_free(e-l1_backup_table);
+g_free(e-type);
 if (e-file != bs-file) {
 bdrv_unref(e-file);
 }
@@ -711,6 +715,8 @@ static int vmdk_parse_extents(const char *desc, 
BlockDriverState *bs,
 int64_t flat_offset;
 char extent_path[PATH_MAX];
 BlockDriverState *extent_file;
+BDRVVmdkState *s = bs-opaque;
+VmdkExtent *extent;
 
 while (*p) {
 /* parse extent line:
@@ -751,7 +757,6 @@ static int vmdk_parse_extents(const char *desc, 
BlockDriverState *bs,
 /* save to extents array */
 if (!strcmp(type, FLAT) || !strcmp(type, VMFS)) {
 /* FLAT extent */
-VmdkExtent *extent;
 
 ret = vmdk_add_extent(bs, extent_file, true, sectors,
 0, 0, 0, 0, 0, extent, errp);
@@ -766,10 +771,12 @@ static int vmdk_parse_extents(const char *desc, 
BlockDriverState *bs,
 bdrv_unref(extent_file);
 return ret;
 }
+extent = s-extents[s-num_extents - 1];
 } else {
 error_setg(errp, Unsupported extent type '%s', type);
 return -ENOTSUP;
 }
+extent-type = g_strdup(type);
 next_line:
 /* move to next line */
 while (*p  *p != '\n') {
@@ -814,6 +821,7 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int 
flags,
 ret = -ENOTSUP;
 goto exit;
 }
+s-create_type = g_strdup(ct);
 s-desc_offset = 0;
 ret = vmdk_parse_extents(buf, bs, bs-file-filename, errp);
 exit:
@@ -1763,6 +1771,7 @@ static void vmdk_close(BlockDriverState *bs)
 BDRVVmdkState *s = bs-opaque;
 
 vmdk_free_extents(bs);
+g_free(s-create_type);
 
 migrate_del_blocker(s-migration_blocker);
 error_free(s-migration_blocker);
@@ -1824,6 +1833,51 @@ static int vmdk_has_zero_init(BlockDriverState *bs)
 return 1;
 }
 
+static ImageInfo *vmdk_get_extent_info(VmdkExtent *extent)
+{
+ImageInfo *info = g_new0(ImageInfo, 1);
+
+*info = (ImageInfo){
+.filename = g_strdup(extent-file-filename),
+.format   = g_strdup(extent-type),
+.virtual_size = extent-sectors * BDRV_SECTOR_SIZE,
+.compressed   = extent-compressed,
+.has_compressed   = extent-compressed,
+.cluster_size = extent-cluster_sectors * BDRV_SECTOR_SIZE,
+.has_cluster_size = !extent-flat,
+};
+
+return info;
+}
+
+static ImageInfoSpecific *vmdk_get_specific_info(BlockDriverState *bs)
+{
+int i;
+BDRVVmdkState *s = bs-opaque;
+ImageInfoSpecific *spec_info = g_new0(ImageInfoSpecific, 1);
+ImageInfoList **next;
+
+*spec_info = (ImageInfoSpecific){
+.kind = IMAGE_INFO_SPECIFIC_KIND_VMDK,
+.vmdk = g_new0(ImageInfoSpecificVmdk, 1),
+};
+
+*spec_info-vmdk = (ImageInfoSpecificVmdk) {
+.create_type = g_strdup(s-create_type),
+.cid = s-cid,
+};
+
+next = spec_info-vmdk-extents;
+for (i = 0; i  s-num_extents; i++) {
+*next = g_new0(ImageInfoList, 1);
+(*next)-value = vmdk_get_extent_info(s-extents[i]);
+(*next)-next = NULL;
+next = (*next)-next;
+}
+
+return spec_info;
+}
+
 static QEMUOptionParameter vmdk_create_options[] = {
 {
 .name = BLOCK_OPT_SIZE,
@@ -1876,6 +1930,7 @@ 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_specific_info   = vmdk_get_specific_info,
 
 .create_options   = vmdk_create_options,
 };
diff --git a/qapi-schema.json b/qapi-schema.json
index add97e2..ca21733 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -225,6 +225,27 @@
   } }