qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Shwetha Mathangi Chandra Choodamani <saphira.brightscales@gmail.com>
To: qemu-devel@nongnu.org
Cc: kwolf@redhat.com, famz@redhat.com, stefanha@redhat.com
Subject: [Qemu-devel] [PATCH] Fix for qemu-img info to supply FORMAT values for SPARSE extents
Date: Mon, 31 Mar 2014 12:05:55 -0400	[thread overview]
Message-ID: <20140331160555.GA4992@smaugslair> (raw)

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

             reply	other threads:[~2014-03-31 16:06 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-31 16:05 Shwetha Mathangi Chandra Choodamani [this message]
2014-04-01  2:12 ` [Qemu-devel] [PATCH] Fix for qemu-img info to supply FORMAT values for SPARSE extents Fam Zheng

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20140331160555.GA4992@smaugslair \
    --to=saphira.brightscales@gmail.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).