qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
To: Roman Kagan <rvkagan@yandex-team.ru>,
	qemu-devel@nongnu.org, yc-core@yandex-team.ru,
	Eric Blake <eblake@redhat.com>, Max Reitz <mreitz@redhat.com>,
	Kevin Wolf <kwolf@redhat.com>,
	qemu-block@nongnu.org
Subject: Re: [PATCH 0/7] block/nbd: decouple reconnect from drain
Date: Wed, 7 Apr 2021 13:13:07 +0300	[thread overview]
Message-ID: <be0d4446-61ca-cb44-2205-62255e12abe4@virtuozzo.com> (raw)
In-Reply-To: <YG1jMSzW4uySSOyR@rvkaganb.lan>

07.04.2021 10:45, Roman Kagan wrote:
> On Wed, Mar 17, 2021 at 11:35:31AM +0300, Vladimir Sementsov-Ogievskiy wrote:
>> 15.03.2021 09:06, Roman Kagan wrote:
>>> The reconnection logic doesn't need to stop while in a drained section.
>>> Moreover it has to be active during the drained section, as the requests
>>> that were caught in-flight with the connection to the server broken can
>>> only usefully get drained if the connection is restored.  Otherwise such
>>> requests can only either stall resulting in a deadlock (before
>>> 8c517de24a), or be aborted defeating the purpose of the reconnection
>>> machinery (after 8c517de24a).
>>>
>>> This series aims to just stop messing with the drained section in the
>>> reconnection code.
>>>
>>> While doing so it undoes the effect of 5ad81b4946 ("nbd: Restrict
>>> connection_co reentrance"); as I've missed the point of that commit I'd
>>> appreciate more scrutiny in this area.
>>>
>>> Roman Kagan (7):
>>>     block/nbd: avoid touching freed connect_thread
>>>     block/nbd: use uniformly nbd_client_connecting_wait
>>>     block/nbd: assert attach/detach runs in the proper context
>>>     block/nbd: transfer reconnection stuff across aio_context switch
>>>     block/nbd: better document a case in nbd_co_establish_connection
>>>     block/nbd: decouple reconnect from drain
>>>     block/nbd: stop manipulating in_flight counter
>>>
>>>    block/nbd.c  | 191 +++++++++++++++++++++++----------------------------
>>>    nbd/client.c |   2 -
>>>    2 files changed, 86 insertions(+), 107 deletions(-)
>>>
>>
>>
>> Hmm. The huge source of problems for this series is weird logic around
>> drain and aio context switch in NBD driver.
>>
>> Why do we have all these too complicated logic with abuse of in_flight
>> counter in NBD? The answer is connection_co. NBD differs from other
>> drivers, it has a coroutine independent of request coroutines. And we
>> have to move this coroutine carefully to new aio context. We can't
>> just enter it from the new context, we want to be sure that
>> connection_co is in one of yield points that supports reentering.
>>
>> I have an idea of how to avoid this thing: drop connection_co at all.
>>
>> 1. nbd negotiation goes to connection thread and becomes independent
>> of any aio context.
>>
>> 2. waiting for server reply goes to request code. So, instead of
>> reading the replay from socket always in connection_co, we read in the
>> request coroutine, after sending the request. We'll need a CoMutex for
>> it (as only one request coroutine should read from socket), and be
>> prepared to coming reply is not for _this_ request (in this case we
>> should wake another request and continue read from socket).
> 
> The problem with this approach is that it would change the reconnect
> behavior.
> 
> Currently connection_co purpose is three-fold:
> 
> 1) receive the header of the server response, identify the request it
>     pertains to, and wake the resective request coroutine
> 
> 2) take on the responsibility to reestablish the connection when it's
>     lost
> 
> 3) monitor the idle connection and initiate the reconnect as soon as the
>     connection is lost
> 
> Points 1 and 2 can be moved to the request coroutines indeed.  However I
> don't see how to do 3 without an extra ever-running coroutine.
> Sacrificing it would mean that a connection loss wouldn't be noticed and
> the recovery wouldn't be attempted until a request arrived.
> 
> This change looks to me like a degradation compared to the current
> state.
> 

For 3 we can check the connection by timeout:

  - getsockopt( .. SO_ERROR .. ), which could be done from bs aio context, or even from reconnect-thread context

  - or, we can create a PING request: just use some request with parameters for which we are sure that NBD server should do no action but report some expected error. We can create such request by timeout when there no more requests, just to check that connection still works.

Note, that neither of this (and nor current [3] which is just endless read from socket) will work only with keep-alive set, which is not by default for now.

Anyway I think first step is splitting connect-thread out of nbd.c which is overcomplicated now, I'm going to send a refactoring series for this.

-- 
Best regards,
Vladimir


      reply	other threads:[~2021-04-07 10:15 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15  6:06 [PATCH 0/7] block/nbd: decouple reconnect from drain Roman Kagan
2021-03-15  6:06 ` [PATCH 1/7] block/nbd: avoid touching freed connect_thread Roman Kagan
2021-03-15 15:40   ` Vladimir Sementsov-Ogievskiy
2021-03-16 15:29     ` Roman Kagan
2021-04-06 16:21   ` Vladimir Sementsov-Ogievskiy
2021-03-15  6:06 ` [PATCH 2/7] block/nbd: use uniformly nbd_client_connecting_wait Roman Kagan
2021-03-15 15:48   ` Vladimir Sementsov-Ogievskiy
2021-03-15  6:06 ` [PATCH 3/7] block/nbd: assert attach/detach runs in the proper context Roman Kagan
2021-03-15 16:41   ` Vladimir Sementsov-Ogievskiy
2021-03-15 19:57     ` Roman Kagan
2021-03-15  6:06 ` [PATCH 4/7] block/nbd: transfer reconnection stuff across aio_context switch Roman Kagan
2021-03-15  6:06 ` [PATCH 5/7] block/nbd: better document a case in nbd_co_establish_connection Roman Kagan
2021-03-15  6:06 ` [PATCH 6/7] block/nbd: decouple reconnect from drain Roman Kagan
2021-03-15 20:10   ` Vladimir Sementsov-Ogievskiy
2021-03-16 16:03     ` Roman Kagan
2021-03-16 18:09       ` Vladimir Sementsov-Ogievskiy
2021-03-26  6:16         ` Roman Kagan
2021-03-15  6:06 ` [PATCH 7/7] block/nbd: stop manipulating in_flight counter Roman Kagan
2021-03-15 20:15   ` Vladimir Sementsov-Ogievskiy
2021-03-16 16:08     ` Roman Kagan
2021-03-16 18:37       ` Vladimir Sementsov-Ogievskiy
2021-03-26  7:41         ` Roman Kagan
2021-03-15 19:45 ` [PATCH 0/7] block/nbd: decouple reconnect from drain Vladimir Sementsov-Ogievskiy
2021-03-16 15:52   ` Roman Kagan
2021-03-16 14:41 ` Eric Blake
2021-03-16 16:10   ` Roman Kagan
2021-03-17  8:35 ` Vladimir Sementsov-Ogievskiy
2021-03-26  8:07   ` Roman Kagan
2021-04-07  7:45   ` Roman Kagan
2021-04-07 10:13     ` Vladimir Sementsov-Ogievskiy [this message]

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=be0d4446-61ca-cb44-2205-62255e12abe4@virtuozzo.com \
    --to=vsementsov@virtuozzo.com \
    --cc=eblake@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rvkagan@yandex-team.ru \
    --cc=yc-core@yandex-team.ru \
    /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).