From e3778b99ee7d4f24ceffac37696065b98588d2a8 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Wed, 28 May 2025 17:26:13 +0200 Subject: [PATCH] storage_file_probe: Move logic from qcow2GetClusterSize to qcow2GetImageSpecific MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Move the cluster size parser into the image specific code for qcow2, which will later allow us to remove the callback for cluster size which is not used by any other format. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/storage_file/storage_file_probe.c | 31 ++++++++------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/storage_file/storage_file_probe.c b/src/storage_file/storage_file_probe.c index ce8ba4b884..21a1013102 100644 --- a/src/storage_file/storage_file_probe.c +++ b/src/storage_file/storage_file_probe.c @@ -114,9 +114,6 @@ static int qcow2GetImageSpecific(virStorageSource *meta, const char *buf, size_t buf_size); -static unsigned long long -qcow2GetClusterSize(const char *buf, - size_t buf_size); static int qcow2GetDataFile(char **, virBitmap *, char *, size_t); static int qcow2GetFeatures(virBitmap **features, int format, char *buf, ssize_t len); @@ -329,7 +326,7 @@ static struct FileTypeInfo const fileTypeInfo[] = { LV_BIG_ENDIAN, 4, 4, {2, 3}, QCOWX_HDR_IMAGE_SIZE, 8, 1, qcow2EncryptionInfo, - qcow2GetClusterSize, + NULL, NULL, qcow2GetDataFile, qcow2GetFeatures, @@ -532,24 +529,6 @@ qcow2GetExtensions(const char *buf, } -static unsigned long long -qcow2GetClusterSize(const char *buf, - size_t buf_size) -{ - int clusterBits = 0; - - if ((QCOWX_HDR_CLUSTER_BITS_OFFSET + 4) > buf_size) - return 0; - - clusterBits = virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS_OFFSET); - - if (clusterBits > 0) - return 1ULL << clusterBits; - - return 0; -} - - static int qcowXGetBackingStore(virStorageSource *meta, const char *buf, @@ -601,6 +580,14 @@ qcow2GetImageSpecific(virStorageSource *meta, { int format; + meta->clusterSize = 0; + if (buf_size > (QCOWX_HDR_CLUSTER_BITS_OFFSET + 4)) { + int clusterBits = virReadBufInt32BE(buf + QCOWX_HDR_CLUSTER_BITS_OFFSET); + + if (clusterBits > 0) + meta->clusterSize = 1ULL << clusterBits; + } + if (qcowXGetBackingStore(meta, buf, buf_size) < 0) return -1; -- 2.47.3