render / rpms / libvirt

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