|
|
9ae3a8 |
From feb051e6d8bc62e6b9e162ada4dc576c59edc00f Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
Message-Id: <feb051e6d8bc62e6b9e162ada4dc576c59edc00f.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:06 -0600
|
|
|
9ae3a8 |
Subject: [CHANGE 12/31] vmdk: push vmdk_read_desc up to caller
|
|
|
9ae3a8 |
To: rhvirt-patches@redhat.com,
|
|
|
9ae3a8 |
jen@redhat.com
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1417651524-18041-13-git-send-email-famz@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 62685
|
|
|
9ae3a8 |
O-Subject: [RHEL-7.1 qemu-kvm PATCH v5 12/30] vmdk: push vmdk_read_desc up to caller
|
|
|
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 |
Currently, we just try reading a VMDK file as both image and descriptor.
|
|
|
9ae3a8 |
This makes it hard to choose which of the two attempts gave the best error.
|
|
|
9ae3a8 |
We'll decide in advance if the file looks like an image or a descriptor,
|
|
|
9ae3a8 |
and this patch is the first step to that end.
|
|
|
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 d1833ef52be349e41d17e9c5ddaea8bb4ad3a7fb)
|
|
|
9ae3a8 |
Signed-off-by: Fam Zheng <famz@redhat.com>
|
|
|
9ae3a8 |
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
block/vmdk.c | 55 +++++++++++++++++++++++++++++++------------------------
|
|
|
9ae3a8 |
1 file changed, 31 insertions(+), 24 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/block/vmdk.c b/block/vmdk.c
|
|
|
9ae3a8 |
index 425064c..458bceb 100644
|
|
|
9ae3a8 |
--- a/block/vmdk.c
|
|
|
9ae3a8 |
+++ b/block/vmdk.c
|
|
|
9ae3a8 |
@@ -526,8 +526,8 @@ static int vmdk_open_vmfs_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
|
|
|
9ae3a8 |
- uint64_t desc_offset, Error **errp);
|
|
|
9ae3a8 |
+static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
|
|
|
9ae3a8 |
+ Error **errp);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset,
|
|
|
9ae3a8 |
Error **errp)
|
|
|
9ae3a8 |
@@ -576,7 +576,13 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
|
|
|
9ae3a8 |
if (header.capacity == 0) {
|
|
|
9ae3a8 |
uint64_t desc_offset = le64_to_cpu(header.desc_offset);
|
|
|
9ae3a8 |
if (desc_offset) {
|
|
|
9ae3a8 |
- return vmdk_open_desc_file(bs, flags, desc_offset << 9, errp);
|
|
|
9ae3a8 |
+ char *buf = vmdk_read_desc(file, desc_offset << 9, errp);
|
|
|
9ae3a8 |
+ if (!buf) {
|
|
|
9ae3a8 |
+ return -EINVAL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+ ret = vmdk_open_desc_file(bs, flags, buf, errp);
|
|
|
9ae3a8 |
+ g_free(buf);
|
|
|
9ae3a8 |
+ return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -727,16 +733,12 @@ static int vmdk_parse_description(const char *desc, const char *opt_name,
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/* Open an extent file and append to bs array */
|
|
|
9ae3a8 |
static int vmdk_open_sparse(BlockDriverState *bs,
|
|
|
9ae3a8 |
- BlockDriverState *file,
|
|
|
9ae3a8 |
- int flags, Error **errp)
|
|
|
9ae3a8 |
+ BlockDriverState *file, int flags,
|
|
|
9ae3a8 |
+ char *buf, Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
uint32_t magic;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (bdrv_pread(file, 0, &magic, sizeof(magic)) != sizeof(magic)) {
|
|
|
9ae3a8 |
- return -EIO;
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
- magic = be32_to_cpu(magic);
|
|
|
9ae3a8 |
+ magic = ldl_be_p(buf);
|
|
|
9ae3a8 |
switch (magic) {
|
|
|
9ae3a8 |
case VMDK3_MAGIC:
|
|
|
9ae3a8 |
return vmdk_open_vmfs_sparse(bs, file, flags, errp);
|
|
|
9ae3a8 |
@@ -821,8 +823,14 @@ static int vmdk_parse_extents(const char *desc, BlockDriverState *bs,
|
|
|
9ae3a8 |
extent->flat_start_offset = flat_offset << 9;
|
|
|
9ae3a8 |
} else if (!strcmp(type, "SPARSE") || !strcmp(type, "VMFSSPARSE")) {
|
|
|
9ae3a8 |
/* SPARSE extent and VMFSSPARSE extent are both "COWD" sparse file*/
|
|
|
9ae3a8 |
- ret = vmdk_open_sparse(bs, extent_file, bs->open_flags, errp);
|
|
|
9ae3a8 |
+ char *buf = vmdk_read_desc(extent_file, 0, errp);
|
|
|
9ae3a8 |
+ if (!buf) {
|
|
|
9ae3a8 |
+ ret = -EINVAL;
|
|
|
9ae3a8 |
+ } else {
|
|
|
9ae3a8 |
+ ret = vmdk_open_sparse(bs, extent_file, bs->open_flags, buf, errp);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
+ g_free(buf);
|
|
|
9ae3a8 |
bdrv_unref(extent_file);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -845,20 +853,13 @@ next_line:
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
-static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
|
|
|
9ae3a8 |
- uint64_t desc_offset, Error **errp)
|
|
|
9ae3a8 |
+static int vmdk_open_desc_file(BlockDriverState *bs, int flags, char *buf,
|
|
|
9ae3a8 |
+ Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
- char *buf;
|
|
|
9ae3a8 |
char ct[128];
|
|
|
9ae3a8 |
BDRVVmdkState *s = bs->opaque;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- buf = vmdk_read_desc(bs->file, desc_offset, errp);
|
|
|
9ae3a8 |
- if (!buf) {
|
|
|
9ae3a8 |
- return -EINVAL;
|
|
|
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 |
@@ -877,20 +878,25 @@ static int vmdk_open_desc_file(BlockDriverState *bs, int flags,
|
|
|
9ae3a8 |
s->desc_offset = 0;
|
|
|
9ae3a8 |
ret = vmdk_parse_extents(buf, bs, bs->file->filename, errp);
|
|
|
9ae3a8 |
exit:
|
|
|
9ae3a8 |
- g_free(buf);
|
|
|
9ae3a8 |
return ret;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
Error **errp)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
+ char *buf = NULL;
|
|
|
9ae3a8 |
int ret;
|
|
|
9ae3a8 |
BDRVVmdkState *s = bs->opaque;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (vmdk_open_sparse(bs, bs->file, flags, errp) == 0) {
|
|
|
9ae3a8 |
+ buf = vmdk_read_desc(bs->file, 0, errp);
|
|
|
9ae3a8 |
+ if (!buf) {
|
|
|
9ae3a8 |
+ return -EINVAL;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
+ if (vmdk_open_sparse(bs, bs->file, flags, buf, errp) == 0) {
|
|
|
9ae3a8 |
s->desc_offset = 0x200;
|
|
|
9ae3a8 |
} else {
|
|
|
9ae3a8 |
- ret = vmdk_open_desc_file(bs, flags, 0, errp);
|
|
|
9ae3a8 |
+ ret = vmdk_open_desc_file(bs, flags, buf, errp);
|
|
|
9ae3a8 |
if (ret) {
|
|
|
9ae3a8 |
goto fail;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -909,10 +915,11 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
|
|
|
9ae3a8 |
QERR_BLOCK_FORMAT_FEATURE_NOT_SUPPORTED,
|
|
|
9ae3a8 |
"vmdk", bs->device_name, "live migration");
|
|
|
9ae3a8 |
migrate_add_blocker(s->migration_blocker);
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
+ g_free(buf);
|
|
|
9ae3a8 |
return 0;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
fail:
|
|
|
9ae3a8 |
+ g_free(buf);
|
|
|
9ae3a8 |
g_free(s->create_type);
|
|
|
9ae3a8 |
s->create_type = NULL;
|
|
|
9ae3a8 |
vmdk_free_extents(bs);
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
2.1.0
|
|
|
9ae3a8 |
|