mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-23 22:17:19 +00:00
dragonball: Remove virtio-net and vsock devices gracefully
This MR implements removing virtio-net and virtio-vsock devices gracefully when shutting down VMM. Fixes: #6684 Signed-off-by: Zizheng Bian <zizheng.bian@linux.alibaba.com> Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
This commit is contained in:
parent
e762f70920
commit
ee6deef09d
@ -278,6 +278,11 @@ where
|
||||
self.info_list.iter_mut()
|
||||
}
|
||||
|
||||
/// Remove the last device config info from the `info_list`.
|
||||
pub fn pop(&mut self) -> Option<DeviceConfigInfo<T>> {
|
||||
self.info_list.pop()
|
||||
}
|
||||
|
||||
fn get_index_by_id(&self, config: &T) -> Option<usize> {
|
||||
self.info_list
|
||||
.iter()
|
||||
|
@ -714,6 +714,14 @@ impl DeviceManager {
|
||||
|
||||
#[cfg(feature = "virtio-blk")]
|
||||
self.block_manager.remove_devices(&mut ctx)?;
|
||||
// FIXME: To acquire the full abilities for gracefully removing
|
||||
// virtio-net and virtio-vsock devices, updating dragonball-sandbox
|
||||
// is required.
|
||||
#[cfg(feature = "virtio-net")]
|
||||
self.virtio_net_manager.remove_devices(&mut ctx)?;
|
||||
#[cfg(feature = "virtio-vsock")]
|
||||
self.vsock_manager.remove_devices(&mut ctx)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -374,6 +374,21 @@ impl VirtioNetDeviceMgr {
|
||||
|
||||
Ok(Box::new(net_device))
|
||||
}
|
||||
|
||||
/// Remove all virtio-net devices.
|
||||
pub fn remove_devices(&mut self, ctx: &mut DeviceOpContext) -> Result<(), DeviceMgrError> {
|
||||
while let Some(mut info) = self.info_list.pop() {
|
||||
slog::info!(
|
||||
ctx.logger(),
|
||||
"remove virtio-net device: {}",
|
||||
info.config.iface_id
|
||||
);
|
||||
if let Some(device) = info.device.take() {
|
||||
DeviceManager::destroy_mmio_virtio_device(device, ctx)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for VirtioNetDeviceMgr {
|
||||
|
@ -17,7 +17,7 @@ use dbs_virtio_devices::vsock::Vsock;
|
||||
use dbs_virtio_devices::Error as VirtioError;
|
||||
use serde_derive::{Deserialize, Serialize};
|
||||
|
||||
use super::StartMicroVmError;
|
||||
use super::{DeviceMgrError, StartMicroVmError};
|
||||
use crate::config_manager::{ConfigItem, DeviceConfigInfo, DeviceConfigInfos};
|
||||
use crate::device_manager::{DeviceManager, DeviceOpContext};
|
||||
|
||||
@ -284,6 +284,21 @@ impl VsockDeviceMgr {
|
||||
// safe to unwrap, because we created the inner connector before
|
||||
Ok(self.default_inner_connector.clone().unwrap())
|
||||
}
|
||||
|
||||
/// Remove all virtio-vsock devices
|
||||
pub fn remove_devices(&mut self, ctx: &mut DeviceOpContext) -> Result<(), DeviceMgrError> {
|
||||
while let Some(mut info) = self.info_list.pop() {
|
||||
slog::info!(
|
||||
ctx.logger(),
|
||||
"remove virtio-vsock device: {}",
|
||||
info.config.id
|
||||
);
|
||||
if let Some(device) = info.device.take() {
|
||||
DeviceManager::destroy_mmio_virtio_device(device, ctx)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for VsockDeviceMgr {
|
||||
|
Loading…
Reference in New Issue
Block a user