qemu: block: Introduce helpers for properly testing for 'raw' and 'luks' images

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 helpers which will simplify this task.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Spellchecked-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2023-12-12 17:11:45 +01:00
parent aded3c622f
commit 04b94593d1
2 changed files with 48 additions and 0 deletions

View File

@ -3237,6 +3237,49 @@ qemuBlockReopenReadOnly(virDomainObj *vm,
return qemuBlockReopenAccess(vm, src, true, asyncJob); return qemuBlockReopenAccess(vm, src, true, asyncJob);
} }
/**
* qemuBlockStorageSourceIsLUKS:
* @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
qemuBlockStorageSourceIsLUKS(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 (qemuBlockStorageSourceIsLUKS(src))
return false;
return true;
}
/** /**
* qemuBlockStorageSourceNeedSliceLayer: * qemuBlockStorageSourceNeedSliceLayer:
* @src: source to inspect * @src: source to inspect

View File

@ -267,6 +267,11 @@ qemuBlockReopenReadOnly(virDomainObj *vm,
virStorageSource *src, virStorageSource *src,
virDomainAsyncJob asyncJob); virDomainAsyncJob asyncJob);
bool
qemuBlockStorageSourceIsLUKS(const virStorageSource *src);
bool
qemuBlockStorageSourceIsRaw(const virStorageSource *src);
bool bool
qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src); qemuBlockStorageSourceNeedsStorageSliceLayer(const virStorageSource *src);