From nobody Sun Apr 28 19:50:29 2024 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 (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 152206092883295.6536566593661; Mon, 26 Mar 2018 03:42:08 -0700 (PDT) Received: from localhost ([::1]:55772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0PZi-00081g-6p for importer@patchew.org; Mon, 26 Mar 2018 06:42:02 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40323) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1f0PYh-0007ct-JH for qemu-devel@nongnu.org; Mon, 26 Mar 2018 06:41:00 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1f0PYg-0005AB-GQ for qemu-devel@nongnu.org; Mon, 26 Mar 2018 06:40:59 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:47564 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1f0PYb-00053q-Vp; Mon, 26 Mar 2018 06:40:54 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C0A4A8424D; Mon, 26 Mar 2018 10:40:48 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-130.ams2.redhat.com [10.36.117.130]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8046111DCFA; Mon, 26 Mar 2018 10:40:43 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 26 Mar 2018 12:40:37 +0200 Message-Id: <20180326104037.6894-1-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 26 Mar 2018 10:40:48 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.2]); Mon, 26 Mar 2018 10:40:48 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'pbonzini@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2] block: simplify code around releasing bitmaps 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: Vladimir Sementsov-Ogievskiy , qemu-block@nongnu.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" QLIST_REMOVE does not require walking the list, and once the "bitmap" argument is removed from bdrv_do_release_matching_dirty_bitmap_locked the code simplifies a lot and it is worth inlining everything in the callers of bdrv_do_release_matching_dirty_bitmap. Reviewed-by: Vladimir Sementsov-Ogievskiy Signed-off-by: Paolo Bonzini Reviewed-by: John Snow --- Notes: v1->v2: improve locking comments [Vladimir] block/dirty-bitmap.c | 84 ++++++++++++++++++++----------------------------= ---- 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index ea82c06f07..a7eaa1051d 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -249,49 +249,16 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitm= ap *bitmap) qemu_mutex_unlock(bitmap->mutex); } =20 -/* Called within bdrv_dirty_bitmap_lock..unlock */ -static void bdrv_do_release_matching_dirty_bitmap_locked( - BlockDriverState *bs, BdrvDirtyBitmap *bitmap, - bool (*cond)(BdrvDirtyBitmap *bitmap)) +/* Called within bdrv_dirty_bitmap_lock..unlock and with BQL taken. */ +static void bdrv_release_dirty_bitmap_locked(BdrvDirtyBitmap *bitmap) { - BdrvDirtyBitmap *bm, *next; - - QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) { - if ((!bitmap || bm =3D=3D bitmap) && (!cond || cond(bm))) { - assert(!bm->active_iterators); - assert(!bdrv_dirty_bitmap_frozen(bm)); - assert(!bm->meta); - QLIST_REMOVE(bm, list); - hbitmap_free(bm->bitmap); - g_free(bm->name); - g_free(bm); - - if (bitmap) { - return; - } - } - } - - if (bitmap) { - abort(); - } -} - -/* Called with BQL taken. */ -static void bdrv_do_release_matching_dirty_bitmap( - BlockDriverState *bs, BdrvDirtyBitmap *bitmap, - bool (*cond)(BdrvDirtyBitmap *bitmap)) -{ - bdrv_dirty_bitmaps_lock(bs); - bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, cond); - bdrv_dirty_bitmaps_unlock(bs); -} - -/* Called within bdrv_dirty_bitmap_lock..unlock */ -static void bdrv_release_dirty_bitmap_locked(BlockDriverState *bs, - BdrvDirtyBitmap *bitmap) -{ - bdrv_do_release_matching_dirty_bitmap_locked(bs, bitmap, NULL); + assert(!bitmap->active_iterators); + assert(!bdrv_dirty_bitmap_frozen(bitmap)); + assert(!bitmap->meta); + QLIST_REMOVE(bitmap, list); + hbitmap_free(bitmap->bitmap); + g_free(bitmap->name); + g_free(bitmap); } =20 /** @@ -344,7 +311,7 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap_locked(Block= DriverState *bs, error_setg(errp, "Merging of parent and successor bitmap failed"); return NULL; } - bdrv_release_dirty_bitmap_locked(bs, successor); + bdrv_release_dirty_bitmap_locked(successor); parent->successor =3D NULL; =20 return parent; @@ -382,15 +349,12 @@ void bdrv_dirty_bitmap_truncate(BlockDriverState *bs,= int64_t bytes) bdrv_dirty_bitmaps_unlock(bs); } =20 -static bool bdrv_dirty_bitmap_has_name(BdrvDirtyBitmap *bitmap) -{ - return !!bdrv_dirty_bitmap_name(bitmap); -} - /* Called with BQL taken. */ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap) { - bdrv_do_release_matching_dirty_bitmap(bs, bitmap, NULL); + bdrv_dirty_bitmaps_lock(bs); + bdrv_release_dirty_bitmap_locked(bitmap); + bdrv_dirty_bitmaps_unlock(bs); } =20 /** @@ -401,7 +365,15 @@ void bdrv_release_dirty_bitmap(BlockDriverState *bs, B= drvDirtyBitmap *bitmap) */ void bdrv_release_named_dirty_bitmaps(BlockDriverState *bs) { - bdrv_do_release_matching_dirty_bitmap(bs, NULL, bdrv_dirty_bitmap_has_= name); + BdrvDirtyBitmap *bm, *next; + + bdrv_dirty_bitmaps_lock(bs); + QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) { + if (bdrv_dirty_bitmap_name(bm)) { + bdrv_release_dirty_bitmap_locked(bm); + } + } + bdrv_dirty_bitmaps_unlock(bs); } =20 /** @@ -409,11 +381,19 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverStat= e *bs) * bdrv_inactivate_recurse()). * There must not be any frozen bitmaps attached. * This function does not remove persistent bitmaps from the storage. + * Called with BQL taken. */ void bdrv_release_persistent_dirty_bitmaps(BlockDriverState *bs) { - bdrv_do_release_matching_dirty_bitmap(bs, NULL, - bdrv_dirty_bitmap_get_persistanc= e); + BdrvDirtyBitmap *bm, *next; + + bdrv_dirty_bitmaps_lock(bs); + QLIST_FOREACH_SAFE(bm, &bs->dirty_bitmaps, list, next) { + if (bdrv_dirty_bitmap_get_persistance(bm)) { + bdrv_release_dirty_bitmap_locked(bm); + } + } + bdrv_dirty_bitmaps_unlock(bs); } =20 /** --=20 2.16.2