render / rpms / qemu

Forked from rpms/qemu 10 months ago
Clone

Blame 0108-virtiofsd-add-definition-of-fuse_buf_writev.patch

1d442b
From: piaojun <piaojun@huawei.com>
1d442b
Date: Mon, 27 Jan 2020 19:02:17 +0000
1d442b
Subject: [PATCH] virtiofsd: add definition of fuse_buf_writev()
1d442b
MIME-Version: 1.0
1d442b
Content-Type: text/plain; charset=UTF-8
1d442b
Content-Transfer-Encoding: 8bit
1d442b
1d442b
Define fuse_buf_writev() which use pwritev and writev to improve io
1d442b
bandwidth. Especially, the src bufs with 0 size should be skipped as
1d442b
their mems are not *block_size* aligned which will cause writev failed
1d442b
in direct io mode.
1d442b
1d442b
Signed-off-by: Jun Piao <piaojun@huawei.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 9ceaaa15cf21073c2b23058c374f61c30cd39c31)
1d442b
---
1d442b
 tools/virtiofsd/buffer.c | 38 ++++++++++++++++++++++++++++++++++++++
1d442b
 1 file changed, 38 insertions(+)
1d442b
1d442b
diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c
1d442b
index 42a608f6bd..37befebac2 100644
1d442b
--- a/tools/virtiofsd/buffer.c
1d442b
+++ b/tools/virtiofsd/buffer.c
1d442b
@@ -14,6 +14,7 @@
1d442b
 #include "fuse_lowlevel.h"
1d442b
 #include <assert.h>
1d442b
 #include <errno.h>
1d442b
+#include <stdlib.h>
1d442b
 #include <string.h>
1d442b
 #include <unistd.h>
1d442b
 
1d442b
@@ -33,6 +34,43 @@ 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
+    ssize_t res, i, j;
1d442b
+    size_t iovcnt = in_buf->count;
1d442b
+    struct iovec *iov;
1d442b
+    int fd = out_buf->fd;
1d442b
+
1d442b
+    iov = calloc(iovcnt, sizeof(struct iovec));
1d442b
+    if (!iov) {
1d442b
+        return -ENOMEM;
1d442b
+    }
1d442b
+
1d442b
+    for (i = 0, j = 0; i < iovcnt; i++) {
1d442b
+        /* Skip the buf with 0 size */
1d442b
+        if (in_buf->buf[i].size) {
1d442b
+            iov[j].iov_base = in_buf->buf[i].mem;
1d442b
+            iov[j].iov_len = in_buf->buf[i].size;
1d442b
+            j++;
1d442b
+        }
1d442b
+    }
1d442b
+
1d442b
+    if (out_buf->flags & FUSE_BUF_FD_SEEK) {
1d442b
+        res = pwritev(fd, iov, iovcnt, out_buf->pos);
1d442b
+    } else {
1d442b
+        res = writev(fd, iov, iovcnt);
1d442b
+    }
1d442b
+
1d442b
+    if (res == -1) {
1d442b
+        res = -errno;
1d442b
+    }
1d442b
+
1d442b
+    free(iov);
1d442b
+    return res;
1d442b
+}
1d442b
+
1d442b
 static size_t min_size(size_t s1, size_t s2)
1d442b
 {
1d442b
     return s1 < s2 ? s1 : s2;