From nobody Thu May 2 19:33:40 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510023906415659.255960738509; Mon, 6 Nov 2017 19:05:06 -0800 (PST) Received: from localhost ([::1]:51194 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuC8-0000HQ-TT for importer@patchew.org; Mon, 06 Nov 2017 22:04:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37552) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuA1-0007TL-4B for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:45 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBuA0-0003Pl-7n for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:45 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56214) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBu9y-0003Oh-5B; Mon, 06 Nov 2017 22:02:42 -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 1C06D81DE5; Tue, 7 Nov 2017 03:02:41 +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 0323F600D3; Tue, 7 Nov 2017 03:02:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1C06D81DE5 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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:29 -0600 Message-Id: <20171107030236.23633-2-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.25]); Tue, 07 Nov 2017 03:02:41 +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 1/8] nbd-client: Fix error message typos 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" Provide missing spaces that are required when using string concatenation to break error messages across source lines. Signed-off-by: Eric Blake --- block/nbd-client.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index b44d4d4a01..de6c153328 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -248,7 +248,7 @@ static int nbd_parse_error_payload(NBDStructuredReplyCh= unk *chunk, error =3D nbd_errno_to_system_errno(payload_advance32(&payload)); if (error =3D=3D 0) { - error_setg(errp, "Protocol error: server sent structured error chu= nk" + error_setg(errp, "Protocol error: server sent structured error chu= nk " "with error =3D 0"); return -EINVAL; } @@ -257,7 +257,7 @@ static int nbd_parse_error_payload(NBDStructuredReplyCh= unk *chunk, message_size =3D payload_advance16(&payload); if (message_size > chunk->length - sizeof(error) - sizeof(message_size= )) { - error_setg(errp, "Protocol error: server sent structured error chu= nk" + error_setg(errp, "Protocol error: server sent structured error chu= nk " "with incorrect message size"); return -EINVAL; } @@ -408,7 +408,7 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( if (chunk->type =3D=3D NBD_REPLY_TYPE_NONE) { if (!(chunk->flags & NBD_REPLY_FLAG_DONE)) { error_setg(errp, "Protocol error: NBD_REPLY_TYPE_NONE chunk wi= thout" - "NBD_REPLY_FLAG_DONE flag set"); + " NBD_REPLY_FLAG_DONE flag set"); return -EINVAL; } return 0; --=20 2.13.6 From nobody Thu May 2 19:33:40 2024 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 1510024207796631.8222847374055; Mon, 6 Nov 2017 19:10:07 -0800 (PST) Received: from localhost ([::1]:51222 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuH8-00048T-Pp for importer@patchew.org; Mon, 06 Nov 2017 22:10:06 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuA2-0007Uh-DT for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBuA1-0003QZ-Ig for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44406) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBu9z-0003P1-8P; Mon, 06 Nov 2017 22:02:43 -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 381A6883C7; Tue, 7 Nov 2017 03:02:42 +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 62038600D3; Tue, 7 Nov 2017 03:02:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 381A6883C7 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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:30 -0600 Message-Id: <20171107030236.23633-3-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.26]); Tue, 07 Nov 2017 03:02:42 +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 2/8] nbd/client: Nicer trace of structured reply 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: pbonzini@redhat.com, vsementsov@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" It's useful to know which structured reply chunk is being processed. Signed-off-by: Eric Blake --- nbd/client.c | 4 +++- nbd/trace-events | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/nbd/client.c b/nbd/client.c index 3d680e63e1..1880103d2a 100644 --- a/nbd/client.c +++ b/nbd/client.c @@ -979,6 +979,7 @@ static int nbd_receive_structured_reply_chunk(QIOChanne= l *ioc, int nbd_receive_reply(QIOChannel *ioc, NBDReply *reply, Error **errp) { int ret; + const char *type; ret =3D nbd_read_eof(ioc, &reply->magic, sizeof(reply->magic), errp); if (ret <=3D 0) { @@ -1008,8 +1009,9 @@ int nbd_receive_reply(QIOChannel *ioc, NBDReply *repl= y, Error **errp) if (ret < 0) { break; } + type =3D nbd_reply_type_lookup(reply->structured.type); trace_nbd_receive_structured_reply_chunk(reply->structured.flags, - reply->structured.type, + reply->structured.type, t= ype, reply->structured.handle, reply->structured.length); break; diff --git a/nbd/trace-events b/nbd/trace-events index 4a13757524..bbc75f6414 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -27,7 +27,7 @@ nbd_client_clear_queue(void) "Clearing NBD queue" nbd_client_clear_socket(void) "Clearing NBD socket" nbd_send_request(uint64_t from, uint32_t len, uint64_t handle, uint16_t fl= ags, uint16_t type, const char *name) "Sending request to server: { .from = =3D %" PRIu64", .len =3D %" PRIu32 ", .handle =3D %" PRIu64 ", .flags =3D 0= x%" PRIx16 ", .type =3D %" PRIu16 " (%s) }" nbd_receive_simple_reply(int32_t error, const char *errname, uint64_t hand= le) "Got simple reply: { .error =3D %" PRId32 " (%s), handle =3D %" PRIu64"= }" -nbd_receive_structured_reply_chunk(uint16_t flags, uint16_t type, uint64_t= handle, uint32_t length) "Got structured reply chunk: { flags =3D 0x%" PRI= x16 ", type =3D %d, handle =3D %" PRIu64 ", length =3D %" PRIu32 " }" +nbd_receive_structured_reply_chunk(uint16_t flags, uint16_t type, const ch= ar *name, uint64_t handle, uint32_t length) "Got structured reply chunk: { = flags =3D 0x%" PRIx16 ", type =3D %d (%s), handle =3D %" PRIu64 ", length = =3D %" PRIu32 " }" # nbd/common.c nbd_unknown_error(int err) "Squashing unexpected error %d to EINVAL" --=20 2.13.6 From nobody Thu May 2 19:33:40 2024 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 1510024076952969.0632919046794; Mon, 6 Nov 2017 19:07:56 -0800 (PST) Received: from localhost ([::1]:51212 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuEx-0002cf-4m for importer@patchew.org; Mon, 06 Nov 2017 22:07:51 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37595) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuA3-0007Va-CH for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBuA2-0003R3-Ji for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:44436) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBuA0-0003Pe-JS; Mon, 06 Nov 2017 22:02:44 -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 9452F883D9; Tue, 7 Nov 2017 03:02:43 +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 7C9C1600D3; Tue, 7 Nov 2017 03:02:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9452F883D9 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.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:31 -0600 Message-Id: <20171107030236.23633-4-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.26]); Tue, 07 Nov 2017 03:02:43 +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 3/8] raw: Reflect read-only protocol layer 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: kwolf@redhat.com, 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" We forbid operations like a zero-length write zero or a discard at the protocol layer when it is marked read-only, but those same operations were succeeding at the format layer because the raw format was not reflecting the underlying read-only status to the block layer, which then took short circuit paths on zero-length operations. Signed-off-by: Eric Blake --- block/raw-format.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/block/raw-format.c b/block/raw-format.c index 830243a8e4..717b8eff65 100644 --- a/block/raw-format.c +++ b/block/raw-format.c @@ -418,6 +418,12 @@ static int raw_open(BlockDriverState *bs, QDict *optio= ns, int flags, bs->file->bs->supported_write_flags; bs->supported_zero_flags =3D (BDRV_REQ_FUA | BDRV_REQ_MAY_UNMAP) & bs->file->bs->supported_zero_flags; + if (bdrv_is_read_only(bs->file->bs)) { + ret =3D bdrv_set_read_only(bs, true, errp); + if (ret < 0) { + return ret; + } + } if (bs->probed && !bdrv_is_read_only(bs)) { fprintf(stderr, --=20 2.13.6 From nobody Thu May 2 19:33:40 2024 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 1510023913482922.709160824603; Mon, 6 Nov 2017 19:05:13 -0800 (PST) Received: from localhost ([::1]:51196 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuCM-0000P4-F1 for importer@patchew.org; Mon, 06 Nov 2017 22:05:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37672) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuA9-0007a3-1i for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBuA4-0003SG-Dn for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54874) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBuA1-0003QS-VQ; Mon, 06 Nov 2017 22:02:46 -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 004BCC047B62; Tue, 7 Nov 2017 03:02:45 +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 D82CF600D3; Tue, 7 Nov 2017 03:02:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 004BCC047B62 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.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:32 -0600 Message-Id: <20171107030236.23633-5-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.31]); Tue, 07 Nov 2017 03:02:45 +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 4/8] nbd-client: Honor server read-only advertisement 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 says that clients should not try to write/trim to an export advertised as read-only by the server. But we failed to inform the block layer of what we learned from the server, meaning that we were depending on the server sending a proper EPERM failure for various commands. In fact, this was noticeable in the case of a 0-length write: we had a difference in behavior depending on whether we were writing zero (silent success locally, because the driver is not invoked from the block layer) or normal writes (noisy failure, because we sent a 0-length request across the wire and the server flagged it as invalid); now we always fail locally without sending anything over the wire. Signed-off-by: Eric Blake --- block/nbd-client.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/block/nbd-client.c b/block/nbd-client.c index de6c153328..c35aad59b0 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -697,6 +697,7 @@ int nbd_client_co_pwritev(BlockDriverState *bs, uint64_= t offset, .len =3D bytes, }; + assert(!(client->info.flags & NBD_FLAG_READ_ONLY)); if (flags & BDRV_REQ_FUA) { assert(client->info.flags & NBD_FLAG_SEND_FUA); request.flags |=3D NBD_CMD_FLAG_FUA; @@ -717,6 +718,7 @@ int nbd_client_co_pwrite_zeroes(BlockDriverState *bs, i= nt64_t offset, .len =3D bytes, }; + assert(!(client->info.flags & NBD_FLAG_READ_ONLY)); if (!(client->info.flags & NBD_FLAG_SEND_WRITE_ZEROES)) { return -ENOTSUP; } @@ -756,6 +758,7 @@ int nbd_client_co_pdiscard(BlockDriverState *bs, int64_= t offset, int bytes) .len =3D bytes, }; + assert(!(client->info.flags & NBD_FLAG_READ_ONLY)); if (!(client->info.flags & NBD_FLAG_SEND_TRIM)) { return 0; } @@ -814,6 +817,12 @@ int nbd_client_init(BlockDriverState *bs, logout("Failed to negotiate with the NBD server\n"); return ret; } + if (client->info.flags & NBD_FLAG_READ_ONLY) { + ret =3D bdrv_set_read_only(bs, true, errp); + if (ret < 0) { + return ret; + } + } if (client->info.flags & NBD_FLAG_SEND_FUA) { bs->supported_write_flags =3D BDRV_REQ_FUA; bs->supported_zero_flags |=3D BDRV_REQ_FUA; --=20 2.13.6 From nobody Thu May 2 19:33:40 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1510023914775988.1111550654088; Mon, 6 Nov 2017 19:05:14 -0800 (PST) Received: from localhost ([::1]:51195 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuCF-0000Kp-VH for importer@patchew.org; Mon, 06 Nov 2017 22:05:04 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuA8-0007Zw-WA for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBuA5-0003TF-MA for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:53 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58102) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBuA3-0003RJ-C4; Mon, 06 Nov 2017 22:02:47 -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 57C3083F3E; Tue, 7 Nov 2017 03:02:46 +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 42C9B600D3; Tue, 7 Nov 2017 03:02:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 57C3083F3E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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:33 -0600 Message-Id: <20171107030236.23633-6-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.27]); Tue, 07 Nov 2017 03:02:46 +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 5/8] nbd: Fix struct name for structured reads 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" A closer read of the NBD spec shows that a structured reply chunk for a hole is not quite identical to the prefix of a data chunk, because the hole has to also send a 32-bit size field. Although we do not yet send holes, we should fix the misleading information in our header and make it easier for a future patch to support sparse reads. Signed-off-by: Eric Blake --- include/block/nbd.h | 18 +++++++++++++----- nbd/server.c | 2 +- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/include/block/nbd.h b/include/block/nbd.h index 92d1723d7c..113c707a5e 100644 --- a/include/block/nbd.h +++ b/include/block/nbd.h @@ -86,15 +86,23 @@ typedef union NBDReply { } QEMU_PACKED; } NBDReply; -/* Header of NBD_REPLY_TYPE_OFFSET_DATA, complete NBD_REPLY_TYPE_OFFSET_HO= LE */ -typedef struct NBDStructuredRead { - NBDStructuredReplyChunk h; +/* Header of chunk for NBD_REPLY_TYPE_OFFSET_DATA */ +typedef struct NBDStructuredReadData { + NBDStructuredReplyChunk h; /* h.length >=3D 9 */ uint64_t offset; -} QEMU_PACKED NBDStructuredRead; + /* At least one byte of data payload follows, calculated from h.length= */ +} QEMU_PACKED NBDStructuredReadData; + +/* Complete chunk for NBD_REPLY_TYPE_OFFSET_HOLE */ +typedef struct NBDStructuredReadHole { + NBDStructuredReplyChunk h; /* h.length =3D=3D 12 */ + uint64_t offset; + uint32_t length; +} QEMU_PACKED NBDStructuredReadHole; /* Header of all NBD_REPLY_TYPE_ERROR* errors */ typedef struct NBDStructuredError { - NBDStructuredReplyChunk h; + NBDStructuredReplyChunk h; /* h.length >=3D 6 */ uint32_t error; uint16_t message_length; } QEMU_PACKED NBDStructuredError; diff --git a/nbd/server.c b/nbd/server.c index bcf0cdb47c..6ebb7d9c2e 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1280,7 +1280,7 @@ static int coroutine_fn nbd_co_send_structured_read(N= BDClient *client, size_t size, Error **errp) { - NBDStructuredRead chunk; + NBDStructuredReadData chunk; struct iovec iov[] =3D { {.iov_base =3D &chunk, .iov_len =3D sizeof(chunk)}, {.iov_base =3D data, .iov_len =3D size} --=20 2.13.6 From nobody Thu May 2 19:33:40 2024 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 From nobody Thu May 2 19:33:40 2024 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 1510024215136427.95295401418093; Mon, 6 Nov 2017 19:10:15 -0800 (PST) Received: from localhost ([::1]:51219 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuH3-00043P-BE for importer@patchew.org; Mon, 06 Nov 2017 22:10:01 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuAE-0007fR-AL for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBuAA-0003X2-FN for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56368) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBuA6-0003T9-2o; Mon, 06 Nov 2017 22:02:50 -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 1B38881DF8; Tue, 7 Nov 2017 03:02:49 +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 00245600D3; Tue, 7 Nov 2017 03:02:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1B38881DF8 Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.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:35 -0600 Message-Id: <20171107030236.23633-8-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.25]); Tue, 07 Nov 2017 03:02:49 +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 7/8] nbd-client: Stricter enforcing of structured reply spec 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" Ensure that the server is not sending unexpected chunk lengths for either the NONE or the OFFSET_DATA chunk, nor unexpected hole length for OFFSET_HOLE. This will flag any server that responds to a zero-length read with an OFFSET_DATA as broken, but we just fixed things to never send that request. Signed-off-by: Eric Blake --- block/nbd-client.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/block/nbd-client.c b/block/nbd-client.c index d8ad2ba57c..992c6e1493 100644 --- a/block/nbd-client.c +++ b/block/nbd-client.c @@ -216,7 +216,7 @@ static int nbd_parse_offset_hole_payload(NBDStructuredR= eplyChunk *chunk, offset =3D payload_advance64(&payload); hole_size =3D payload_advance32(&payload); - if (offset < orig_offset || hole_size > qiov->size || + if (!hole_size || offset < orig_offset || hole_size > qiov->size || offset > orig_offset + qiov->size - hole_size) { error_setg(errp, "Protocol error: server sent chunk exceeding requ= ested" " region"); @@ -281,7 +281,8 @@ static int nbd_co_receive_offset_data_payload(NBDClient= Session *s, assert(nbd_reply_is_structured(&s->reply)); - if (chunk->length < sizeof(offset)) { + /* The NBD spec requires at least one byte of payload */ + if (chunk->length <=3D sizeof(offset)) { error_setg(errp, "Protocol error: invalid payload for " "NBD_REPLY_TYPE_OFFSET_DATA"); return -EINVAL; @@ -293,7 +294,7 @@ static int nbd_co_receive_offset_data_payload(NBDClient= Session *s, be64_to_cpus(&offset); data_size =3D chunk->length - sizeof(offset); - if (offset < orig_offset || data_size > qiov->size || + if (!data_size || offset < orig_offset || data_size > qiov->size || offset > orig_offset + qiov->size - data_size) { error_setg(errp, "Protocol error: server sent chunk exceeding requ= ested" " region"); @@ -411,6 +412,11 @@ static coroutine_fn int nbd_co_do_receive_one_chunk( " NBD_REPLY_FLAG_DONE flag set"); return -EINVAL; } + if (chunk->length) { + error_setg(errp, "Protocol error: NBD_REPLY_TYPE_NONE chunk wi= th" + " nonzero length"); + return -EINVAL; + } return 0; } --=20 2.13.6 From nobody Thu May 2 19:33:40 2024 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 1510024081975925.3056156690723; Mon, 6 Nov 2017 19:08:01 -0800 (PST) Received: from localhost ([::1]:51213 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuF5-0002j8-6L for importer@patchew.org; Mon, 06 Nov 2017 22:07:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37722) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eBuAB-0007e5-IE for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:56 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eBuAA-0003Wo-A8 for qemu-devel@nongnu.org; Mon, 06 Nov 2017 22:02:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58164) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eBuA7-0003Ug-E8; Mon, 06 Nov 2017 22:02:51 -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 72C5683F3E; Tue, 7 Nov 2017 03:02:50 +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 62453600D3; Tue, 7 Nov 2017 03:02:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 72C5683F3E Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.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:36 -0600 Message-Id: <20171107030236.23633-9-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.27]); Tue, 07 Nov 2017 03:02:50 +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 8/8] nbd/server: Fix structured read of length 0 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: pbonzini@redhat.com, vsementsov@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 being clarified that a read of length 0 should not be attempted by a compliant client; but that a server must handle it correctly. However, it also implies that NBD_REPLY_TYPE_OFFSET_DATA must have a non-zero payload length, which means that we must either give an error or use a no-op REPLY_TYPE_NONE in response to a zero-length read, so that we don't trip up any clients that might kill the connection if we send a data chunk without data. Signed-off-by: Eric Blake --- nbd/server.c | 21 ++++++++++++++++++++- nbd/trace-events | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/nbd/server.c b/nbd/server.c index 6ebb7d9c2e..df771fd42f 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1273,6 +1273,21 @@ static inline void set_be_chunk(NBDStructuredReplyCh= unk *chunk, uint16_t flags, stl_be_p(&chunk->length, length); } +static int coroutine_fn nbd_co_send_structured_done(NBDClient *client, + uint64_t handle, + Error **errp) +{ + NBDStructuredReplyChunk chunk; + struct iovec iov[] =3D { + {.iov_base =3D &chunk, .iov_len =3D sizeof(chunk)}, + }; + + trace_nbd_co_send_structured_done(handle); + set_be_chunk(&chunk, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_NONE, handle,= 0); + + return nbd_co_send_iov(client, iov, 1, errp); +} + static int coroutine_fn nbd_co_send_structured_read(NBDClient *client, uint64_t handle, uint64_t offset, @@ -1286,6 +1301,7 @@ static int coroutine_fn nbd_co_send_structured_read(N= BDClient *client, {.iov_base =3D data, .iov_len =3D size} }; + assert(size); trace_nbd_co_send_structured_read(handle, offset, data, size); set_be_chunk(&chunk.h, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_OFFSET_DATA, handle, sizeof(chunk) - sizeof(chunk.h) + size); @@ -1544,10 +1560,13 @@ reply: if (ret < 0) { ret =3D nbd_co_send_structured_error(req->client, request.hand= le, -ret, msg, &local_err); - } else { + } else if (reply_data_len) { ret =3D nbd_co_send_structured_read(req->client, request.handl= e, request.from, req->data, reply_data_len, &local_err); + } else { + ret =3D nbd_co_send_structured_done(req->client, request.handl= e, + &local_err); } } else { ret =3D nbd_co_send_simple_reply(req->client, request.handle, diff --git a/nbd/trace-events b/nbd/trace-events index bbc75f6414..92568edce5 100644 --- a/nbd/trace-events +++ b/nbd/trace-events @@ -55,6 +55,7 @@ nbd_receive_request(uint32_t magic, uint16_t flags, uint1= 6_t type, uint64_t from nbd_blk_aio_attached(const char *name, void *ctx) "Export %s: Attaching cl= ients to AIO context %p\n" nbd_blk_aio_detach(const char *name, void *ctx) "Export %s: Detaching clie= nts from AIO context %p\n" nbd_co_send_simple_reply(uint64_t handle, uint32_t error, const char *errn= ame, int len) "Send simple reply: handle =3D %" PRIu64 ", error =3D %" PRIu= 32 " (%s), len =3D %d" +nbd_co_send_structured_done(uint64_t handle) "Send structured reply done: = handle =3D %" PRIu64 nbd_co_send_structured_read(uint64_t handle, uint64_t offset, void *data, = size_t size) "Send structured read data reply: handle =3D %" PRIu64 ", offs= et =3D %" PRIu64 ", data =3D %p, len =3D %zu" nbd_co_send_structured_error(uint64_t handle, int err, const char *errname= , const char *msg) "Send structured error reply: handle =3D %" PRIu64 ", er= ror =3D %d (%s), msg =3D '%s'" nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type, const c= har *name) "Decoding type: handle =3D %" PRIu64 ", type =3D %" PRIu16 " (%s= )" --=20 2.13.6