From c7c3dd3dd9b8869f45c5bd9c17af83d230ac7886 Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Thu, 1 Apr 2021 02:39:26 -0300 Subject: [PATCH 1/5] Add io_driver to Libvirt VM Def --- .../resource/LibvirtComputingResource.java | 13 ++++++++++ .../hypervisor/kvm/resource/LibvirtVMDef.java | 24 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 64a2883b7924..3b914a31b0d7 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -2619,6 +2619,8 @@ public int compare(final DiskTO arg0, final DiskTO arg1) { disk.setDiscard(DiscardType.UNMAP); } + setDiskIoDriver(disk); + if (pool.getType() == StoragePoolType.RBD) { /* For RBD pools we use the secret mechanism in libvirt. @@ -2714,6 +2716,17 @@ public int compare(final DiskTO arg0, final DiskTO arg1) { } } + private void setDiskIoDriver(DiskDef disk) { + /* + * IO Driver works for + * - Qemu >= 5.0 + * - Libvirt >= 6.3.0 + */ + if(_hypervisorLibvirtVersion >= 6030000 && _hypervisorQemuVersion >= 5000000) { + disk.setIoDriver(DiskDef.IoDriver.IOURING); + } + } + private KVMPhysicalDisk getPhysicalDiskPrimaryStore(PrimaryDataStoreTO primaryDataStoreTO, DataTO data) { KVMStoragePool storagePool = _storagePoolMgr.getStoragePool(primaryDataStoreTO.getPoolType(), primaryDataStoreTO.getUuid()); return storagePool.getPhysicalDisk(data.getPath()); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index e2d506ce09fb..536ac617a88b 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -651,6 +651,20 @@ public String toString() { } + public enum IoDriver { + IOURING("io_uring"); + String ioDriver; + + IoDriver(String driver) { + ioDriver = driver; + } + + @Override + public String toString() { + return ioDriver; + } + } + private DeviceType _deviceType; /* floppy, disk, cdrom */ private DiskType _diskType; private DiskProtocol _diskProtocol; @@ -681,6 +695,7 @@ public String toString() { private String _serial; private boolean qemuDriver = true; private DiscardType _discard = DiscardType.IGNORE; + private IoDriver ioDriver; public DiscardType getDiscard() { return _discard; @@ -690,6 +705,10 @@ public void setDiscard(DiscardType discard) { this._discard = discard; } + public void setIoDriver(IoDriver ioDriver) { + this.ioDriver = ioDriver; + } + public void setDeviceType(DeviceType deviceType) { _deviceType = deviceType; } @@ -1001,6 +1020,11 @@ public String toString() { if(_discard != null && _discard != DiscardType.IGNORE) { diskBuilder.append("discard='" + _discard.toString() + "' "); } + + if(ioDriver != null) { + diskBuilder.append("io='" + ioDriver.toString() + "'"); + } + diskBuilder.append("/>\n"); } From cdcfd0360aa046f85f21f588ca7fe9deaf1f8b63 Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Thu, 1 Apr 2021 12:56:26 -0300 Subject: [PATCH 2/5] Enhancements on documentation and ENUM --- .../com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index 536ac617a88b..beb31acd89d5 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -651,16 +651,19 @@ public String toString() { } + /** + * This enum specifies IO Drivers, each option controls specific policies on I/O. + * Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0). + */ public enum IoDriver { - IOURING("io_uring"); + NATIVE("native"), THREADS("threads"), IOURING("io_uring"); String ioDriver; IoDriver(String driver) { ioDriver = driver; } - @Override - public String toString() { + @Override public String toString() { return ioDriver; } } From c2e4e7f5a2547a2a27977652a9568d4de651adcf Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Fri, 7 May 2021 12:52:10 -0300 Subject: [PATCH 3/5] Enhance code and Add tests --- .../resource/LibvirtComputingResource.java | 24 +++++++++---- .../hypervisor/kvm/resource/LibvirtVMDef.java | 13 +++++-- .../LibvirtComputingResourceTest.java | 36 +++++++++++++++++++ 3 files changed, 63 insertions(+), 10 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 3b914a31b0d7..f945e0bc8674 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -253,6 +253,8 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected static final String DEFAULT_OVS_VIF_DRIVER_CLASS_NAME = "com.cloud.hypervisor.kvm.resource.OvsVifDriver"; protected static final String DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver"; + private final static long HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IO_URING = 6030000; + private final static long HYPERVISOR_QEMU_VERSION_SUPPORTS_IO_URING = 5000000; protected HypervisorType _hypervisorType; protected String _hypervisorURI; @@ -342,6 +344,14 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected MemStat _memStat = new MemStat(_dom0MinMem, _dom0OvercommitMem); private final LibvirtUtilitiesHelper libvirtUtilitiesHelper = new LibvirtUtilitiesHelper(); + protected long getHypervisorLibvirtVersion() { + return _hypervisorLibvirtVersion; + } + + protected long getHypervisorQemuVersion() { + return _hypervisorQemuVersion; + } + @Override public ExecutionResult executeInVR(final String routerIp, final String script, final String args) { return executeInVR(routerIp, script, args, _timeout); @@ -2716,22 +2726,22 @@ public int compare(final DiskTO arg0, final DiskTO arg1) { } } - private void setDiskIoDriver(DiskDef disk) { + private KVMPhysicalDisk getPhysicalDiskPrimaryStore(PrimaryDataStoreTO primaryDataStoreTO, DataTO data) { + KVMStoragePool storagePool = _storagePoolMgr.getStoragePool(primaryDataStoreTO.getPoolType(), primaryDataStoreTO.getUuid()); + return storagePool.getPhysicalDisk(data.getPath()); + } + + protected void setDiskIoDriver(DiskDef disk) { /* * IO Driver works for * - Qemu >= 5.0 * - Libvirt >= 6.3.0 */ - if(_hypervisorLibvirtVersion >= 6030000 && _hypervisorQemuVersion >= 5000000) { + if (getHypervisorLibvirtVersion() >= HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IO_URING && getHypervisorQemuVersion() >= HYPERVISOR_QEMU_VERSION_SUPPORTS_IO_URING) { disk.setIoDriver(DiskDef.IoDriver.IOURING); } } - private KVMPhysicalDisk getPhysicalDiskPrimaryStore(PrimaryDataStoreTO primaryDataStoreTO, DataTO data) { - KVMStoragePool storagePool = _storagePoolMgr.getStoragePool(primaryDataStoreTO.getPoolType(), primaryDataStoreTO.getUuid()); - return storagePool.getPhysicalDisk(data.getPath()); - } - private KVMPhysicalDisk getPhysicalDiskFromNfsStore(String dataStoreUrl, DataTO data) { final String volPath = dataStoreUrl + File.separator + data.getPath(); final int index = volPath.lastIndexOf("/"); diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index beb31acd89d5..5b5ac36e244d 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -656,14 +656,17 @@ public String toString() { * Qemu guests support "threads" and "native" options Since 0.8.8 ; "io_uring" is supported Since 6.3.0 (QEMU 5.0). */ public enum IoDriver { - NATIVE("native"), THREADS("threads"), IOURING("io_uring"); + NATIVE("native"), + THREADS("threads"), + IOURING("io_uring"); String ioDriver; IoDriver(String driver) { ioDriver = driver; } - @Override public String toString() { + @Override + public String toString() { return ioDriver; } } @@ -708,6 +711,10 @@ public void setDiscard(DiscardType discard) { this._discard = discard; } + public DiskDef.IoDriver getIoDriver() { + return ioDriver; + } + public void setIoDriver(IoDriver ioDriver) { this.ioDriver = ioDriver; } @@ -1025,7 +1032,7 @@ public String toString() { } if(ioDriver != null) { - diskBuilder.append("io='" + ioDriver.toString() + "'"); + diskBuilder.append("io='" + ioDriver + "'"); } diskBuilder.append("/>\n"); diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java index bd651f4c02c2..57ca3b2fbe38 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java @@ -202,6 +202,9 @@ public class LibvirtComputingResourceTest { @Mock LibvirtVMDef vmDef; + private final static long HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IOURING = 6030000; + private final static long HYPERVISOR_QEMU_VERSION_SUPPORTS_IOURING = 5000000; + String hyperVisorType = "kvm"; Random random = new Random(); final String memInfo = "MemTotal: 5830236 kB\n" + @@ -5209,4 +5212,37 @@ public void testAddExtraConfigComponentNotEmptyExtraConfig() { libvirtComputingResource.addExtraConfigComponent(extraConfig, vmDef); Mockito.verify(vmDef, times(1)).addComp(any()); } + + @Test + public void setDiskIoDriverTestIoUring() { + DiskDef diskDef = configureAndTestSetDiskIoDriverTest(HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IOURING, HYPERVISOR_QEMU_VERSION_SUPPORTS_IOURING); + Assert.assertEquals(DiskDef.IoDriver.IOURING, diskDef.getIoDriver()); + } + + @Test + public void setDiskIoDriverTestLibvirtSupportsIoUring() { + DiskDef diskDef = configureAndTestSetDiskIoDriverTest(123l, HYPERVISOR_QEMU_VERSION_SUPPORTS_IOURING); + Assert.assertNotEquals(DiskDef.IoDriver.IOURING, diskDef.getIoDriver()); + } + + @Test + public void setDiskIoDriverTestQemuSupportsIoUring() { + DiskDef diskDef = configureAndTestSetDiskIoDriverTest(HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IOURING, 123l); + Assert.assertNotEquals(DiskDef.IoDriver.IOURING, diskDef.getIoDriver()); + } + + @Test + public void setDiskIoDriverTestNoSupportToIoUring() { + DiskDef diskDef = configureAndTestSetDiskIoDriverTest(123l, 123l); + Assert.assertNotEquals(DiskDef.IoDriver.IOURING, diskDef.getIoDriver()); + } + + private DiskDef configureAndTestSetDiskIoDriverTest(long hypervisorLibvirtVersion, long hypervisorQemuVersion) { + DiskDef diskDef = new DiskDef(); + LibvirtComputingResource libvirtComputingResourceSpy = Mockito.spy(new LibvirtComputingResource()); + Mockito.when(libvirtComputingResourceSpy.getHypervisorLibvirtVersion()).thenReturn(hypervisorLibvirtVersion); + Mockito.when(libvirtComputingResourceSpy.getHypervisorQemuVersion()).thenReturn(hypervisorQemuVersion); + libvirtComputingResourceSpy.setDiskIoDriver(diskDef); + return diskDef; + } } From fe05a59427d166ac27a0ac0ad792a445375237f0 Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Thu, 27 May 2021 21:05:48 -0300 Subject: [PATCH 4/5] Enhance Javadoc & use String.format --- .../kvm/resource/LibvirtComputingResource.java | 11 ++++++----- .../cloud/hypervisor/kvm/resource/LibvirtVMDef.java | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index f945e0bc8674..284b4cd678e4 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -2731,12 +2731,13 @@ private KVMPhysicalDisk getPhysicalDiskPrimaryStore(PrimaryDataStoreTO primaryDa return storagePool.getPhysicalDisk(data.getPath()); } + /** + * Set Disk IO Driver, if supported by the Libvirt/Qemu version. + * IO Driver works for: + * (i) Qemu >= 5.0; + * (ii) Libvirt >= 6.3.0 + */ protected void setDiskIoDriver(DiskDef disk) { - /* - * IO Driver works for - * - Qemu >= 5.0 - * - Libvirt >= 6.3.0 - */ if (getHypervisorLibvirtVersion() >= HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IO_URING && getHypervisorQemuVersion() >= HYPERVISOR_QEMU_VERSION_SUPPORTS_IO_URING) { disk.setIoDriver(DiskDef.IoDriver.IOURING); } diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index 5b5ac36e244d..49a17ef344b2 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -1032,7 +1032,7 @@ public String toString() { } if(ioDriver != null) { - diskBuilder.append("io='" + ioDriver + "'"); + diskBuilder.append(String.format("io='%s'", ioDriver)); } diskBuilder.append("/>\n"); From b9702955a555aab39de5b2cebaa234f15978d95d Mon Sep 17 00:00:00 2001 From: Gabriel Brascher Date: Sat, 10 Jul 2021 01:57:46 -0300 Subject: [PATCH 5/5] Fix Libvirt version typo --- .../cloud/hypervisor/kvm/resource/LibvirtComputingResource.java | 2 +- .../hypervisor/kvm/resource/LibvirtComputingResourceTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 284b4cd678e4..31420c7d2932 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -253,7 +253,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv protected static final String DEFAULT_OVS_VIF_DRIVER_CLASS_NAME = "com.cloud.hypervisor.kvm.resource.OvsVifDriver"; protected static final String DEFAULT_BRIDGE_VIF_DRIVER_CLASS_NAME = "com.cloud.hypervisor.kvm.resource.BridgeVifDriver"; - private final static long HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IO_URING = 6030000; + private final static long HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IO_URING = 6003000; private final static long HYPERVISOR_QEMU_VERSION_SUPPORTS_IO_URING = 5000000; protected HypervisorType _hypervisorType; diff --git a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java index 57ca3b2fbe38..61572554d9e9 100644 --- a/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java +++ b/plugins/hypervisors/kvm/src/test/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResourceTest.java @@ -202,7 +202,7 @@ public class LibvirtComputingResourceTest { @Mock LibvirtVMDef vmDef; - private final static long HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IOURING = 6030000; + private final static long HYPERVISOR_LIBVIRT_VERSION_SUPPORTS_IOURING = 6003000; private final static long HYPERVISOR_QEMU_VERSION_SUPPORTS_IOURING = 5000000; String hyperVisorType = "kvm";