On 3/17/20 1:16 PM, Alberto Garcia wrote:
Subcluster allocation in qcow2 is implemented by extending the
existing L2 table entries and adding additional information to
indicate the allocation status of each subcluster.
This patch documents the changes to the qcow2 format and how they
affect the calculation of the L2 cache size.
Signed-off-by: Alberto Garcia <be...@igalia.com>
---
docs/interop/qcow2.txt | 68 ++++++++++++++++++++++++++++++++++++++++--
docs/qcow2-cache.txt | 19 +++++++++++-
2 files changed, 83 insertions(+), 4 deletions(-)
+== Extended L2 Entries ==
+
+An image uses Extended L2 Entries if bit 4 is set on the incompatible_features
+field of the header.
+
+In these images standard data clusters are divided into 32 subclusters of the
+same size. They are contiguous and start from the beginning of the cluster.
+Subclusters can be allocated independently and the L2 entry contains
information
+indicating the status of each one of them. Compressed data clusters don't have
+subclusters so they are treated the same as in images without this feature.
+
+The size of an extended L2 entry is 128 bits so the number of entries per table
+is calculated using this formula:
+
+ l2_entries = (cluster_size / (2 * sizeof(uint64_t)))
+
+The first 64 bits have the same format as the standard L2 table entry described
+in the previous section, with the exception of bit 0 of the standard cluster
+descriptor.
+
+The last 64 bits contain a subcluster allocation bitmap with this format:
+
+Subcluster Allocation Bitmap (for standard clusters):
+
+ Bit 0 - 31: Allocation status (one bit per subcluster)
+
+ 1: the subcluster is allocated. In this case the
+ host cluster offset field must contain a valid
+ offset.
+ 0: the subcluster is not allocated. In this case
+ read requests shall go to the backing file or
+ return zeros if there is no backing file data.
Hmm - raw external files are incompatible with backing files. Should we
also document that extended L2 entries are incompatible with raw
external files? (The text here reminded me about it, but it would be
the text earlier at the incompatible feature bits that we edit if we
want that additional restriction; compare to the restriction in the
autoclear bit 1). After all, when raw external file is enabled, the
entire image is allocated, at which point subclusters don't make much sense.
And in stating that, it looks like we have a pre-existing hole in that
header bytes 8-15 don't mention the incompatibility with autoclear (when
things are incompatible, it's best to mention the restriction from both
sides, rather than only one of the sides, to make sure the reader
notices the restriction regardless of which field they look up first).
But tweaking that would be a separate patch.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org