diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f8e48d2089..28d8146624 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -1442,8 +1442,7 @@ qemuBuildDriveSourceStr(virDomainDiskDefPtr disk, if (disk->src->format > 0 && disk->src->type != VIR_STORAGE_TYPE_DIR) { const char *qemuformat = virStorageFileFormatTypeToString(disk->src->format); - if (disk->src->encryption && - disk->src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) + if (qemuDomainDiskHasEncryptionSecret(disk->src)) qemuformat = "luks"; virBufferAsprintf(buf, "format=%s,", qemuformat); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index acfa69589b..25cb4ad590 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1174,6 +1174,18 @@ qemuDomainSecretDiskCapable(virStorageSourcePtr src) } +bool +qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src) +{ + if (!virStorageSourceIsEmpty(src) && src->encryption && + src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS && + src->encryption->nsecrets > 0) + return true; + + return false; +} + + /* qemuDomainSecretDiskPrepare: * @conn: Pointer to connection * @priv: pointer to domain private object @@ -1209,8 +1221,7 @@ qemuDomainSecretDiskPrepare(virConnectPtr conn, diskPriv->secinfo = secinfo; } - if (!virStorageSourceIsEmpty(src) && src->encryption && - src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { + if (qemuDomainDiskHasEncryptionSecret(src)) { if (VIR_ALLOC(secinfo) < 0) return -1; diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h index b2db45e877..cce879f763 100644 --- a/src/qemu/qemu_domain.h +++ b/src/qemu/qemu_domain.h @@ -734,6 +734,9 @@ void qemuDomainSecretDiskDestroy(virDomainDiskDefPtr disk) bool qemuDomainSecretDiskCapable(virStorageSourcePtr src) ATTRIBUTE_NONNULL(1); +bool qemuDomainDiskHasEncryptionSecret(virStorageSourcePtr src) + ATTRIBUTE_NONNULL(1); + int qemuDomainSecretDiskPrepare(virConnectPtr conn, qemuDomainObjPrivatePtr priv, virDomainDiskDefPtr disk) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 92a2e73711..f2e98469e0 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -3583,8 +3583,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, /* Similarly, if this is possible a device using LUKS encryption, we * can remove the luks object password too */ - if (!virStorageSourceIsEmpty(disk->src) && disk->src->encryption && - disk->src->encryption->format == VIR_STORAGE_ENCRYPTION_FORMAT_LUKS) { + if (qemuDomainDiskHasEncryptionSecret(disk->src)) { if (!(encAlias = qemuDomainGetSecretAESAlias(disk->info.alias, true))) {