All of lore.kernel.org
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Stefan Hajnoczi <stefanha@gmail.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
	Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <famz@redhat.com>,
	qemu-devel@nongnu.org, Stefan Hajnoczi <stefanha@redhat.com>
Subject: Re: [Qemu-devel] [RFC 3/5] nbd: Use aio_set_fd_handler2()
Date: Thu, 05 Jun 2014 20:18:46 +0200	[thread overview]
Message-ID: <5390B486.6060800@redhat.com> (raw)
In-Reply-To: <20140604123748.GD11073@stefanha-thinkpad.redhat.com>

On 04.06.2014 14:37, Stefan Hajnoczi wrote:
> On Sat, May 31, 2014 at 08:43:10PM +0200, Max Reitz wrote:
>> Instead of using the main loop function qemu_set_fd_handler2(), use the
>> AIO function in the context of the exported BDS.
> Managing fd handlers shouldn't be necessary at the NBD code level.  The
> current NBD code hasn't been fully converted to coroutines.
>
> This email explains how the NBD code can be fully converted to
> coroutines.  It should simplify the code and reduce the chance of bugs.
> Whether you want to actually do the conversion is up to you, since it's
> somewhat orthogonal to the purpose of this patch series.
>
> The point of coroutines is that blocking operations like send/recv on a
> socket should look like regular blocking calls.  Let coroutines handle
> the event loop housekeeping (registering fd handlers, callbacks).  Only
> use aio explicitly when concurrency is needed.
>
> Here is how I would structure NBD using coroutines:
>
> 1 coroutine per connection to receive NBD commands and submit I/O
> requests:
>
> def nbd_server_receive_co(conn):
>      while True:
>          req = nbd_read_req(conn)
>      if req is None:
>          break
>      if req.type == NBD_READ:
>          bdrv_aio_readv(bs, ...)
>      elif req.type == NBD_WRITE:
>          ...
>
> Notice that bdrv_aio_*() is used since we want concurrent I/O requests.
>
> 1 coroutine per connection to send NBD replies:
>
> def nbd_server_send_co(conn):
>      while True:
>          while conn.send_queue:
>              resp = conn.send_queue.pop()
>              nbd_write_resp(conn, resp)
>          qemu_coroutine_yield()
>
> And finally the bdrv_aio_*() callback to put responses on to the send
> queue:
>
> def nbd_server_aio_cb(conn):
>      resp = NBDResponse(...)
>      conn.send_queue.push(resp)
>      conn.send_co.enter()
>
> Why is this design cleaner?  Because NBD code doesn't have to worry
> about fd handlers.  It uses straightforward coroutine send/recv for
> socket I/O inside nbd_read_req() and nbd_write_resp().  It's easy to see
> that only one coroutine receives from the socket and that only one
> coroutine writes to the socket.

Yes, this sounds better. I'll take a look into it and see how far I can get.

Max

  parent reply	other threads:[~2014-06-05 18:19 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1401561792-13410-1-git-send-email-mreitz@redhat.com>
2014-06-03 14:38 ` [Qemu-devel] [RFC 0/5] nbd: Adapt for dataplane Stefan Hajnoczi
2014-06-05 17:41   ` Max Reitz
     [not found] ` <1401561792-13410-3-git-send-email-mreitz@redhat.com>
2014-06-03 17:55   ` [Qemu-devel] [RFC 2/5] aio: Add io_read_poll() callback Paolo Bonzini
2014-06-05 17:29     ` Max Reitz
2014-06-04 11:59   ` Stefan Hajnoczi
     [not found] ` <1401561792-13410-2-git-send-email-mreitz@redhat.com>
2014-06-04 11:52   ` [Qemu-devel] [RFC 1/5] nbd: Correct name comparison for export_set_name() Stefan Hajnoczi
2014-06-05 17:28     ` Max Reitz
     [not found] ` <1401561792-13410-4-git-send-email-mreitz@redhat.com>
2014-06-04 12:37   ` [Qemu-devel] [RFC 3/5] nbd: Use aio_set_fd_handler2() Stefan Hajnoczi
2014-06-04 18:02     ` Paolo Bonzini
2014-06-05  8:12       ` Stefan Hajnoczi
2014-06-05  9:27         ` Paolo Bonzini
2014-06-05 13:32           ` Stefan Hajnoczi
2014-06-05 18:18     ` Max Reitz [this message]
2014-06-06  7:44       ` Paolo Bonzini
2014-06-07 19:27         ` Max Reitz
2014-06-09 13:35           ` Stefan Hajnoczi
     [not found] ` <1401561792-13410-5-git-send-email-mreitz@redhat.com>
2014-06-04 12:41   ` [Qemu-devel] [RFC 4/5] block: Add AIO followers Stefan Hajnoczi
2014-06-05 17:31     ` Max Reitz
     [not found] ` <538A3A8F.3060508@redhat.com>
2014-06-04 12:47   ` [Qemu-devel] [RFC 0/5] nbd: Adapt for dataplane Stefan Hajnoczi
2014-06-04 12:50 ` Stefan Hajnoczi

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=5390B486.6060800@redhat.com \
    --to=mreitz@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@gmail.com \
    --cc=stefanha@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.