hypervisor: drop create_device from Vm trait

This then avoids the need for creating a generic DeviceFd type in the
hypervisor crate.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu
2022-07-20 15:11:27 +00:00
committed by Liu Wei
parent 500d91311f
commit 422bf89d4d
3 changed files with 28 additions and 26 deletions

View File

@@ -913,6 +913,20 @@ pub struct MshvVm {
dirty_log_slots: Arc<RwLock<HashMap<u64, MshvDirtyLogSlot>>>,
}
impl MshvVm {
///
/// Creates an in-kernel device.
///
/// See the documentation for `MSHV_CREATE_DEVICE`.
fn create_device(&self, device: &mut CreateDevice) -> vm::Result<Arc<dyn device::Device>> {
let device_fd = self
.fd
.create_device(device)
.map_err(|e| vm::HypervisorVmError::CreateDevice(e.into()))?;
Ok(Arc::new(device_fd))
}
}
///
/// Implementation of Vm trait for Mshv
/// Example:
@@ -1096,18 +1110,6 @@ impl vm::Vm for MshvVm {
.into()
}
///
/// Creates an in-kernel device.
///
/// See the documentation for `MSHV_CREATE_DEVICE`.
fn create_device(&self, device: &mut CreateDevice) -> vm::Result<Arc<dyn device::Device>> {
let device_fd = self
.fd
.create_device(device)
.map_err(|e| vm::HypervisorVmError::CreateDevice(e.into()))?;
Ok(Arc::new(device_fd))
}
fn create_passthrough_device(&self) -> vm::Result<Arc<dyn device::Device>> {
let mut vfio_dev = mshv_create_device {
type_: mshv_device_type_MSHV_DEV_TYPE_VFIO,