From d6cd406527adf7ee5c20a83a329515b0f12e0391 Mon Sep 17 00:00:00 2001 From: Nate Gordon Date: Tue, 22 Nov 2022 12:46:36 -0600 Subject: [PATCH] Applying PR 2870 from upstream. This adds additional hyper-v enlightenments. https://github.com/apache/cloudstack/pull/2870 --- .../resource/LibvirtComputingResource.java | 27 ++++++++++++------- .../hypervisor/kvm/resource/LibvirtVMDef.java | 2 ++ .../kvm/resource/LibvirtVMDefTest.java | 7 +---- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index bdbef5890392..3032fc8f3021 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -2023,6 +2023,19 @@ protected void setQuotaAndPeriod(VirtualMachineTO vmTO, CpuTuneDef ctd) { } } + protected void enlightenWindowsVm(VirtualMachineTO vmTO, FeaturesDef features) { + if (vmTO.getOs().contains("Windows PV")) { + // If OS is Windows PV, then enable the features. Features supported on Windows 2008 and later + LibvirtVMDef.HyperVEnlightenmentFeatureDef hyv = new LibvirtVMDef.HyperVEnlightenmentFeatureDef(); + hyv.setFeature("relaxed", true); + hyv.setFeature("vapic", true); + hyv.setFeature("spinlocks", true); + hyv.setRetries(8096); + features.addHyperVFeature(hyv); + s_logger.info("Enabling KVM Enlightment Features to VM domain " + vmTO.getUuid()); + } + } + public LibvirtVMDef createVMFromSpec(final VirtualMachineTO vmTO) { final LibvirtVMDef vm = new LibvirtVMDef(); vm.setDomainName(vmTO.getName()); @@ -2109,14 +2122,10 @@ So if getMinSpeed() returns null we fall back to getSpeed(). features.addFeatures("pae"); features.addFeatures("apic"); features.addFeatures("acpi"); - //for rhel 6.5 and above, hyperv enlightment feature is added - /* - * if (vmTO.getOs().contains("Windows Server 2008") && hostOsVersion != null && ((hostOsVersion.first() == 6 && hostOsVersion.second() >= 5) || (hostOsVersion.first() >= 7))) { - * LibvirtVMDef.HyperVEnlightenmentFeatureDef hyv = new LibvirtVMDef.HyperVEnlightenmentFeatureDef(); - * hyv.setRelaxed(true); - * features.addHyperVFeature(hyv); - * } - */ + + //KVM hyperv enlightenment features based on OS Type + enlightenWindowsVm(vmTO, features); + vm.addComp(features); final TermPolicy term = new TermPolicy(); @@ -2128,7 +2137,7 @@ So if getMinSpeed() returns null we fall back to getSpeed(). final ClockDef clock = new ClockDef(); if (vmTO.getOs().startsWith("Windows")) { clock.setClockOffset(ClockDef.ClockOffset.LOCALTIME); - clock.setTimer("rtc", "catchup", null); + clock.setTimer("hypervclock", null, null); } else if (vmTO.getType() != VirtualMachine.Type.User || isGuestPVEnabled(vmTO.getOs())) { if (_hypervisorLibvirtVersion >= 9 * 1000 + 10) { clock.setTimer("kvmclock", null, null, _noKvmClock); diff --git a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java index 20730211361f..83034a215a10 100644 --- a/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java +++ b/plugins/hypervisors/kvm/src/com/cloud/hypervisor/kvm/resource/LibvirtVMDef.java @@ -379,6 +379,8 @@ public String toString() { if (_timerName.equals("kvmclock") && _noKvmClock) { clockBuilder.append("present='no' />"); + } else if (_timerName.equals("hypervclock")) { + clockBuilder.append("present='yes' />"); } else { if (_tickPolicy != null) { clockBuilder.append("tickpolicy='"); diff --git a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java index c3b3a8b76ddc..277934683332 100644 --- a/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java +++ b/plugins/hypervisors/kvm/test/com/cloud/hypervisor/kvm/resource/LibvirtVMDefTest.java @@ -24,7 +24,6 @@ import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.ChannelDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.DiskDef; import com.cloud.hypervisor.kvm.resource.LibvirtVMDef.SCSIDef; -import com.cloud.utils.Pair; import junit.framework.TestCase; @@ -188,12 +187,8 @@ public void testHypervEnlightDef() { assertFalse(defs.contains("relaxed")); assertFalse(defs.contains("vapic")); assertFalse(defs.contains("spinlocks")); - assertTrue("Windows Server 2008 R2".contains("Windows Server 2008")); + assertTrue("Windows PV".contains("Windows PV")); - Pair hostOsVersion = new Pair(6,5); - assertTrue((hostOsVersion.first() == 6 && hostOsVersion.second() >= 5) || (hostOsVersion.first() >= 7)); - hostOsVersion = new Pair(7,1); - assertTrue((hostOsVersion.first() == 6 && hostOsVersion.second() >= 5) || (hostOsVersion.first() >= 7)); } public void testRngDef() {