render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
d76c62
From d926f32560cb7996b6a5ec08545d946bf0594fe8 Mon Sep 17 00:00:00 2001
d76c62
Message-Id: <d926f32560cb7996b6a5ec08545d946bf0594fe8@dist-git>
d76c62
From: Peter Krempa <pkrempa@redhat.com>
d76c62
Date: Fri, 28 Feb 2020 10:24:28 +0100
d76c62
Subject: [PATCH] util: storagefile: Drop image format probing by file suffix
d76c62
MIME-Version: 1.0
d76c62
Content-Type: text/plain; charset=UTF-8
d76c62
Content-Transfer-Encoding: 8bit
d76c62
d76c62
Probing by file suffix was meant to be a last resort if probing by
d76c62
contents fails or is not supported. For most formats we never specified
d76c62
any suffix. There's a few formats implementing both magic bytes and
d76c62
suffix and finally DMG which had only suffix probing. Since suffix
d76c62
probing is nowhere reliable and only one format depends on in which has a
d76c62
comment that qemu doesn't do the probing either drop the whole
d76c62
infrastructure.
d76c62
d76c62
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
d76c62
Reviewed-by: Eric Blake <eblake@redhat.com>
d76c62
(cherry picked from commit 181fccc2ed67a79d462dfcf5b6fcfd2fbb1702b9)
d76c62
d76c62
https://bugzilla.redhat.com/show_bug.cgi?id=1798148
d76c62
Message-Id: <113e583f0c032b616ea5c691fe36540ebb8e7c8f.1582881363.git.pkrempa@redhat.com>
d76c62
Reviewed-by: Ján Tomko <jtomko@redhat.com>
d76c62
---
d76c62
 src/util/virstoragefile.c | 58 ++++++++++++---------------------------
d76c62
 1 file changed, 17 insertions(+), 41 deletions(-)
d76c62
d76c62
diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
d76c62
index fcbc97d96a..6b83fc0e24 100644
d76c62
--- a/src/util/virstoragefile.c
d76c62
+++ b/src/util/virstoragefile.c
d76c62
@@ -146,12 +146,10 @@ struct FileEncryptionInfo {
d76c62
     int payloadOffset; /* start offset of the volume data (in 512 byte sectors) */
d76c62
 };
d76c62
 
d76c62
-/* Either 'magic' or 'extension' *must* be provided */
d76c62
 struct FileTypeInfo {
d76c62
     int magicOffset;    /* Byte offset of the magic */
d76c62
     const char *magic;  /* Optional string of file magic
d76c62
                          * to check at head of file */
d76c62
-    const char *extension; /* Optional file extension to check */
d76c62
     enum lv_endian endian; /* Endianness of file format */
d76c62
 
d76c62
     int versionOffset;    /* Byte offset from start of file
d76c62
@@ -297,17 +295,17 @@ static struct FileEncryptionInfo const qcow2EncryptionInfo[] = {
d76c62
 };
d76c62
 
d76c62
 static struct FileTypeInfo const fileTypeInfo[] = {
d76c62
-    [VIR_STORAGE_FILE_NONE] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
d76c62
+    [VIR_STORAGE_FILE_NONE] = { 0, NULL, LV_LITTLE_ENDIAN,
d76c62
                                 -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL },
d76c62
-    [VIR_STORAGE_FILE_RAW] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
d76c62
+    [VIR_STORAGE_FILE_RAW] = { 0, NULL, LV_LITTLE_ENDIAN,
d76c62
                                -1, 0, {0}, 0, 0, 0,
d76c62
                                luksEncryptionInfo,
d76c62
                                NULL, NULL },
d76c62
-    [VIR_STORAGE_FILE_DIR] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
d76c62
+    [VIR_STORAGE_FILE_DIR] = { 0, NULL, LV_LITTLE_ENDIAN,
d76c62
                                -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL },
d76c62
     [VIR_STORAGE_FILE_BOCHS] = {
d76c62
         /*"Bochs Virtual HD Image", */ /* Untested */
d76c62
-        0, NULL, NULL,
d76c62
+        0, NULL,
d76c62
         LV_LITTLE_ENDIAN, 64, 4, {0x20000},
d76c62
         32+16+16+4+4+4+4+4, 8, 1, NULL, NULL, NULL
d76c62
     },
d76c62
@@ -316,7 +314,7 @@ static struct FileTypeInfo const fileTypeInfo[] = {
d76c62
            #V2.0 Format
d76c62
            modprobe cloop file=$0 && mount -r -t iso9660 /dev/cloop $1
d76c62
         */ /* Untested */
d76c62
-        0, NULL, NULL,
d76c62
+        0, NULL,
d76c62
         LV_LITTLE_ENDIAN, -1, 0, {0},
d76c62
         -1, 0, 0, NULL, NULL, NULL
d76c62
     },
d76c62
@@ -324,50 +322,50 @@ static struct FileTypeInfo const fileTypeInfo[] = {
d76c62
         /* XXX QEMU says there's no magic for dmg,
d76c62
          * /usr/share/misc/magic lists double magic (both offsets
d76c62
          * would have to match) but then disables that check. */
d76c62
-        0, NULL, ".dmg",
d76c62
+        0, NULL,
d76c62
         0, -1, 0, {0},
d76c62
         -1, 0, 0, NULL, NULL, NULL
d76c62
     },
d76c62
     [VIR_STORAGE_FILE_ISO] = {
d76c62
-        32769, "CD001", ".iso",
d76c62
+        32769, "CD001",
d76c62
         LV_LITTLE_ENDIAN, -2, 0, {0},
d76c62
         -1, 0, 0, NULL, NULL, NULL
d76c62
     },
d76c62
     [VIR_STORAGE_FILE_VPC] = {
d76c62
-        0, "conectix", NULL,
d76c62
+        0, "conectix",
d76c62
         LV_BIG_ENDIAN, 12, 4, {0x10000},
d76c62
         8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, NULL, NULL, NULL
d76c62
     },
d76c62
     /* TODO: add getBackingStore function */
d76c62
     [VIR_STORAGE_FILE_VDI] = {
d76c62
-        64, "\x7f\x10\xda\xbe", ".vdi",
d76c62
+        64, "\x7f\x10\xda\xbe",
d76c62
         LV_LITTLE_ENDIAN, 68, 4, {0x00010001},
d76c62
         64 + 5 * 4 + 256 + 7 * 4, 8, 1, NULL, NULL, NULL},
d76c62
 
d76c62
     /* Not direct file formats, but used for various drivers */
d76c62
-    [VIR_STORAGE_FILE_FAT] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
d76c62
+    [VIR_STORAGE_FILE_FAT] = { 0, NULL, LV_LITTLE_ENDIAN,
d76c62
                                -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL },
d76c62
-    [VIR_STORAGE_FILE_VHD] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
d76c62
+    [VIR_STORAGE_FILE_VHD] = { 0, NULL, LV_LITTLE_ENDIAN,
d76c62
                                -1, 0, {0}, 0, 0, 0, NULL, NULL, NULL },
d76c62
-    [VIR_STORAGE_FILE_PLOOP] = { 0, "WithouFreSpacExt", NULL, LV_LITTLE_ENDIAN,
d76c62
+    [VIR_STORAGE_FILE_PLOOP] = { 0, "WithouFreSpacExt", LV_LITTLE_ENDIAN,
d76c62
                                  -2, 0, {0}, PLOOP_IMAGE_SIZE_OFFSET, 0,
d76c62
                                  PLOOP_SIZE_MULTIPLIER, NULL, NULL, NULL },
d76c62
 
d76c62
     /* All formats with a backing store probe below here */
d76c62
     [VIR_STORAGE_FILE_COW] = {
d76c62
-        0, "OOOM", NULL,
d76c62
+        0, "OOOM",
d76c62
         LV_BIG_ENDIAN, 4, 4, {2},
d76c62
         4+4+1024+4, 8, 1, NULL, cowGetBackingStore, NULL
d76c62
     },
d76c62
     [VIR_STORAGE_FILE_QCOW] = {
d76c62
-        0, "QFI", NULL,
d76c62
+        0, "QFI",
d76c62
         LV_BIG_ENDIAN, 4, 4, {1},
d76c62
         QCOWX_HDR_IMAGE_SIZE, 8, 1,
d76c62
         qcow1EncryptionInfo,
d76c62
         qcowXGetBackingStore, NULL
d76c62
     },
d76c62
     [VIR_STORAGE_FILE_QCOW2] = {
d76c62
-        0, "QFI", NULL,
d76c62
+        0, "QFI",
d76c62
         LV_BIG_ENDIAN, 4, 4, {2, 3},
d76c62
         QCOWX_HDR_IMAGE_SIZE, 8, 1,
d76c62
         qcow2EncryptionInfo,
d76c62
@@ -376,12 +374,12 @@ static struct FileTypeInfo const fileTypeInfo[] = {
d76c62
     },
d76c62
     [VIR_STORAGE_FILE_QED] = {
d76c62
         /* https://wiki.qemu.org/Features/QED */
d76c62
-        0, "QED", NULL,
d76c62
+        0, "QED",
d76c62
         LV_LITTLE_ENDIAN, -2, 0, {0},
d76c62
         QED_HDR_IMAGE_SIZE, 8, 1, NULL, qedGetBackingStore, NULL
d76c62
     },
d76c62
     [VIR_STORAGE_FILE_VMDK] = {
d76c62
-        0, "KDMV", NULL,
d76c62
+        0, "KDMV",
d76c62
         LV_LITTLE_ENDIAN, 4, 4, {1, 2, 3},
d76c62
         4+4+4, 8, 512, NULL, vmdk4GetBackingStore, NULL
d76c62
     },
d76c62
@@ -707,20 +705,6 @@ virStorageFileMatchesMagic(int magicOffset,
d76c62
 }
d76c62
 
d76c62
 
d76c62
-static bool
d76c62
-virStorageFileMatchesExtension(const char *extension,
d76c62
-                               const char *path)
d76c62
-{
d76c62
-    if (extension == NULL)
d76c62
-        return false;
d76c62
-
d76c62
-    if (virStringHasCaseSuffix(path, extension))
d76c62
-        return true;
d76c62
-
d76c62
-    return false;
d76c62
-}
d76c62
-
d76c62
-
d76c62
 static bool
d76c62
 virStorageFileMatchesVersion(int versionOffset,
d76c62
                              int versionSize,
d76c62
@@ -842,14 +826,6 @@ virStorageFileProbeFormatFromBuf(const char *path,
d76c62
                  "Please report new version to libvir-list@redhat.com",
d76c62
                  path, virStorageFileFormatTypeToString(possibleFormat));
d76c62
 
d76c62
-    /* No magic, so check file extension */
d76c62
-    for (i = 0; i < VIR_STORAGE_FILE_LAST; i++) {
d76c62
-        if (virStorageFileMatchesExtension(fileTypeInfo[i].extension, path)) {
d76c62
-            format = i;
d76c62
-            goto cleanup;
d76c62
-        }
d76c62
-    }
d76c62
-
d76c62
  cleanup:
d76c62
     VIR_DEBUG("format=%d", format);
d76c62
     return format;
d76c62
-- 
d76c62
2.25.1
d76c62