cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtiofsd-Plumb-fuse_bufvec-through-to-do_write_buf.patch

22c213
From 9e4320eec5204da851ac95fb7a7e6520c9ccee7d Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Mon, 27 Jan 2020 19:01:19 +0100
22c213
Subject: [PATCH 048/116] virtiofsd: Plumb fuse_bufvec through to do_write_buf
22c213
MIME-Version: 1.0
22c213
Content-Type: text/plain; charset=UTF-8
22c213
Content-Transfer-Encoding: 8bit
22c213
22c213
RH-Author: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Message-id: <20200127190227.40942-45-dgilbert@redhat.com>
22c213
Patchwork-id: 93499
22c213
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 044/112] virtiofsd: Plumb fuse_bufvec through to do_write_buf
22c213
Bugzilla: 1694164
22c213
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
22c213
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
RH-Acked-by: Sergio Lopez Pascual <slp@redhat.com>
22c213
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
22c213
Let fuse_session_process_buf_int take a fuse_bufvec * instead of a
22c213
fuse_buf;  and then through to do_write_buf - where in the best
22c213
case it can pass that straight through to op.write_buf without copying
22c213
(other than skipping a header).
22c213
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit 469f9d2fc405b0508e6cf1b4b5bbcadfc82064e5)
22c213
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
22c213
---
22c213
 tools/virtiofsd/fuse_i.h        |  2 +-
22c213
 tools/virtiofsd/fuse_lowlevel.c | 61 +++++++++++++++++++++++++++--------------
22c213
 tools/virtiofsd/fuse_virtio.c   |  3 +-
22c213
 3 files changed, 44 insertions(+), 22 deletions(-)
22c213
22c213
diff --git a/tools/virtiofsd/fuse_i.h b/tools/virtiofsd/fuse_i.h
22c213
index 45995f3..a20854f 100644
22c213
--- a/tools/virtiofsd/fuse_i.h
22c213
+++ b/tools/virtiofsd/fuse_i.h
22c213
@@ -100,7 +100,7 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
22c213
 void fuse_free_req(fuse_req_t req);
22c213
 
22c213
 void fuse_session_process_buf_int(struct fuse_session *se,
22c213
-                                  const struct fuse_buf *buf,
22c213
+                                  struct fuse_bufvec *bufv,
22c213
                                   struct fuse_chan *ch);
22c213
 
22c213
 
22c213
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
22c213
index 95f4db8..7e10995 100644
22c213
--- a/tools/virtiofsd/fuse_lowlevel.c
22c213
+++ b/tools/virtiofsd/fuse_lowlevel.c
22c213
@@ -1004,11 +1004,12 @@ static void do_write(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
 }
22c213
 
22c213
 static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg,
22c213
-                         const struct fuse_buf *ibuf)
22c213
+                         struct fuse_bufvec *ibufv)
22c213
 {
22c213
     struct fuse_session *se = req->se;
22c213
-    struct fuse_bufvec bufv = {
22c213
-        .buf[0] = *ibuf,
22c213
+    struct fuse_bufvec *pbufv = ibufv;
22c213
+    struct fuse_bufvec tmpbufv = {
22c213
+        .buf[0] = ibufv->buf[0],
22c213
         .count = 1,
22c213
     };
22c213
     struct fuse_write_in *arg = (struct fuse_write_in *)inarg;
22c213
@@ -1018,22 +1019,31 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg,
22c213
     fi.fh = arg->fh;
22c213
     fi.writepage = arg->write_flags & FUSE_WRITE_CACHE;
22c213
 
22c213
-    fi.lock_owner = arg->lock_owner;
22c213
-    fi.flags = arg->flags;
22c213
-    if (!(bufv.buf[0].flags & FUSE_BUF_IS_FD)) {
22c213
-        bufv.buf[0].mem = PARAM(arg);
22c213
-    }
22c213
-
22c213
-    bufv.buf[0].size -=
22c213
-        sizeof(struct fuse_in_header) + sizeof(struct fuse_write_in);
22c213
-    if (bufv.buf[0].size < arg->size) {
22c213
-        fuse_log(FUSE_LOG_ERR, "fuse: do_write_buf: buffer size too small\n");
22c213
-        fuse_reply_err(req, EIO);
22c213
-        return;
22c213
+    if (ibufv->count == 1) {
22c213
+        fi.lock_owner = arg->lock_owner;
22c213
+        fi.flags = arg->flags;
22c213
+        if (!(tmpbufv.buf[0].flags & FUSE_BUF_IS_FD)) {
22c213
+            tmpbufv.buf[0].mem = PARAM(arg);
22c213
+        }
22c213
+        tmpbufv.buf[0].size -=
22c213
+            sizeof(struct fuse_in_header) + sizeof(struct fuse_write_in);
22c213
+        if (tmpbufv.buf[0].size < arg->size) {
22c213
+            fuse_log(FUSE_LOG_ERR,
22c213
+                     "fuse: do_write_buf: buffer size too small\n");
22c213
+            fuse_reply_err(req, EIO);
22c213
+            return;
22c213
+        }
22c213
+        tmpbufv.buf[0].size = arg->size;
22c213
+        pbufv = &tmpbufv;
22c213
+    } else {
22c213
+        /*
22c213
+         *  Input bufv contains the headers in the first element
22c213
+         * and the data in the rest, we need to skip that first element
22c213
+         */
22c213
+        ibufv->buf[0].size = 0;
22c213
     }
22c213
-    bufv.buf[0].size = arg->size;
22c213
 
22c213
-    se->op.write_buf(req, nodeid, &bufv, arg->offset, &fi);
22c213
+    se->op.write_buf(req, nodeid, pbufv, arg->offset, &fi);
22c213
 }
22c213
 
22c213
 static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
22c213
@@ -2024,13 +2034,24 @@ static const char *opname(enum fuse_opcode opcode)
22c213
 void fuse_session_process_buf(struct fuse_session *se,
22c213
                               const struct fuse_buf *buf)
22c213
 {
22c213
-    fuse_session_process_buf_int(se, buf, NULL);
22c213
+    struct fuse_bufvec bufv = { .buf[0] = *buf, .count = 1 };
22c213
+    fuse_session_process_buf_int(se, &bufv, NULL);
22c213
 }
22c213
 
22c213
+/*
22c213
+ * Restriction:
22c213
+ *   bufv is normally a single entry buffer, except for a write
22c213
+ *   where (if it's in memory) then the bufv may be multiple entries,
22c213
+ *   where the first entry contains all headers and subsequent entries
22c213
+ *   contain data
22c213
+ *   bufv shall not use any offsets etc to make the data anything
22c213
+ *   other than contiguous starting from 0.
22c213
+ */
22c213
 void fuse_session_process_buf_int(struct fuse_session *se,
22c213
-                                  const struct fuse_buf *buf,
22c213
+                                  struct fuse_bufvec *bufv,
22c213
                                   struct fuse_chan *ch)
22c213
 {
22c213
+    const struct fuse_buf *buf = bufv->buf;
22c213
     struct fuse_in_header *in;
22c213
     const void *inarg;
22c213
     struct fuse_req *req;
22c213
@@ -2108,7 +2129,7 @@ void fuse_session_process_buf_int(struct fuse_session *se,
22c213
 
22c213
     inarg = (void *)&in[1];
22c213
     if (in->opcode == FUSE_WRITE && se->op.write_buf) {
22c213
-        do_write_buf(req, in->nodeid, inarg, buf);
22c213
+        do_write_buf(req, in->nodeid, inarg, bufv);
22c213
     } else {
22c213
         fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
22c213
     }
22c213
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
22c213
index 635f877..fd588a4 100644
22c213
--- a/tools/virtiofsd/fuse_virtio.c
22c213
+++ b/tools/virtiofsd/fuse_virtio.c
22c213
@@ -501,7 +501,8 @@ static void *fv_queue_thread(void *opaque)
22c213
             /* TODO! Endianness of header */
22c213
 
22c213
             /* TODO: Add checks for fuse_session_exited */
22c213
-            fuse_session_process_buf_int(se, &fbuf, &ch);
22c213
+            struct fuse_bufvec bufv = { .buf[0] = fbuf, .count = 1 };
22c213
+            fuse_session_process_buf_int(se, &bufv, &ch);
22c213
 
22c213
             if (!qi->reply_sent) {
22c213
                 fuse_log(FUSE_LOG_DEBUG, "%s: elem %d no reply sent\n",
22c213
-- 
22c213
1.8.3.1
22c213