qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "Marc-André Lureau" <marcandre.lureau@gmail.com>
Cc: "Michael S. Tsirkin" <mst@redhat.com>,
	QEMU <qemu-devel@nongnu.org>,
	piaojun@huawei.com, Stefan Hajnoczi <stefanha@redhat.com>,
	eguan@linux.alibaba.com, vgoyal@redhat.com
Subject: Re: [PATCH 21/30] virtiofsd: Start reading commands from queue
Date: Tue, 22 Oct 2019 11:28:05 +0100	[thread overview]
Message-ID: <20191022102805.GE2815@work-vm> (raw)
In-Reply-To: <CAJ+F1CJ+P2Um+SGFu4dMoxcgWXTq3ZXqeTBjW01hgaJS3V2s-g@mail.gmail.com>

* Marc-André Lureau (marcandre.lureau@gmail.com) wrote:
> On Mon, Oct 21, 2019 at 1:09 PM Dr. David Alan Gilbert (git)
> <dgilbert@redhat.com> wrote:
> >
> > From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
> >
> > Pop queue elements off queues, copy the data from them and
> > pass that to fuse.
> >
> >   Note: 'out' in a VuVirtqElement is from QEMU
> >         'in' in libfuse is into the daemon
> >
> >   So we read from the out iov's to get a fuse_in_header
> >
> > When we get a kick we've got to read all the elements until the queue
> > is empty.
> >
> > Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
> > ---
> >  contrib/virtiofsd/fuse_i.h      |  2 +
> >  contrib/virtiofsd/fuse_virtio.c | 99 ++++++++++++++++++++++++++++++++-
> >  2 files changed, 98 insertions(+), 3 deletions(-)
> >
> > diff --git a/contrib/virtiofsd/fuse_i.h b/contrib/virtiofsd/fuse_i.h
> > index ea55f618a5..5b6ef09df5 100644
> > --- a/contrib/virtiofsd/fuse_i.h
> > +++ b/contrib/virtiofsd/fuse_i.h
> > @@ -14,6 +14,7 @@
> >  #include "fuse_lowlevel.h"
> >
> >  struct fv_VuDev;
> > +struct fv_QueueInfo;
> >
> >  struct fuse_req {
> >         struct fuse_session *se;
> > @@ -75,6 +76,7 @@ struct fuse_chan {
> >         pthread_mutex_t lock;
> >         int ctr;
> >         int fd;
> > +       struct fv_QueueInfo *qi;
> >  };
> >
> >  /**
> > diff --git a/contrib/virtiofsd/fuse_virtio.c b/contrib/virtiofsd/fuse_virtio.c
> > index 0513531c13..e189511729 100644
> > --- a/contrib/virtiofsd/fuse_virtio.c
> > +++ b/contrib/virtiofsd/fuse_virtio.c
> > @@ -32,6 +32,7 @@
> >
> >  #include "contrib/libvhost-user/libvhost-user.h"
> >
> > +struct fv_VuDev;
> >  struct fv_QueueInfo {
> >      pthread_t thread;
> >      struct fv_VuDev *virtio_dev;
> > @@ -101,10 +102,42 @@ static void fv_panic(VuDev *dev, const char *err)
> >      exit(EXIT_FAILURE);
> >  }
> >
> > +/*
> > + * Copy from an iovec into a fuse_buf (memory only)
> > + * Caller must ensure there is space
> > + */
> > +static void copy_from_iov(struct fuse_buf *buf, size_t out_num,
> > +                          const struct iovec *out_sg)
> > +{
> > +    void *dest = buf->mem;
> > +
> > +    while (out_num) {
> > +        size_t onelen = out_sg->iov_len;
> > +        memcpy(dest, out_sg->iov_base, onelen);
> > +        dest += onelen;
> > +        out_sg++;
> > +        out_num--;
> > +    }
> > +}
> 
> Or iov_to_buf()

Is there a variant there that will copy the whole of an iovec?
I just tried swapping the copy_from_iov out, but it's messier to use
because it wants the bytes length; where in most cases I'm taking a
single element from the iovec, or the 'rest of the iovec' by element
count.

Dave

> Just found out that vhost-user-blk.c should probably link too with
> util/iov.o, instead of copying the code.
> 
> > +
> >  /* Thread function for individual queues, created when a queue is 'started' */
> >  static void *fv_queue_thread(void *opaque)
> >  {
> >      struct fv_QueueInfo *qi = opaque;
> > +    struct VuDev *dev = &qi->virtio_dev->dev;
> > +    struct VuVirtq *q = vu_get_queue(dev, qi->qidx);
> > +    struct fuse_session *se = qi->virtio_dev->se;
> > +    struct fuse_chan ch;
> > +    struct fuse_buf fbuf;
> > +
> > +    fbuf.mem = NULL;
> > +    fbuf.flags = 0;
> > +
> > +    fuse_mutex_init(&ch.lock);
> > +    ch.fd = (int)0xdaff0d111;
> > +    ch.ctr = 1;
> > +    ch.qi = qi;
> > +
> >      fuse_log(FUSE_LOG_INFO, "%s: Start for queue %d kick_fd %d\n", __func__,
> >               qi->qidx, qi->kick_fd);
> >      while (1) {
> > @@ -141,11 +174,71 @@ static void *fv_queue_thread(void *opaque)
> >              fuse_log(FUSE_LOG_ERR, "Eventfd_read for queue: %m\n");
> >              break;
> >          }
> > -        if (qi->virtio_dev->se->debug) {
> > -            fprintf(stderr, "%s: Queue %d gave evalue: %zx\n", __func__,
> > -                    qi->qidx, (size_t)evalue);
> > +        /* out is from guest, in is too guest */
> > +        unsigned int in_bytes, out_bytes;
> > +        vu_queue_get_avail_bytes(dev, q, &in_bytes, &out_bytes, ~0, ~0);
> > +
> > +        fuse_log(FUSE_LOG_DEBUG,
> > +                 "%s: Queue %d gave evalue: %zx available: in: %u out: %u\n",
> > +                 __func__, qi->qidx, (size_t)evalue, in_bytes, out_bytes);
> > +
> > +        while (1) {
> > +            /*
> > +             * An element contains one request and the space to send our
> > +             * response They're spread over multiple descriptors in a
> > +             * scatter/gather set and we can't trust the guest to keep them
> > +             * still; so copy in/out.
> > +             */
> > +            VuVirtqElement *elem = vu_queue_pop(dev, q, sizeof(VuVirtqElement));
> > +            if (!elem) {
> > +                break;
> > +            }
> > +
> > +            if (!fbuf.mem) {
> > +                fbuf.mem = malloc(se->bufsize);
> > +                assert(fbuf.mem);
> > +                assert(se->bufsize > sizeof(struct fuse_in_header));
> > +            }
> > +            /* The 'out' part of the elem is from qemu */
> > +            unsigned int out_num = elem->out_num;
> > +            struct iovec *out_sg = elem->out_sg;
> > +            size_t out_len = iov_length(out_sg, out_num);
> > +            fuse_log(FUSE_LOG_DEBUG,
> > +                     "%s: elem %d: with %d out desc of length %zd\n", __func__,
> > +                     elem->index, out_num, out_len);
> > +
> > +            /*
> > +             * The elem should contain a 'fuse_in_header' (in to fuse)
> > +             * plus the data based on the len in the header.
> > +             */
> > +            if (out_len < sizeof(struct fuse_in_header)) {
> > +                fuse_log(FUSE_LOG_ERR, "%s: elem %d too short for in_header\n",
> > +                         __func__, elem->index);
> > +                assert(0); /* TODO */
> > +            }
> > +            if (out_len > se->bufsize) {
> > +                fuse_log(FUSE_LOG_ERR, "%s: elem %d too large for buffer\n",
> > +                         __func__, elem->index);
> > +                assert(0); /* TODO */
> > +            }
> > +            copy_from_iov(&fbuf, out_num, out_sg);
> > +            fbuf.size = out_len;
> > +
> > +            /* TODO! Endianness of header */
> > +
> > +            /* TODO: Fixup fuse_send_msg */
> > +            /* TODO: Add checks for fuse_session_exited */
> > +            fuse_session_process_buf_int(se, &fbuf, &ch);
> > +
> > +            /* TODO: vu_queue_push(dev, q, elem, qi->write_count); */
> > +            vu_queue_notify(dev, q);
> > +
> > +            free(elem);
> > +            elem = NULL;
> >          }
> >      }
> > +    pthread_mutex_destroy(&ch.lock);
> > +    free(fbuf.mem);
> >
> >      return NULL;
> >  }
> > --
> > 2.23.0
> >
> >
> 
> 
> -- 
> Marc-André Lureau
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2019-10-22 10:29 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-21 10:58 [PATCH 00/30] virtiofs daemon (base) Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 01/30] virtiofsd: Pull in upstream headers Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 02/30] virtiofsd: Pull in kernel's fuse.h Dr. David Alan Gilbert (git)
2019-10-24 11:10   ` Michael S. Tsirkin
2019-10-24 14:28     ` Dr. David Alan Gilbert
2019-10-24 11:13   ` Michael S. Tsirkin
2019-10-24 15:49     ` Dr. David Alan Gilbert
2019-10-21 10:58 ` [PATCH 03/30] virtiofsd: Add auxiliary .c's Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 04/30] virtiofsd: Add fuse_lowlevel.c Dr. David Alan Gilbert (git)
2019-10-24 11:11   ` Michael S. Tsirkin
2019-10-24 14:31     ` Dr. David Alan Gilbert
2019-10-21 10:58 ` [PATCH 05/30] virtiofsd: Add passthrough_ll Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 06/30] virtiofsd: Trim down imported files Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 07/30] virtiofsd: remove mountpoint dummy argument Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 08/30] virtiofsd: remove unused notify reply support Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 09/30] virtiofsd: Fix fuse_daemonize ignored return values Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 10/30] virtiofsd: Fix common header and define for QEMU builds Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 11/30] virtiofsd: fuse: Make iov_length usable outside fuse_lowlevel.c Dr. David Alan Gilbert (git)
2019-10-21 14:47   ` Marc-André Lureau
2019-10-22 10:01     ` Dr. David Alan Gilbert
2019-10-21 10:58 ` [PATCH 12/30] virtiofsd: Make fsync work even if only inode is passed in Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 13/30] virtiofsd: Add options for virtio Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 14/30] virtiofsd: add -o source=PATH to help output Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 15/30] virtiofsd: Open vhost connection instead of mounting Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 16/30] virtiofsd: Start wiring up vhost-user Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 17/30] virtiofsd: Add main virtio loop Dr. David Alan Gilbert (git)
2019-10-21 14:51   ` Marc-André Lureau
2019-10-22 11:07     ` Dr. David Alan Gilbert
2019-11-14 14:13       ` Stefan Hajnoczi
2019-10-21 10:58 ` [PATCH 18/30] virtiofsd: get/set features callbacks Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 19/30] virtiofsd: Start queue threads Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 20/30] virtiofsd: Poll kick_fd for queue Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 21/30] virtiofsd: Start reading commands from queue Dr. David Alan Gilbert (git)
2019-10-21 14:57   ` Marc-André Lureau
2019-10-22 10:28     ` Dr. David Alan Gilbert [this message]
2019-10-21 10:58 ` [PATCH 22/30] virtiofsd: Send replies to messages Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 23/30] virtiofsd: Keep track of replies Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 24/30] virtiofsd: Add Makefile wiring for virtiofsd contrib Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 25/30] virtiofsd: Fast path for virtio read Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 26/30] virtiofsd: add --fd=FDNUM fd passing option Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 27/30] virtiofsd: make -f (foreground) the default Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 28/30] virtiofsd: add vhost-user.json file Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 29/30] virtiofsd: add --print-capabilities option Dr. David Alan Gilbert (git)
2019-10-21 10:58 ` [PATCH 30/30] virtiofs: Add maintainers entry Dr. David Alan Gilbert (git)
     [not found] ` <157166664425.24734.3489596262271351160@37313f22b938>
2019-10-21 14:33   ` [PATCH 00/30] virtiofs daemon (base) Dr. David Alan Gilbert
2019-10-24 10:59     ` Michael S. Tsirkin
2019-10-24 11:02       ` Dr. David Alan Gilbert
2019-10-24 11:07       ` Daniel P. Berrangé
2019-10-24 11:14         ` Dr. David Alan Gilbert
2019-10-24 11:19           ` Michael S. Tsirkin
2019-10-24 12:54             ` Dr. David Alan Gilbert
2019-10-24 11:25           ` Daniel P. Berrangé
2019-10-24 13:36             ` Dr. David Alan Gilbert
2019-10-24 11:14 ` Michael S. Tsirkin
2019-10-24 16:19   ` Dr. David Alan Gilbert
2019-10-27 13:11 ` Michael S. Tsirkin
2019-10-28 13:24   ` Dr. David Alan Gilbert
2019-10-29 22:50 ` Michael S. Tsirkin
2019-10-30 10:47   ` Dr. David Alan Gilbert
2019-10-31  0:34     ` Michael S. Tsirkin
2019-10-31 13:20       ` Dr. David Alan Gilbert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191022102805.GE2815@work-vm \
    --to=dgilbert@redhat.com \
    --cc=eguan@linux.alibaba.com \
    --cc=marcandre.lureau@gmail.com \
    --cc=mst@redhat.com \
    --cc=piaojun@huawei.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    --cc=vgoyal@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).