Unfortunately a LUKS image to be decrypted by qemu has
VIR_STORAGE_FILE_RAW as format, but has encryption properties populated.
Many places in the code don't check it properly and also don't check
properly whether the image is indeed LUKS to be decrypted by qemu.
Introduce helpes which will simplify this task.
Signed-off-by: Peter Krempa <pkrempa(a)redhat.com>
---
src/qemu/qemu_block.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/qemu/qemu_block.h | 5 +++++
2 files changed, 48 insertions(+)
diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c
index 7e9daf0bdc..845b273b27 100644
--- a/src/qemu/qemu_block.c
+++ b/src/qemu/qemu_block.c
@@ -3237,6 +3237,49 @@ qemuBlockReopenReadOnly(virDomainObj *vm,
return qemuBlockReopenAccess(vm, src, true, asyncJob);
}
+
+/**
+ * qemuBlockStorageSourceIsQEMULuks:
+ * @src: storage source object
+ *
+ * Returns true if @src is an image in 'luks' format, which is to be decrypted
+ * in qemu (rather than transparently by the transport layer or host's kernel).
+ */
+bool
+qemuBlockStorageSourceIsQEMULuks(const virStorageSource *src)
+{
+ if (src->format != VIR_STORAGE_FILE_RAW)
+ return false;
+
+ if (src->encryption &&
+ src->encryption->engine == VIR_STORAGE_ENCRYPTION_ENGINE_QEMU &&
+ src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS)
+ return true;
+
+ return false;
+}
+
+
+/**
+ * qemuBlockStorageSourceIsRaw:
+ * @src: storage source object
+ *
+ * Returns true if @src is a true 'raw' image. This specifically excludes
+ * LUKS encrypted images to be decrypted by qemu.
+ */
+bool
+qemuBlockStorageSourceIsRaw(const virStorageSource *src)
+{
+ if (src->format != VIR_STORAGE_FILE_RAW)
+ return false;
+
+ if (qemuBlockStorageSourceIsQEMULuks(src))
+ return false;
+
+ return true;
+}
+
+
/**
* qemuBlockStorageSourceNeedSliceLayer:
* @src: source to inspect
diff --git a/src/qemu/qemu_block.h b/src/qemu/qemu_block.h
index 0eab0d822c..9d6167b6ef 100644
--- a/src/qemu/qemu_block.h
+++ b/src/qemu/qemu_block.h
@@ -267,6 +267,11 @@ qemuBlockReopenReadOnly(virDomainObj *vm,
virStorageSource *src,
virDomainAsyncJob asyncJob);
+bool
+qemuBlockStorageSourceIsQEMULuks(const virStorageSource *src);
+bool
+qemuBlockStorageSourceIsRaw(const virStorageSource *src);
+
bool
qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src);
--
2.43.0