dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0050-virtiofsd-Plumb-fuse_bufvec-through-to-do_write_buf.patch

1d442b
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
1d442b
Date: Mon, 27 Jan 2020 19:01:19 +0000
1d442b
Subject: [PATCH] virtiofsd: Plumb fuse_bufvec through to do_write_buf
1d442b
1d442b
Let fuse_session_process_buf_int take a fuse_bufvec * instead of a
1d442b
fuse_buf;  and then through to do_write_buf - where in the best
1d442b
case it can pass that straight through to op.write_buf without copying
1d442b
(other than skipping a header).
1d442b
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
1d442b
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit 469f9d2fc405b0508e6cf1b4b5bbcadfc82064e5)
1d442b
---
1d442b
 tools/virtiofsd/fuse_i.h        |  2 +-
1d442b
 tools/virtiofsd/fuse_lowlevel.c | 61 ++++++++++++++++++++++-----------
1d442b
 tools/virtiofsd/fuse_virtio.c   |  3 +-
1d442b
 3 files changed, 44 insertions(+), 22 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/fuse_i.h b/tools/virtiofsd/fuse_i.h
1d442b
index 45995f3246..a20854f1c4 100644
1d442b
--- a/tools/virtiofsd/fuse_i.h
1d442b
+++ b/tools/virtiofsd/fuse_i.h
1d442b
@@ -100,7 +100,7 @@ int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov,
1d442b
 void fuse_free_req(fuse_req_t req);
1d442b
 
1d442b
 void fuse_session_process_buf_int(struct fuse_session *se,
1d442b
-                                  const struct fuse_buf *buf,
1d442b
+                                  struct fuse_bufvec *bufv,
1d442b
                                   struct fuse_chan *ch);
1d442b
 
1d442b
 
1d442b
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
1d442b
index 95f4db8fcf..7e10995adc 100644
1d442b
--- a/tools/virtiofsd/fuse_lowlevel.c
1d442b
+++ b/tools/virtiofsd/fuse_lowlevel.c
1d442b
@@ -1004,11 +1004,12 @@ static void do_write(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1d442b
 }
1d442b
 
1d442b
 static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg,
1d442b
-                         const struct fuse_buf *ibuf)
1d442b
+                         struct fuse_bufvec *ibufv)
1d442b
 {
1d442b
     struct fuse_session *se = req->se;
1d442b
-    struct fuse_bufvec bufv = {
1d442b
-        .buf[0] = *ibuf,
1d442b
+    struct fuse_bufvec *pbufv = ibufv;
1d442b
+    struct fuse_bufvec tmpbufv = {
1d442b
+        .buf[0] = ibufv->buf[0],
1d442b
         .count = 1,
1d442b
     };
1d442b
     struct fuse_write_in *arg = (struct fuse_write_in *)inarg;
1d442b
@@ -1018,22 +1019,31 @@ static void do_write_buf(fuse_req_t req, fuse_ino_t nodeid, const void *inarg,
1d442b
     fi.fh = arg->fh;
1d442b
     fi.writepage = arg->write_flags & FUSE_WRITE_CACHE;
1d442b
 
1d442b
-    fi.lock_owner = arg->lock_owner;
1d442b
-    fi.flags = arg->flags;
1d442b
-    if (!(bufv.buf[0].flags & FUSE_BUF_IS_FD)) {
1d442b
-        bufv.buf[0].mem = PARAM(arg);
1d442b
-    }
1d442b
-
1d442b
-    bufv.buf[0].size -=
1d442b
-        sizeof(struct fuse_in_header) + sizeof(struct fuse_write_in);
1d442b
-    if (bufv.buf[0].size < arg->size) {
1d442b
-        fuse_log(FUSE_LOG_ERR, "fuse: do_write_buf: buffer size too small\n");
1d442b
-        fuse_reply_err(req, EIO);
1d442b
-        return;
1d442b
+    if (ibufv->count == 1) {
1d442b
+        fi.lock_owner = arg->lock_owner;
1d442b
+        fi.flags = arg->flags;
1d442b
+        if (!(tmpbufv.buf[0].flags & FUSE_BUF_IS_FD)) {
1d442b
+            tmpbufv.buf[0].mem = PARAM(arg);
1d442b
+        }
1d442b
+        tmpbufv.buf[0].size -=
1d442b
+            sizeof(struct fuse_in_header) + sizeof(struct fuse_write_in);
1d442b
+        if (tmpbufv.buf[0].size < arg->size) {
1d442b
+            fuse_log(FUSE_LOG_ERR,
1d442b
+                     "fuse: do_write_buf: buffer size too small\n");
1d442b
+            fuse_reply_err(req, EIO);
1d442b
+            return;
1d442b
+        }
1d442b
+        tmpbufv.buf[0].size = arg->size;
1d442b
+        pbufv = &tmpbufv;
1d442b
+    } else {
1d442b
+        /*
1d442b
+         *  Input bufv contains the headers in the first element
1d442b
+         * and the data in the rest, we need to skip that first element
1d442b
+         */
1d442b
+        ibufv->buf[0].size = 0;
1d442b
     }
1d442b
-    bufv.buf[0].size = arg->size;
1d442b
 
1d442b
-    se->op.write_buf(req, nodeid, &bufv, arg->offset, &fi);
1d442b
+    se->op.write_buf(req, nodeid, pbufv, arg->offset, &fi);
1d442b
 }
1d442b
 
1d442b
 static void do_flush(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
1d442b
@@ -2024,13 +2034,24 @@ static const char *opname(enum fuse_opcode opcode)
1d442b
 void fuse_session_process_buf(struct fuse_session *se,
1d442b
                               const struct fuse_buf *buf)
1d442b
 {
1d442b
-    fuse_session_process_buf_int(se, buf, NULL);
1d442b
+    struct fuse_bufvec bufv = { .buf[0] = *buf, .count = 1 };
1d442b
+    fuse_session_process_buf_int(se, &bufv, NULL);
1d442b
 }
1d442b
 
1d442b
+/*
1d442b
+ * Restriction:
1d442b
+ *   bufv is normally a single entry buffer, except for a write
1d442b
+ *   where (if it's in memory) then the bufv may be multiple entries,
1d442b
+ *   where the first entry contains all headers and subsequent entries
1d442b
+ *   contain data
1d442b
+ *   bufv shall not use any offsets etc to make the data anything
1d442b
+ *   other than contiguous starting from 0.
1d442b
+ */
1d442b
 void fuse_session_process_buf_int(struct fuse_session *se,
1d442b
-                                  const struct fuse_buf *buf,
1d442b
+                                  struct fuse_bufvec *bufv,
1d442b
                                   struct fuse_chan *ch)
1d442b
 {
1d442b
+    const struct fuse_buf *buf = bufv->buf;
1d442b
     struct fuse_in_header *in;
1d442b
     const void *inarg;
1d442b
     struct fuse_req *req;
1d442b
@@ -2108,7 +2129,7 @@ void fuse_session_process_buf_int(struct fuse_session *se,
1d442b
 
1d442b
     inarg = (void *)&in[1];
1d442b
     if (in->opcode == FUSE_WRITE && se->op.write_buf) {
1d442b
-        do_write_buf(req, in->nodeid, inarg, buf);
1d442b
+        do_write_buf(req, in->nodeid, inarg, bufv);
1d442b
     } else {
1d442b
         fuse_ll_ops[in->opcode].func(req, in->nodeid, inarg);
1d442b
     }
1d442b
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
1d442b
index 635f87756a..fd588a4829 100644
1d442b
--- a/tools/virtiofsd/fuse_virtio.c
1d442b
+++ b/tools/virtiofsd/fuse_virtio.c
1d442b
@@ -501,7 +501,8 @@ static void *fv_queue_thread(void *opaque)
1d442b
             /* TODO! Endianness of header */
1d442b
 
1d442b
             /* TODO: Add checks for fuse_session_exited */
1d442b
-            fuse_session_process_buf_int(se, &fbuf, &ch);
1d442b
+            struct fuse_bufvec bufv = { .buf[0] = fbuf, .count = 1 };
1d442b
+            fuse_session_process_buf_int(se, &bufv, &ch);
1d442b
 
1d442b
             if (!qi->reply_sent) {
1d442b
                 fuse_log(FUSE_LOG_DEBUG, "%s: elem %d no reply sent\n",