yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
958e1b
From 153d5ee0b61926664684a28cdfc982f956c329a2 Mon Sep 17 00:00:00 2001
958e1b
Message-Id: <153d5ee0b61926664684a28cdfc982f956c329a2.1418766606.git.jen@redhat.com>
958e1b
In-Reply-To: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
958e1b
References: <6f81b4847eb68ebdf54a8f1a771e19d112d74152.1418766606.git.jen@redhat.com>
958e1b
From: Fam Zheng <famz@redhat.com>
958e1b
Date: Thu, 4 Dec 2014 00:05:07 -0600
958e1b
Subject: [CHANGE 13/31] vmdk: do not try opening a file as both image and
958e1b
 descriptor
958e1b
To: rhvirt-patches@redhat.com,
958e1b
    jen@redhat.com
958e1b
958e1b
RH-Author: Fam Zheng <famz@redhat.com>
958e1b
Message-id: <1417651524-18041-14-git-send-email-famz@redhat.com>
958e1b
Patchwork-id: 62686
958e1b
O-Subject: [RHEL-7.1 qemu-kvm PATCH v5 13/30] vmdk: do not try opening a file as both image and descriptor
958e1b
Bugzilla: 1134251
958e1b
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
958e1b
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
958e1b
RH-Acked-by: Max Reitz <mreitz@redhat.com>
958e1b
958e1b
From: Paolo Bonzini <pbonzini@redhat.com>
958e1b
958e1b
This prepares for propagating errors from vmdk_open_sparse and
958e1b
vmdk_open_desc_file up to the caller of vmdk_open.
958e1b
958e1b
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
958e1b
Reviewed-by: Fam Zheng <famz@redhat.com>
958e1b
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
958e1b
(cherry picked from commit 37f09e5e3d206e7c555d28a7755cecfa137dad22)
958e1b
Signed-off-by: Fam Zheng <famz@redhat.com>
958e1b
Signed-off-by: Jeff E. Nelson <jen@redhat.com>
958e1b
---
958e1b
 block/vmdk.c               | 22 +++++++++++++++-------
958e1b
 tests/qemu-iotests/059.out |  4 ++--
958e1b
 2 files changed, 17 insertions(+), 9 deletions(-)
958e1b
958e1b
diff --git a/block/vmdk.c b/block/vmdk.c
958e1b
index 458bceb..94f7dae 100644
958e1b
--- a/block/vmdk.c
958e1b
+++ b/block/vmdk.c
958e1b
@@ -887,20 +887,28 @@ static int vmdk_open(BlockDriverState *bs, QDict *options, int flags,
958e1b
     char *buf = NULL;
958e1b
     int ret;
958e1b
     BDRVVmdkState *s = bs->opaque;
958e1b
+    uint32_t magic;
958e1b
 
958e1b
     buf = vmdk_read_desc(bs->file, 0, errp);
958e1b
     if (!buf) {
958e1b
         return -EINVAL;
958e1b
     }
958e1b
 
958e1b
-    if (vmdk_open_sparse(bs, bs->file, flags, buf, errp) == 0) {
958e1b
-        s->desc_offset = 0x200;
958e1b
-    } else {
958e1b
-        ret = vmdk_open_desc_file(bs, flags, buf, errp);
958e1b
-        if (ret) {
958e1b
-            goto fail;
958e1b
-        }
958e1b
+    magic = ldl_be_p(buf);
958e1b
+    switch (magic) {
958e1b
+        case VMDK3_MAGIC:
958e1b
+        case VMDK4_MAGIC:
958e1b
+            ret = vmdk_open_sparse(bs, bs->file, flags, buf, errp);
958e1b
+            s->desc_offset = 0x200;
958e1b
+            break;
958e1b
+        default:
958e1b
+            ret = vmdk_open_desc_file(bs, flags, buf, errp);
958e1b
+            break;
958e1b
     }
958e1b
+    if (ret) {
958e1b
+        goto fail;
958e1b
+    }
958e1b
+
958e1b
     /* try to open parent images, if exist */
958e1b
     ret = vmdk_parent_open(bs);
958e1b
     if (ret) {
958e1b
diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out
958e1b
index f4ca52d..0220774 100644
958e1b
--- a/tests/qemu-iotests/059.out
958e1b
+++ b/tests/qemu-iotests/059.out
958e1b
@@ -8,7 +8,7 @@ no file open, try 'help open'
958e1b
 
958e1b
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864
958e1b
 L2 table size too big
958e1b
-qemu-io: can't open device TEST_DIR/t.vmdk: Could not open 'TEST_DIR/t.vmdk': Wrong medium type
958e1b
+qemu-io: can't open device TEST_DIR/t.vmdk: Could not open 'TEST_DIR/t.vmdk': Invalid argument
958e1b
 no file open, try 'help open'
958e1b
 === Testing too big L1 table size ===
958e1b
 
958e1b
@@ -2046,7 +2046,7 @@ RW 12582912 VMFS "dummy.IMGFMT" 1
958e1b
 === Testing truncated sparse ===
958e1b
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=107374182400
958e1b
 qemu-img: File truncated, expecting at least 13172736 bytes
958e1b
-qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Wrong medium type
958e1b
+qemu-img: Could not open 'TEST_DIR/t.IMGFMT': Could not open 'TEST_DIR/t.IMGFMT': Invalid argument
958e1b
 
958e1b
 === Testing version 3 ===
958e1b
 image: TEST_DIR/iotest-version3.IMGFMT
958e1b
-- 
958e1b
2.1.0
958e1b