mirror of https://github.com/apache/cloudstack.git
[KVM] CPU Features for System VMs (#10964)
* CPU features for System VMs * Apply guest.cpu.features for System VMs
This commit is contained in:
parent
2c34f5e495
commit
ba2d70ab21
|
|
@ -213,8 +213,9 @@ hypervisor.type=kvm
|
||||||
# If null (default), defaults to the VM's OS architecture
|
# If null (default), defaults to the VM's OS architecture
|
||||||
#guest.cpu.arch=
|
#guest.cpu.arch=
|
||||||
|
|
||||||
# This param will require CPU features on the CPU section.
|
# Specifies required CPU features for end-user and system VMs.
|
||||||
# The features listed in this property must be separated by a blank space (e.g.: vmx vme)
|
# These features must be present on the host CPU for VM deployment.
|
||||||
|
# Multiple features should be separated by whitespace (e.g.: vmx vme).
|
||||||
#guest.cpu.features=
|
#guest.cpu.features=
|
||||||
|
|
||||||
# Disables memory ballooning on VM guests for overcommit.
|
# Disables memory ballooning on VM guests for overcommit.
|
||||||
|
|
|
||||||
|
|
@ -425,8 +425,9 @@ public class AgentProperties{
|
||||||
public static final Property<String> GUEST_CPU_ARCH = new Property<>("guest.cpu.arch", null, String.class);
|
public static final Property<String> GUEST_CPU_ARCH = new Property<>("guest.cpu.arch", null, String.class);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This param will require CPU features on the CPU section.<br>
|
* Specifies required CPU features for end-user and system VMs.<br>
|
||||||
* The features listed in this property must be separated by a blank space (see example below).<br>
|
* These features must be present on the host CPU for VM deployment.<br>
|
||||||
|
* Multiple features should be separated by whitespace (see example below).<br>
|
||||||
* Possible values: vmx vme <br>
|
* Possible values: vmx vme <br>
|
||||||
* Data type: String.<br>
|
* Data type: String.<br>
|
||||||
* Default value: <code>null</code>
|
* Default value: <code>null</code>
|
||||||
|
|
|
||||||
|
|
@ -1316,15 +1316,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||||
params.put("guest.cpu.model", guestCpuModel);
|
params.put("guest.cpu.model", guestCpuModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
final String cpuFeatures = AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_FEATURES);
|
this.cpuFeatures = parseCpuFeatures(AgentPropertiesFileHandler.getPropertyValue(AgentProperties.GUEST_CPU_FEATURES));
|
||||||
if (cpuFeatures != null) {
|
|
||||||
this.cpuFeatures = new ArrayList<String>();
|
|
||||||
for (final String feature: cpuFeatures.split(" ")) {
|
|
||||||
if (!feature.isEmpty()) {
|
|
||||||
this.cpuFeatures.add(feature);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final String[] info = NetUtils.getNetworkParams(privateNic);
|
final String[] info = NetUtils.getNetworkParams(privateNic);
|
||||||
|
|
||||||
|
|
@ -1430,6 +1422,22 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses a string containing whitespace-separated CPU feature names and converts it into a list.
|
||||||
|
*
|
||||||
|
* @param features A string containing whitespace-separated CPU feature names to be parsed.
|
||||||
|
* @return A list of CPU feature strings. Returns an empty list if {@code features} is null.
|
||||||
|
*/
|
||||||
|
protected List<String> parseCpuFeatures(String features) {
|
||||||
|
if (features == null) {
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Arrays.stream(features.split(" "))
|
||||||
|
.filter(feature -> !feature.isEmpty())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the ID list of the VMs to set memory balloon stats period.
|
* Gets the ID list of the VMs to set memory balloon stats period.
|
||||||
* @param conn the Libvirt connection.
|
* @param conn the Libvirt connection.
|
||||||
|
|
@ -3210,9 +3218,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv
|
||||||
String cpuModel = MapUtils.isNotEmpty(details) && details.get(VmDetailConstants.GUEST_CPU_MODEL) != null ? details.get(VmDetailConstants.GUEST_CPU_MODEL) : guestCpuModel;
|
String cpuModel = MapUtils.isNotEmpty(details) && details.get(VmDetailConstants.GUEST_CPU_MODEL) != null ? details.get(VmDetailConstants.GUEST_CPU_MODEL) : guestCpuModel;
|
||||||
cmd.setMode(cpuMode);
|
cmd.setMode(cpuMode);
|
||||||
cmd.setModel(cpuModel);
|
cmd.setModel(cpuModel);
|
||||||
if (VirtualMachine.Type.User.equals(vmTO.getType())) {
|
cmd.setFeatures(cpuFeatures);
|
||||||
cmd.setFeatures(cpuFeatures);
|
|
||||||
}
|
|
||||||
int vCpusInDef = vmTO.getVcpuMaxLimit() == null ? vcpus : vmTO.getVcpuMaxLimit();
|
int vCpusInDef = vmTO.getVcpuMaxLimit() == null ? vcpus : vmTO.getVcpuMaxLimit();
|
||||||
setCpuTopology(cmd, vCpusInDef, vmTO.getDetails());
|
setCpuTopology(cmd, vCpusInDef, vmTO.getDetails());
|
||||||
return cmd;
|
return cmd;
|
||||||
|
|
|
||||||
|
|
@ -7126,4 +7126,20 @@ public class LibvirtComputingResourceTest {
|
||||||
assertEquals("2g.10gb", vfInstance2.getModelName());
|
assertEquals("2g.10gb", vfInstance2.getModelName());
|
||||||
assertNull(vfInstance2.getVmName());
|
assertNull(vfInstance2.getVmName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseCpuFeaturesTestReturnEmptyListWhenFeaturesIsNull() {
|
||||||
|
List<String> cpuFeatures = libvirtComputingResourceSpy.parseCpuFeatures(null);
|
||||||
|
Assert.assertEquals(0, cpuFeatures.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseCpuFeaturesTestReturnListOfCpuFeaturesAndIgnoreMultipleWhitespacesAlongsideEachOther() {
|
||||||
|
List<String> cpuFeatures = libvirtComputingResourceSpy.parseCpuFeatures(" -mca mce -mmx hle ");
|
||||||
|
Assert.assertEquals(4, cpuFeatures.size());
|
||||||
|
Assert.assertEquals("-mca", cpuFeatures.get(0));
|
||||||
|
Assert.assertEquals("mce", cpuFeatures.get(1));
|
||||||
|
Assert.assertEquals("-mmx", cpuFeatures.get(2));
|
||||||
|
Assert.assertEquals("hle", cpuFeatures.get(3));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue