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:
alex.lyn
2023-11-14 11:56:36 +08:00
parent c858ea1460
commit 4d65c2e8a2
13 changed files with 59 additions and 0 deletions

View File

@@ -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 {

View File

@@ -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

View File

@@ -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 => {

View File

@@ -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())
}

View File

@@ -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())
}

View File

@@ -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())
}

View File

@@ -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())
}

View File

@@ -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

View File

@@ -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();

View File

@@ -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

View File

@@ -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>;

View File

@@ -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(())
}
}

View File

@@ -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