From 80034cacde8f9c4d7cd4ae73316eeec6cc2fd67a Mon Sep 17 00:00:00 2001 From: Sergio Lopez Date: Thu, 10 Mar 2022 12:03:13 +0100 Subject: [PATCH 2/3] Set the number of written bytes for used descs As the Linux driver ignores the "len" field of used descriptors, we didn't bother to set it properly when return those descriptors to the queue. The problem is that other implementations (at least, the Windows one), do care about it, so let's do the right thing and set it properly. Resolves: rhbz#2057252 Signed-off-by: Sergio Lopez (cherry picked from commit 2bc7c2102d18f47b309fd5f767b5349d9e08d2b8) Signed-off-by: Sergio Lopez --- src/main.rs | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 5a9914f..ca183e8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,7 +6,7 @@ use futures::executor::{ThreadPool, ThreadPoolBuilder}; use libc::EFD_NONBLOCK; use log::*; use passthrough::xattrmap::XattrMap; -use std::convert::{self, TryFrom}; +use std::convert::{self, TryFrom, TryInto}; use std::ffi::CString; use std::os::unix::io::{FromRawFd, RawFd}; use std::sync::{Arc, Mutex, RwLock}; @@ -128,8 +128,18 @@ impl VhostUserFsThread { }) } - fn return_descriptor(vring_state: &mut VringState, head_index: u16, event_idx: bool) { - if vring_state.add_used(head_index, 0).is_err() { + fn return_descriptor( + vring_state: &mut VringState, + head_index: u16, + event_idx: bool, + len: usize, + ) { + let used_len: u32 = match len.try_into() { + Ok(l) => l, + Err(_) => panic!("Invalid used length, can't return used descritors to the ring"), + }; + + if vring_state.add_used(head_index, used_len).is_err() { warn!("Couldn't return used descriptors to the ring"); } @@ -185,12 +195,12 @@ impl VhostUserFsThread { .map_err(Error::QueueWriter) .unwrap(); - server + let len = server .handle_message(reader, writer, vu_req.as_mut()) .map_err(Error::ProcessQueue) .unwrap(); - Self::return_descriptor(&mut worker_vring.get_mut(), head_index, event_idx); + Self::return_descriptor(&mut worker_vring.get_mut(), head_index, event_idx, len); }); } @@ -222,12 +232,13 @@ impl VhostUserFsThread { .map_err(Error::QueueWriter) .unwrap(); - self.server + let len = self + .server .handle_message(reader, writer, self.vu_req.as_mut()) .map_err(Error::ProcessQueue) .unwrap(); - Self::return_descriptor(vring_state, head_index, self.event_idx); + Self::return_descriptor(vring_state, head_index, self.event_idx, len); } Ok(used_any) -- 2.35.1