cryptospore / rpms / qemu-kvm

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