mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-08-11 21:02:34 +00:00
runtime-rs: add support resize_vcpu for cloud-hypervisor
This commit add support of resize_vcpu for cloud-hypervisor using the it's vm resize api. It can support bothof vcpu hotplug and hot unplug. Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
This commit is contained in:
parent
a3671b7a5c
commit
1c59516d72
@ -681,8 +681,50 @@ impl CloudHypervisorInner {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn resize_vcpu(&self, old_vcpu: u32, new_vcpu: u32) -> Result<(u32, u32)> {
|
pub(crate) async fn resize_vcpu(
|
||||||
Ok((old_vcpu, new_vcpu))
|
&self,
|
||||||
|
old_vcpus: u32,
|
||||||
|
mut new_vcpus: u32,
|
||||||
|
) -> Result<(u32, u32)> {
|
||||||
|
info!(
|
||||||
|
sl!(),
|
||||||
|
"cloud hypervisor resize_vcpu(): {} -> {}", old_vcpus, new_vcpus
|
||||||
|
);
|
||||||
|
|
||||||
|
if new_vcpus == 0 {
|
||||||
|
return Err(anyhow!("resize to 0 vcpus requested"));
|
||||||
|
}
|
||||||
|
|
||||||
|
if new_vcpus > self.config.cpu_info.default_maxvcpus {
|
||||||
|
warn!(
|
||||||
|
sl!(),
|
||||||
|
"Cannot allocate more vcpus than the max allowed number of vcpus. The maximum allowed amount of vcpus will be used instead.");
|
||||||
|
new_vcpus = self.config.cpu_info.default_maxvcpus;
|
||||||
|
}
|
||||||
|
|
||||||
|
if new_vcpus == old_vcpus {
|
||||||
|
return Ok((old_vcpus, new_vcpus));
|
||||||
|
}
|
||||||
|
|
||||||
|
let socket = self
|
||||||
|
.api_socket
|
||||||
|
.as_ref()
|
||||||
|
.ok_or("missing socket")
|
||||||
|
.map_err(|e| anyhow!(e))?;
|
||||||
|
|
||||||
|
let vmresize = VmResize {
|
||||||
|
desired_vcpus: Some(new_vcpus as u8),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
|
||||||
|
cloud_hypervisor_vm_resize(
|
||||||
|
socket.try_clone().context("failed to clone socket")?,
|
||||||
|
vmresize,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.context("resize vcpus")?;
|
||||||
|
|
||||||
|
Ok((old_vcpus, new_vcpus))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn get_pids(&self) -> Result<Vec<u32>> {
|
pub(crate) async fn get_pids(&self) -> Result<Vec<u32>> {
|
||||||
|
Loading…
Reference in New Issue
Block a user