[PATCH RFC 08/16] util: Modify the FileTypeInfo for meta data checks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Currently the assumption is there is one type of disk encryption - in
some qcow format which is old and crusty... But there's a new sheriff
in town known as 'luks' and we'll need to handle that shortly

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/util/virstoragefile.c | 54 ++++++++++++++++++++++++++++-------------------
 1 file changed, 32 insertions(+), 22 deletions(-)

diff --git a/src/util/virstoragefile.c b/src/util/virstoragefile.c
index 54940a0..5d086b9 100644
--- a/src/util/virstoragefile.c
+++ b/src/util/virstoragefile.c
@@ -1,7 +1,7 @@
 /*
  * virstoragefile.c: file utility functions for FS storage backend
  *
- * Copyright (C) 2007-2014 Red Hat, Inc.
+ * Copyright (C) 2007-2014, 2016 Red Hat, Inc.
  * Copyright (C) 2007-2008 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -111,6 +111,11 @@ enum {
     BACKING_STORE_ERROR,
 };
 
+enum fi_crypt {
+    FI_CRYPT_NONE = 0,
+    FI_CRYPT_QCOW
+};
+
 #define FILE_TYPE_VERSIONS_LAST 2
 
 /* Either 'magic' or 'extension' *must* be provided */
@@ -134,7 +139,8 @@ struct FileTypeInfo {
                           /* Store a COW base image path (possibly relative),
                            * or NULL if there is no COW base image, to RES;
                            * return BACKING_STORE_* */
-    int qcowCryptOffset;  /* Byte offset from start of file
+    enum fi_crypt cryptType; /* Style of crypt */
+    int cryptOffset;      /* Byte offset from start of file
                            * where to find encryption mode,
                            * -1 if encryption is not used */
     int (*getBackingStore)(char **res, int *format,
@@ -189,16 +195,16 @@ qedGetBackingStore(char **, int *, const char *, size_t);
 
 static struct FileTypeInfo const fileTypeInfo[] = {
     [VIR_STORAGE_FILE_NONE] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
-                                -1, {0}, 0, 0, 0, 0, NULL, NULL },
+                                -1, {0}, 0, 0, 0, FI_CRYPT_NONE, 0, NULL, NULL },
     [VIR_STORAGE_FILE_RAW] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
-                               -1, {0}, 0, 0, 0, 0, NULL, NULL },
+                               -1, {0}, 0, 0, 0, FI_CRYPT_NONE, 0, NULL, NULL },
     [VIR_STORAGE_FILE_DIR] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
-                               -1, {0}, 0, 0, 0, 0, NULL, NULL },
+                               -1, {0}, 0, 0, 0, FI_CRYPT_NONE, 0, NULL, NULL },
     [VIR_STORAGE_FILE_BOCHS] = {
         /*"Bochs Virtual HD Image", */ /* Untested */
         0, NULL, NULL,
         LV_LITTLE_ENDIAN, 64, {0x20000},
-        32+16+16+4+4+4+4+4, 8, 1, -1, NULL, NULL
+        32+16+16+4+4+4+4+4, 8, 1, FI_CRYPT_NONE, -1, NULL, NULL
     },
     [VIR_STORAGE_FILE_CLOOP] = {
         /* #!/bin/sh
@@ -207,7 +213,7 @@ static struct FileTypeInfo const fileTypeInfo[] = {
         */ /* Untested */
         0, NULL, NULL,
         LV_LITTLE_ENDIAN, -1, {0},
-        -1, 0, 0, -1, NULL, NULL
+        -1, 0, 0, FI_CRYPT_NONE, -1, NULL, NULL
     },
     [VIR_STORAGE_FILE_DMG] = {
         /* XXX QEMU says there's no magic for dmg,
@@ -215,60 +221,64 @@ static struct FileTypeInfo const fileTypeInfo[] = {
          * would have to match) but then disables that check. */
         0, NULL, ".dmg",
         0, -1, {0},
-        -1, 0, 0, -1, NULL, NULL
+        -1, 0, 0, FI_CRYPT_NONE, -1, NULL, NULL
     },
     [VIR_STORAGE_FILE_ISO] = {
         32769, "CD001", ".iso",
         LV_LITTLE_ENDIAN, -2, {0},
-        -1, 0, 0, -1, NULL, NULL
+        -1, 0, 0, FI_CRYPT_NONE, -1, NULL, NULL
     },
     [VIR_STORAGE_FILE_VPC] = {
         0, "conectix", NULL,
         LV_BIG_ENDIAN, 12, {0x10000},
-        8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, -1, NULL, NULL
+        8 + 4 + 4 + 8 + 4 + 4 + 2 + 2 + 4, 8, 1, FI_CRYPT_NONE, -1, NULL, NULL
     },
     /* TODO: add getBackingStore function */
     [VIR_STORAGE_FILE_VDI] = {
         64, "\x7f\x10\xda\xbe", ".vdi",
         LV_LITTLE_ENDIAN, 68, {0x00010001},
-        64 + 5 * 4 + 256 + 7 * 4, 8, 1, -1, NULL, NULL},
+        64 + 5 * 4 + 256 + 7 * 4, 8, 1, FI_CRYPT_NONE, -1, NULL, NULL},
 
     /* Not direct file formats, but used for various drivers */
     [VIR_STORAGE_FILE_FAT] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
-                               -1, {0}, 0, 0, 0, 0, NULL, NULL },
+                               -1, {0}, 0, 0, 0, FI_CRYPT_NONE, 0, NULL, NULL },
     [VIR_STORAGE_FILE_VHD] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
-                               -1, {0}, 0, 0, 0, 0, NULL, NULL },
+                               -1, {0}, 0, 0, 0, FI_CRYPT_NONE, 0, NULL, NULL },
     [VIR_STORAGE_FILE_PLOOP] = { 0, "WithouFreSpacExt", NULL, LV_LITTLE_ENDIAN,
                                  -2, {0}, PLOOP_IMAGE_SIZE_OFFSET, 0,
-                                 PLOOP_SIZE_MULTIPLIER, -1, NULL, NULL },
+                                 PLOOP_SIZE_MULTIPLIER,
+                                 FI_CRYPT_NONE, -1, NULL, NULL },
 
     /* All formats with a backing store probe below here */
     [VIR_STORAGE_FILE_COW] = {
         0, "OOOM", NULL,
         LV_BIG_ENDIAN, 4, {2},
-        4+4+1024+4, 8, 1, -1, cowGetBackingStore, NULL
+        4+4+1024+4, 8, 1, FI_CRYPT_NONE, -1, cowGetBackingStore, NULL
     },
     [VIR_STORAGE_FILE_QCOW] = {
         0, "QFI", NULL,
         LV_BIG_ENDIAN, 4, {1},
-        QCOWX_HDR_IMAGE_SIZE, 8, 1, QCOW1_HDR_CRYPT, qcow1GetBackingStore, NULL
+        QCOWX_HDR_IMAGE_SIZE, 8, 1,
+        FI_CRYPT_QCOW, QCOW1_HDR_CRYPT,
+        qcow1GetBackingStore, NULL
     },
     [VIR_STORAGE_FILE_QCOW2] = {
         0, "QFI", NULL,
         LV_BIG_ENDIAN, 4, {2, 3},
-        QCOWX_HDR_IMAGE_SIZE, 8, 1, QCOW2_HDR_CRYPT, qcow2GetBackingStore,
-        qcow2GetFeatures
+        QCOWX_HDR_IMAGE_SIZE, 8, 1,
+        FI_CRYPT_QCOW, QCOW2_HDR_CRYPT,
+        qcow2GetBackingStore, qcow2GetFeatures
     },
     [VIR_STORAGE_FILE_QED] = {
         /* http://wiki.qemu.org/Features/QED */
         0, "QED", NULL,
         LV_LITTLE_ENDIAN, -2, {0},
-        QED_HDR_IMAGE_SIZE, 8, 1, -1, qedGetBackingStore, NULL
+        QED_HDR_IMAGE_SIZE, 8, 1, FI_CRYPT_NONE, -1, qedGetBackingStore, NULL
     },
     [VIR_STORAGE_FILE_VMDK] = {
         0, "KDMV", NULL,
         LV_LITTLE_ENDIAN, 4, {1, 2},
-        4+4+4, 8, 512, -1, vmdk4GetBackingStore, NULL
+        4+4+4, 8, 512, FI_CRYPT_NONE, -1, vmdk4GetBackingStore, NULL
     },
 };
 verify(ARRAY_CARDINALITY(fileTypeInfo) == VIR_STORAGE_FILE_LAST);
@@ -814,11 +824,11 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
         meta->capacity *= fileTypeInfo[meta->format].sizeMultiplier;
     }
 
-    if (fileTypeInfo[meta->format].qcowCryptOffset != -1) {
+    if (fileTypeInfo[meta->format].cryptType == FI_CRYPT_QCOW) {
         int crypt_format;
 
         crypt_format = virReadBufInt32BE(buf +
-                                         fileTypeInfo[meta->format].qcowCryptOffset);
+                                         fileTypeInfo[meta->format].cryptOffset);
         if (crypt_format && !meta->encryption &&
             VIR_ALLOC(meta->encryption) < 0)
             goto cleanup;
-- 
2.5.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]