Skip to content

Commit 566082e

Browse files
committed
Change hot-plug API endpoint
Change from `add` to `target`. The user now supplies the number of vCPUs they would like to reach, rather than the number of vCPUs to add to the system. Obviously to make this work, hot-unplug functionality is needed as well. Examples: - Currently 1 vCPU, would like 16 vCPUs: target = 16 - Currently 32 vCPUs, would like 2 vCPUs: target = 2 Signed-off-by: James Curtis <[email protected]>
1 parent a541725 commit 566082e

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

src/vmm/src/lib.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -615,31 +615,23 @@ impl Vmm {
615615
config: HotplugVcpuConfig,
616616
) -> Result<MachineConfigUpdate, HotplugVcpuError> {
617617
use crate::logger::IncMetric;
618-
if config.add < 1 {
619-
return Err(HotplugVcpuError::VcpuCountTooLow);
620-
} else if self
621-
.vcpus_handles
622-
.len()
623-
.checked_add(config.add.into())
624-
.ok_or(HotplugVcpuError::VcpuCountTooHigh)?
625-
> MAX_SUPPORTED_VCPUS.into()
626-
{
618+
if config.target > MAX_SUPPORTED_VCPUS.into() {
627619
return Err(HotplugVcpuError::VcpuCountTooHigh);
628620
}
629621

630622
if let Some(kvm_config) = self.vcpu_config.as_mut() {
631-
kvm_config.vcpu_count += config.add;
623+
kvm_config.vcpu_count = config.target;
632624
}
633625
// Create and start new vcpus
634-
let mut vcpus = Vec::with_capacity(config.add.into());
626+
let mut vcpus = Vec::with_capacity(config.target.into());
635627

636628
#[allow(clippy::cast_possible_truncation)]
637629
let start_idx = self.vcpus_handles.len().try_into().unwrap();
638630
if let Some(devices::BusDevice::CpuContainer(cont)) =
639631
self.get_bus_device(DeviceType::CpuContainer, "CpuContainer")
640632
{
641633
let mut locked_container = cont.lock().expect("Poisoned lock");
642-
for cpu_idx in start_idx..(start_idx + config.add) {
634+
for cpu_idx in start_idx..config.target {
643635
let exit_evt = self
644636
.vcpus_exit_evt
645637
.try_clone()
@@ -666,7 +658,10 @@ impl Vmm {
666658
.map_err(HotplugVcpuError::VcpuStart)?;
667659

668660
#[allow(clippy::cast_lossless)]
669-
METRICS.hotplug.vcpus_added.add(config.add.into());
661+
METRICS
662+
.hotplug
663+
.vcpus_added
664+
.add(self.vcpus_handles.len() as u64 - config.target as u64);
670665

671666
// Update VM config to reflect new CPUs added
672667
#[allow(clippy::cast_possible_truncation)]
@@ -686,6 +681,7 @@ impl Vmm {
686681
Ok(new_machine_config)
687682
}
688683

684+
/// Removes vCPUs from VMM.
689685
/// Retrieves the KVM dirty bitmap for each of the guest's memory regions.
690686
pub fn reset_dirty_bitmap(&self) {
691687
self.guest_memory

src/vmm/src/vmm_config/hotplug.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ pub enum HotplugVcpuError {
5050
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
5151
#[serde(deny_unknown_fields)]
5252
pub struct HotplugVcpuConfig {
53-
/// Number of vcpus to start.
54-
pub add: u8,
53+
/// Number of vcpus after operation.
54+
pub target: u8,
5555
}

0 commit comments

Comments
 (0)