From nobody Sun Feb 8 11:21:36 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530703508684416.62975771821255; Wed, 4 Jul 2018 04:25:08 -0700 (PDT) Received: from localhost ([::1]:46261 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fafu9-0008LB-Hz for importer@patchew.org; Wed, 04 Jul 2018 07:25:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57230) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fafsL-0007OM-53 for qemu-devel@nongnu.org; Wed, 04 Jul 2018 07:23:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fafsI-0004eW-1p for qemu-devel@nongnu.org; Wed, 04 Jul 2018 07:23:09 -0400 Received: from relay.sw.ru ([185.231.240.75]:34678) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fafsH-0004bu-Po; Wed, 04 Jul 2018 07:23:05 -0400 Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fafsF-0000H9-4A; Wed, 04 Jul 2018 14:23:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 4 Jul 2018 14:23:01 +0300 Message-Id: <20180704112302.471456-2-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180704112302.471456-1-vsementsov@virtuozzo.com> References: <20180704112302.471456-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 1/2] nbd/server: fix nbd_co_send_block_status 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, den@openvz.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" Call nbd_co_send_extents() with correct length parameter (extent.length may be smaller than original length). Also, switch length parameter type to uint32_t, to correspond with request->len and similar nbd_co_send_bitmap(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index e52b76bd1a..ea5fe0eb33 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1910,7 +1910,7 @@ static int nbd_co_send_extents(NBDClient *client, uin= t64_t handle, /* Get block status from the exported device and send it to the client */ static int nbd_co_send_block_status(NBDClient *client, uint64_t handle, BlockDriverState *bs, uint64_t offset, - uint64_t length, bool last, + uint32_t length, bool last, uint32_t context_id, Error **errp) { int ret; @@ -1922,7 +1922,8 @@ static int nbd_co_send_block_status(NBDClient *client= , uint64_t handle, client, handle, -ret, "can't get block status", errp); } =20 - return nbd_co_send_extents(client, handle, &extent, 1, length, last, + return nbd_co_send_extents(client, handle, &extent, 1, + be32_to_cpu(extent.length), last, context_id, errp); } =20 --=20 2.11.1 From nobody Sun Feb 8 11:21:36 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; dmarc=fail(p=none dis=none) header.from=virtuozzo.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530703508661105.8292618048107; Wed, 4 Jul 2018 04:25:08 -0700 (PDT) Received: from localhost ([::1]:46262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fafuC-0008Lk-Kj for importer@patchew.org; Wed, 04 Jul 2018 07:25:04 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fafsL-0007OL-4z for qemu-devel@nongnu.org; Wed, 04 Jul 2018 07:23:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fafsI-0004ef-1z for qemu-devel@nongnu.org; Wed, 04 Jul 2018 07:23:09 -0400 Received: from relay.sw.ru ([185.231.240.75]:34680) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fafsH-0004bv-Pl; Wed, 04 Jul 2018 07:23:05 -0400 Received: from vz-out.virtuozzo.com ([185.231.240.5] helo=kvm.sw.ru) by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1fafsF-0000H9-7W; Wed, 04 Jul 2018 14:23:03 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-devel@nongnu.org, qemu-block@nongnu.org Date: Wed, 4 Jul 2018 14:23:02 +0300 Message-Id: <20180704112302.471456-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20180704112302.471456-1-vsementsov@virtuozzo.com> References: <20180704112302.471456-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 Subject: [Qemu-devel] [PATCH 2/2] nbd/server: send more than one extent of base:allocation context 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, den@openvz.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" This is necessary for efficient block-status export, for clients which support it. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 77 +++++++++++++++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 58 insertions(+), 19 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index ea5fe0eb33..a6d013aec4 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -1844,11 +1844,22 @@ static int coroutine_fn nbd_co_send_sparse_read(NBD= Client *client, return ret; } =20 -static int blockstatus_to_extent_be(BlockDriverState *bs, uint64_t offset, - uint64_t bytes, NBDExtent *extent) +/* + * Populate @extents from block status. Store in @bytes the byte length en= coded + * (which may be smaller but (unlike bitmap_to_extents) _never_ larger tha= n the + * original), and store in @nb_extents the number of extents used. + * + * Returns zero on success and -errno on bdrv_block_status_above failure. + */ +static int blockstatus_to_extents(BlockDriverState *bs, uint64_t offset, + uint64_t *bytes, NBDExtent *extents, + unsigned int *nb_extents) { - uint64_t remaining_bytes =3D bytes; + uint64_t remaining_bytes =3D *bytes; + NBDExtent *extent =3D extents, *extents_end =3D extents + *nb_extents; + bool first_extent =3D true; =20 + assert(*nb_extents); while (remaining_bytes) { uint32_t flags; int64_t num; @@ -1860,21 +1871,40 @@ static int blockstatus_to_extent_be(BlockDriverStat= e *bs, uint64_t offset, =20 flags =3D (ret & BDRV_BLOCK_ALLOCATED ? 0 : NBD_STATE_HOLE) | (ret & BDRV_BLOCK_ZERO ? NBD_STATE_ZERO : 0); + offset +=3D num; + remaining_bytes -=3D num; =20 - if (remaining_bytes =3D=3D bytes) { + if (first_extent) { extent->flags =3D flags; + extent->length =3D num; + first_extent =3D false; + continue; } =20 - if (flags !=3D extent->flags) { - break; + if (flags =3D=3D extent->flags) { + /* extend current extent */ + extent->length +=3D num; + } else { + if (extent + 1 =3D=3D extents_end) { + break; + } + + /* start new extent */ + extent++; + extent->flags =3D flags; + extent->length =3D num; } + } =20 - offset +=3D num; - remaining_bytes -=3D num; + extents_end =3D extent + 1; + + for (extent =3D extents; extent < extents_end; extent++) { + cpu_to_be32s(&extent->flags); + cpu_to_be32s(&extent->length); } =20 - cpu_to_be32s(&extent->flags); - extent->length =3D cpu_to_be32(bytes - remaining_bytes); + *bytes -=3D remaining_bytes; + *nb_extents =3D extents_end - extents; =20 return 0; } @@ -1910,21 +1940,29 @@ static int nbd_co_send_extents(NBDClient *client, u= int64_t handle, /* Get block status from the exported device and send it to the client */ static int nbd_co_send_block_status(NBDClient *client, uint64_t handle, BlockDriverState *bs, uint64_t offset, - uint32_t length, bool last, - uint32_t context_id, Error **errp) + uint32_t length, bool dont_fragment, + bool last, uint32_t context_id, + Error **errp) { int ret; - NBDExtent extent; + unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BITMAP_EXTENTS; + NBDExtent *extents =3D g_new(NBDExtent, nb_extents); + uint64_t final_length =3D length; =20 - ret =3D blockstatus_to_extent_be(bs, offset, length, &extent); + ret =3D blockstatus_to_extents(bs, offset, &final_length, extents, + &nb_extents); if (ret < 0) { + g_free(extents); return nbd_co_send_structured_error( client, handle, -ret, "can't get block status", errp); } =20 - return nbd_co_send_extents(client, handle, &extent, 1, - be32_to_cpu(extent.length), last, - context_id, errp); + ret =3D nbd_co_send_extents(client, handle, extents, nb_extents, + final_length, last, context_id, errp); + + g_free(extents); + + return ret; } =20 /* @@ -2228,10 +2266,11 @@ static coroutine_fn int nbd_handle_request(NBDClien= t *client, (client->export_meta.base_allocation || client->export_meta.bitmap)) { + bool dont_fragment =3D request->flags & NBD_CMD_FLAG_REQ_ONE; if (client->export_meta.base_allocation) { ret =3D nbd_co_send_block_status(client, request->handle, blk_bs(exp->blk), request->= from, - request->len, + request->len, dont_fragment, !client->export_meta.bitmap, NBD_META_ID_BASE_ALLOCATION, errp); @@ -2244,7 +2283,7 @@ static coroutine_fn int nbd_handle_request(NBDClient = *client, ret =3D nbd_co_send_bitmap(client, request->handle, client->exp->export_bitmap, request->from, request->len, - request->flags & NBD_CMD_FLAG_REQ= _ONE, + dont_fragment, true, NBD_META_ID_DIRTY_BITMAP, e= rrp); if (ret < 0) { return ret; --=20 2.11.1