]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage_file_probe: Move logic from qcow2GetClusterSize to qcow2GetImageSpecific
authorPeter Krempa <pkrempa@redhat.com>
Wed, 28 May 2025 15:26:13 +0000 (17:26 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 3 Jun 2025 11:11:03 +0000 (13:11 +0200)
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 <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage_file/storage_file_probe.c

index ce8ba4b88465de7c3e7669ae2ce1c0c81f7a4ce8..21a1013102067ec682e7246da78ce7d0bc4dff89 100644 (file)
@@ -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;