From nobody Sun Oct 5 21:17:17 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 1544882760916397.984023158881; Sat, 15 Dec 2018 06:06:00 -0800 (PST) Received: from localhost ([::1]:39186 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYAZr-0006Ad-Ph for importer@patchew.org; Sat, 15 Dec 2018 09:05:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34675) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gYAOp-0005NG-8C for qemu-devel@nongnu.org; Sat, 15 Dec 2018 08:54:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gYAOo-0000CA-7n for qemu-devel@nongnu.org; Sat, 15 Dec 2018 08:54:35 -0500 Received: from mx1.redhat.com ([209.132.183.28]:55584) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gYAOl-00009k-UT; Sat, 15 Dec 2018 08:54:32 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4B3CAC0587F9; Sat, 15 Dec 2018 13:54:31 +0000 (UTC) Received: from red.redhat.com (ovpn-122-76.rdu2.redhat.com [10.10.122.76]) by smtp.corp.redhat.com (Postfix) with ESMTP id C255E5C3FD; Sat, 15 Dec 2018 13:54:18 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Sat, 15 Dec 2018 07:53:19 -0600 Message-Id: <20181215135324.152629-18-eblake@redhat.com> In-Reply-To: <20181215135324.152629-1-eblake@redhat.com> References: <20181215135324.152629-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 15 Dec 2018 13:54:31 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 17/22] nbd/client: Pull out oldstyle size determination 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: nsoffer@redhat.com, vsementsov@virtuozzo.com, jsnow@redhat.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Another refactoring creating nbd_negotiate_finish_oldstyle() for further reuse during 'qemu-nbd --list'. Signed-off-by: Eric Blake Reviewed-by: Richard W.M. Jones --- v2: new patch [Vladimir] --- nbd/client.c | 49 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 17 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 8b0ae20fae8..4bdfba43068 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -811,7 +811,7 @@ static int nbd_negotiate_simple_meta_context(QIOChannel= *ioc, * Start the handshake to the server. After a positive return, the server * is ready to accept additional NBD_OPT requests. * Returns: negative errno: failure talking to server - * 0: server is oldstyle, client must still parse export size + * 0: server is oldstyle, must call nbd_negotiate_finish_oldstyle * 1: server is newstyle, but can only accept EXPORT_NAME * 2: server is newstyle, but lacks structured replies * 3: server is newstyle and set up for structured replies @@ -916,6 +916,36 @@ static int nbd_start_negotiate(QIOChannel *ioc, QCrypt= oTLSCreds *tlscreds, } } +/* + * nbd_negotiate_finish_oldstyle: + * Populate @info with the size and export flags from an oldstyle server, + * but does not consume 124 bytes of reserved zero padding. + * Returns 0 on success, -1 with @errp set on failure + */ +static int nbd_negotiate_finish_oldstyle(QIOChannel *ioc, NBDExportInfo *i= nfo, + Error **errp) +{ + uint32_t oldflags; + + if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) { + error_prepend(errp, "Failed to read export length: "); + return -EINVAL; + } + info->size =3D be64_to_cpu(info->size); + + if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) { + error_prepend(errp, "Failed to read export flags: "); + return -EINVAL; + } + oldflags =3D be32_to_cpu(oldflags); + if (oldflags & ~0xffff) { + error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflags); + return -EINVAL; + } + info->flags =3D oldflags; + return 0; +} + /* * nbd_receive_negotiate: * Connect to server, complete negotiation, and move into transmission pha= se. @@ -929,7 +959,6 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTLSCr= eds *tlscreds, int result; bool zeroes =3D true; bool base_allocation =3D info->base_allocation; - uint32_t oldflags; assert(info->name); trace_nbd_receive_negotiate_name(info->name); @@ -1002,23 +1031,9 @@ int nbd_receive_negotiate(QIOChannel *ioc, QCryptoTL= SCreds *tlscreds, error_setg(errp, "Server does not support non-empty export nam= es"); return -EINVAL; } - - if (nbd_read(ioc, &info->size, sizeof(info->size), errp) < 0) { - error_prepend(errp, "Failed to read export length: "); + if (nbd_negotiate_finish_oldstyle(ioc, info, errp) < 0) { return -EINVAL; } - info->size =3D be64_to_cpu(info->size); - - if (nbd_read(ioc, &oldflags, sizeof(oldflags), errp) < 0) { - error_prepend(errp, "Failed to read export flags: "); - return -EINVAL; - } - oldflags =3D be32_to_cpu(oldflags); - if (oldflags & ~0xffff) { - error_setg(errp, "Unexpected export flags %0x" PRIx32, oldflag= s); - return -EINVAL; - } - info->flags =3D oldflags; break; default: return result; --=20 2.17.2