aboutsummaryrefslogtreecommitdiff
path: root/block/vmdk.c
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2014-02-17 14:44:04 +0100
committerKevin Wolf <kwolf@redhat.com>2014-02-21 21:02:24 +0100
commit37f09e5e3d206e7c555d28a7755cecfa137dad22 (patch)
tree47cacc5a2a75c12ff1dd246b36cc7ba4ce7091e9 /block/vmdk.c
parentd1833ef52be349e41d17e9c5ddaea8bb4ad3a7fb (diff)
vmdk: do not try opening a file as both image and descriptor
This prepares for propagating errors from vmdk_open_sparse and vmdk_open_desc_file up to the caller of vmdk_open. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Fam Zheng <famz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/vmdk.c')
-rw-r--r--block/vmdk.c22
1 files changed, 15 insertions, 7 deletions
diff --git a/block/vmdk.c b/block/vmdk.c
index f34c16db7c..50a279a8d8 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -886,20 +886,28 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
char *buf = NULL;
int ret;
BDRVVmdkState *s = bs->opaque;
+ uint32_t magic;
buf = vmdk_read_desc(bs->file, 0, errp);
if (!buf) {
return -EINVAL;
}
- if (vmdk_open_sparse(bs, bs->file, flags, buf, errp) == 0) {
- s->desc_offset = 0x200;
- } else {
- ret = vmdk_open_desc_file(bs, flags, buf, errp);
- if (ret) {
- goto fail;
- }
+ magic = ldl_be_p(buf);
+ switch (magic) {
+ case VMDK3_MAGIC:
+ case VMDK4_MAGIC:
+ ret = vmdk_open_sparse(bs, bs->file, flags, buf, errp);
+ s->desc_offset = 0x200;
+ break;
+ default:
+ ret = vmdk_open_desc_file(bs, flags, buf, errp);
+ break;
}
+ if (ret) {
+ goto fail;
+ }
+
/* try to open parent images, if exist */
ret = vmdk_parent_open(bs);
if (ret) {