From 47b5581c50eec2906a044eb61e203fb0a80bf571 Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Sat, 9 Jul 2022 16:01:14 +0000 Subject: [PATCH] hypervisor: drop a level of indirection for MSHV's DeviceFd Signed-off-by: Wei Liu --- hypervisor/src/mshv/mod.rs | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/hypervisor/src/mshv/mod.rs b/hypervisor/src/mshv/mod.rs index 509da4757..0f0adfb8e 100644 --- a/hypervisor/src/mshv/mod.rs +++ b/hypervisor/src/mshv/mod.rs @@ -35,7 +35,7 @@ pub use x86_64::*; #[cfg(target_arch = "x86_64")] use std::fs::File; -use std::os::unix::io::{AsRawFd, RawFd}; +use std::os::unix::io::AsRawFd; const DIRTY_BITMAP_CLEAR_DIRTY: u64 = 0x4; const DIRTY_BITMAP_SET_DIRTY: u64 = 0x8; @@ -667,25 +667,21 @@ impl cpu::Vcpu for MshvVcpu { } /// Device struct for MSHV -pub struct MshvDevice { - fd: DeviceFd, -} +pub type MshvDevice = DeviceFd; impl device::Device for MshvDevice { /// /// Set device attribute /// fn set_device_attr(&self, attr: &DeviceAttr) -> device::Result<()> { - self.fd - .set_device_attr(attr) + self.set_device_attr(attr) .map_err(|e| device::HypervisorDeviceError::SetDeviceAttribute(e.into())) } /// /// Get device attribute /// fn get_device_attr(&self, attr: &mut DeviceAttr) -> device::Result<()> { - self.fd - .get_device_attr(attr) + self.get_device_attr(attr) .map_err(|e| device::HypervisorDeviceError::GetDeviceAttribute(e.into())) } /// @@ -696,12 +692,6 @@ impl device::Device for MshvDevice { } } -impl AsRawFd for MshvDevice { - fn as_raw_fd(&self) -> RawFd { - self.fd.as_raw_fd() - } -} - struct MshvEmulatorContext<'a> { vcpu: &'a MshvVcpu, map: (u64, u64), // Initial GVA to GPA mapping provided by the hypervisor @@ -1029,12 +1019,11 @@ impl vm::Vm for MshvVm { /// /// See the documentation for `MSHV_CREATE_DEVICE`. fn create_device(&self, device: &mut CreateDevice) -> vm::Result> { - let fd = self + let device_fd = self .fd .create_device(device) .map_err(|e| vm::HypervisorVmError::CreateDevice(e.into()))?; - let device = MshvDevice { fd }; - Ok(Arc::new(device)) + Ok(Arc::new(device_fd)) } fn create_passthrough_device(&self) -> vm::Result> {