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 v2] Fix for qemu-img info to supply FORMAT values for SPARSE extents
Date: Tue, 1 Apr 2014 17:49:54 -0400 [thread overview]
Message-ID: <20140401214954.GA2902@smaugslair> (raw)
This patch fixes the bug in qemu-img info that wouldn't populate the extent type for default formats.
The extent type has now been set where necessary. This is the second version in the series after inputs
from Fam Zheng(famz@redhat.com).
Signed-off-by: Shwetha Mathangi Chandra Choodamani <saphira.brightscales@gmail.com>
---
block/vmdk.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 49 insertions(+), 4 deletions(-)
diff --git a/block/vmdk.c b/block/vmdk.c
index b69988d..d4a37ad 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -499,6 +499,18 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
VMDK3Header header;
VmdkExtent *extent;
+ 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);
+ sscanf(buf, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,
+ access, §ors, type, fname, &flat_offset);
ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
if (ret < 0) {
error_setg_errno(errp, -ret,
@@ -515,6 +527,18 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
le32_to_cpu(header.granularity),
&extent,
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++;
+ }
+ }
+ extent->type = g_strdup(type);
if (ret < 0) {
return ret;
}
@@ -523,6 +547,7 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
/* free extent allocated by vmdk_add_extent */
vmdk_free_last_extent(bs);
}
+ g_free(buf);
return ret;
}
@@ -566,7 +591,11 @@ 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) {
error_setg_errno(errp, -ret,
@@ -586,11 +615,9 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
return ret;
}
}
-
if (!s->create_type) {
s->create_type = g_strdup("monolithicSparse");
}
-
if (le64_to_cpu(header.gd_offset) == VMDK4_GD_AT_END) {
/*
* The footer takes precedence over the header, so read it in. The
@@ -694,6 +721,25 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
g_free(s->create_type);
s->create_type = g_strdup("streamOptimized");
}
+
+ if (!extent->type) {
+ uint64_t desc_offset = le64_to_cpu(header.desc_offset);
+ char *buf = vmdk_read_desc(file, desc_offset<<9, errp);
+ sscanf(buf, "%10s %" SCNd64 " %10s \"%511[^\n\r\"]\" %" SCNd64,
+ access, §ors, type, fname, &flat_offset);
+ 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);
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;
@@ -711,7 +757,6 @@ static int vmdk_parse_description(const char *desc, const char *opt_name,
{
char *opt_pos, *opt_end;
const char *end = desc + strlen(desc);
-
opt_pos = strstr(desc, opt_name);
if (!opt_pos) {
return VMDK_ERROR;
--
1.7.9.5
next reply other threads:[~2014-04-01 21:50 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-04-01 21:49 Shwetha Mathangi Chandra Choodamani [this message]
2014-04-01 23:15 ` [Qemu-devel] [PATCH v2] Fix for qemu-img info to supply FORMAT values for SPARSE extents Eric Blake
2014-04-02 2:14 ` 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=20140401214954.GA2902@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).