|
|
ddf19c |
From 7d2efc3e4af15eff57b0c38cff7c81b371a98303 Mon Sep 17 00:00:00 2001
|
|
|
ddf19c |
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
|
|
|
ddf19c |
Date: Mon, 27 Jan 2020 19:01:06 +0100
|
|
|
ddf19c |
Subject: [PATCH 035/116] virtiofsd: Fast path for virtio read
|
|
|
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-32-dgilbert@redhat.com>
|
|
|
ddf19c |
Patchwork-id: 93480
|
|
|
ddf19c |
O-Subject: [RHEL-AV-8.2 qemu-kvm PATCH 031/112] virtiofsd: Fast path for virtio read
|
|
|
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 |
Readv the data straight into the guests buffer.
|
|
|
ddf19c |
|
|
|
ddf19c |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
With fix by:
|
|
|
ddf19c |
Signed-off-by: Eryu Guan <eguan@linux.alibaba.com>
|
|
|
ddf19c |
Reviewed-by: Masayoshi Mizuma <m.mizuma@jp.fujitsu.com>
|
|
|
ddf19c |
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
|
|
|
ddf19c |
(cherry picked from commit eb49d187ef5134483a34c970bbfece28aaa686a7)
|
|
|
ddf19c |
|
|
|
ddf19c |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
ddf19c |
---
|
|
|
ddf19c |
tools/virtiofsd/fuse_lowlevel.c | 5 ++
|
|
|
ddf19c |
tools/virtiofsd/fuse_virtio.c | 162 ++++++++++++++++++++++++++++++++++++++++
|
|
|
ddf19c |
tools/virtiofsd/fuse_virtio.h | 4 +
|
|
|
ddf19c |
3 files changed, 171 insertions(+)
|
|
|
ddf19c |
|
|
|
ddf19c |
diff --git a/tools/virtiofsd/fuse_lowlevel.c b/tools/virtiofsd/fuse_lowlevel.c
|
|
|
ddf19c |
index 380d93b..4f4684d 100644
|
|
|
ddf19c |
--- a/tools/virtiofsd/fuse_lowlevel.c
|
|
|
ddf19c |
+++ b/tools/virtiofsd/fuse_lowlevel.c
|
|
|
ddf19c |
@@ -475,6 +475,11 @@ static int fuse_send_data_iov_fallback(struct fuse_session *se,
|
|
|
ddf19c |
return fuse_send_msg(se, ch, iov, iov_count);
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
+ if (fuse_lowlevel_is_virtio(se) && buf->count == 1 &&
|
|
|
ddf19c |
+ buf->buf[0].flags == (FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK)) {
|
|
|
ddf19c |
+ return virtio_send_data_iov(se, ch, iov, iov_count, buf, len);
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+
|
|
|
ddf19c |
abort(); /* Will have taken vhost path */
|
|
|
ddf19c |
return 0;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
diff --git a/tools/virtiofsd/fuse_virtio.c b/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
index f1adeb6..7e2711b 100644
|
|
|
ddf19c |
--- a/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
+++ b/tools/virtiofsd/fuse_virtio.c
|
|
|
ddf19c |
@@ -230,6 +230,168 @@ err:
|
|
|
ddf19c |
return ret;
|
|
|
ddf19c |
}
|
|
|
ddf19c |
|
|
|
ddf19c |
+/*
|
|
|
ddf19c |
+ * Callback from fuse_send_data_iov_* when it's virtio and the buffer
|
|
|
ddf19c |
+ * is a single FD with FUSE_BUF_IS_FD | FUSE_BUF_FD_SEEK
|
|
|
ddf19c |
+ * We need send the iov and then the buffer.
|
|
|
ddf19c |
+ * Return 0 on success
|
|
|
ddf19c |
+ */
|
|
|
ddf19c |
+int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
|
|
|
ddf19c |
+ struct iovec *iov, int count, struct fuse_bufvec *buf,
|
|
|
ddf19c |
+ size_t len)
|
|
|
ddf19c |
+{
|
|
|
ddf19c |
+ int ret = 0;
|
|
|
ddf19c |
+ VuVirtqElement *elem;
|
|
|
ddf19c |
+ VuVirtq *q;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ assert(count >= 1);
|
|
|
ddf19c |
+ assert(iov[0].iov_len >= sizeof(struct fuse_out_header));
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ struct fuse_out_header *out = iov[0].iov_base;
|
|
|
ddf19c |
+ /* TODO: Endianness! */
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ size_t iov_len = iov_size(iov, count);
|
|
|
ddf19c |
+ size_t tosend_len = iov_len + len;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ out->len = tosend_len;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG, "%s: count=%d len=%zd iov_len=%zd\n", __func__,
|
|
|
ddf19c |
+ count, len, iov_len);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* unique == 0 is notification which we don't support */
|
|
|
ddf19c |
+ assert(out->unique);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* For virtio we always have ch */
|
|
|
ddf19c |
+ assert(ch);
|
|
|
ddf19c |
+ assert(!ch->qi->reply_sent);
|
|
|
ddf19c |
+ elem = ch->qi->qe;
|
|
|
ddf19c |
+ q = &ch->qi->virtio_dev->dev.vq[ch->qi->qidx];
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* The 'in' part of the elem is to qemu */
|
|
|
ddf19c |
+ unsigned int in_num = elem->in_num;
|
|
|
ddf19c |
+ struct iovec *in_sg = elem->in_sg;
|
|
|
ddf19c |
+ size_t in_len = iov_size(in_sg, in_num);
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG, "%s: elem %d: with %d in desc of length %zd\n",
|
|
|
ddf19c |
+ __func__, elem->index, in_num, in_len);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /*
|
|
|
ddf19c |
+ * The elem should have room for a 'fuse_out_header' (out from fuse)
|
|
|
ddf19c |
+ * plus the data based on the len in the header.
|
|
|
ddf19c |
+ */
|
|
|
ddf19c |
+ if (in_len < sizeof(struct fuse_out_header)) {
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_ERR, "%s: elem %d too short for out_header\n",
|
|
|
ddf19c |
+ __func__, elem->index);
|
|
|
ddf19c |
+ ret = E2BIG;
|
|
|
ddf19c |
+ goto err;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ if (in_len < tosend_len) {
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_ERR, "%s: elem %d too small for data len %zd\n",
|
|
|
ddf19c |
+ __func__, elem->index, tosend_len);
|
|
|
ddf19c |
+ ret = E2BIG;
|
|
|
ddf19c |
+ goto err;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* TODO: Limit to 'len' */
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* First copy the header data from iov->in_sg */
|
|
|
ddf19c |
+ copy_iov(iov, count, in_sg, in_num, iov_len);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /*
|
|
|
ddf19c |
+ * Build a copy of the the in_sg iov so we can skip bits in it,
|
|
|
ddf19c |
+ * including changing the offsets
|
|
|
ddf19c |
+ */
|
|
|
ddf19c |
+ struct iovec *in_sg_cpy = calloc(sizeof(struct iovec), in_num);
|
|
|
ddf19c |
+ assert(in_sg_cpy);
|
|
|
ddf19c |
+ memcpy(in_sg_cpy, in_sg, sizeof(struct iovec) * in_num);
|
|
|
ddf19c |
+ /* These get updated as we skip */
|
|
|
ddf19c |
+ struct iovec *in_sg_ptr = in_sg_cpy;
|
|
|
ddf19c |
+ int in_sg_cpy_count = in_num;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* skip over parts of in_sg that contained the header iov */
|
|
|
ddf19c |
+ size_t skip_size = iov_len;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ size_t in_sg_left = 0;
|
|
|
ddf19c |
+ do {
|
|
|
ddf19c |
+ while (skip_size != 0 && in_sg_cpy_count) {
|
|
|
ddf19c |
+ if (skip_size >= in_sg_ptr[0].iov_len) {
|
|
|
ddf19c |
+ skip_size -= in_sg_ptr[0].iov_len;
|
|
|
ddf19c |
+ in_sg_ptr++;
|
|
|
ddf19c |
+ in_sg_cpy_count--;
|
|
|
ddf19c |
+ } else {
|
|
|
ddf19c |
+ in_sg_ptr[0].iov_len -= skip_size;
|
|
|
ddf19c |
+ in_sg_ptr[0].iov_base += skip_size;
|
|
|
ddf19c |
+ break;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ int i;
|
|
|
ddf19c |
+ for (i = 0, in_sg_left = 0; i < in_sg_cpy_count; i++) {
|
|
|
ddf19c |
+ in_sg_left += in_sg_ptr[i].iov_len;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG,
|
|
|
ddf19c |
+ "%s: after skip skip_size=%zd in_sg_cpy_count=%d "
|
|
|
ddf19c |
+ "in_sg_left=%zd\n",
|
|
|
ddf19c |
+ __func__, skip_size, in_sg_cpy_count, in_sg_left);
|
|
|
ddf19c |
+ ret = preadv(buf->buf[0].fd, in_sg_ptr, in_sg_cpy_count,
|
|
|
ddf19c |
+ buf->buf[0].pos);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ if (ret == -1) {
|
|
|
ddf19c |
+ ret = errno;
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG, "%s: preadv failed (%m) len=%zd\n",
|
|
|
ddf19c |
+ __func__, len);
|
|
|
ddf19c |
+ free(in_sg_cpy);
|
|
|
ddf19c |
+ goto err;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG, "%s: preadv ret=%d len=%zd\n", __func__,
|
|
|
ddf19c |
+ ret, len);
|
|
|
ddf19c |
+ if (ret < len && ret) {
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG, "%s: ret < len\n", __func__);
|
|
|
ddf19c |
+ /* Skip over this much next time around */
|
|
|
ddf19c |
+ skip_size = ret;
|
|
|
ddf19c |
+ buf->buf[0].pos += ret;
|
|
|
ddf19c |
+ len -= ret;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* Lets do another read */
|
|
|
ddf19c |
+ continue;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ if (!ret) {
|
|
|
ddf19c |
+ /* EOF case? */
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG, "%s: !ret in_sg_left=%zd\n", __func__,
|
|
|
ddf19c |
+ in_sg_left);
|
|
|
ddf19c |
+ break;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ if (ret != len) {
|
|
|
ddf19c |
+ fuse_log(FUSE_LOG_DEBUG, "%s: ret!=len\n", __func__);
|
|
|
ddf19c |
+ ret = EIO;
|
|
|
ddf19c |
+ free(in_sg_cpy);
|
|
|
ddf19c |
+ goto err;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+ in_sg_left -= ret;
|
|
|
ddf19c |
+ len -= ret;
|
|
|
ddf19c |
+ } while (in_sg_left);
|
|
|
ddf19c |
+ free(in_sg_cpy);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ /* Need to fix out->len on EOF */
|
|
|
ddf19c |
+ if (len) {
|
|
|
ddf19c |
+ struct fuse_out_header *out_sg = in_sg[0].iov_base;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ tosend_len -= len;
|
|
|
ddf19c |
+ out_sg->len = tosend_len;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ ret = 0;
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ vu_queue_push(&se->virtio_dev->dev, q, elem, tosend_len);
|
|
|
ddf19c |
+ vu_queue_notify(&se->virtio_dev->dev, q);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+err:
|
|
|
ddf19c |
+ if (ret == 0) {
|
|
|
ddf19c |
+ ch->qi->reply_sent = true;
|
|
|
ddf19c |
+ }
|
|
|
ddf19c |
+
|
|
|
ddf19c |
+ return ret;
|
|
|
ddf19c |
+}
|
|
|
ddf19c |
+
|
|
|
ddf19c |
/* Thread function for individual queues, created when a queue is 'started' */
|
|
|
ddf19c |
static void *fv_queue_thread(void *opaque)
|
|
|
ddf19c |
{
|
|
|
ddf19c |
diff --git a/tools/virtiofsd/fuse_virtio.h b/tools/virtiofsd/fuse_virtio.h
|
|
|
ddf19c |
index 135a148..cc676b9 100644
|
|
|
ddf19c |
--- a/tools/virtiofsd/fuse_virtio.h
|
|
|
ddf19c |
+++ b/tools/virtiofsd/fuse_virtio.h
|
|
|
ddf19c |
@@ -26,4 +26,8 @@ int virtio_loop(struct fuse_session *se);
|
|
|
ddf19c |
int virtio_send_msg(struct fuse_session *se, struct fuse_chan *ch,
|
|
|
ddf19c |
struct iovec *iov, int count);
|
|
|
ddf19c |
|
|
|
ddf19c |
+int virtio_send_data_iov(struct fuse_session *se, struct fuse_chan *ch,
|
|
|
ddf19c |
+ struct iovec *iov, int count,
|
|
|
ddf19c |
+ struct fuse_bufvec *buf, size_t len);
|
|
|
ddf19c |
+
|
|
|
ddf19c |
#endif
|
|
|
ddf19c |
--
|
|
|
ddf19c |
1.8.3.1
|
|
|
ddf19c |
|