From nobody Sun Feb 8 23:50:36 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637168646950318.60669628226685; Wed, 17 Nov 2021 09:04:06 -0800 (PST) Received: from localhost ([::1]:51558 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnOLt-0007Ic-Oq for importer@patchew.org; Wed, 17 Nov 2021 12:04:05 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnOKb-00053z-5c for qemu-devel@nongnu.org; Wed, 17 Nov 2021 12:02:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:57855) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnOKW-00047n-2t for qemu-devel@nongnu.org; Wed, 17 Nov 2021 12:02:44 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-582-QmInAoaiMnujZ52zqszwLA-1; Wed, 17 Nov 2021 12:02:34 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 92C8E15722; Wed, 17 Nov 2021 17:02:33 +0000 (UTC) Received: from blue.redhat.com (ovpn-114-146.phx2.redhat.com [10.3.114.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id 24A3B1F464; Wed, 17 Nov 2021 17:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637168557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=gGVOPtBEqvJrdeQyp6+oQnMHMyze/5v7+vSZUhVMg5o=; b=BgGBNYFGeaDlRdxKmDEwGGOS7jAK5Xeexcg50yCQYO6s3CN9cKh5iXzwhKXdZrLjXW5G+v 7vjitj6+RtsrvLofMmmsQUVN3SRw/iAsphl/RKkq6/hn+UZXM58X5LKH4enS8i+eS0j76R lUqKJYTVng5ToR8oYhVRf7p0SMyUqXw= X-MC-Unique: QmInAoaiMnujZ52zqszwLA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH for-6.2 1/2] nbd/server: Don't complain on certain client disconnects Date: Wed, 17 Nov 2021 11:02:29 -0600 Message-Id: <20211117170230.1128262-2-eblake@redhat.com> In-Reply-To: <20211117170230.1128262-1-eblake@redhat.com> References: <20211117170230.1128262-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.701, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vsementsov@virtuozzo.com, rjones@redhat.com, qemu-block@nongnu.org, qemu-stable@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637168652064100001 Content-Type: text/plain; charset="utf-8" When a client disconnects abruptly, but did not have any pending requests (for example, when using nbdsh without calling h.shutdown), we used to output the following message: $ qemu-nbd -f raw file $ nbdsh -u 'nbd://localhost:10809' -c 'h.trim(1,0)' qemu-nbd: Disconnect client, due to: Failed to read request: Unexpected end= -of-file before all bytes were read Then in commit f148ae7, we refactored nbd_receive_request() to use nbd_read_eof(); when this returns 0, we regressed into tracing uninitialized memory (if tracing is enabled) and reporting a less-specific: qemu-nbd: Disconnect client, due to: Request handling failed in intermediat= e state Note that with Unix sockets, we have yet another error message, unchanged by the 6.0 regression: $ qemu-nbd -k /tmp/sock -f raw file $ nbdsh -u 'nbd+unix:///?socket=3D/tmp/sock' -c 'h.trim(1,0)' qemu-nbd: Disconnect client, due to: Failed to send reply: Unable to write = to socket: Broken pipe But in all cases, the error message goes away if the client performs a soft shutdown by using NBD_CMD_DISC, rather than a hard shutdown by abrupt disconnect: $ nbdsh -u 'nbd://localhost:10809' -c 'h.trim(1,0)' -c 'h.shutdown()' This patch fixes things to avoid uninitialized memory, and in general avoids warning about a client that does a hard shutdown when not in the middle of a packet. A client that aborts mid-request, or which does not read the full server's reply, can still result in warnings, but those are indeed much more unusual situations. CC: qemu-stable@nongnu.org Fixes: f148ae7d36 (nbd/server: Quiesce coroutines on context switch) Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index d9164ee6d0da..85877f630533 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1418,6 +1418,9 @@ static int nbd_receive_request(NBDClient *client, NBD= Request *request, if (ret < 0) { return ret; } + if (ret =3D=3D 0) { + return -EIO; + } /* Request [ 0 .. 3] magic (NBD_REQUEST_MAGIC) @@ -2285,7 +2288,7 @@ static int nbd_co_receive_request(NBDRequestData *req= , NBDRequest *request, assert(client->recv_coroutine =3D=3D qemu_coroutine_self()); ret =3D nbd_receive_request(client, request, errp); if (ret < 0) { - return ret; + return ret; } trace_nbd_co_receive_request_decode_type(request->handle, request->typ= e, @@ -2662,7 +2665,7 @@ static coroutine_fn void nbd_trip(void *opaque) } if (ret < 0) { - /* It wans't -EIO, so, according to nbd_co_receive_request() + /* It wasn't -EIO, so, according to nbd_co_receive_request() * semantics, we should return the error to the client. */ Error *export_err =3D local_err; --=20 2.33.1 From nobody Sun Feb 8 23:50:36 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.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 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1637168819215265.7103244476066; Wed, 17 Nov 2021 09:06:59 -0800 (PST) Received: from localhost ([::1]:58286 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mnOOg-0003YA-00 for importer@patchew.org; Wed, 17 Nov 2021 12:06:58 -0500 Received: from eggs.gnu.org ([209.51.188.92]:40352) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnOKb-00053T-To for qemu-devel@nongnu.org; Wed, 17 Nov 2021 12:02:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:56066) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mnOKW-00047v-3F for qemu-devel@nongnu.org; Wed, 17 Nov 2021 12:02:44 -0500 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-564-olR736txPN6FUHJ0a9qpcA-1; Wed, 17 Nov 2021 12:02:35 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 293D98042F0; Wed, 17 Nov 2021 17:02:34 +0000 (UTC) Received: from blue.redhat.com (ovpn-114-146.phx2.redhat.com [10.3.114.146]) by smtp.corp.redhat.com (Postfix) with ESMTP id C0AC71F450; Wed, 17 Nov 2021 17:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637168558; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qe1/1VXXsPYjIhnJjmG1lHnXhuOOlyZUq0OJIq2hEbA=; b=FYe2HZ3Va4yjO9hN3Oj3tqptbi1s7KBEX6wgh50KvVgGK9HBabMpqQbz/QJ4tKIxFdXloO ktX0LeTtlnn3UyVmzanWzG8va4YKhpIj82L9wisvjMJ7qfnl5dgEpeapltzL8X4o2SfytU 5JGLviQGa7tboBsOrw8u8W5h4Zf8jQY= X-MC-Unique: olR736txPN6FUHJ0a9qpcA-1 From: Eric Blake To: qemu-devel@nongnu.org Subject: [PATCH for-6.2? 2/2] nbd/server: Simplify zero and trim Date: Wed, 17 Nov 2021 11:02:30 -0600 Message-Id: <20211117170230.1128262-3-eblake@redhat.com> In-Reply-To: <20211117170230.1128262-1-eblake@redhat.com> References: <20211117170230.1128262-1-eblake@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=eblake@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=eblake@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.701, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=unavailable autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: vsementsov@virtuozzo.com, rjones@redhat.com, qemu-block@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1637168821219100001 Content-Type: text/plain; charset="utf-8" Now that the block layer supports 64-bit operations, we no longer have to self-fragment requests larger than 2G, reverting the workaround added in 890cbccb08 (nbd: Fix large trim/zero requests). Signed-off-by: Eric Blake Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 85877f630533..1b3945220bd3 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2509,16 +2509,8 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, if (request->flags & NBD_CMD_FLAG_FAST_ZERO) { flags |=3D BDRV_REQ_NO_FALLBACK; } - ret =3D 0; - /* FIXME simplify this when blk_pwrite_zeroes switches to 64-bit */ - while (ret >=3D 0 && request->len) { - int align =3D client->check_align ?: 1; - int len =3D MIN(request->len, QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX= _BYTES, - align)); - ret =3D blk_pwrite_zeroes(exp->common.blk, request->from, len,= flags); - request->len -=3D len; - request->from +=3D len; - } + ret =3D blk_pwrite_zeroes(exp->common.blk, request->from, request-= >len, + flags); return nbd_send_generic_reply(client, request->handle, ret, "writing to file failed", errp); @@ -2532,16 +2524,7 @@ static coroutine_fn int nbd_handle_request(NBDClient= *client, "flush failed", errp); case NBD_CMD_TRIM: - ret =3D 0; - /* FIXME simplify this when blk_co_pdiscard switches to 64-bit */ - while (ret >=3D 0 && request->len) { - int align =3D client->check_align ?: 1; - int len =3D MIN(request->len, QEMU_ALIGN_DOWN(BDRV_REQUEST_MAX= _BYTES, - align)); - ret =3D blk_co_pdiscard(exp->common.blk, request->from, len); - request->len -=3D len; - request->from +=3D len; - } + ret =3D blk_co_pdiscard(exp->common.blk, request->from, request->l= en); if (ret >=3D 0 && request->flags & NBD_CMD_FLAG_FUA) { ret =3D blk_co_flush(exp->common.blk); } --=20 2.33.1