From nobody Sun Oct 5 19:25:47 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1525209526515731.9736648048515; Tue, 1 May 2018 14:18:46 -0700 (PDT) Received: from localhost ([::1]:46226 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDcfb-0001fD-EM for importer@patchew.org; Tue, 01 May 2018 17:18:43 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46210) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDcav-0006lx-PY for qemu-devel@nongnu.org; Tue, 01 May 2018 17:13:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDcau-0001Zr-RZ for qemu-devel@nongnu.org; Tue, 01 May 2018 17:13:53 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42962 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fDcar-0001XH-Ai; Tue, 01 May 2018 17:13:49 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 03E1B4075A9D; Tue, 1 May 2018 21:13:49 +0000 (UTC) Received: from red.redhat.com (ovpn-123-248.rdu2.redhat.com [10.10.123.248]) by smtp.corp.redhat.com (Postfix) with ESMTP id 759C9214138C; Tue, 1 May 2018 21:13:48 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 1 May 2018 16:13:34 -0500 Message-Id: <20180501211336.986372-3-eblake@redhat.com> In-Reply-To: <20180501211336.986372-1-eblake@redhat.com> References: <20180501211336.986372-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 01 May 2018 21:13:49 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 01 May 2018 21:13:49 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'eblake@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH 2/4] nbd/client: Refactor in preparation for more limits 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: Paolo Bonzini , vsementsov@virtuozzo.com, edgar.kaziakhmedov@virtuozzo.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The next patch will ask the server for more items of NBD_INFO. However, the server is free to respond with INFO items in a different order than what we request, so performing any sanity checks about constraints that occur between multiple INFO items must be done after all items have been received. Make it easier to see that such checks are last by sinking the final processing after the while loop, rather than embedded in the NBD_REP_ACK processing that occurs textually within the loop before other INFO processing. Signed-off-by: Eric Blake Reviewed-by:=C2=A0 Vladimir Sementsov-Ogievskiy --- nbd/client.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 232ff4f46da..0abb195b856 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016-2017 Red Hat, Inc. + * Copyright (C) 2016-2018 Red Hat, Inc. * Copyright (C) 2005 Anthony Liguori * * Network Block Device Client Side @@ -365,17 +365,12 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wa= ntname, if (reply.type =3D=3D NBD_REP_ACK) { /* Server is done sending info and moved into transmission - phase, but make sure it sent flags */ + phase */ if (len) { error_setg(errp, "server sent invalid NBD_REP_ACK"); return -1; } - if (!info->flags) { - error_setg(errp, "broken server omitted NBD_INFO_EXPORT"); - return -1; - } - trace_nbd_opt_go_success(); - return 1; + break; } if (reply.type !=3D NBD_REP_INFO) { error_setg(errp, "unexpected reply type %" PRIu32 @@ -482,6 +477,14 @@ static int nbd_opt_go(QIOChannel *ioc, const char *wan= tname, break; } } + + /* Sanity check that server's responses make sense */ + if (!info->flags) { + error_setg(errp, "broken server omitted NBD_INFO_EXPORT"); + return -1; + } + trace_nbd_opt_go_success(); + return 1; } /* Return -1 on failure, 0 if wantname is an available export. */ --=20 2.14.3