qemu-stable
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-stable] [PATCH 3/3] nbd/client: Send NBD_CMD_DISC if open fail


From: Vladimir Sementsov-Ogievskiy
Subject: Re: [Qemu-stable] [PATCH 3/3] nbd/client: Send NBD_CMD_DISC if open fails after connect
Date: Fri, 30 Nov 2018 08:29:29 +0000

30.11.2018 5:32, Eric Blake wrote:
> If nbd_client_init() fails after we are already connected,
> then the server will spam logs with:
> 
> Disconnect client, due to: Unexpected end-of-file before all bytes were read
> 
> unless we gracefully disconnect before closing the connection.
> 
> Ways to trigger this:
> 
> $ 
> opts=driver=nbd,export=foo,server.type=inet,server.host=localhost,server.port=10809
> $  qemu-img map --output=json --image-opts $opts,read-only=off
> $  qemu-img map --output=json --image-opts $opts,x-dirty-bitmap=nosuch:
> 
> Signed-off-by: Eric Blake <address@hidden>

Reviewed-by: Vladimir Sementsov-Ogievskiy <address@hidden>

> ---
>   block/nbd-client.c | 18 ++++++++++++++++--
>   1 file changed, 16 insertions(+), 2 deletions(-)
> 
> diff --git a/block/nbd-client.c b/block/nbd-client.c
> index e6e27dafa6a..fc5b7eda8ee 100644
> --- a/block/nbd-client.c
> +++ b/block/nbd-client.c
> @@ -995,12 +995,13 @@ int nbd_client_init(BlockDriverState *bs,
>       if (x_dirty_bitmap && !client->info.base_allocation) {
>           error_setg(errp, "requested x-dirty-bitmap %s not found",
>                      x_dirty_bitmap);
> -        return -EINVAL;
> +        ret = -EINVAL;
> +        goto fail;
>       }
>       if (client->info.flags & NBD_FLAG_READ_ONLY) {
>           ret = bdrv_apply_auto_read_only(bs, "NBD export is read-only", 
> errp);
>           if (ret < 0) {
> -            return ret;
> +            goto fail;
>           }
>       }
>       if (client->info.flags & NBD_FLAG_SEND_FUA) {
> @@ -1029,4 +1030,17 @@ int nbd_client_init(BlockDriverState *bs,
> 
>       logout("Established connection with NBD server\n");
>       return 0;
> +
> + fail:
> +    /*
> +     * We have connected, but must fail for other reasons. The
> +     * connection is still blocking; send NBD_CMD_DISC as a courtesy
> +     * to the server.
> +     */
> +    {
> +        NBDRequest request = { .type = NBD_CMD_DISC };
> +
> +        nbd_send_request(client->ioc ?: QIO_CHANNEL(sioc), &request);
> +        return ret;
> +    }
>   }
> 


-- 
Best regards,
Vladimir

reply via email to

[Prev in Thread] Current Thread [Next in Thread]