yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

Blame SOURCES/kvm-virtiofsd-add-definition-of-fuse_buf_writev.patch

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