Blame SOURCES/Set-the-number-of-written-bytes-for-used-descs.patch

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