From nobody Sun Feb 8 05:35:19 2026 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 1513785740287400.3621174695144; Wed, 20 Dec 2017 08:02:20 -0800 (PST) Received: from localhost ([::1]:56950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRgox-0005sH-92 for importer@patchew.org; Wed, 20 Dec 2017 11:02:15 -0500 Received: from eggs.gnu.org ([208.118.235.92]:35035) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eRgd5-0003uh-Ou for qemu-devel@nongnu.org; Wed, 20 Dec 2017 10:50:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eRgd1-0005da-9y for qemu-devel@nongnu.org; Wed, 20 Dec 2017 10:49:58 -0500 Received: from mailhub.sw.ru ([195.214.232.25]:40958 helo=relay.sw.ru) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eRgd0-0005YY-Li; Wed, 20 Dec 2017 10:49:55 -0500 Received: from kvm.sw.ru (msk-vpn.virtuozzo.com [195.214.232.6]) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id vBJIs81A000254; Tue, 19 Dec 2017 21:54:10 +0300 (MSK) From: Vladimir Sementsov-Ogievskiy To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Wed, 20 Dec 2017 18:49:34 +0300 Message-Id: <20171220154945.88410-3-vsementsov@virtuozzo.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20171220154945.88410-1-vsementsov@virtuozzo.com> References: <20171220154945.88410-1-vsementsov@virtuozzo.com> X-detected-operating-system: by eggs.gnu.org: OpenBSD 3.x [fuzzy] X-Received-From: 195.214.232.25 Subject: [Qemu-devel] [PATCH v9 02/13] block/dirty-bitmap: fix locking in bdrv_reclaim_dirty_bitmap 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: kwolf@redhat.com, peter.maydell@linaro.org, vsementsov@virtuozzo.com, famz@redhat.com, lirans@il.ibm.com, quintela@redhat.com, jsnow@redhat.com, armbru@redhat.com, mreitz@redhat.com, stefanha@redhat.com, den@openvz.org, amit.shah@redhat.com, pbonzini@redhat.com, dgilbert@redhat.com 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" Like other setters here these functions should take a lock. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Fam Zheng --- block/dirty-bitmap.c | 85 ++++++++++++++++++++++++++++++++----------------= ---- 1 file changed, 53 insertions(+), 32 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 81adbeb6d4..d83da077d5 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -245,6 +245,51 @@ void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitma= p *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)) +{ + 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); +} + /** * For a bitmap with a successor, yield our name to the successor, * delete the old bitmap, and return a handle to the new bitmap. @@ -286,7 +331,11 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriver= State *bs, BdrvDirtyBitmap *parent, Error **errp) { - BdrvDirtyBitmap *successor =3D parent->successor; + BdrvDirtyBitmap *successor; + + qemu_mutex_lock(parent->mutex); + + successor =3D parent->successor; =20 if (!successor) { error_setg(errp, "Cannot reclaim a successor when none is present"= ); @@ -297,9 +346,11 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriver= State *bs, error_setg(errp, "Merging of parent and successor bitmap failed"); return NULL; } - bdrv_release_dirty_bitmap(bs, successor); + bdrv_release_dirty_bitmap_locked(bs, successor); parent->successor =3D NULL; =20 + qemu_mutex_unlock(parent->mutex); + return parent; } =20 @@ -327,36 +378,6 @@ static bool bdrv_dirty_bitmap_has_name(BdrvDirtyBitmap= *bitmap) } =20 /* Called with BQL taken. */ -static void bdrv_do_release_matching_dirty_bitmap( - BlockDriverState *bs, BdrvDirtyBitmap *bitmap, - bool (*cond)(BdrvDirtyBitmap *bitmap)) -{ - BdrvDirtyBitmap *bm, *next; - bdrv_dirty_bitmaps_lock(bs); - 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) { - goto out; - } - } - } - if (bitmap) { - abort(); - } - -out: - bdrv_dirty_bitmaps_unlock(bs); -} - -/* Called with BQL taken. */ void bdrv_release_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitm= ap) { bdrv_do_release_matching_dirty_bitmap(bs, bitmap, NULL); --=20 2.11.1