From nobody Sun Oct 5 17:32:18 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1515425640532571.4096250022652; Mon, 8 Jan 2018 07:34:00 -0800 (PST) Received: from localhost ([::1]:40655 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYZQy-0003hY-2M for importer@patchew.org; Mon, 08 Jan 2018 10:33:56 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36895) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eYZOt-0002Rk-6b for qemu-devel@nongnu.org; Mon, 08 Jan 2018 10:31:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eYZOs-0007jS-A9 for qemu-devel@nongnu.org; Mon, 08 Jan 2018 10:31:47 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36168) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eYZOp-0007fD-0t; Mon, 08 Jan 2018 10:31:43 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 37C2A780DD; Mon, 8 Jan 2018 15:31:42 +0000 (UTC) Received: from red.redhat.com (ovpn-124-124.rdu2.redhat.com [10.10.124.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 97A7760C4E; Mon, 8 Jan 2018 15:31:41 +0000 (UTC) From: Eric Blake To: qemu-devel@nongnu.org Date: Mon, 8 Jan 2018 09:31:36 -0600 Message-Id: <20180108153137.5195-3-eblake@redhat.com> In-Reply-To: <20180108153137.5195-1-eblake@redhat.com> References: <20180108153137.5195-1-eblake@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Mon, 08 Jan 2018 15:31: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] [PULL 2/3] nbd/server: Optimize final chunk of sparse read 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 , "open list:Network Block Dev..." 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" If we are careful to handle 0-length read requests correctly, we can optimize our sparse read to send the NBD_REPLY_FLAG_DONE bit on our last OFFSET_DATA or OFFSET_HOLE chunk rather than needing a separate chunk. Signed-off-by: Eric Blake Message-Id: <20171107030912.23930-3-eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy --- nbd/server.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index be7310cb41..e443b3cf5c 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1339,12 +1339,14 @@ static int coroutine_fn nbd_co_send_sparse_read(NBD= Client *client, offset + progress, size - progress, &pnum, NULL, NULL); + bool final; if (status < 0) { error_setg_errno(errp, -status, "unable to check for holes"); return status; } assert(pnum && pnum <=3D size - progress); + final =3D progress + pnum =3D=3D size; if (status & BDRV_BLOCK_ZERO) { NBDStructuredReadHole chunk; struct iovec iov[] =3D { @@ -1353,7 +1355,8 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, trace_nbd_co_send_structured_read_hole(handle, offset + progre= ss, pnum); - set_be_chunk(&chunk.h, 0, NBD_REPLY_TYPE_OFFSET_HOLE, + set_be_chunk(&chunk.h, final ? NBD_REPLY_FLAG_DONE : 0, + NBD_REPLY_TYPE_OFFSET_HOLE, handle, sizeof(chunk) - sizeof(chunk.h)); stq_be_p(&chunk.offset, offset + progress); stl_be_p(&chunk.length, pnum); @@ -1366,7 +1369,7 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, break; } ret =3D nbd_co_send_structured_read(client, handle, offset + p= rogress, - data + progress, pnum, false, + data + progress, pnum, final, errp); } @@ -1375,9 +1378,6 @@ static int coroutine_fn nbd_co_send_sparse_read(NBDCl= ient *client, } progress +=3D pnum; } - if (!ret) { - ret =3D nbd_co_send_structured_done(client, handle, errp); - } return ret; } @@ -1542,7 +1542,8 @@ static coroutine_fn void nbd_trip(void *opaque) } } - if (client->structured_reply && !(request.flags & NBD_CMD_FLAG_DF)= ) { + if (client->structured_reply && !(request.flags & NBD_CMD_FLAG_DF)= && + request.len) { ret =3D nbd_co_send_sparse_read(req->client, request.handle, request.from, req->data, request= .len, &local_err); --=20 2.14.3