Fix for qemu-img info to supply FORMAT values for SPARSE extents
PATCH 1/1 Fix for qemu-img info to supply FORMAT values for SPARSE extents
This patch fixes the qemu-img info bug to return the right format of an extent. Changes applicable to both VMDK3 and VMDK4 type headers.
--- block/vmdk.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
block/vmdk.c +42 -0
@@ -515,6 +515,28 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,le32_to_cpu (header.granularity), &extent, errp); +char access[11 ]; +char type[11 ]; +char fname[512 ]; +int64_t sectors =0 ; +int64_t flat_offset; +int64_t size; + size =bdrv_getlength (file); +char *buf; + buf =g_malloc0 (size +1 ); +bdrv_pread (file,sizeof (magic), buf, size); +while (strcmp (access,"RW" )) { +while (*buf) { +sscanf (buf,"%10s %" SCNd64" %10s \"%511[^\n\r\"]\" %" SCNd64, + access, §ors, type, fname, &flat_offset); +if (*buf =='\n' ) { + buf++; +break ; + } + buf++; + } + } + extent->type =g_strdup (type);if (ret <0 ) {return ret; }
@@ -566,6 +588,12 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,VmdkExtent *extent;BDRVVmdkState *s = bs->opaque;int64_t l1_backup_offset =0 ; +char access[11 ]; +char type[11 ]; +char fname[512 ]; +int64_t sectors =0 ; +int64_t flat_offset; + ret =bdrv_pread (file,sizeof (magic), &header,sizeof (header));if (ret <0 ) {
@@ -589,6 +617,19 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,if (!s->create_type) { s->create_type =g_strdup ("monolithicSparse" ); +uint64_t desc_offset =le64_to_cpu (header.desc_offset); +char *buf =vmdk_read_desc (file, desc_offset<<9 , errp); +while (strcmp (access,"RW" )) { +while (*buf) { +sscanf (buf,"%10s %" SCNd64" %10s \"%511[^\n\r\"]\" %" SCNd64, + access, §ors, type, fname, &flat_offset); +if (*buf =='\n' ) { + buf++; +break ; + } + buf++; + } + } }if (le64_to_cpu (header.gd_offset) ==VMDK4_GD_AT_END ) {
@@ -697,6 +738,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, extent->has_marker =le32_to_cpu (header.flags) &VMDK4_FLAG_MARKER ; extent->version =le32_to_cpu (header.version); extent->has_zero_grain =le32_to_cpu (header.flags) &VMDK4_FLAG_ZERO_GRAIN ; + extent->type =g_strdup (type); ret =vmdk_init_tables (bs, extent, errp);if (ret) {/* free extent allocated by vmdk_add_extent */
Signature · 1 line
1.7.9.5
Quoted 12 lines · Shwetha Mathangi Chandra Choodamani
This patch fixes the qemu-img info bug to return the right format of an extent. Changes applicable to both VMDK3 and VMDK4 type headers.
Signed-off-by Shwetha Mathangi Chandra Choodamani <[email protected]>--- block/vmdk.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)block/vmdk.c +0
-0@@ -515,6 +515,28 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs, le32_to_cpu(header.granularity),
block/vmdk.c static int vmdk_open_vmfs_sparse(BlockDriverState *bs, · line 525
Quoted 10 lines
block/vmdk.c +8
-0&extent, errp); +char access[11 ]; +char type[11 ]; +char fname[512 ]; +int64_t sectors =0 ; +int64_t flat_offset; +int64_t size; + size =bdrv_getlength (file); +char *buf;
Please put variable declarations in the beginning of code block.
block/vmdk.c static int vmdk_open_vmfs_sparse(BlockDriverState *bs, · line 526
Quoted 1 line
block/vmdk.c +1
-0+ buf =g_malloc0 (size +1 );
buf is allocated and incremented, but the buffer is never released.
block/vmdk.c static int vmdk_open_vmfs_sparse(BlockDriverState *bs, · line 528
Quoted 2 lines
block/vmdk.c +2
-0+bdrv_pread (file,sizeof (magic), buf, size); +while (strcmp (access,"RW" )) {
access is used before initialization. Does this work?
block/vmdk.c static int vmdk_open_vmfs_sparse(BlockDriverState *bs, · line 531
Quoted 3 lines
block/vmdk.c +3
-0+while (*buf) { +sscanf (buf,"%10s %" SCNd64" %10s \"%511[^\n\r\"]\" %" SCNd64, + access, §ors, type, fname, &flat_offset);
Better to align the parameters with first line:
access, §ors, ...);
However I don't think VMDK3 needs this fix, what we care here is monolithicSparse, which is specifically VMDK4.
Quoted 25 lines
block/vmdk.c +14
-0+if (*buf =='\n' ) { + buf++; +break ; + } + buf++; + } + } + extent->type =g_strdup (type);if (ret <0 ) {return ret; }@@ -566,6 +588,12 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,VmdkExtent *extent;BDRVVmdkState *s = bs->opaque;int64_t l1_backup_offset =0 ; +char access[11 ]; +char type[11 ]; +char fname[512 ]; +int64_t sectors =0 ; +int64_t flat_offset; + ret =bdrv_pread (file,sizeof (magic), &header,sizeof (header));if (ret <0 ) {
block/vmdk.c static int vmdk_open_vmdk4(BlockDriverState *bs, · line 619
Quoted 3 lines
block/vmdk.c +0
-0@@ -589,6 +617,19 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,if (!s->create_type) { s->create_type =g_strdup ("monolithicSparse" );
For VMDK4, this duplicates with vmdk_parse_extents(). I think this patch can be simplified by moving this if block after vmdk_add_extent, where the "extent" variable is set and we can set its type field safely.
And please fix in the same way for streamOptimized.
Thanks,
Fam
Quoted 27 lines
block/vmdk.c +14
-0+uint64_t desc_offset =le64_to_cpu (header.desc_offset); +char *buf =vmdk_read_desc (file, desc_offset<<9 , errp); +while (strcmp (access,"RW" )) { +while (*buf) { +sscanf (buf,"%10s %" SCNd64" %10s \"%511[^\n\r\"]\" %" SCNd64, + access, §ors, type, fname, &flat_offset); +if (*buf =='\n' ) { + buf++; +break ; + } + buf++; + } + } }if (le64_to_cpu (header.gd_offset) ==VMDK4_GD_AT_END ) {@@ -697,6 +738,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs, extent->has_marker =le32_to_cpu (header.flags) &VMDK4_FLAG_MARKER ; extent->version =le32_to_cpu (header.version); extent->has_zero_grain =le32_to_cpu (header.flags) &VMDK4_FLAG_ZERO_GRAIN ; + extent->type =g_strdup (type); ret =vmdk_init_tables (bs, extent, errp);if (ret) {/* free extent allocated by vmdk_add_extent */ Signature · 1 line
1.7.9.5