From eae4f1d249927a4a942f9820deb00b5670eaf215 Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Fri, 21 Feb 2020 11:54:35 +0100 Subject: [PATCH] vhost_user_fs: Add support for indirect descriptors Now that Queue supports indirect descriptors, expose the feature and support them in vhost_user_fs too. Signed-off-by: Sergio Lopez --- src/bin/vhost_user_fs.rs | 5 ++++- vhost_user_fs/src/descriptor_utils.rs | 21 +++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/bin/vhost_user_fs.rs b/src/bin/vhost_user_fs.rs index a9cd8ebe5..c0f8ff72c 100644 --- a/src/bin/vhost_user_fs.rs +++ b/src/bin/vhost_user_fs.rs @@ -25,6 +25,7 @@ use vhost_user_fs::passthrough::{self, PassthroughFs}; use vhost_user_fs::server::Server; use vhost_user_fs::Error as VhostUserFsError; use virtio_bindings::bindings::virtio_net::*; +use virtio_bindings::bindings::virtio_ring::VIRTIO_RING_F_INDIRECT_DESC; use vm_memory::GuestMemoryMmap; use vmm_sys_util::eventfd::EventFd; @@ -138,7 +139,9 @@ impl VhostUserBackend for VhostUserFsBack } fn features(&self) -> u64 { - 1 << VIRTIO_F_VERSION_1 | VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits() + 1 << VIRTIO_F_VERSION_1 + | 1 << VIRTIO_RING_F_INDIRECT_DESC + | VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits() } fn protocol_features(&self) -> VhostUserProtocolFeatures { diff --git a/vhost_user_fs/src/descriptor_utils.rs b/vhost_user_fs/src/descriptor_utils.rs index d0d26802d..c0cb29a94 100644 --- a/vhost_user_fs/src/descriptor_utils.rs +++ b/vhost_user_fs/src/descriptor_utils.rs @@ -15,6 +15,7 @@ use vm_memory::{ Address, ByteValued, Bytes, GuestAddress, GuestMemory, GuestMemoryError, GuestMemoryMmap, GuestMemoryRegion, Le16, Le32, Le64, VolatileMemory, VolatileMemoryError, VolatileSlice, }; +use vm_virtio::queue::Error as QueueError; use vm_virtio::DescriptorChain; use crate::file_traits::{FileReadWriteAtVolatile, FileReadWriteVolatile}; @@ -25,6 +26,7 @@ pub enum Error { FindMemoryRegion, GuestMemoryError(GuestMemoryError), InvalidChain, + ConvertIndirectDescriptor(QueueError), IoError(io::Error), SplitOutOfBounds(usize), VolatileMemoryError(VolatileMemoryError), @@ -35,6 +37,7 @@ impl Display for Error { use self::Error::*; match self { + ConvertIndirectDescriptor(e) => write!(f, "invalid indirect descriptor: {}", e), DescriptorChainOverflow => write!( f, "the combined length of all the buffers in a `DescriptorChain` would overflow" @@ -191,7 +194,14 @@ impl<'a> Reader<'a> { /// Construct a new Reader wrapper over `desc_chain`. pub fn new(mem: &'a GuestMemoryMmap, desc_chain: DescriptorChain<'a>) -> Result> { let mut total_len: usize = 0; - let buffers = desc_chain + let chain = if desc_chain.is_indirect() { + desc_chain + .new_from_indirect() + .map_err(Error::ConvertIndirectDescriptor)? + } else { + desc_chain + }; + let buffers = chain .into_iter() .readable() .map(|desc| { @@ -343,7 +353,14 @@ impl<'a> Writer<'a> { /// Construct a new Writer wrapper over `desc_chain`. pub fn new(mem: &'a GuestMemoryMmap, desc_chain: DescriptorChain<'a>) -> Result> { let mut total_len: usize = 0; - let buffers = desc_chain + let chain = if desc_chain.is_indirect() { + desc_chain + .new_from_indirect() + .map_err(Error::ConvertIndirectDescriptor)? + } else { + desc_chain + }; + let buffers = chain .into_iter() .writable() .map(|desc| {