From patchwork Thu Feb 4 13:50:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 8221751 Return-Path: X-Original-To: patchwork-qemu-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 3A40BBEEE5 for ; Thu, 4 Feb 2016 13:55:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8F461201EF for ; Thu, 4 Feb 2016 13:55:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D20F3201CD for ; Thu, 4 Feb 2016 13:55:20 +0000 (UTC) Received: from localhost ([::1]:41932 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRKNU-0002BU-7r for patchwork-qemu-devel@patchwork.kernel.org; Thu, 04 Feb 2016 08:55:20 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRKJ7-0003Ty-0Z for qemu-devel@nongnu.org; Thu, 04 Feb 2016 08:50:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1aRKJ5-0003E7-SP for qemu-devel@nongnu.org; Thu, 04 Feb 2016 08:50:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:50936) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1aRKJ5-0003Dq-DG for qemu-devel@nongnu.org; Thu, 04 Feb 2016 08:50:47 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 05450A3815 for ; Thu, 4 Feb 2016 13:50:47 +0000 (UTC) Received: from t530wlan.home.berrange.com.com (vpn1-6-8.ams2.redhat.com [10.36.6.8]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u14DoTEP028626; Thu, 4 Feb 2016 08:50:45 -0500 From: "Daniel P. Berrange" To: qemu-devel@nongnu.org Date: Thu, 4 Feb 2016 13:50:15 +0000 Message-Id: <1454593822-7321-10-git-send-email-berrange@redhat.com> In-Reply-To: <1454593822-7321-1-git-send-email-berrange@redhat.com> References: <1454593822-7321-1-git-send-email-berrange@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Paolo Bonzini , Max Reitz Subject: [Qemu-devel] [PATCH v5 09/16] nbd: make client request fixed new style if advertized X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the server advertizes support for the fixed new style negotiation, the client should in turn enable new style. This will allow the client to negotiate further NBD options besides the export name. Signed-off-by: Daniel P. Berrange --- nbd/client.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 65c8a27..22d69ff 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -75,7 +75,6 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags, { char buf[256]; uint64_t magic, s; - uint16_t tmp; int rc; TRACE("Receiving negotiation."); @@ -116,19 +115,26 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags, TRACE("Magic is 0x%" PRIx64, magic); if (magic == NBD_OPTS_MAGIC) { - uint32_t reserved = 0; + uint32_t clientflags = 0; uint32_t opt; uint32_t namesize; + uint16_t globalflags; + uint16_t exportflags; - if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) { + if (read_sync(ioc, &globalflags, sizeof(globalflags)) != + sizeof(globalflags)) { error_setg(errp, "Failed to read server flags"); goto fail; } - *flags = be16_to_cpu(tmp) << 16; - /* reserved for future use */ - if (write_sync(ioc, &reserved, sizeof(reserved)) != - sizeof(reserved)) { - error_setg(errp, "Failed to read reserved field"); + *flags = be16_to_cpu(globalflags) << 16; + if (globalflags & NBD_FLAG_FIXED_NEWSTYLE) { + TRACE("Server supports fixed new style"); + clientflags |= NBD_FLAG_C_FIXED_NEWSTYLE; + } + /* client requested flags */ + if (write_sync(ioc, &clientflags, sizeof(clientflags)) != + sizeof(clientflags)) { + error_setg(errp, "Failed to send clientflags field"); goto fail; } /* write the export name */ @@ -164,11 +170,12 @@ int nbd_receive_negotiate(QIOChannel *ioc, const char *name, uint32_t *flags, *size = be64_to_cpu(s); TRACE("Size is %" PRIu64, *size); - if (read_sync(ioc, &tmp, sizeof(tmp)) != sizeof(tmp)) { + if (read_sync(ioc, &exportflags, sizeof(exportflags)) != + sizeof(exportflags)) { error_setg(errp, "Failed to read export flags"); goto fail; } - *flags |= be16_to_cpu(tmp); + *flags |= be16_to_cpu(exportflags); } else if (magic == NBD_CLIENT_MAGIC) { if (name) { error_setg(errp, "Server does not support export names");