9ae3a8
From b72998772910dbd04c86a2332b1c69ac1afc7a9e Mon Sep 17 00:00:00 2001
9ae3a8
From: Fam Zheng <famz@redhat.com>
9ae3a8
Date: Mon, 15 Feb 2016 09:28:30 +0100
9ae3a8
Subject: [PATCH 17/18] vmdk: Fix converting to streamOptimized
9ae3a8
9ae3a8
RH-Author: Fam Zheng <famz@redhat.com>
9ae3a8
Message-id: <1455528511-9357-18-git-send-email-famz@redhat.com>
9ae3a8
Patchwork-id: 69183
9ae3a8
O-Subject: [RHEL-7.3 qemu-kvm PATCH 17/18] vmdk: Fix converting to streamOptimized
9ae3a8
Bugzilla: 1299116
9ae3a8
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
RH-Acked-by: Max Reitz <mreitz@redhat.com>
9ae3a8
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
9ae3a8
BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1299116
9ae3a8
9ae3a8
Commit d62d9dc4b8 lifted streamOptimized images's version to 3, but we
9ae3a8
now refuse to open version 3 images read-write.  We need to make
9ae3a8
streamOptimized an exception to allow converting to it. This fixes the
9ae3a8
accidentally broken iotests case 059 for the same reason.
9ae3a8
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
9ae3a8
Signed-off-by: Max Reitz <mreitz@redhat.com>
9ae3a8
(cherry picked from commit 3db1d98a20262228373bb973ca62b1ab64b29af4)
9ae3a8
Signed-off-by: Fam Zheng <famz@redhat.com>
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 block/vmdk.c | 6 +++++-
9ae3a8
 1 file changed, 5 insertions(+), 1 deletion(-)
9ae3a8
9ae3a8
diff --git a/block/vmdk.c b/block/vmdk.c
9ae3a8
index 7b3e397..b0c312b 100644
9ae3a8
--- a/block/vmdk.c
9ae3a8
+++ b/block/vmdk.c
9ae3a8
@@ -592,6 +592,7 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
9ae3a8
     VmdkExtent *extent;
9ae3a8
     BDRVVmdkState *s = bs->opaque;
9ae3a8
     int64_t l1_backup_offset = 0;
9ae3a8
+    bool compressed;
9ae3a8
 
9ae3a8
     ret = bdrv_pread(file, sizeof(magic), &header, sizeof(header));
9ae3a8
     if (ret < 0) {
9ae3a8
@@ -666,6 +667,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
9ae3a8
         header = footer.header;
9ae3a8
     }
9ae3a8
 
9ae3a8
+    compressed =
9ae3a8
+        le16_to_cpu(header.compressAlgorithm) == VMDK4_COMPRESSION_DEFLATE;
9ae3a8
     if (le32_to_cpu(header.version) > 3) {
9ae3a8
         char buf[64];
9ae3a8
         snprintf(buf, sizeof(buf), "VMDK version %" PRId32,
9ae3a8
@@ -673,7 +676,8 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
9ae3a8
         error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
9ae3a8
                   bs->device_name, "vmdk", buf);
9ae3a8
         return -ENOTSUP;
9ae3a8
-    } else if (le32_to_cpu(header.version) == 3 && (flags & BDRV_O_RDWR)) {
9ae3a8
+    } else if (le32_to_cpu(header.version) == 3 && (flags & BDRV_O_RDWR) &&
9ae3a8
+               !compressed) {
9ae3a8
         /* VMware KB 2064959 explains that version 3 added support for
9ae3a8
          * persistent changed block tracking (CBT), and backup software can
9ae3a8
          * read it as version=1 if it doesn't care about the changed area
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8