|
|
ddf19c |
From d5986c804f05070a07dfe702f7c66357daaa1ab6 Mon Sep 17 00:00:00 2001
|
|
|
ddf19c |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
ddf19c |
Date: Mon, 27 Jan 2020 19:01:20 +0100
|
|
|
ddf19c |
Subject: [PATCH 049/116] virtiofsd: Pass write iov's all the way through
|
|
|
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-46-dgilbert@redhat.com>
|
|
|
ddf19c |
Patchwork-id: 93497
|
|
|
ddf19c |
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 045/112] virtiofsd: Pass write iov's all the way through
|
|
|
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: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
ddf19c |
|
|
|
ddf19c |
Pass the write iov pointing to guest RAM all the way through rather
|
|
|
ddf19c |
than copying the data.
|
|
|
ddf19c |
|
|
|
ddf19c |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
Reviewed-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
|
|
|
ddf19c |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
(cherry picked from commit e17f7a580e2c599330ad3a6946be615ca2fe97d9)
|
|
|
ddf19c |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ddf19c |
---
|
|
|
ddf19c |
tools/virtiofsd/fuse_virtio.c | 79 +++++++++++++++++++++++++++++++++++++++----
|
|
|
ddf19c |
1 file changed, 73 insertions(+), 6 deletions(-)
|
|
|
ddf19c |
|
|
|
ddf19c |
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
index fd588a4..872968f 100644
|
|
|
ddf19c |
--- a/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
+++ b/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
@@ -454,6 +454,10 @@ static void *fv_queue_thread(void *opaque)
|
|
|
ddf19c |
__func__, qi->qidx, (size_t)evalue, in_bytes, out_bytes);
|
|
|
ddf19c |
|
|
|
ddf19c |
while (1) {
|
|
|
ddf19c |
+ bool allocated_bufv = false;
|
|
|
ddf19c |
+ struct fuse_bufvec bufv;
|
|
|
ddf19c |
+ struct fuse_bufvec *pbufv;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
/*
|
|
|
ddf19c |
* An element contains one request and the space to send our
|
|
|
ddf19c |
* response They're spread over multiple descriptors in a
|
|
|
ddf19c |
@@ -495,14 +499,76 @@ static void *fv_queue_thread(void *opaque)
|
|
|
ddf19c |
__func__, elem->index);
|
|
|
ddf19c |
assert(0); /* TODO */
|
|
|
ddf19c |
}
|
|
|
ddf19c |
- copy_from_iov(&fbuf, out_num, out_sg);
|
|
|
ddf19c |
- fbuf.size = out_len;
|
|
|
ddf19c |
+ /* Copy just the first element and look at it */
|
|
|
ddf19c |
+ copy_from_iov(&fbuf, 1, out_sg);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ if (out_num > 2 &&
|
|
|
ddf19c |
+ out_sg[0].iov_len == sizeof(struct fuse_in_header) &&
|
|
|
ddf19c |
+ ((struct fuse_in_header *)fbuf.mem)->opcode == FUSE_WRITE &&
|
|
|
ddf19c |
+ out_sg[1].iov_len == sizeof(struct fuse_write_in)) {
|
|
|
ddf19c |
+ /*
|
|
|
ddf19c |
+ * For a write we don't actually need to copy the
|
|
|
ddf19c |
+ * data, we can just do it straight out of guest memory
|
|
|
ddf19c |
+ * but we must still copy the headers in case the guest
|
|
|
ddf19c |
+ * was nasty and changed them while we were using them.
|
|
|
ddf19c |
+ */
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG, "%s: Write special case\n", __func__);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* copy the fuse_write_in header after the fuse_in_header */
|
|
|
ddf19c |
+ fbuf.mem += out_sg->iov_len;
|
|
|
ddf19c |
+ copy_from_iov(&fbuf, 1, out_sg + 1);
|
|
|
ddf19c |
+ fbuf.mem -= out_sg->iov_len;
|
|
|
ddf19c |
+ fbuf.size = out_sg[0].iov_len + out_sg[1].iov_len;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* Allocate the bufv, with space for the rest of the iov */
|
|
|
ddf19c |
+ allocated_bufv = true;
|
|
|
ddf19c |
+ pbufv = malloc(sizeof(struct fuse_bufvec) +
|
|
|
ddf19c |
+ sizeof(struct fuse_buf) * (out_num - 2));
|
|
|
ddf19c |
+ if (!pbufv) {
|
|
|
ddf19c |
+ vu_queue_unpop(dev, q, elem, 0);
|
|
|
ddf19c |
+ free(elem);
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_ERR, "%s: pbufv malloc failed\n",
|
|
|
ddf19c |
+ __func__);
|
|
|
ddf19c |
+ goto out;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ pbufv->count = 1;
|
|
|
ddf19c |
+ pbufv->buf[0] = fbuf;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ size_t iovindex, pbufvindex;
|
|
|
ddf19c |
+ iovindex = 2; /* 2 headers, separate iovs */
|
|
|
ddf19c |
+ pbufvindex = 1; /* 2 headers, 1 fusebuf */
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ for (; iovindex < out_num; iovindex++, pbufvindex++) {
|
|
|
ddf19c |
+ pbufv->count++;
|
|
|
ddf19c |
+ pbufv->buf[pbufvindex].pos = ~0; /* Dummy */
|
|
|
ddf19c |
+ pbufv->buf[pbufvindex].flags = 0;
|
|
|
ddf19c |
+ pbufv->buf[pbufvindex].mem = out_sg[iovindex].iov_base;
|
|
|
ddf19c |
+ pbufv->buf[pbufvindex].size = out_sg[iovindex].iov_len;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ } else {
|
|
|
ddf19c |
+ /* Normal (non fast write) path */
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* Copy the rest of the buffer */
|
|
|
ddf19c |
+ fbuf.mem += out_sg->iov_len;
|
|
|
ddf19c |
+ copy_from_iov(&fbuf, out_num - 1, out_sg + 1);
|
|
|
ddf19c |
+ fbuf.mem -= out_sg->iov_len;
|
|
|
ddf19c |
+ fbuf.size = out_len;
|
|
|
ddf19c |
|
|
|
ddf19c |
- /* TODO! Endianness of header */
|
|
|
ddf19c |
+ /* TODO! Endianness of header */
|
|
|
ddf19c |
|
|
|
ddf19c |
- /* TODO: Add checks for fuse_session_exited */
|
|
|
ddf19c |
- struct fuse_bufvec bufv = { .buf[0] = fbuf, .count = 1 };
|
|
|
ddf19c |
- fuse_session_process_buf_int(se, &bufv, &ch);
|
|
|
ddf19c |
+ /* TODO: Add checks for fuse_session_exited */
|
|
|
ddf19c |
+ bufv.buf[0] = fbuf;
|
|
|
ddf19c |
+ bufv.count = 1;
|
|
|
ddf19c |
+ pbufv = &buf;;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ pbufv->idx = 0;
|
|
|
ddf19c |
+ pbufv->off = 0;
|
|
|
ddf19c |
+ fuse_session_process_buf_int(se, pbufv, &ch);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ if (allocated_bufv) {
|
|
|
ddf19c |
+ free(pbufv);
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
|
|
|
ddf19c |
if (!qi->reply_sent) {
|
|
|
ddf19c |
fuse_log(FUSE_LOG_DEBUG, "%s: elem %d no reply sent\n",
|
|
|
ddf19c |
@@ -516,6 +582,7 @@ static void *fv_queue_thread(void *opaque)
|
|
|
ddf19c |
elem = NULL;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
}
|
|
|
ddf19c |
+out:
|
|
|
ddf19c |
pthread_mutex_destroy(&ch.lock);
|
|
|
ddf19c |
free(fbuf.mem);
|
|
|
ddf19c |
|
|
|
ddf19c |
--
|
|
|
ddf19c |
1.8.3.1
|
|
|
ddf19c |
|