render / rpms / libvirt

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