Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,10 @@ public boolean supportsImageFormat(QemuImg.PhysicalDiskFormat format) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,21 @@ public void testHelpSupportsImageFormat() throws QemuImgException, LibvirtExcept
Assert.assertFalse("should not support http", QemuImg.helpSupportsImageFormat(partialHelp, PhysicalDiskFormat.SHEEPDOG));
}

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

@Test
public void testCheckAndRepair() throws LibvirtException {
String filename = "/tmp/" + UUID.randomUUID() + ".qcow2";
Expand Down
Loading