On 11/30/20 7:40 AM, Vladimir Sementsov-Ogievskiy wrote:
> We are going to implement reconnect-on-open. Let's reuse existing
> reconnect loop. For this, do initial connect in connection coroutine.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
> ---
> block/nbd.c | 94 ++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 53 insertions(+), 41 deletions(-)
>
> @@ -2279,6 +2268,29 @@ static int nbd_open(BlockDriverState *bs, QDict
> *options, int flags,
> bdrv_inc_in_flight(bs);
> aio_co_schedule(bdrv_get_aio_context(bs), s->connection_co);
>
> + if (qemu_in_coroutine()) {
> + s->open_co = qemu_coroutine_self();
> + qemu_coroutine_yield();
> + } else {
> + BDRV_POLL_WHILE(bs, s->state == NBD_CLIENT_OPENING);
> + }
> +
> + if (s->state != NBD_CLIENT_CONNECTED && s->connect_status < 0) {
> + /*
> + * It's possible that state != NBD_CLIENT_CONNECTED, but
> connect_status
> + * is 0. This means that initial connecting succeed, but failed later
> + * (during BDRV_POLL_WHILE). It's a rare case, but it happen in
> iotest
This means that starting the initial connection succeeded, but we failed
later (during BDRV_POLL_WHILE).
happens
> + * 83. Let's don't care and just report success in this case: it not
> + * much differs from the case when connection failed immediately
> after
> + * succeeded open.
We don't care, and just report success in this case, as it does not
change our behavior from the case when the connection fails right after
open succeeds.
> + */
> + assert(s->connect_err);
> + error_propagate(errp, s->connect_err);
> + s->connect_err = NULL;
> + nbd_clear_bdrvstate(s);
> + return s->connect_status;
> + }
> +
> return 0;
> }
>
>
Reviewed-by: Eric Blake <[email protected]>
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org