hypervisor: Refactor create_passthrough_device() for generic type

Changed the return type of create_passthrough_device() to generic type
hypervisor::Device.

Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
Michael Zhao
2020-07-21 17:56:00 +08:00
committed by Samuel Ortiz
parent 6c8749adf2
commit ddf1b76906
4 changed files with 32 additions and 22 deletions

View File

@@ -9,6 +9,7 @@
//
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
use std::os::unix::io::{AsRawFd, RawFd};
use std::result;
use std::sync::Arc;
#[cfg(target_arch = "x86_64")]
@@ -303,15 +304,14 @@ impl vm::Vm for KvmVm {
self.fd.check_extension(c)
}
/// Create a device that is used for passthrough
fn create_passthrough_device(&self) -> vm::Result<DeviceFd> {
fn create_passthrough_device(&self) -> vm::Result<Arc<dyn device::Device>> {
let mut vfio_dev = kvm_create_device {
type_: kvm_device_type_KVM_DEV_TYPE_VFIO,
fd: 0,
flags: 0,
};
self.fd
.create_device(&mut vfio_dev)
self.create_device(&mut vfio_dev)
.map_err(|e| vm::HypervisorVmError::CreatePassthroughDevice(e.into()))
}
}
@@ -869,3 +869,9 @@ impl device::Device for KvmDevice {
.map_err(|e| device::HypervisorDeviceError::SetDeviceAttribute(e.into()))
}
}
impl AsRawFd for KvmDevice {
fn as_raw_fd(&self) -> RawFd {
self.fd.as_raw_fd()
}
}