mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-10-22 12:29:49 +00:00
runtime-rs: introduce update_device
in trait Hypervisor
Introduce the `update_device` trait in Hypervisor to enable device updates for VMMs.This trait will initially be utilized for virtiofs Mount operations. Fixes: #7915 Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
@@ -108,6 +108,10 @@ impl CloudHypervisorInner {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn update_device(&mut self, _device: DeviceType) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn handle_share_fs_device(&mut self, sharefs: ShareFsDevice) -> Result<DeviceType> {
|
||||
let device: ShareFsDevice = sharefs.clone();
|
||||
if device.config.fs_type != VIRTIO_FS {
|
||||
|
@@ -89,6 +89,11 @@ impl Hypervisor for CloudHypervisor {
|
||||
inner.remove_device(device).await
|
||||
}
|
||||
|
||||
async fn update_device(&self, device: DeviceType) -> Result<()> {
|
||||
let mut inner = self.inner.write().await;
|
||||
inner.update_device(device).await
|
||||
}
|
||||
|
||||
async fn get_agent_socket(&self) -> Result<String> {
|
||||
let inner = self.inner.write().await;
|
||||
inner.get_agent_socket().await
|
||||
|
@@ -543,6 +543,11 @@ impl Device for VfioDevice {
|
||||
Ok(device_index)
|
||||
}
|
||||
|
||||
async fn update(&mut self, _h: &dyn hypervisor) -> Result<()> {
|
||||
// There's no need to do update for vfio device
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn increase_attach_count(&mut self) -> Result<bool> {
|
||||
match self.attach_count {
|
||||
0 => {
|
||||
|
@@ -86,6 +86,11 @@ impl Device for VhostUserBlkDevice {
|
||||
Ok(Some(self.config.index))
|
||||
}
|
||||
|
||||
async fn update(&mut self, _h: &dyn hypervisor) -> Result<()> {
|
||||
// There's no need to do update for vhost-user-blk
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_device_info(&self) -> DeviceType {
|
||||
DeviceType::VhostUserBlk(self.clone())
|
||||
}
|
||||
|
@@ -114,6 +114,11 @@ impl Device for BlockDevice {
|
||||
Ok(Some(self.config.index))
|
||||
}
|
||||
|
||||
async fn update(&mut self, _h: &dyn hypervisor) -> Result<()> {
|
||||
// There's no need to do update for virtio-blk
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_device_info(&self) -> DeviceType {
|
||||
DeviceType::Block(self.clone())
|
||||
}
|
||||
|
@@ -95,6 +95,11 @@ impl Device for NetworkDevice {
|
||||
Ok(Some(self.config.index))
|
||||
}
|
||||
|
||||
async fn update(&mut self, _h: &dyn hypervisor) -> Result<()> {
|
||||
// There's no need to do update for network device
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_device_info(&self) -> DeviceType {
|
||||
DeviceType::Network(self.clone())
|
||||
}
|
||||
|
@@ -62,6 +62,11 @@ impl Device for HybridVsockDevice {
|
||||
Ok(None)
|
||||
}
|
||||
|
||||
async fn update(&mut self, _h: &dyn hypervisor) -> Result<()> {
|
||||
// There's no need to do update for hvsock device
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn get_device_info(&self) -> DeviceType {
|
||||
DeviceType::HybridVsock(self.clone())
|
||||
}
|
||||
|
@@ -54,6 +54,8 @@ pub trait Device: std::fmt::Debug + Send + Sync {
|
||||
async fn attach(&mut self, h: &dyn hypervisor) -> Result<()>;
|
||||
// detach is to unplug device from VM
|
||||
async fn detach(&mut self, h: &dyn hypervisor) -> Result<Option<u64>>;
|
||||
// update is to do update for some device
|
||||
async fn update(&mut self, h: &dyn hypervisor) -> Result<()>;
|
||||
// get_device_info returns device config
|
||||
async fn get_device_info(&self) -> DeviceType;
|
||||
// increase_attach_count is used to increase the attach count for a device
|
||||
|
@@ -101,6 +101,12 @@ impl DragonballInner {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) async fn update_device(&mut self, device: DeviceType) -> Result<()> {
|
||||
info!(sl!(), "dragonball update device {:?}", &device);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn add_vfio_device(&mut self, device: &VfioDevice) -> Result<()> {
|
||||
let vfio_device = device.clone();
|
||||
|
||||
|
@@ -110,6 +110,11 @@ impl Hypervisor for Dragonball {
|
||||
inner.remove_device(device).await
|
||||
}
|
||||
|
||||
async fn update_device(&self, device: DeviceType) -> Result<()> {
|
||||
let mut inner = self.inner.write().await;
|
||||
inner.update_device(device).await
|
||||
}
|
||||
|
||||
async fn get_agent_socket(&self) -> Result<String> {
|
||||
let inner = self.inner.read().await;
|
||||
inner.get_agent_socket().await
|
||||
|
@@ -87,6 +87,7 @@ pub trait Hypervisor: std::fmt::Debug + Send + Sync {
|
||||
// device manager
|
||||
async fn add_device(&self, device: DeviceType) -> Result<DeviceType>;
|
||||
async fn remove_device(&self, device: DeviceType) -> Result<()>;
|
||||
async fn update_device(&self, device: DeviceType) -> Result<()>;
|
||||
|
||||
// utils
|
||||
async fn get_agent_socket(&self) -> Result<String>;
|
||||
|
@@ -155,4 +155,10 @@ impl QemuInner {
|
||||
info!(sl!(), "QemuInner::remove_device() {} ", device);
|
||||
todo!()
|
||||
}
|
||||
|
||||
pub(crate) async fn update_device(&mut self, device: DeviceType) -> Result<()> {
|
||||
info!(sl!(), "QemuInner::update_device() {:?}", &device);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@@ -84,6 +84,11 @@ impl Hypervisor for Qemu {
|
||||
inner.remove_device(device).await
|
||||
}
|
||||
|
||||
async fn update_device(&self, device: DeviceType) -> Result<()> {
|
||||
let mut inner = self.inner.write().await;
|
||||
inner.update_device(device).await
|
||||
}
|
||||
|
||||
async fn get_agent_socket(&self) -> Result<String> {
|
||||
let inner = self.inner.read().await;
|
||||
inner.get_agent_socket().await
|
||||
|
Reference in New Issue
Block a user