dcavalca / rpms / qemu

Forked from rpms/qemu a year ago
Clone

Blame 0109-virtiofsd-use-fuse_buf_writev-to-replace-fuse_buf_wr.patch

1d442b
From: piaojun <piaojun@huawei.com>
1d442b
Date: Mon, 27 Jan 2020 19:02:18 +0000
1d442b
Subject: [PATCH] virtiofsd: use fuse_buf_writev to replace fuse_buf_write for
1d442b
 better performance
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
fuse_buf_writev() only handles the normal write in which src is buffer
1d442b
and dest is fd. Specially if src buffer represents guest physical
1d442b
address that can't be mapped by the daemon process, IO must be bounced
1d442b
back to the VMM to do it by fuse_buf_copy().
1d442b
1d442b
Signed-off-by: Jun Piao <piaojun@huawei.com>
1d442b
Suggested-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
1d442b
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
1d442b
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
1d442b
(cherry picked from commit c465bba2c90a810f6e71e4f2646b1b4ee4b478de)
1d442b
---
1d442b
 tools/virtiofsd/buffer.c | 20 ++++++++++++++++++--
1d442b
 1 file changed, 18 insertions(+), 2 deletions(-)
1d442b
1d442b
diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c
1d442b
index 37befebac2..27c1377f22 100644
1d442b
--- a/tools/virtiofsd/buffer.c
1d442b
+++ b/tools/virtiofsd/buffer.c
1d442b
@@ -34,7 +34,6 @@ size_t fuse_buf_size(const struct fuse_bufvec *bufv)
1d442b
     return size;
1d442b
 }
1d442b
 
1d442b
-__attribute__((unused))
1d442b
 static ssize_t fuse_buf_writev(struct fuse_buf *out_buf,
1d442b
                                struct fuse_bufvec *in_buf)
1d442b
 {
1d442b
@@ -262,12 +261,29 @@ static int fuse_bufvec_advance(struct fuse_bufvec *bufv, size_t len)
1d442b
 
1d442b
 ssize_t fuse_buf_copy(struct fuse_bufvec *dstv, struct fuse_bufvec *srcv)
1d442b
 {
1d442b
-    size_t copied = 0;
1d442b
+    size_t copied = 0, i;
1d442b
 
1d442b
     if (dstv == srcv) {
1d442b
         return fuse_buf_size(dstv);
1d442b
     }
1d442b
 
1d442b
+    /*
1d442b
+     * use writev to improve bandwidth when all the
1d442b
+     * src buffers already mapped by the daemon
1d442b
+     * process
1d442b
+     */
1d442b
+    for (i = 0; i < srcv->count; i++) {
1d442b
+        if (srcv->buf[i].flags & FUSE_BUF_IS_FD) {
1d442b
+            break;
1d442b
+        }
1d442b
+    }
1d442b
+    if ((i == srcv->count) && (dstv->count == 1) &&
1d442b
+        (dstv->idx == 0) &&
1d442b
+        (dstv->buf[0].flags & FUSE_BUF_IS_FD)) {
1d442b
+        dstv->buf[0].pos += dstv->off;
1d442b
+        return fuse_buf_writev(&dstv->buf[0], srcv);
1d442b
+    }
1d442b
+
1d442b
     for (;;) {
1d442b
         const struct fuse_buf *src = fuse_bufvec_current(srcv);
1d442b
         const struct fuse_buf *dst = fuse_bufvec_current(dstv);