]> Git Repo - qemu.git/commitdiff
qcow2: Prepare qcow2_get_cluster_type() for external data file
authorKevin Wolf <[email protected]>
Tue, 29 Jan 2019 12:47:24 +0000 (13:47 +0100)
committerKevin Wolf <[email protected]>
Fri, 8 Mar 2019 11:26:45 +0000 (12:26 +0100)
Signed-off-by: Kevin Wolf <[email protected]>
block/qcow2.h

index 7a34bd0c53849ddce79c8d5e02ee61c53b7bc971..8fe2d55005734caf3ac487690b530f1bd4b7280a 100644 (file)
@@ -521,7 +521,15 @@ static inline QCow2ClusterType qcow2_get_cluster_type(BlockDriverState *bs,
         }
         return QCOW2_CLUSTER_ZERO_PLAIN;
     } else if (!(l2_entry & L2E_OFFSET_MASK)) {
-        return QCOW2_CLUSTER_UNALLOCATED;
+        /* Offset 0 generally means unallocated, but it is ambiguous with
+         * external data files because 0 is a valid offset there. However, all
+         * clusters in external data files always have refcount 1, so we can
+         * rely on QCOW_OFLAG_COPIED to disambiguate. */
+        if (has_data_file(bs) && (l2_entry & QCOW_OFLAG_COPIED)) {
+            return QCOW2_CLUSTER_NORMAL;
+        } else {
+            return QCOW2_CLUSTER_UNALLOCATED;
+        }
     } else {
         return QCOW2_CLUSTER_NORMAL;
     }
This page took 0.026172 seconds and 4 git commands to generate.