All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] Fix for qemu-img info to supply FORMAT values for SPARSE extents
@ 2014-03-31 16:05 Shwetha Mathangi Chandra Choodamani
  2014-04-01  2:12 ` Fam Zheng
  0 siblings, 1 reply; 2+ messages in thread
From: Shwetha Mathangi Chandra Choodamani @ 2014-03-31 16:05 UTC (permalink / raw)
  To: qemu-devel; +Cc: kwolf, famz, stefanha

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 <saphira.brightscales@gmail.com>
---
 block/vmdk.c |   42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/block/vmdk.c b/block/vmdk.c
index b69988d..81fcb92 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -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, &sectors, 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, &sectors, 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 */
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [Qemu-devel] [PATCH] Fix for qemu-img info to supply FORMAT values for SPARSE extents
  2014-03-31 16:05 [Qemu-devel] [PATCH] Fix for qemu-img info to supply FORMAT values for SPARSE extents Shwetha Mathangi Chandra Choodamani
@ 2014-04-01  2:12 ` Fam Zheng
  0 siblings, 0 replies; 2+ messages in thread
From: Fam Zheng @ 2014-04-01  2:12 UTC (permalink / raw)
  To: Shwetha Mathangi Chandra Choodamani; +Cc: kwolf, qemu-devel, stefanha

On Mon, 03/31 12:05, Shwetha Mathangi Chandra Choodamani wrote:
> 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 <saphira.brightscales@gmail.com>
> ---
>  block/vmdk.c |   42 ++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 42 insertions(+)
> 
> diff --git a/block/vmdk.c b/block/vmdk.c
> index b69988d..81fcb92 100644
> --- a/block/vmdk.c
> +++ b/block/vmdk.c
> @@ -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;

Please put variable declarations in the beginning of code block.

> +    buf = g_malloc0(size + 1);

buf is allocated and incremented, but the buffer is never released.

> +    bdrv_pread(file, sizeof(magic), buf, size);
> +    while (strcmp(access, "RW")) {

access is used before initialization. Does this work?

> +        while (*buf) {
> +            sscanf(buf, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,
> +             access, &sectors, type, fname, &flat_offset);

Better to align the parameters with first line:

                      access, &sectors, ...);


However I don't think VMDK3 needs this fix, what we care here is
monolithicSparse, which is specifically VMDK4.

> +            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");

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

> +        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, &sectors, 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 */
> -- 
> 1.7.9.5
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-04-01  2:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-31 16:05 [Qemu-devel] [PATCH] Fix for qemu-img info to supply FORMAT values for SPARSE extents Shwetha Mathangi Chandra Choodamani
2014-04-01  2:12 ` Fam Zheng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.