All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>,
	qemu-devel@nongnu.org, qemu-block@nongnu.org
Cc: armbru@redhat.com, mreitz@redhat.com, kwolf@redhat.com,
	pbonzini@redhat.com, den@openvz.org,
	"Daniel P. Berrangé" <berrange@redhat.com>
Subject: Re: [Qemu-devel] [PATCH v4 06/10] block/nbd-client: move from quit to state
Date: Wed, 16 Jan 2019 10:25:03 -0600	[thread overview]
Message-ID: <64d9a2e7-6dd9-d71b-b9bf-c476e9e218f8@redhat.com> (raw)
In-Reply-To: <20180731173033.75467-7-vsementsov@virtuozzo.com>

[-- Attachment #1: Type: text/plain, Size: 5104 bytes --]

[adding Dan]

On 7/31/18 12:30 PM, Vladimir Sementsov-Ogievskiy wrote:
> To implement reconnect we need several states for the client:
> CONNECTED, QUIT and two CONNECTING states. CONNECTING states will
> be realized in the following patches. This patch implements CONNECTED
> and QUIT.
> 
> QUIT means, that we should close the connection and fail all current
> and further requests (like old quit = true).
> 
> CONNECTED means that connection is ok, we can send requests (like old
> quit = false).
> 
> For receiving loop we use a comparison of the current state with QUIT,
> because reconnect will be in the same loop, so it should be looping
> until the end.
> 
> Opposite, for requests we use a comparison of the current state with
> CONNECTED, as we don't want to send requests in CONNECTING states (
> which are unreachable now, but will be reachable after the following
> commits)
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  block/nbd-client.h |  9 ++++++++-
>  block/nbd-client.c | 55 ++++++++++++++++++++++++++++++++----------------------
>  2 files changed, 41 insertions(+), 23 deletions(-)

Dan just recently proposed patches to SocketChardev in general to use a
state machine that distinguishes between connecting and connected:

https://lists.gnu.org/archive/html/qemu-devel/2019-01/msg03339.html

I'm wondering how much of his work is related or can be reused to get
restartable connections on NBD sockets?

Remember, right now, the NBD code always starts in blocking mode, and
does single-threaded handshaking until it is ready for transmission,
then switches to non-blocking mode for all subsequent transmissions (so,
for example, servicing a read request can assume that the socket is
valid without further waiting).  But once we start allowing reconnects,
a read request will need to detect when one socket has gone down, and
wait for its replacement socket to come back up, in order to retry the
request; this retry is in a context where we are in non-blocking
context, but the retry must establish a new socket, and possibly convert
the socket into TLS mode, all before being ready to retry the read request.

> 
> diff --git a/block/nbd-client.h b/block/nbd-client.h
> index 2f047ba614..5367425774 100644
> --- a/block/nbd-client.h
> +++ b/block/nbd-client.h
> @@ -23,6 +23,13 @@ typedef struct {
>      bool receiving;         /* waiting for read_reply_co? */
>  } NBDClientRequest;
>  
> +typedef enum NBDClientState {
> +    NBD_CLIENT_CONNECTING_WAIT,
> +    NBD_CLIENT_CONNECTING_NOWAIT,

Would we be better off adding these enum values in the later patch that
uses them?

> +    NBD_CLIENT_CONNECTED,
> +    NBD_CLIENT_QUIT
> +} NBDClientState;
> +
>  typedef struct NBDClientSession {
>      QIOChannelSocket *sioc; /* The master data channel */
>      QIOChannel *ioc; /* The current I/O channel which may differ (eg TLS) */
> @@ -32,10 +39,10 @@ typedef struct NBDClientSession {
>      CoQueue free_sema;
>      Coroutine *read_reply_co;
>      int in_flight;
> +    NBDClientState state;
>  
>      NBDClientRequest requests[MAX_NBD_REQUESTS];
>      NBDReply reply;
> -    bool quit;
>  } NBDClientSession;
>  
>  NBDClientSession *nbd_get_client_session(BlockDriverState *bs);
> diff --git a/block/nbd-client.c b/block/nbd-client.c
> index 7eaf0149f0..a91fd3ea3e 100644
> --- a/block/nbd-client.c
> +++ b/block/nbd-client.c
> @@ -34,6 +34,12 @@
>  #define HANDLE_TO_INDEX(bs, handle) ((handle) ^ (uint64_t)(intptr_t)(bs))
>  #define INDEX_TO_HANDLE(bs, index)  ((index)  ^ (uint64_t)(intptr_t)(bs))
>  
> +/* @ret would be used for reconnect in future */

s/would/will/

> +static void nbd_channel_error(NBDClientSession *s, int ret)
> +{
> +    s->state = NBD_CLIENT_QUIT;
> +}
> +
>  static void nbd_recv_coroutines_wake_all(NBDClientSession *s)
>  {
>      int i;
> @@ -73,14 +79,15 @@ static coroutine_fn void nbd_read_reply_entry(void *opaque)
>      int ret = 0;
>      Error *local_err = NULL;
>  
> -    while (!s->quit) {
> +    while (s->state != NBD_CLIENT_QUIT) {
>          assert(s->reply.handle == 0);
>          ret = nbd_receive_reply(s->ioc, &s->reply, &local_err);
>          if (local_err) {
>              error_report_err(local_err);
>          }
>          if (ret <= 0) {
> -            break;
> +            nbd_channel_error(s, ret ? ret : -EIO);
> +            continue;

I guess the continue instead of the break is pre-supposing that
nbd_channel_error() might be able to recover in later patches?  But for
this patch, there is no change in control flow, because the loop
condition is met for no further iterations, the same as a break would
have done.

The rest of the patch looks sane, but fails to apply easily for me (I'm
getting enough rebase churn, that it's getting harder to state if it is
accurate against the latest git master).

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2019-01-16 16:25 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-31 17:30 [Qemu-devel] [PATCH v4 00/10] NBD reconnect Vladimir Sementsov-Ogievskiy
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 01/10] block/nbd-client: split channel errors from export errors Vladimir Sementsov-Ogievskiy
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 02/10] block/nbd: move connection code from block/nbd to block/nbd-client Vladimir Sementsov-Ogievskiy
2019-01-16 15:56   ` Eric Blake
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 03/10] block/nbd-client: split connection from initialization Vladimir Sementsov-Ogievskiy
2019-01-16 15:52   ` Eric Blake
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 04/10] block/nbd-client: fix nbd_reply_chunk_iter_receive Vladimir Sementsov-Ogievskiy
2019-01-16 16:01   ` Eric Blake
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 05/10] block/nbd-client: don't check ioc Vladimir Sementsov-Ogievskiy
2019-01-16 16:05   ` Eric Blake
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 06/10] block/nbd-client: move from quit to state Vladimir Sementsov-Ogievskiy
2019-01-16 16:25   ` Eric Blake [this message]
2019-01-16 16:58     ` Daniel P. Berrangé
2019-02-05 16:35       ` Vladimir Sementsov-Ogievskiy
2019-02-06  8:51         ` Vladimir Sementsov-Ogievskiy
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 07/10] block/nbd-client: rename read_reply_co to connection_co Vladimir Sementsov-Ogievskiy
2019-01-16 16:35   ` Eric Blake
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 08/10] block/nbd: add cmdline and qapi parameter reconnect-delay Vladimir Sementsov-Ogievskiy
2019-01-04 22:25   ` Eric Blake
2019-02-05 16:48     ` Vladimir Sementsov-Ogievskiy
2019-04-11 15:47     ` Vladimir Sementsov-Ogievskiy
2019-04-11 15:47       ` Vladimir Sementsov-Ogievskiy
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 09/10] block/nbd-client: nbd reconnect Vladimir Sementsov-Ogievskiy
2018-11-02 12:39   ` Vladimir Sementsov-Ogievskiy
2019-01-16 17:04   ` Eric Blake
2019-02-05 17:07     ` Vladimir Sementsov-Ogievskiy
2019-02-05 17:15       ` Eric Blake
2018-07-31 17:30 ` [Qemu-devel] [PATCH v4 10/10] iotests: test " Vladimir Sementsov-Ogievskiy
2019-01-16 17:11   ` Eric Blake
2019-04-11 16:02     ` Vladimir Sementsov-Ogievskiy
2019-04-11 16:02       ` Vladimir Sementsov-Ogievskiy
     [not found] ` <fc24ba9e-e325-6478-cb22-bc0a256c6e87@virtuozzo.com>
2018-10-09 19:33   ` [Qemu-devel] [Qemu-block] [PATCH v4 00/10] NBD reconnect John Snow
2018-10-09 21:59     ` Vladimir Sementsov-Ogievskiy
2018-12-12 10:33 ` [Qemu-devel] ping " Vladimir Sementsov-Ogievskiy
2018-12-29 12:23 ` [Qemu-devel] ping3 " 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=64d9a2e7-6dd9-d71b-b9bf-c476e9e218f8@redhat.com \
    --to=eblake@redhat.com \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=den@openvz.org \
    --cc=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=pbonzini@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 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.