From nobody Mon Feb 9 08:10:35 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1562716155; cv=none; d=zoho.com; s=zohoarc; b=cPksCbTfwlHm535oDj0OCktszLWlsHMXrGKDMeha9KTGNh7GPqRelTufzeyPpLZDNrFmHkdlvjQNV3M76Kl24y6uRjRjzDe/ttbdne0uI8meScUas35zKKN7v96E0j35LqWDZxrCNxOzrK+558RHKe7ZT5Fu6kl40K0dY8e9hSk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562716155; 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:ARC-Authentication-Results; bh=+8EUmEVLRH/74ceQjm9Eio4Pcq3uhAd8WUjSh1yIIlI=; b=SXenGPJb4jb/RWO/v77gRv+Ua6CyunwJKJ7PToavnecnE0mw/9mEc6WpCEdqJuBbBfXWGvoJW1tBolH7+FTqpaHgFzve0nlpNQ8IZNfQOZRtjWX7Yn4Zz2YxfJ5y7co8qfqY3YYlwMgw2www9/nTea7HmCumszNqowcu62ieRj4= 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 1562716155583972.6409378225702; Tue, 9 Jul 2019 16:49:15 -0700 (PDT) Received: from localhost ([::1]:56890 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkzrC-0001lA-I6 for importer@patchew.org; Tue, 09 Jul 2019 19:49:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:49118) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hkzVX-0007OZ-Eo for qemu-devel@nongnu.org; Tue, 09 Jul 2019 19:26:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hkzVL-0003IO-CU for qemu-devel@nongnu.org; Tue, 09 Jul 2019 19:26:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37298) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hkzVD-0002mC-Sh; Tue, 09 Jul 2019 19:26:29 -0400 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3632FC05678B; Tue, 9 Jul 2019 23:26:15 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-215.bos.redhat.com [10.18.17.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id 369BE5B0BD; Tue, 9 Jul 2019 23:26:09 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Tue, 9 Jul 2019 19:25:41 -0400 Message-Id: <20190709232550.10724-10-jsnow@redhat.com> In-Reply-To: <20190709232550.10724-1-jsnow@redhat.com> References: <20190709232550.10724-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Tue, 09 Jul 2019 23:26:15 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v4 09/18] block/dirty-bitmap: add bdrv_dirty_bitmap_merge_internal 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: Kevin Wolf , Fam Zheng , vsementsov@virtuozzo.com, Juan Quintela , John Snow , Xie Changlong , "Dr. David Alan Gilbert" , Max Reitz , Stefan Hajnoczi , Wen Congyang , Markus Armbruster Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" I'm surprised it didn't come up sooner, but sometimes we have a +busy bitmap as a source. This is dangerous from the QMP API, but if we are the owner that marked the bitmap busy, it's safe to merge it using it as a read only source. It is not safe in the general case to allow users to read from in-use bitmaps, so create an internal variant that foregoes the safety checking. Signed-off-by: John Snow Reviewed-by: Max Reitz --- block/dirty-bitmap.c | 54 +++++++++++++++++++++++++++++++++++---- include/block/block_int.h | 3 +++ 2 files changed, 52 insertions(+), 5 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 95a9c2a5d8..7881fea684 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -810,6 +810,12 @@ bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitmap= *bitmap, return hbitmap_next_dirty_area(bitmap->bitmap, offset, bytes); } =20 +/** + * bdrv_merge_dirty_bitmap: merge src into dest. + * Ensures permissions on bitmaps are reasonable; use for public API. + * + * @backup: If provided, make a copy of dest here prior to merge. + */ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, const BdrvDirtyBitmap = *src, HBitmap **backup, Error **errp) { @@ -833,6 +839,42 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, co= nst BdrvDirtyBitmap *src, goto out; } =20 + ret =3D bdrv_dirty_bitmap_merge_internal(dest, src, backup, false); + assert(ret); + +out: + qemu_mutex_unlock(dest->mutex); + if (src->mutex !=3D dest->mutex) { + qemu_mutex_unlock(src->mutex); + } +} + +/** + * bdrv_dirty_bitmap_merge_internal: merge src into dest. + * Does NOT check bitmap permissions; not suitable for use as public API. + * + * @backup: If provided, make a copy of dest here prior to merge. + * @lock: If true, lock and unlock bitmaps on the way in/out. + * returns true if the merge succeeded; false if unattempted. + */ +bool bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest, + const BdrvDirtyBitmap *src, + HBitmap **backup, + bool lock) +{ + bool ret; + + assert(!bdrv_dirty_bitmap_readonly(dest)); + assert(!bdrv_dirty_bitmap_inconsistent(dest)); + assert(!bdrv_dirty_bitmap_inconsistent(src)); + + if (lock) { + qemu_mutex_lock(dest->mutex); + if (src->mutex !=3D dest->mutex) { + qemu_mutex_lock(src->mutex); + } + } + if (backup) { *backup =3D dest->bitmap; dest->bitmap =3D hbitmap_alloc(dest->size, hbitmap_granularity(*ba= ckup)); @@ -840,11 +882,13 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, c= onst BdrvDirtyBitmap *src, } else { ret =3D hbitmap_merge(dest->bitmap, src->bitmap, dest->bitmap); } - assert(ret); =20 -out: - qemu_mutex_unlock(dest->mutex); - if (src->mutex !=3D dest->mutex) { - qemu_mutex_unlock(src->mutex); + if (lock) { + qemu_mutex_unlock(dest->mutex); + if (src->mutex !=3D dest->mutex) { + qemu_mutex_unlock(src->mutex); + } } + + return ret; } diff --git a/include/block/block_int.h b/include/block/block_int.h index e1f2aa627e..83ffdf4950 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1238,6 +1238,9 @@ void bdrv_set_dirty(BlockDriverState *bs, int64_t off= set, int64_t bytes); =20 void bdrv_clear_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap **out); void bdrv_restore_dirty_bitmap(BdrvDirtyBitmap *bitmap, HBitmap *backup); +bool bdrv_dirty_bitmap_merge_internal(BdrvDirtyBitmap *dest, + const BdrvDirtyBitmap *src, + HBitmap **backup, bool lock); =20 void bdrv_inc_in_flight(BlockDriverState *bs); void bdrv_dec_in_flight(BlockDriverState *bs); --=20 2.21.0