22c213
From e4c8fd1060fb69a093064851ebf66dd82533ec0e Mon Sep 17 00:00:00 2001
22c213
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
22c213
Date: Mon, 27 Jan 2020 19:02:17 +0100
22c213
Subject: [PATCH 106/116] virtiofsd: add definition of fuse_buf_writev()
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-103-dgilbert@redhat.com>
22c213
Patchwork-id: 93557
22c213
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 102/112] virtiofsd: add definition of fuse_buf_writev()
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: piaojun <piaojun@huawei.com>
22c213
22c213
Define fuse_buf_writev() which use pwritev and writev to improve io
22c213
bandwidth. Especially, the src bufs with 0 size should be skipped as
22c213
their mems are not *block_size* aligned which will cause writev failed
22c213
in direct io mode.
22c213
22c213
Signed-off-by: Jun Piao <piaojun@huawei.com>
22c213
Suggested-by: Stefan Hajnoczi <stefanha@redhat.com>
22c213
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
22c213
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
22c213
(cherry picked from commit 9ceaaa15cf21073c2b23058c374f61c30cd39c31)
22c213
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
22c213
---
22c213
 tools/virtiofsd/buffer.c | 38 ++++++++++++++++++++++++++++++++++++++
22c213
 1 file changed, 38 insertions(+)
22c213
22c213
diff --git a/tools/virtiofsd/buffer.c b/tools/virtiofsd/buffer.c
22c213
index 42a608f..37befeb 100644
22c213
--- a/tools/virtiofsd/buffer.c
22c213
+++ b/tools/virtiofsd/buffer.c
22c213
@@ -14,6 +14,7 @@
22c213
 #include "fuse_lowlevel.h"
22c213
 #include <assert.h>
22c213
 #include <errno.h>
22c213
+#include <stdlib.h>
22c213
 #include <string.h>
22c213
 #include <unistd.h>
22c213
 
22c213
@@ -33,6 +34,43 @@ size_t fuse_buf_size(const struct fuse_bufvec *bufv)
22c213
     return size;
22c213
 }
22c213
 
22c213
+__attribute__((unused))
22c213
+static ssize_t fuse_buf_writev(struct fuse_buf *out_buf,
22c213
+                               struct fuse_bufvec *in_buf)
22c213
+{
22c213
+    ssize_t res, i, j;
22c213
+    size_t iovcnt = in_buf->count;
22c213
+    struct iovec *iov;
22c213
+    int fd = out_buf->fd;
22c213
+
22c213
+    iov = calloc(iovcnt, sizeof(struct iovec));
22c213
+    if (!iov) {
22c213
+        return -ENOMEM;
22c213
+    }
22c213
+
22c213
+    for (i = 0, j = 0; i < iovcnt; i++) {
22c213
+        /* Skip the buf with 0 size */
22c213
+        if (in_buf->buf[i].size) {
22c213
+            iov[j].iov_base = in_buf->buf[i].mem;
22c213
+            iov[j].iov_len = in_buf->buf[i].size;
22c213
+            j++;
22c213
+        }
22c213
+    }
22c213
+
22c213
+    if (out_buf->flags & FUSE_BUF_FD_SEEK) {
22c213
+        res = pwritev(fd, iov, iovcnt, out_buf->pos);
22c213
+    } else {
22c213
+        res = writev(fd, iov, iovcnt);
22c213
+    }
22c213
+
22c213
+    if (res == -1) {
22c213
+        res = -errno;
22c213
+    }
22c213
+
22c213
+    free(iov);
22c213
+    return res;
22c213
+}
22c213
+
22c213
 static size_t min_size(size_t s1, size_t s2)
22c213
 {
22c213
     return s1 < s2 ? s1 : s2;
22c213
-- 
22c213
1.8.3.1
22c213