From nobody Mon Feb 9 06:34:25 2026 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510024078419953.9760136641638; Mon, 6 Nov 2017 19:07:58 -0800 (PST) Received: from localhost ([::1]:51211 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuEr-0002ZJ-21 for importer@patchew.org; Mon, 06 Nov 2017 22:07:45 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37702) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuA9-0007c3-SE for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBuA9-0003WE-59 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34836) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBuA4-0003S7-N4; Mon, 06 Nov 2017 22:02:48 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B13B07EA92; Tue, 7 Nov 2017 03:02:47 +0000 (UTC) Received: from red.redhat.com (ovpn-125-14.rdu2.redhat.com [10.10.125.14]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9AAB5600D3; Tue, 7 Nov 2017 03:02:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B13B07EA92 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=eblake@redhat.com From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 6 Nov 2017 21:02:34 -0600 Message-Id: <20171107030236.23633-7-eblake@redhat.com> In-Reply-To: <20171107030236.23633-1-eblake@redhat.com> References: <20171107030236.23633-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 07 Nov 2017 03:02:47 +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 6/8] nbd-client: Short-circuit 0-length operations 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: Kevin Wolf , pbonzini@redhat.com, vsementsov@virtuozzo.com, qemu-block@nongnu.org, Max Reitz 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 being clarified to state that clients should not send 0-length requests to the server, as the server behavior is undefined. While such requests are unlikely to occur from real guest behavior, qemu-io can force the driver to perform them; avoid any questionable server implementations by short-circuiting such operations as a no-op success (we are relying on the block layer for already filtering out things like invalid offset, write to a read-only volume, and so forth). Signed-off-by: Eric Blake --- block/nbd-client.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index c35aad59b0..d8ad2ba57c 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -673,6 +673,9 @@ int nbd_client_co_preadv(BlockDriverState *bs, uint64_t= offset, assert(bytes <=3D NBD_MAX_BUFFER_SIZE); assert(!flags); + if (!bytes) { + return 0; + } ret =3D nbd_co_send_request(bs, &request, NULL); if (ret < 0) { @@ -705,6 +708,9 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, assert(bytes <=3D NBD_MAX_BUFFER_SIZE); + if (!bytes) { + return 0; + } return nbd_co_request(bs, &request, qiov); } @@ -731,6 +737,9 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, i= nt64_t offset, request.flags |=3D NBD_CMD_FLAG_NO_HOLE; } + if (!bytes) { + return 0; + } return nbd_co_request(bs, &request, NULL); } @@ -759,7 +768,7 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_= t offset, int bytes) }; assert(!(client->info.flags & NBD_FLAG_READ_ONLY)); - if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) { + if (!(client->info.flags & NBD_FLAG_SEND_TRIM) || !bytes) { return 0; } --=20 2.13.6