deps: Update vhost crate from 1a03a2a to 9982541

This dependency bump needed some manual handling since the API changed
quite a lot regarding some RawFd being changed into either File or
AsRawFd traits.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2021-06-24 09:47:49 +02:00 committed by Rob Bradford
parent c4be0f4235
commit d4d62fc9dc
5 changed files with 42 additions and 48 deletions

2
Cargo.lock generated
View File

@ -1118,7 +1118,7 @@ dependencies = [
[[package]]
name = "vhost"
version = "0.1.0"
source = "git+https://github.com/rust-vmm/vhost?branch=master#1a03a2aca700421f258b094b1a845f6420d8cfa9"
source = "git+https://github.com/rust-vmm/vhost?branch=master#9982541776a603d30556a06df55e8c0491072763"
dependencies = [
"bitflags",
"libc",

2
fuzz/Cargo.lock generated
View File

@ -652,7 +652,7 @@ dependencies = [
[[package]]
name = "vhost"
version = "0.1.0"
source = "git+https://github.com/rust-vmm/vhost?branch=master#a8ff939161d41fc2f449b80e461d013c1e19f666"
source = "git+https://github.com/rust-vmm/vhost?branch=master#9982541776a603d30556a06df55e8c0491072763"
dependencies = [
"bitflags",
"libc",

View File

@ -11,12 +11,12 @@ use std::error;
use std::fs::File;
use std::io;
use std::num::Wrapping;
use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
use std::result;
use std::sync::{Arc, Mutex, RwLock};
use std::thread;
use vhost::vhost_user::message::{
VhostUserConfigFlags, VhostUserMemoryRegion, VhostUserProtocolFeatures,
VhostUserConfigFlags, VhostUserInflight, VhostUserMemoryRegion, VhostUserProtocolFeatures,
VhostUserSingleMemoryRegion, VhostUserVirtioFeatures, VhostUserVringAddrFlags,
VhostUserVringState,
};
@ -235,6 +235,7 @@ pub struct Vring {
queue: Queue,
kick: Option<EventFd>,
call: Option<EventFd>,
#[allow(dead_code)]
err: Option<EventFd>,
enabled: bool,
}
@ -625,18 +626,17 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandlerMut for VhostUserHandler<S> {
fn set_mem_table(
&mut self,
ctx: &[VhostUserMemoryRegion],
fds: &[RawFd],
mut files: Vec<File>,
) -> VhostUserResult<()> {
// We need to create tuple of ranges from the list of VhostUserMemoryRegion
// that we get from the caller.
let mut regions: Vec<(GuestAddress, usize, Option<FileOffset>)> = Vec::new();
let mut mappings: Vec<AddrMapping> = Vec::new();
for (idx, region) in ctx.iter().enumerate() {
for region in ctx.iter() {
let g_addr = GuestAddress(region.guest_phys_addr);
let len = region.memory_size as usize;
let file = unsafe { File::from_raw_fd(fds[idx]) };
let f_off = FileOffset::new(file, region.mmap_offset);
let f_off = FileOffset::new(files.remove(0), region.mmap_offset);
regions.push((g_addr, len, Some(f_off)));
mappings.push(AddrMapping {
@ -770,17 +770,13 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandlerMut for VhostUserHandler<S> {
Ok(VhostUserVringState::new(index, u32::from(next_avail)))
}
fn set_vring_kick(&mut self, index: u8, fd: Option<RawFd>) -> VhostUserResult<()> {
fn set_vring_kick(&mut self, index: u8, fd: Option<File>) -> VhostUserResult<()> {
if index as usize >= self.num_queues {
return Err(VhostUserError::InvalidParam);
}
if let Some(kick) = self.vrings[index as usize].write().unwrap().kick.take() {
// Close file descriptor set by previous operations.
let _ = unsafe { libc::close(kick.as_raw_fd()) };
}
self.vrings[index as usize].write().unwrap().kick =
fd.map(|x| unsafe { EventFd::from_raw_fd(x) });
fd.map(|x| unsafe { EventFd::from_raw_fd(x.into_raw_fd()) });
// Quote from vhost-user specification:
// Client must start ring upon receiving a kick (that is, detecting
@ -808,32 +804,24 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandlerMut for VhostUserHandler<S> {
Ok(())
}
fn set_vring_call(&mut self, index: u8, fd: Option<RawFd>) -> VhostUserResult<()> {
fn set_vring_call(&mut self, index: u8, fd: Option<File>) -> VhostUserResult<()> {
if index as usize >= self.num_queues {
return Err(VhostUserError::InvalidParam);
}
if let Some(call) = self.vrings[index as usize].write().unwrap().call.take() {
// Close file descriptor set by previous operations.
let _ = unsafe { libc::close(call.as_raw_fd()) };
}
self.vrings[index as usize].write().unwrap().call =
fd.map(|x| unsafe { EventFd::from_raw_fd(x) });
fd.map(|x| unsafe { EventFd::from_raw_fd(x.into_raw_fd()) });
Ok(())
}
fn set_vring_err(&mut self, index: u8, fd: Option<RawFd>) -> VhostUserResult<()> {
fn set_vring_err(&mut self, index: u8, fd: Option<File>) -> VhostUserResult<()> {
if index as usize >= self.num_queues {
return Err(VhostUserError::InvalidParam);
}
if let Some(err) = self.vrings[index as usize].write().unwrap().err.take() {
// Close file descriptor set by previous operations.
let _ = unsafe { libc::close(err.as_raw_fd()) };
}
self.vrings[index as usize].write().unwrap().err =
fd.map(|x| unsafe { EventFd::from_raw_fd(x) });
fd.map(|x| unsafe { EventFd::from_raw_fd(x.into_raw_fd()) });
Ok(())
}
@ -889,11 +877,10 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandlerMut for VhostUserHandler<S> {
fn add_mem_region(
&mut self,
region: &VhostUserSingleMemoryRegion,
fd: RawFd,
fd: File,
) -> VhostUserResult<()> {
let file = unsafe { File::from_raw_fd(fd) };
let mmap_region = MmapRegion::from_file(
FileOffset::new(file, region.mmap_offset),
FileOffset::new(fd, region.mmap_offset),
region.memory_size as usize,
)
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e)))?;
@ -962,19 +949,12 @@ impl<S: VhostUserBackend> VhostUserSlaveReqHandlerMut for VhostUserHandler<S> {
fn get_inflight_fd(
&mut self,
_: &vhost::vhost_user::message::VhostUserInflight,
) -> std::result::Result<
(vhost::vhost_user::message::VhostUserInflight, i32),
vhost::vhost_user::Error,
> {
_: &VhostUserInflight,
) -> VhostUserResult<(VhostUserInflight, File)> {
std::unimplemented!()
}
fn set_inflight_fd(
&mut self,
_: &vhost::vhost_user::message::VhostUserInflight,
_: std::fs::File,
) -> std::result::Result<(), vhost::vhost_user::Error> {
fn set_inflight_fd(&mut self, _: &VhostUserInflight, _: File) -> VhostUserResult<()> {
std::unimplemented!()
}
}

View File

@ -17,7 +17,7 @@ use libc::{self, c_void, off64_t, pread64, pwrite64};
use seccomp::{SeccompAction, SeccompFilter};
use std::io;
use std::ops::Deref;
use std::os::unix::io::{AsRawFd, RawFd};
use std::os::unix::io::AsRawFd;
use std::result;
use std::sync::{Arc, Barrier, Mutex};
use std::thread;
@ -62,7 +62,7 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
Ok(0)
}
fn fs_slave_map(&self, fs: &VhostUserFSSlaveMsg, fd: RawFd) -> HandlerResult<u64> {
fn fs_slave_map(&self, fs: &VhostUserFSSlaveMsg, fd: &dyn AsRawFd) -> HandlerResult<u64> {
debug!("fs_slave_map");
for i in 0..VHOST_USER_FS_SLAVE_ENTRIES {
@ -86,7 +86,7 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
len as usize,
flags.bits() as i32,
libc::MAP_SHARED | libc::MAP_FIXED,
fd,
fd.as_raw_fd(),
fs.fd_offset[i] as libc::off_t,
)
};
@ -94,7 +94,7 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
return Err(io::Error::last_os_error());
}
let ret = unsafe { libc::close(fd) };
let ret = unsafe { libc::close(fd.as_raw_fd()) };
if ret == -1 {
return Err(io::Error::last_os_error());
}
@ -171,7 +171,7 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
Ok(0)
}
fn fs_slave_io(&self, fs: &VhostUserFSSlaveMsg, fd: RawFd) -> HandlerResult<u64> {
fn fs_slave_io(&self, fs: &VhostUserFSSlaveMsg, fd: &dyn AsRawFd) -> HandlerResult<u64> {
debug!("fs_slave_io");
let mut done: u64 = 0;
@ -218,10 +218,24 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
== VhostUserFSSlaveMsgFlags::MAP_W
{
debug!("write: foffset={}, len={}", foffset, len);
unsafe { pwrite64(fd, ptr as *const c_void, len as usize, foffset as off64_t) }
unsafe {
pwrite64(
fd.as_raw_fd(),
ptr as *const c_void,
len as usize,
foffset as off64_t,
)
}
} else {
debug!("read: foffset={}, len={}", foffset, len);
unsafe { pread64(fd, ptr as *mut c_void, len as usize, foffset as off64_t) }
unsafe {
pread64(
fd.as_raw_fd(),
ptr as *mut c_void,
len as usize,
foffset as off64_t,
)
}
};
if ret < 0 {
@ -242,7 +256,7 @@ impl VhostUserMasterReqHandler for SlaveReqHandler {
}
}
let ret = unsafe { libc::close(fd) };
let ret = unsafe { libc::close(fd.as_raw_fd()) };
if ret == -1 {
return Err(io::Error::last_os_error());
}

View File

@ -197,7 +197,7 @@ pub fn setup_vhost_user<S: VhostUserMasterReqHandler>(
}
if let Some(slave_req_handler) = slave_req_handler {
vu.set_slave_request_fd(slave_req_handler.get_tx_raw_fd())
vu.set_slave_request_fd(&slave_req_handler.get_tx_raw_fd())
.map_err(Error::VhostUserSetSlaveRequestFd)
} else {
Ok(())