From nobody Fri Nov 14 05:14:58 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) client-ip=216.205.24.74; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-74.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1584563190; cv=none; d=zohomail.com; s=zohoarc; b=BcW25s5W8kJUYB2YPodH2+ar2TtvmWkb6ywBIAtF0Xqz51wg7aqAE+bDTdS4LoSLlBM/Nfg1PxVL0CAaP+q0P0Q54NOPbHQEIzbg9RyapUdlfAPiTBBwSUYT0gRjBAHrovVvjKXYX+BCmI5m77Ye0N+DCWRxvtaVqQYiWhLkew0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1584563190; h=Content-Type: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=7S4pvEvRq43tAOJ+VoWTNYoKkV9GHiGO1EgDeCec5QM=; b=Knivk/i+5sSLqlo3/ByBjraNHttlZwRYVsgX77s+H4/wflhNefuzK334O9yYNTZmy/+BqQk1A/z0J+AcNpEcwa5HBoi1RzhhdLA0oFrT5e7QGBLTfZjvRXQTJVWQdkCTZtBhle3z/uX5hWtQzU7Vy3RQtlg7Q2ALrLmejn9qjEI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.74 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-74.mimecast.com (us-smtp-delivery-74.mimecast.com [216.205.24.74]) by mx.zohomail.com with SMTPS id 1584563190262570.4853211611663; Wed, 18 Mar 2020 13:26:30 -0700 (PDT) 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-77-xDsAdoRlMqWYAsKyZ0XOvw-1; Wed, 18 Mar 2020 16:26:26 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A4BE8113784F; Wed, 18 Mar 2020 20:26:20 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 719535DA7C; Wed, 18 Mar 2020 20:26:20 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2AF461804744; Wed, 18 Mar 2020 20:26:20 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 02IKPEAJ004710 for ; Wed, 18 Mar 2020 16:25:14 -0400 Received: by smtp.corp.redhat.com (Postfix) id 46BD260C84; Wed, 18 Mar 2020 20:25:14 +0000 (UTC) Received: from probe.redhat.com (ovpn-112-191.rdu2.redhat.com [10.10.112.191]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0615B60BF1; Wed, 18 Mar 2020 20:25:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1584563189; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=7S4pvEvRq43tAOJ+VoWTNYoKkV9GHiGO1EgDeCec5QM=; b=Ti2krzlr5UTkjcicynupNJzrN7pGqA5ajLx1T5TGSamTTJ+qktSLCSAFBnqcOKMZ4Nn8bT 4OwkMbaNLkw0nXmlGSwn4BAVFKuW9KT1fI0qpr/IFwqGp38EES7GCFd6BL1pGW09GUxH7u Gc509yYakEJSxm/KYCfNwE7lIGKjwHk= X-MC-Unique: xDsAdoRlMqWYAsKyZ0XOvw-1 From: John Snow To: qemu-devel@nongnu.org, jsnow@redhat.com, Peter Maydell Subject: [PULL v2 10/11] nbd/server: use bdrv_dirty_bitmap_next_dirty_area Date: Wed, 18 Mar 2020 16:23:40 -0400 Message-Id: <20200318202341.6961-11-jsnow@redhat.com> In-Reply-To: <20200318202341.6961-1-jsnow@redhat.com> References: <20200318202341.6961-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: Kevin Wolf , Fam Zheng , Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.org, Juan Quintela , libvir-list@redhat.com, Max Reitz , Stefan Hajnoczi , "Dr. David Alan Gilbert" X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" From: Vladimir Sementsov-Ogievskiy 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 Message-id: 20200205112041.6003-10-vsementsov@virtuozzo.com Signed-off-by: John Snow --- nbd/server.c | 59 +++++++++++++++++----------------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/nbd/server.c b/nbd/server.c index f90bb33a75..02b1ed0801 100644 --- a/nbd/server.c +++ b/nbd/server.c @@ -2068,57 +2068,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, @@ -2129,7 +2108,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.1