diff --git a/vhost_user_devices/src/lib.rs b/vhost_user_devices/src/lib.rs index 831112f49d..827ec9ed42 100644 --- a/vhost_user_devices/src/lib.rs +++ b/vhost_user_devices/src/lib.rs @@ -46,12 +46,16 @@ // implementation (this is what our devices implement). use std::convert::TryFrom; +use std::fs::File; use std::num::Wrapping; -use std::os::unix::io::{AsRawFd, RawFd}; +use std::os::unix::io::AsRawFd; use std::path::Path; use std::sync::Arc; -use base::{error, Event, FromRawDescriptor, SafeDescriptor, SharedMemory, SharedMemoryUnix}; +use base::{ + error, Event, FromRawDescriptor, IntoRawDescriptor, SafeDescriptor, SharedMemory, + SharedMemoryUnix, +}; use cros_async::{AsyncError, AsyncWrapper, Executor}; use devices::virtio::{Queue, SignalableInterrupt}; use remain::sorted; @@ -60,7 +64,7 @@ use sys_util::clear_fd_flags; use thiserror::Error as ThisError; use vm_memory::{GuestAddress, GuestMemory, MemoryRegion}; use vmm_vhost::vhost_user::message::{ - VhostUserConfigFlags, VhostUserMemoryRegion, VhostUserProtocolFeatures, + VhostUserConfigFlags, VhostUserInflight, VhostUserMemoryRegion, VhostUserProtocolFeatures, VhostUserSingleMemoryRegion, VhostUserVirtioFeatures, VhostUserVringAddrFlags, VhostUserVringState, }; @@ -343,26 +347,19 @@ impl VhostUserSlaveReqHandlerMut for DeviceRequestHandler, ) -> VhostResult<()> { - if fds.len() != contexts.len() { + if files.len() != contexts.len() { return Err(VhostError::InvalidParam); } - let mut regions = Vec::with_capacity(fds.len()); - for (region, &fd) in contexts.iter().zip(fds.iter()) { - let rd = base::validate_raw_descriptor(fd).map_err(|e| { - error!("invalid fd is given: {}", e); - VhostError::InvalidParam - })?; - // Safe because we verified that we are the unique owner of `rd`. - let sd = unsafe { SafeDescriptor::from_raw_descriptor(rd) }; - + let mut regions = Vec::with_capacity(files.len()); + for (region, file) in contexts.iter().zip(files.into_iter()) { let region = MemoryRegion::new( region.memory_size, GuestAddress(region.guest_phys_addr), region.mmap_offset, - Arc::new(SharedMemory::from_safe_descriptor(sd).unwrap()), + Arc::new(SharedMemory::from_safe_descriptor(SafeDescriptor::from(file)).unwrap()), ) .map_err(|e| { error!("failed to create a memory region: {}", e); @@ -457,7 +454,7 @@ impl VhostUserSlaveReqHandlerMut for DeviceRequestHandler) -> VhostResult<()> { + fn set_vring_kick(&mut self, index: u8, file: Option) -> VhostResult<()> { if index as usize >= self.vrings.len() { return Err(VhostError::InvalidParam); } @@ -468,24 +465,16 @@ impl VhostUserSlaveReqHandlerMut for DeviceRequestHandler VhostUserSlaveReqHandlerMut for DeviceRequestHandler) -> VhostResult<()> { + fn set_vring_call(&mut self, index: u8, file: Option) -> VhostResult<()> { if index as usize >= self.vrings.len() { return Err(VhostError::InvalidParam); } - if let Some(fd) = fd { - let rd = base::validate_raw_descriptor(fd).map_err(|e| { - error!("invalid fd is given: {}", e); - VhostError::InvalidParam - })?; - // Safe because the FD is now owned. - let call_evt = CallEvent(unsafe { Event::from_raw_descriptor(rd) }); + if let Some(file) = file { + // Safe because we own the file. + let call_evt = + CallEvent(unsafe { Event::from_raw_descriptor(file.into_raw_descriptor()) }); match &self.vrings[index as usize].call_evt { None => { self.vrings[index as usize].call_evt = Some(Arc::new(Mutex::new(call_evt))); @@ -541,7 +527,7 @@ impl VhostUserSlaveReqHandlerMut for DeviceRequestHandler) -> VhostResult<()> { + fn set_vring_err(&mut self, _index: u8, _fd: Option) -> VhostResult<()> { // TODO Ok(()) } @@ -595,6 +581,17 @@ impl VhostUserSlaveReqHandlerMut for DeviceRequestHandler VhostResult<(VhostUserInflight, File)> { + unimplemented!("get_inflight_fd"); + } + + fn set_inflight_fd(&mut self, _inflight: &VhostUserInflight, _file: File) -> VhostResult<()> { + unimplemented!("set_inflight_fd"); + } + fn get_max_mem_slots(&mut self) -> VhostResult { //TODO Ok(0) @@ -603,7 +600,7 @@ impl VhostUserSlaveReqHandlerMut for DeviceRequestHandler VhostResult<()> { //TODO Ok(())