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 1525209351702793.7034127704698; Tue, 1 May 2018 14:15:51 -0700 (PDT) Received: from localhost ([::1]:46211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDcco-0008Hb-Rl for importer@patchew.org; Tue, 01 May 2018 17:15:50 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46232) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fDcax-0006n0-0x for qemu-devel@nongnu.org; Tue, 01 May 2018 17:13:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fDcav-0001ae-T5 for qemu-devel@nongnu.org; Tue, 01 May 2018 17:13:55 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:42360 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 1fDcat-0001Yi-14; Tue, 01 May 2018 17:13:51 -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 B04C784257; Tue, 1 May 2018 21:13:50 +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 38D06214138C; Tue, 1 May 2018 21:13:49 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Tue, 1 May 2018 16:13:36 -0500 Message-Id: <20180501211336.986372-5-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.2]); Tue, 01 May 2018 21:13:50 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Tue, 01 May 2018 21:13:50 +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 4/4] nbd/server: Support requests of additional block sizing info 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 NBD spec is clarifying [1] that a server may want to advertise different limits for READ/WRITE (in our case, 32M) than for TRIM/ZERO (in our case, nearly 4G). Implement the server side support for these alternate limits, by always advertising the new information (a compliant client must ignore a gratuitous advertisement if it is unknown). [1] https://lists.debian.org/nbd/2018/03/msg00048.html Signed-off-by: Eric Blake --- The given URL for the NBD spec was v3; it will change to be a v4 version of that patch in part to point back to this qemu commit as a proof of implementation. --- nbd/server.c | 30 ++++++++++++++++++++++++++++++ nbd/trace-events | 2 ++ 2 files changed, 32 insertions(+) diff --git a/nbd/server.c b/nbd/server.c index 9e1f2271784..39502b58446 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -617,6 +617,36 @@ static int nbd_negotiate_handle_info(NBDClient *client= , uint16_t myflags, return rc; } + /* Send NBD_INFO_TRIM_SIZE always. */ + /* minimum - Hard-code to 4096 for now, matching preferred block. + * TODO: consult blk_bs(blk)->bl.pdiscard_alignment? */ + sizes[0] =3D 4096; + /* maximum - < 2G (then block layer fragments to bl.max_pdiscard). */ + sizes[1] =3D QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES, sizes[0]); + trace_nbd_negotiate_handle_info_trim_size(sizes[0], sizes[1]); + cpu_to_be32s(&sizes[0]); + cpu_to_be32s(&sizes[1]); + rc =3D nbd_negotiate_send_info(client, NBD_INFO_TRIM_SIZE, + 2 * sizeof(sizes[0]), sizes, errp); + if (rc < 0) { + return rc; + } + + /* Send NBD_INFO_ZERO_SIZE always. */ + /* minimum - Hard-code to 4096 for now, matching preferred block. + * TODO: consult blk_bs(blk)->bl.pwrite_zeroes_alignment? */ + sizes[0] =3D 4096; + /* maximum - < 2G (then block layer fragments to bl.max_pwrite_zeroes)= . */ + sizes[1] =3D QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX_BYTES, sizes[0]); + trace_nbd_negotiate_handle_info_zero_size(sizes[0], sizes[1]); + cpu_to_be32s(&sizes[0]); + cpu_to_be32s(&sizes[1]); + rc =3D nbd_negotiate_send_info(client, NBD_INFO_ZERO_SIZE, + 2 * sizeof(sizes[0]), sizes, errp); + if (rc < 0) { + return rc; + } + /* Send NBD_INFO_EXPORT always */ trace_nbd_negotiate_new_style_size_flags(exp->size, exp->nbdflags | myflags); diff --git a/nbd/trace-events b/nbd/trace-events index ddb9d0a2b3e..d8849c43b21 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -46,6 +46,8 @@ nbd_negotiate_send_info(int info, const char *name, uint3= 2_t length) "Sending NB nbd_negotiate_handle_info_requests(int requests) "Client requested %d item= s of info" nbd_negotiate_handle_info_request(int request, const char *name) "Client r= equested info %d (%s)" nbd_negotiate_handle_info_block_size(uint32_t minimum, uint32_t preferred,= uint32_t maximum) "advertising minimum 0x%" PRIx32 ", preferred 0x%" PRIx3= 2 ", maximum 0x%" PRIx32 +nbd_negotiate_handle_info_trim_size(uint32_t minimum, uint32_t maximum) "a= dvertising minimum 0x%" PRIx32 ", maximum 0x%" PRIx32 +nbd_negotiate_handle_info_zero_size(uint32_t minimum, uint32_t maximum) "a= dvertising minimum 0x%" PRIx32 ", maximum 0x%" PRIx32 nbd_negotiate_handle_starttls(void) "Setting up TLS" nbd_negotiate_handle_starttls_handshake(void) "Starting TLS handshake" nbd_negotiate_meta_context(const char *optname, const char *export, uint32= _t queries) "Client requested %s for export %s, with %" PRIu32 " queries" --=20 2.14.3