
On Thu, May 20, 2021 at 17:14:32 +0200, Pavel Hrdina wrote:
From QEMU docs/interop/qcow2.txt :
Byte 20 - 23: cluster_bits Number of bits that are used for addressing an offset within a cluster (1 << cluster_bits is the cluster size).
With this patch libvirt will be able to report the current cluster_size for all existing storage volumes managed by storage driver.
Signed-off-by: Pavel Hrdina <phrdina@redhat.com> ---
Changes in v2: - Reworkded to use callback.
src/storage/storage_util.c | 3 ++ src/storage_file/storage_file_probe.c | 70 ++++++++++++++++++++------- 2 files changed, 56 insertions(+), 17 deletions(-)
[...]
@@ -468,6 +477,28 @@ qcow2GetExtensions(const char *buf, }
+static unsigned long long +qcow2GetClusterSize(const char *buf, + size_t buf_size, + int endian)
The 'endian' argument makes sense only for generic getters. You know that qcow2 has always LV_BIG_ENDIAN set.
+{ + int clusterBits = 0; + + if ((QCOWX_HDR_CLUSTER_BITS_OFFSET + 4) > buf_size) + return 0; + + if (endian == LV_LITTLE_ENDIAN) + clusterBits = virReadBufInt32LE(buf + QCOWX_HDR_CLUSTER_BITS_OFFSET); + else + clusterBits = virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS_OFFSET); + + if (clusterBits > 0) + return 1 << clusterBits; + + return 0; +}
Drop the 'endian' argument with appropriate cleanup and: Reviewed-by: Peter Krempa <pkrempa@redhat.com>