qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Hanna Reitz <hreitz@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-block@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Eric Blake <eblake@redhat.com>,
	qemu-devel@nongnu.org
Subject: Re: [RFC] block/nbd: Move s->ioc on AioContext change
Date: Tue, 1 Feb 2022 12:40:12 +0100	[thread overview]
Message-ID: <6b28a0b4-8244-54bc-ec1b-91a123569c7c@redhat.com> (raw)
In-Reply-To: <4836201a-a469-c063-babb-4e293daee297@virtuozzo.com>

On 01.02.22 12:18, Vladimir Sementsov-Ogievskiy wrote:
> 28.01.2022 18:51, Hanna Reitz wrote:
>> s->ioc must always be attached to the NBD node's AioContext.  If that
>> context changes, s->ioc must be attached to the new context.
>>
>> Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1990835
>> Signed-off-by: Hanna Reitz <hreitz@redhat.com>
>> ---
>> This is an RFC because I believe there are some other things in the NBD
>> block driver that need attention on an AioContext change, too. Namely,
>> there are two timers (reconnect_delay_timer and open_timer) that are
>> also attached to the node's AioContext, and I'm afraid they need to be
>> handled, too.  Probably pause them on detach, and resume them on attach,
>> but I'm not sure, which is why I'm posting this as an RFC to get some
>> comments from that from someone who knows this code better than me. :)
>>
>> (Also, in a real v1, of course I'd want to add a regression test.)
>> ---
>>   block/nbd.c | 28 ++++++++++++++++++++++++++++
>>   1 file changed, 28 insertions(+)
>>
>> diff --git a/block/nbd.c b/block/nbd.c
>> index 63dbfa807d..119a774c04 100644
>> --- a/block/nbd.c
>> +++ b/block/nbd.c
>> @@ -2036,6 +2036,25 @@ static void 
>> nbd_cancel_in_flight(BlockDriverState *bs)
>>       nbd_co_establish_connection_cancel(s->conn);
>>   }
>>   +static void nbd_attach_aio_context(BlockDriverState *bs,
>> +                                   AioContext *new_context)
>> +{
>> +    BDRVNBDState *s = bs->opaque;
>> +
>> +    if (s->ioc) {
>> +        qio_channel_attach_aio_context(s->ioc, new_context);
>> +    }
>> +}
>> +
>> +static void nbd_detach_aio_context(BlockDriverState *bs)
>> +{
>> +    BDRVNBDState *s = bs->opaque;
>> +
>> +    if (s->ioc) {
>> +        qio_channel_detach_aio_context(s->ioc);
>> +    }
>> +}
>> +
>>   static BlockDriver bdrv_nbd = {
>>       .format_name                = "nbd",
>>       .protocol_name              = "nbd",
>> @@ -2059,6 +2078,9 @@ static BlockDriver bdrv_nbd = {
>>       .bdrv_dirname               = nbd_dirname,
>>       .strong_runtime_opts        = nbd_strong_runtime_opts,
>>       .bdrv_cancel_in_flight      = nbd_cancel_in_flight,
>> +
>> +    .bdrv_attach_aio_context    = nbd_attach_aio_context,
>> +    .bdrv_detach_aio_context    = nbd_detach_aio_context,
>>   };
>>     static BlockDriver bdrv_nbd_tcp = {
>> @@ -2084,6 +2106,9 @@ static BlockDriver bdrv_nbd_tcp = {
>>       .bdrv_dirname               = nbd_dirname,
>>       .strong_runtime_opts        = nbd_strong_runtime_opts,
>>       .bdrv_cancel_in_flight      = nbd_cancel_in_flight,
>> +
>> +    .bdrv_attach_aio_context    = nbd_attach_aio_context,
>> +    .bdrv_detach_aio_context    = nbd_detach_aio_context,
>>   };
>>     static BlockDriver bdrv_nbd_unix = {
>> @@ -2109,6 +2134,9 @@ static BlockDriver bdrv_nbd_unix = {
>>       .bdrv_dirname               = nbd_dirname,
>>       .strong_runtime_opts        = nbd_strong_runtime_opts,
>>       .bdrv_cancel_in_flight      = nbd_cancel_in_flight,
>> +
>> +    .bdrv_attach_aio_context    = nbd_attach_aio_context,
>> +    .bdrv_detach_aio_context    = nbd_detach_aio_context,
>>   };
>>     static void bdrv_nbd_init(void)
>>
>
>
> Hmm. I was so happy to remove these handlers together with 
> connection-coroutine :) . But you are right, seems I've removed too 
> much :(.
>
>
> open_timer exists only during bdrv_open() handler, so, I hope on 
> attach/detach it should not exist.

That’s… kind of surprising.  It’s good for me here, but as far as I can 
see it means that all of qemu blocks until the connection succeeds, 
right?  That doesn’t seem quite ideal...

Anyway, good for me. O:)

> reconnect_delay_timer should exist only during IO request: it's 
> created during request if we don't have a connection. And request will 
> not finish until timer elapsed or connection established (timer should 
> be removed in this case too). So, again, when attaching / detaching 
> the context we should be in a drained sections, so no in-flight 
> requests and no reconnect_delay_timer.

Got it.  FWIW, other block drivers rely on this, too (e.g. null-aio with 
latency-ns set creates a timer in every I/O request and settles the 
request once the timer expires).

>
> So, I think assertions that both timer pointers are NULL should be 
> enough in attach / detach handlers.
>

Great!  I’ll cook up v1.



  reply	other threads:[~2022-02-01 11:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-28 15:51 [RFC] block/nbd: Move s->ioc on AioContext change Hanna Reitz
2022-01-28 21:27 ` Eric Blake
2022-02-01 11:18 ` Vladimir Sementsov-Ogievskiy
2022-02-01 11:40   ` Hanna Reitz [this message]
2022-02-01 11:53     ` Vladimir Sementsov-Ogievskiy
2022-02-01 16:14     ` Hanna Reitz
2022-02-01 17:18       ` Vladimir Sementsov-Ogievskiy

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=6b28a0b4-8244-54bc-ec1b-91a123569c7c@redhat.com \
    --to=hreitz@redhat.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=vsementsov@virtuozzo.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).