vmm: don't allow resizing to 0 vCPUs

No sane guest OS will allow hotplugging all cpus.
However, the REST API currently allows specifying
`ch-remote resize --cpus 0`.

On Linux, we can then observe the following error in the kernel log:

processor cpu0: Offline failed.

Subsequent resize commands via ch-remote will then fail with
VcpuPendingRemovedVcpu because the removal of cpu0 was never
successful.

Fix this by disallowing resizing to zero vCPUs.

Signed-off-by: Thomas Prescher <thomas.prescher@cyberus-technology.de>
On-behalf-of: SAP thomas.prescher@sap.com
This commit is contained in:
Thomas Prescher
2025-05-21 16:11:55 +02:00
committed by Rob Bradford
parent 0463f4f156
commit d46517559b

View File

@@ -157,6 +157,9 @@ pub enum Error {
#[error("Error adding CpuManager to MMIO bus: {0}")]
BusError(#[source] vm_device::BusError),
#[error("Requested zero vCPUs")]
DesiredVCpuCountIsZero,
#[error("Requested vCPUs exceed maximum")]
DesiredVCpuCountExceedsMax,
@@ -1320,6 +1323,10 @@ impl CpuManager {
return Ok(false);
}
if desired_vcpus < 1 {
return Err(Error::DesiredVCpuCountIsZero);
}
if self.check_pending_removed_vcpu() {
return Err(Error::VcpuPendingRemovedVcpu);
}