Skip to content

Commit

Permalink
core: block hot plug CPU with exclusive pinning
Browse files Browse the repository at this point in the history
This patch prevent the user from hotplugging CPU when the VM is set with
exclusive pinning as we don't support it. Currently it will validated
only on the hot-plug command, which is less visible to the user.
With this patch, it won't be allowed and the user will be noticed.

Another addition is to consider within the validation the right pool of
shared CPUs to use.

Change-Id: Ie8d32b9e85879e6764bab63399c3d5762ba806db
Signed-off-by: Liran Rotenberg <lrotenbe@redhat.com>
  • Loading branch information
liranr23 committed Jun 16, 2022
1 parent 82bd88a commit 0ca24d3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@ protected boolean validate() {
valid = failValidation(EngineMessage.HOT_PLUG_CPU_CONFLICT,
String.format("%1$s", getVm().getCpuPinningPolicy().name()));
}
if (getVm().getCpuPinningPolicy().isExclusive()) {
valid = failValidation(EngineMessage.HOT_PLUG_CPU_IS_NOT_SUPPORTED_DEDICATED,
String.format("$policy %1$s", getVm().getCpuPinningPolicy().name()));
}

return valid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1195,8 +1195,14 @@ protected boolean validate() {
return failValidation(EngineMessage.USE_HOST_CPU_REQUESTED_ON_UNSUPPORTED_ARCH);
}

if (isHotSetEnabled() && !validateCPUHotplug(getParameters().getVmStaticData())) {
return failValidation(EngineMessage.CPU_HOTPLUG_TOPOLOGY_INVALID);
if (isHotSetEnabled() && getVm().isRunningOrPaused() && getVds() != null) {
if (!validateCPUHotplug(getParameters().getVmStaticData())) {
return failValidation(EngineMessage.CPU_HOTPLUG_TOPOLOGY_INVALID);
}
if (!validateCpuPinningPolicyWithHotplug(getParameters().getVmStaticData())) {
return failValidation(EngineMessage.HOT_PLUG_CPU_IS_NOT_SUPPORTED_DEDICATED,
String.format("$policy %1$s", getVm().getCpuPinningPolicy().name()));
}
}

if (!validateMemoryAlignment(getParameters().getVmStaticData())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.ovirt.engine.core.bll.context.CommandContext;
import org.ovirt.engine.core.bll.numa.vm.NumaValidator;
import org.ovirt.engine.core.bll.profiles.CpuProfileHelper;
import org.ovirt.engine.core.bll.scheduling.utils.VdsCpuUnitPinningHelper;
import org.ovirt.engine.core.common.FeatureSupported;
import org.ovirt.engine.core.common.action.VmManagementParametersBase;
import org.ovirt.engine.core.common.businessentities.ArchitectureType;
Expand Down Expand Up @@ -41,6 +42,8 @@ public abstract class VmManagementCommandBase<T extends VmManagementParametersBa
private VmTemplateDao vmTemplateDao;
@Inject
private VdsDao vdsDao;
@Inject
private VdsCpuUnitPinningHelper vdsCpuUnitPinningHelper;

private InstanceType instanceType;
private Version effectiveCompatibilityVersion;
Expand Down Expand Up @@ -116,15 +119,22 @@ protected boolean setAndValidateCpuProfile() {
}

protected boolean validateCPUHotplug(VmStatic vmStaticData) {
if (getVm().isRunningOrPaused()) {
// Can't set more CPUs than available on the host where VM is running.
// Potential overcommit (interference with other running VMs) will be resolved by scheduler.
// In alignment with the CPUPolicyUnit, VM's hyperthreading is not considered.
if (getVds() != null && vmStaticData.getNumOfCpus(false) > getVds().getCpuThreads()) {
return false;
}
// Can't set more CPUs than available on the host where VM is running.
// Potential overcommit (interference with other running VMs) will be resolved by scheduler.
// In alignment with the CPUPolicyUnit, VM's hyperthreading is not considered.
int unavailableThreads = getVds().getCpuThreads() - vdsCpuUnitPinningHelper.countUnavailableCpus(
getVdsManager(getVdsId()).getCpuTopology(), true);
if (vmStaticData.getNumOfCpus(false) > unavailableThreads) {
return false;
}
return true;
}

protected boolean validateCpuPinningPolicyWithHotplug(VmStatic vmStaticData) {
if (getVm().getCpuPinningPolicy().isExclusive()
&& vmStaticData.getNumOfCpus(false) > getVm().getNumOfCpus(false)) {
return false;
}
return true;
}

Expand Down

0 comments on commit 0ca24d3

Please sign in to comment.