From patchwork Wed Jun 21 15:34:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Sementsov-Ogievskiy X-Patchwork-Id: 778971 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wt81b5rLdz9s2G for ; Thu, 22 Jun 2017 01:35:47 +1000 (AEST) Received: from localhost ([::1]:54698 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNhfV-0008DS-FO for incoming@patchwork.ozlabs.org; Wed, 21 Jun 2017 11:35:45 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50420) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dNheN-0007vg-GN for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:34:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dNheI-0008QG-FE for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:34:35 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:23802 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dNheI-0008Ot-40 for qemu-devel@nongnu.org; Wed, 21 Jun 2017 11:34:30 -0400 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id v5LFYOHf025147; Wed, 21 Jun 2017 18:34:24 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org Date: Wed, 21 Jun 2017 18:34:19 +0300 Message-Id: <20170621153424.16690-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170621153424.16690-1-vsementsov@virtuozzo.com> References: <20170621153424.16690-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v2 1/6] nbd/server: nbd_negotiate: return 1 on NBD_OPT_ABORT X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, vsementsov@virtuozzo.com, stefanha@redhat.com, den@openvz.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Separate case when client sent NBD_OPT_ABORT from other errors. It will be needed for the following patch, where errors will be reported. Considered case is not actually the error - it honestly follows NBD protocol. Therefore it should not be reported like an error. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 8a70c054a6..f0bff23b8b 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -349,9 +349,13 @@ static QIOChannel *nbd_negotiate_handle_starttls(NBDClient *client, return QIO_CHANNEL(tioc); } - -/* Process all NBD_OPT_* client option commands. - * Return -errno on error, 0 on success. */ +/* nbd_negotiate_options + * Process all NBD_OPT_* client option commands. + * Return: + * -errno on error + * 0 on successful negotiation + * 1 if client sent NBD_OPT_ABORT, i.e. on legal disconnect + */ static int nbd_negotiate_options(NBDClient *client) { uint32_t flags; @@ -459,7 +463,7 @@ static int nbd_negotiate_options(NBDClient *client) } /* Let the client keep trying, unless they asked to quit */ if (clientflags == NBD_OPT_ABORT) { - return -EINVAL; + return 1; } break; } @@ -477,7 +481,7 @@ static int nbd_negotiate_options(NBDClient *client) * disconnecting, but that we must also tolerate * guests that don't wait for our reply. */ nbd_negotiate_send_rep(client->ioc, NBD_REP_ACK, clientflags); - return -EINVAL; + return 1; case NBD_OPT_EXPORT_NAME: return nbd_negotiate_handle_export_name(client, length); @@ -533,6 +537,12 @@ static int nbd_negotiate_options(NBDClient *client) } } +/* nbd_negotiate + * Return: + * -errno on error + * 0 on successful negotiation + * 1 if client sent NBD_OPT_ABORT, i.e. on legal disconnect + */ static coroutine_fn int nbd_negotiate(NBDClient *client) { char buf[8 + 8 + 8 + 128];