提交 318ebb36 编写于 作者: J John Ferlan

util: Add 'luks' to the FileTypeInfo

Add the ability to detect a luks encrypted device.
Signed-off-by: NJohn Ferlan <jferlan@redhat.com>
上级 ea0ef33d
...@@ -63,7 +63,7 @@ VIR_ENUM_IMPL(virStorageFileFormat, ...@@ -63,7 +63,7 @@ VIR_ENUM_IMPL(virStorageFileFormat,
"cloop", "dmg", "iso", "cloop", "dmg", "iso",
"vpc", "vdi", "vpc", "vdi",
/* Not direct file formats, but used for various drivers */ /* Not direct file formats, but used for various drivers */
"fat", "vhd", "ploop", "fat", "vhd", "ploop", "luks",
/* Formats with backing file below here */ /* Formats with backing file below here */
"cow", "qcow", "qcow2", "qed", "vmdk") "cow", "qcow", "qcow2", "qed", "vmdk")
...@@ -189,6 +189,13 @@ qedGetBackingStore(char **, int *, const char *, size_t); ...@@ -189,6 +189,13 @@ qedGetBackingStore(char **, int *, const char *, size_t);
#define PLOOP_IMAGE_SIZE_OFFSET 36 #define PLOOP_IMAGE_SIZE_OFFSET 36
#define PLOOP_SIZE_MULTIPLIER 512 #define PLOOP_SIZE_MULTIPLIER 512
#define LUKS_HDR_MAGIC_LEN 6
#define LUKS_HDR_VERSION_LEN 2
/* Format described by qemu commit id '3e308f20e' */
#define LUKS_HDR_VERSION_OFFSET LUKS_HDR_MAGIC_LEN
static struct FileTypeInfo const fileTypeInfo[] = { static struct FileTypeInfo const fileTypeInfo[] = {
[VIR_STORAGE_FILE_NONE] = { 0, NULL, NULL, LV_LITTLE_ENDIAN, [VIR_STORAGE_FILE_NONE] = { 0, NULL, NULL, LV_LITTLE_ENDIAN,
-1, 0, {0}, 0, 0, 0, 0, NULL, NULL }, -1, 0, {0}, 0, 0, 0, 0, NULL, NULL },
...@@ -244,6 +251,13 @@ static struct FileTypeInfo const fileTypeInfo[] = { ...@@ -244,6 +251,13 @@ static struct FileTypeInfo const fileTypeInfo[] = {
-2, 0, {0}, PLOOP_IMAGE_SIZE_OFFSET, 0, -2, 0, {0}, PLOOP_IMAGE_SIZE_OFFSET, 0,
PLOOP_SIZE_MULTIPLIER, -1, NULL, NULL }, PLOOP_SIZE_MULTIPLIER, -1, NULL, NULL },
/* Magic is 'L','U','K','S', 0xBA, 0xBE
* Set sizeOffset = -1 and let hypervisor handle */
[VIR_STORAGE_FILE_LUKS] = {
0, "\x4c\x55\x4b\x53\xba\xbe", NULL,
LV_BIG_ENDIAN, LUKS_HDR_VERSION_OFFSET, 2, {1},
-1, 0, 0, -1, NULL, NULL
},
/* All formats with a backing store probe below here */ /* All formats with a backing store probe below here */
[VIR_STORAGE_FILE_COW] = { [VIR_STORAGE_FILE_COW] = {
0, "OOOM", NULL, 0, "OOOM", NULL,
...@@ -626,7 +640,7 @@ virStorageFileMatchesVersion(int format, ...@@ -626,7 +640,7 @@ virStorageFileMatchesVersion(int format,
char *buf, char *buf,
size_t buflen) size_t buflen)
{ {
int version; int version = 0;
size_t i; size_t i;
/* Validate version number info */ /* Validate version number info */
...@@ -843,6 +857,12 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta, ...@@ -843,6 +857,12 @@ virStorageFileGetMetadataInternal(virStorageSourcePtr meta,
goto cleanup; goto cleanup;
} }
if (meta->format == VIR_STORAGE_FILE_LUKS) {
/* By definition, this is encrypted */
if (!meta->encryption && VIR_ALLOC(meta->encryption) < 0)
goto cleanup;
}
VIR_FREE(meta->backingStoreRaw); VIR_FREE(meta->backingStoreRaw);
if (fileTypeInfo[meta->format].getBackingStore != NULL) { if (fileTypeInfo[meta->format].getBackingStore != NULL) {
int store = fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw, int store = fileTypeInfo[meta->format].getBackingStore(&meta->backingStoreRaw,
......
...@@ -74,6 +74,7 @@ typedef enum { ...@@ -74,6 +74,7 @@ typedef enum {
VIR_STORAGE_FILE_FAT, VIR_STORAGE_FILE_FAT,
VIR_STORAGE_FILE_VHD, VIR_STORAGE_FILE_VHD,
VIR_STORAGE_FILE_PLOOP, VIR_STORAGE_FILE_PLOOP,
VIR_STORAGE_FILE_LUKS,
/* Not a format, but a marker: all formats below this point have /* Not a format, but a marker: all formats below this point have
* libvirt support for following a backing chain */ * libvirt support for following a backing chain */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册