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