From nobody Mon Apr 29 12:19:07 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 (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1521823482032248.76655880530893; Fri, 23 Mar 2018 09:44:42 -0700 (PDT) Received: from localhost ([::1]:38994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezPnu-0000zz-7T for importer@patchew.org; Fri, 23 Mar 2018 12:44:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50086) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ezPmZ-00007W-8u for qemu-devel@nongnu.org; Fri, 23 Mar 2018 12:43:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ezPmY-0000re-7i for qemu-devel@nongnu.org; Fri, 23 Mar 2018 12:43:11 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:56372 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 1ezPmU-0000mB-4J; Fri, 23 Mar 2018 12:43:06 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 8BCFC40201A6; Fri, 23 Mar 2018 16:43:01 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-117-73.ams2.redhat.com [10.36.117.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id C8B592023233; Fri, 23 Mar 2018 16:43:00 +0000 (UTC) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Fri, 23 Mar 2018 17:42:54 +0100 Message-Id: <20180323164254.26487-2-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 23 Mar 2018 16:43:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Fri, 23 Mar 2018 16:43:01 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.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] 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. Signed-off-by: Paolo Bonzini Reviewed-by: Vladimir Sementsov-Ogievskiy --- block/dirty-bitmap.c | 81 +++++++++++++++++++-----------------------------= ---- 1 file changed, 30 insertions(+), 51 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 13bb5066a4..c0fb49bf7b 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -250,48 +250,15 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitm= ap *bitmap) } =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)) +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 /** @@ -412,8 +384,15 @@ void bdrv_release_named_dirty_bitmaps(BlockDriverState= *bs) */ 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