qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@gmail.com>
To: Sam Li <faithilikerun@gmail.com>
Cc: Damien Le Moal <damien.lemoal@opensource.wdc.com>,
	 Dmitry Fomichev <dmitry.fomichev@wdc.com>,
	Hannes Reinecke <hare@suse.de>,
	 qemu-devel <qemu-devel@nongnu.org>,
	qemu block <qemu-block@nongnu.org>
Subject: Re: Outreachy project task: Adding QEMU block layer APIs resembling Linux ZBD ioctls.
Date: Wed, 1 Jun 2022 12:28:25 +0100	[thread overview]
Message-ID: <CAJSP0QUc6ONE9ye0EQppYN+G8zg9JekF5VPNdEsWzPwVTQd+1Q@mail.gmail.com> (raw)
In-Reply-To: <CAAAx-8JxWYBN1Zk6Vk-WHTzYnGE6b_PXHsoVY=gnUcuikW7JCg@mail.gmail.com>

On Wed, 1 Jun 2022 at 11:19, Sam Li <faithilikerun@gmail.com> wrote:
> Damien Le Moal <damien.lemoal@opensource.wdc.com> 于2022年6月1日周三 13:47写道:
> > On 6/1/22 11:57, Sam Li wrote:
> > > Stefan Hajnoczi <stefanha@gmail.com> 于2022年5月30日周一 19:19写道:
> > >> On Mon, 30 May 2022 at 06:09, Sam Li <faithilikerun@gmail.com> wrote:
> > For the zone struct: You may need to add a read-write lock per zone to be
> > able to write lock zones to ensure a sequential write pattern (virtio
> > devices can be multi-queue and so writes may be coming in from different
> > contexts) and to correctly emulate zone append operations with an atomic
> > update of the wp field.
> >
>
> Yes, I haven't thought through the thread-safety problem but I'll come
> up with an approach.

Operations in the I/O code path (as opposed to the control/management
code path) will probably be declared as coroutine_fn, which means that
they execute in a coroutine and can yield back to the event loop when
waiting for something to happen.

Coroutines can use CoMutex locks to serialize execution. This way only
one write request will be in flight at a time and the write pointer
can be updated atomically.

Here is a sketch of what the block/file-posix.c driver's write append
function would look like:

static int coroutine_fn raw_write_append_zone(BlockDriverState *bs,
uint64_t offset, uint64_t bytes, QEMUIOVector *qiov)
{
    BDRVRawState *s = bs->opaque;
    RawPosixAIOData acb = ...; /* fill in aio request state */

    /* Serialize append requests */
    QEMU_LOCK_GUARD(&s->append_locks[offset_to_lock_idx(offset)]);
    return raw_thread_pool_submit(bs, handle_aiocb_append_zone, &acb);
}

The actual system call runs in a thread pool worker function
handle_aiocb_append_zone() that performs the write on the underlying
fd and updates the write pointer if the syscall succeeds.

Stefan


  reply	other threads:[~2022-06-01 11:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-30  5:09 Outreachy project task: Adding QEMU block layer APIs resembling Linux ZBD ioctls Sam Li
2022-05-30  5:38 ` Damien Le Moal
2022-05-30 11:21   ` Stefan Hajnoczi
2022-05-30 11:26     ` Damien Le Moal
2022-05-30 11:19 ` Stefan Hajnoczi
2022-06-01  2:57   ` Sam Li
2022-06-01  5:47     ` Damien Le Moal
2022-06-01 10:19       ` Sam Li
2022-06-01 11:28         ` Stefan Hajnoczi [this message]
2022-06-01 11:43       ` Stefan Hajnoczi
2022-06-02  5:43         ` Sam Li
2022-06-02  8:05           ` Stefan Hajnoczi
2022-06-02 10:28             ` Sam Li
2022-06-02 19:36               ` 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=CAJSP0QUc6ONE9ye0EQppYN+G8zg9JekF5VPNdEsWzPwVTQd+1Q@mail.gmail.com \
    --to=stefanha@gmail.com \
    --cc=damien.lemoal@opensource.wdc.com \
    --cc=dmitry.fomichev@wdc.com \
    --cc=faithilikerun@gmail.com \
    --cc=hare@suse.de \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /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).