|
|
9ae3a8 |
From 09b91873d124019c0ddfc5c714191443a010f581 Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <09b91873d124019c0ddfc5c714191443a010f581.1418766606.git.jen@redhat.com>
|
|
|
9ae3a8 |
In-Reply-To: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
|
|
|
9ae3a8 |
References: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
|
|
|
9ae3a8 |
From: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Date: Thu, 4 Dec 2014 00:05:05 -0600
|
|
|
9ae3a8 |
Subject: [CHANGE 11/31] vmdk: extract vmdk_read_desc
|
|
|
9ae3a8 |
To: rhvirt-patches@redhat.com,
|
|
|
9ae3a8 |
jen@redhat.com
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1417651524-18041-12-git-send-email-famz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 62684
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1 qemu-kvm PATCH v5 11/30] vmdk: extract vmdk_read_desc
|
|
|
9ae3a8 |
Bugzilla: 1134251
|
|
|
9ae3a8 |
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
From: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
Reviewed-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit a8842e6d2acc815e9660cc743bd0b0daba18c935)
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/vmdk.c | 41 ++++++++++++++++++++++++++++++-----------
|
|
|
9ae3a8 |
1 file changed, 30 insertions(+), 11 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/vmdk.c b/block/vmdk.c
|
|
|
9ae3a8 |
index eda2962..425064c 100644
|
|
|
9ae3a8 |
--- a/block/vmdk.c
|
|
|
9ae3a8 |
+++ b/block/vmdk.c
|
|
|
9ae3a8 |
@@ -529,6 +529,32 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
|
|
|
9ae3a8 |
uint64_t desc_offset, Error **errp);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset,
|
|
|
9ae3a8 |
+ Error **errp)
|
|
|
9ae3a8 |
+{
|
|
|
9ae3a8 |
+ int64_t size;
|
|
|
9ae3a8 |
+ char *buf;
|
|
|
9ae3a8 |
+ int ret;
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ size = bdrv_getlength(file);
|
|
|
9ae3a8 |
+ if (size < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -size, "Could not access file");
|
|
|
9ae3a8 |
+ return NULL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ size = MIN(size, 1 << 20); /* avoid unbounded allocation */
|
|
|
9ae3a8 |
+ buf = g_malloc0(size + 1);
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ ret = bdrv_pread(file, desc_offset, buf, size);
|
|
|
9ae3a8 |
+ if (ret < 0) {
|
|
|
9ae3a8 |
+ error_setg_errno(errp, -ret, "Could not read from file");
|
|
|
9ae3a8 |
+ g_free(buf);
|
|
|
9ae3a8 |
+ return NULL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ return buf;
|
|
|
9ae3a8 |
+}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
static int vmdk_open_vmdk4(BlockDriverState *bs,
|
|
|
9ae3a8 |
BlockDriverState *file,
|
|
|
9ae3a8 |
int flags, Error **errp)
|
|
|
9ae3a8 |
@@ -823,23 +849,16 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
|
|
|
9ae3a8 |
uint64_t desc_offset, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
- char *buf = NULL;
|
|
|
9ae3a8 |
+ char *buf;
|
|
|
9ae3a8 |
char ct[128];
|
|
|
9ae3a8 |
BDRVVmdkState *s = bs->opaque;
|
|
|
9ae3a8 |
- int64_t size;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- size = bdrv_getlength(bs->file);
|
|
|
9ae3a8 |
- if (size < 0) {
|
|
|
9ae3a8 |
+ buf = vmdk_read_desc(bs->file, desc_offset, errp);
|
|
|
9ae3a8 |
+ if (!buf) {
|
|
|
9ae3a8 |
return -EINVAL;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- size = MIN(size, 1 << 20); /* avoid unbounded allocation */
|
|
|
9ae3a8 |
- buf = g_malloc0(size + 1);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- ret = bdrv_pread(bs->file, desc_offset, buf, size);
|
|
|
9ae3a8 |
- if (ret < 0) {
|
|
|
9ae3a8 |
goto exit;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
if (vmdk_parse_description(buf, "createType", ct, sizeof(ct))) {
|
|
|
9ae3a8 |
error_setg(errp, "invalid VMDK image descriptor");
|
|
|
9ae3a8 |
ret = -EINVAL;
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
2.1.0
|
|
|
9ae3a8 |
|