From nobody Wed Nov 12 10:09:29 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.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; Authentication-Results: mx.zohomail.com; spf=pass (zoho.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=virtuozzo.com ARC-Seal: i=1; a=rsa-sha256; t=1569857185; cv=none; d=zoho.com; s=zohoarc; b=VAAsRf9NIfTbHkHiAPZrRUh0CJyO0SsqQCyGxHR7XDRzTGKtmj7K6HlxtVquLaAvkqYLGFCT59vPq/TX8ZnqpqNcL76PimMf9swTjkpjVcmCkvq7xQCS1J7fkTgV+BswjVApTpRBRGzjaoJIXQKjBV6k+HqgwNYSpegOWXJh+nI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569857185; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=p8I7mqrbzGQBAt6bxPDd2fk4BAVFKpCEdikr4Z0IgF0=; b=hM9T0Epn5c7TA6jSmHDrjSYh+0M41PggHuDPkJ/d2mxHEzbkO89EVRoKUoHC3MPpTXaq8QPSCuu9145GYCBthZSLDzyYJchTmisdn1AxCA1dr18McSOUH5qrKjrLHjN1x2vnXwH3/FqVJddkyuCy1IWun71R8A1mW/MgdVlEh2w= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1569857185224800.5836341755482; Mon, 30 Sep 2019 08:26:25 -0700 (PDT) Received: from localhost ([::1]:53736 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iExZ5-00034I-1P for importer@patchew.org; Mon, 30 Sep 2019 11:26:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60103) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iExOK-0004Z9-GX for qemu-devel@nongnu.org; Mon, 30 Sep 2019 11:15:14 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iExOI-0005ux-Mc for qemu-devel@nongnu.org; Mon, 30 Sep 2019 11:15:12 -0400 Received: from relay.sw.ru ([185.231.240.75]:46698) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iExOF-0005oy-88; Mon, 30 Sep 2019 11:15:07 -0400 Received: from [10.94.3.0] (helo=kvm.qa.sw.ru) by relay.sw.ru with esmtp (Exim 4.92.2) (envelope-from ) id 1iExOC-0005tD-G1; Mon, 30 Sep 2019 18:15:04 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH 09/10] nbd/server: use bdrv_dirty_bitmap_next_dirty_area Date: Mon, 30 Sep 2019 18:15:01 +0300 Message-Id: <20190930151502.7829-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190930151502.7829-1-vsementsov@virtuozzo.com> References: <20190930151502.7829-1-vsementsov@virtuozzo.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 185.231.240.75 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kwolf@redhat.com, fam@euphon.net, vsementsov@virtuozzo.com, qemu-devel@nongnu.org, mreitz@redhat.com, den@openvz.org, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use bdrv_dirty_bitmap_next_dirty_area for bitmap_to_extents. Since bdrv_dirty_bitmap_next_dirty_area is very accurate in its interface, we'll never exceed requested region with last chunk. So, we don't need dont_fragment, and bitmap_to_extents() interface becomes clean enough to not require any comment. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Eric Blake --- nbd/server.c | 58 ++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 40 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index cc63d8ad21..edbdb1b6b6 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2023,57 +2023,35 @@ static int nbd_co_send_block_status(NBDClient *clie= nt, uint64_t handle, return nbd_co_send_extents(client, handle, ea, last, context_id, errp); } =20 -/* - * Populate @ea from a dirty bitmap. Unless @dont_fragment, the - * final extent may exceed the original @length. - */ static void bitmap_to_extents(BdrvDirtyBitmap *bitmap, uint64_t offset, uint64_t length, - NBDExtentArray *ea, bool dont_fragment) + NBDExtentArray *es) { - uint64_t begin =3D offset, end =3D offset; - uint64_t overall_end =3D offset + length; - BdrvDirtyBitmapIter *it; - bool dirty; + int64_t start, dirty_start, dirty_count; + int64_t end =3D offset + length; + bool full =3D false; =20 bdrv_dirty_bitmap_lock(bitmap); =20 - it =3D bdrv_dirty_iter_new(bitmap); - dirty =3D bdrv_dirty_bitmap_get_locked(bitmap, offset); - - while (begin < overall_end) { - bool next_dirty =3D !dirty; - - if (dirty) { - end =3D bdrv_dirty_bitmap_next_zero(bitmap, begin, INT64_MAX); - } else { - bdrv_set_dirty_iter(it, begin); - end =3D bdrv_dirty_iter_next(it); - } - if (end =3D=3D -1 || end - begin > UINT32_MAX) { - /* Cap to an aligned value < 4G beyond begin. */ - end =3D MIN(bdrv_dirty_bitmap_size(bitmap), - begin + UINT32_MAX + 1 - - bdrv_dirty_bitmap_granularity(bitmap)); - next_dirty =3D dirty; - } - if (dont_fragment && end > overall_end) { - end =3D overall_end; - } - - if (nbd_extent_array_add(ea, end - begin, - dirty ? NBD_STATE_DIRTY : 0) < 0) { + for (start =3D offset; + bdrv_dirty_bitmap_next_dirty_area(bitmap, start, end, INT32_MAX, + &dirty_start, &dirty_count); + start =3D dirty_start + dirty_count) + { + if ((nbd_extent_array_add(es, dirty_start - start, 0) < 0) || + (nbd_extent_array_add(es, dirty_count, NBD_STATE_DIRTY) < 0)) + { + full =3D true; break; } - begin =3D end; - dirty =3D next_dirty; } =20 - bdrv_dirty_iter_free(it); + if (!full) { + /* last non dirty extent */ + nbd_extent_array_add(es, end - start, 0); + } =20 bdrv_dirty_bitmap_unlock(bitmap); - - assert(offset < end); } =20 static int nbd_co_send_bitmap(NBDClient *client, uint64_t handle, @@ -2084,7 +2062,7 @@ static int nbd_co_send_bitmap(NBDClient *client, uint= 64_t handle, unsigned int nb_extents =3D dont_fragment ? 1 : NBD_MAX_BLOCK_STATUS_E= XTENTS; g_autoptr(NBDExtentArray) ea =3D nbd_extent_array_new(nb_extents); =20 - bitmap_to_extents(bitmap, offset, length, ea, dont_fragment); + bitmap_to_extents(bitmap, offset, length, ea); =20 return nbd_co_send_extents(client, handle, ea, last, context_id, errp); } --=20 2.21.0