mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-09-17 06:48:51 +00:00
runtime-rs: make the resize_vcpu sync
When hot plugging vcpu in dragonball hypervisor, use the synchronization interface and wait until the hot plug cpu is executed in the guest before returning. This ensures that the subsequent device hot plug will not conflict with the previous call. Signed-off-by: Fupan Li <fupan.lfp@antgroup.com>
This commit is contained in:
@@ -28,7 +28,7 @@ use kata_types::{
|
||||
};
|
||||
use nix::mount::MsFlags;
|
||||
use persist::sandbox_persist::Persist;
|
||||
use std::cmp::Ordering;
|
||||
use std::{cmp::Ordering, time::Duration};
|
||||
use std::{collections::HashSet, fs::create_dir_all};
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
@@ -37,6 +37,9 @@ const DRAGONBALL_INITRD: &str = "initrd";
|
||||
const DRAGONBALL_ROOT_FS: &str = "rootfs";
|
||||
const BALLOON_DEVICE_ID: &str = "balloon0";
|
||||
const MEM_DEVICE_ID: &str = "memmr0";
|
||||
/// default hotplug timeout
|
||||
const DEFAULT_HOTPLUG_TIMEOUT: u64 = 250;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DragonballInner {
|
||||
/// sandbox id
|
||||
@@ -391,7 +394,10 @@ impl DragonballInner {
|
||||
vcpu_count: Some(new_vcpus as u8),
|
||||
};
|
||||
self.vmm_instance
|
||||
.resize_vcpu(&cpu_resize_info)
|
||||
.resize_vcpu(
|
||||
&cpu_resize_info,
|
||||
Some(Duration::from_millis(DEFAULT_HOTPLUG_TIMEOUT)),
|
||||
)
|
||||
.context(format!(
|
||||
"failed to do_resize_vcpus on new_vcpus={:?}",
|
||||
new_vcpus
|
||||
|
@@ -9,6 +9,7 @@ use std::{
|
||||
os::unix::{io::IntoRawFd, prelude::AsRawFd},
|
||||
sync::{Arc, Mutex, RwLock},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
@@ -292,9 +293,17 @@ impl VmmInstance {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn resize_vcpu(&self, cfg: &VcpuResizeInfo) -> Result<()> {
|
||||
self.handle_request(Request::Sync(VmmAction::ResizeVcpu(cfg.clone())))
|
||||
pub fn resize_vcpu(&self, cfg: &VcpuResizeInfo, timeout: Option<Duration>) -> Result<()> {
|
||||
let vmmdata = self
|
||||
.handle_request(Request::Sync(VmmAction::ResizeVcpu(cfg.clone())))
|
||||
.with_context(|| format!("Failed to resize_vm(hotplug vcpu), cfg: {:?}", cfg))?;
|
||||
|
||||
if let Some(timeout) = timeout {
|
||||
if let VmmData::SyncHotplug((_, receiver)) = vmmdata {
|
||||
let _ = receiver.recv_timeout(timeout)?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user