From nobody Mon Feb 9 16:52:19 2026 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=1571749999; cv=none; d=zoho.com; s=zohoarc; b=lqJcofV8TNFh4foqb1fMTOyn15b7FmGs0nNYzGJ4oJE2MAxrO6lpsTmq2R4CWNMOX7bVS90jzcBWWniyZfg4vXkfQlFktItcyPxbpOfhy+H13Vd0zhPIsIWuq19kSg4y3wCA9RDHjJa4EcU912MMeBgOAsgb9dzzEinqdRWT/rU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1571749999; 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; bh=K03TmnnENjscj6Dve89prE4p+s2/+KuOSmaoIwIJ9Hw=; b=RKKOFakJnqmxxfb5LD1b6OQYc0KGZOsi8vusiHFj4wuQ1UCdwu/y8LI+oCEPosEQ9dRUPd185ft0DD93t24sFF5pvRmpPTfeBl8Id5xIzgPxpGJQ6/xzt4OqtKo3Rxo7erNVWfay6vKqET9QOFTpeTQP9ihapfKfpazdI2Mz+k4= 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 (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1571749999952708.7264167976952; Tue, 22 Oct 2019 06:13:19 -0700 (PDT) Received: from localhost ([::1]:56304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMtyQ-0005jw-QD for importer@patchew.org; Tue, 22 Oct 2019 09:13:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58618) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iMtkW-0006zz-Pb for qemu-devel@nongnu.org; Tue, 22 Oct 2019 08:58:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iMtkV-0006Sw-H8 for qemu-devel@nongnu.org; Tue, 22 Oct 2019 08:58:56 -0400 Received: from relay.sw.ru ([185.231.240.75]:55212) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1iMtkM-0006KJ-Kp; Tue, 22 Oct 2019 08:58:47 -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 1iMtkI-0003xx-KY; Tue, 22 Oct 2019 15:58:42 +0300 From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org Subject: [PATCH v2 09/10] nbd/server: use bdrv_dirty_bitmap_next_dirty_area Date: Tue, 22 Oct 2019 15:58:38 +0300 Message-Id: <20191022125839.12633-10-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20191022125839.12633-1-vsementsov@virtuozzo.com> References: <20191022125839.12633-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, 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 | 59 +++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index 650eebcfff..5a6aa6376a 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2044,57 +2044,36 @@ 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. - */ +/* Populate @ea from a dirty bitmap. */ 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, @@ -2105,7 +2084,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