Skip to content

Commit 055f96f

Browse files
KVM: fix LUKS/volume-encryption detection for qemu-img >= 10.1.0
qemu-img 10.1.0 changed the "qemu-img --help" supported-formats header from "Supported formats:" to "Supported image formats:". The regex in QemuImg.helpSupportsImageFormat() only matched the old header, so hostSupportsVolumeEncryption() returned false on affected hosts even though cryptsetup and the luks format were both available, blocking encrypted offerings. Make the "image" keyword optional in the regex so it matches both the legacy and current qemu-img help output.
1 parent 5767127 commit 055f96f

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/utils/qemu/QemuImg.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -927,7 +927,10 @@ public boolean supportsImageFormat(QemuImg.PhysicalDiskFormat format) {
927927
}
928928

929929
protected static boolean helpSupportsImageFormat(String text, QemuImg.PhysicalDiskFormat format) {
930-
Pattern pattern = Pattern.compile("Supported\\sformats:[a-zA-Z0-9-_\\s]*?\\b" + format + "\\b", CASE_INSENSITIVE);
930+
// QEMU >= 10.1.0 changed the qemu-img --help header from
931+
// "Supported formats:" to "Supported image formats:", so the word
932+
// "image" must be treated as optional here.
933+
Pattern pattern = Pattern.compile("Supported\\s(image\\s)?formats:[a-zA-Z0-9-_\\s]*?\\b" + format + "\\b", CASE_INSENSITIVE);
931934
return pattern.matcher(text).find();
932935
}
933936

plugins/hypervisors/kvm/src/test/java/org/apache/cloudstack/utils/qemu/QemuImgTest.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,21 @@ public void testHelpSupportsImageFormat() throws QemuImgException, LibvirtExcept
390390
Assert.assertFalse("should not support http", QemuImg.helpSupportsImageFormat(partialHelp, PhysicalDiskFormat.SHEEPDOG));
391391
}
392392

393+
@Test
394+
public void testHelpSupportsImageFormatQemu101Header() throws QemuImgException, LibvirtException {
395+
// qemu-img 10.1.0 (e.g. RHEL 9.8: qemu-kvm-10.1.0-17.el9_8.3) changed the
396+
// help header from "Supported formats:" to "Supported image formats:"
397+
String help = "Supported image formats:\n" +
398+
" blkdebug blklogwrites blkverify compress copy-before-write copy-on-read\n" +
399+
" file ftp ftps host_cdrom host_device http https io_uring luks nbd null-aio\n" +
400+
" null-co nvme nvme-io_uring preallocate qcow2 quorum raw rbd\n" +
401+
" snapshot-access throttle vdi vhdx virtio-blk-vfio-pci\n" +
402+
" virtio-blk-vhost-user virtio-blk-vhost-vdpa vmdk vpc\n";
403+
Assert.assertTrue("should support luks", QemuImg.helpSupportsImageFormat(help, PhysicalDiskFormat.LUKS));
404+
Assert.assertTrue("should support qcow2", QemuImg.helpSupportsImageFormat(help, PhysicalDiskFormat.QCOW2));
405+
Assert.assertFalse("should not support sheepdog", QemuImg.helpSupportsImageFormat(help, PhysicalDiskFormat.SHEEPDOG));
406+
}
407+
393408
@Test
394409
public void testCheckAndRepair() throws LibvirtException {
395410
String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";

0 commit comments

Comments
 (0)