From nobody Mon Feb 9 10:58:34 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=1562192267; cv=none; d=zoho.com; s=zohoarc; b=l2l6QbFMwtlOtLrgBnvzj4YhLcPT1YuNL0x4eXYxaoJJo9W7Pk3QIBty6ySo4vwWniuTcp2zDiH122vGuZyc1dZ6MdYTP6WGgkMCDsoH5jHWHw32sSOZxIM8pwdYbpbQCPPxlPKCE2vXAcdOl29LvCoIYDVTJMVRCAl3Awri0EA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1562192267; 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=Gd8sFTf9UWivjyacZLEKZ8gaS/dLAbg0rYQFjSA/4Bs=; b=IpPtun8SCdnJEMQ/oAYFwePIYDy4jCcm5GmHg0STlucyWlnqUWGujPLr1a2qdlr/djowGUhkIByNKst2aqIsv7ysXYfL3sxKr650om9sXGbMXjoBUX+fT+VoUDIQ7A6T7t3nC6KC9M2gEnpD9hT53BxaYF5R+JaaajLBHo7d3TQ= 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 156219226774250.32128593490586; Wed, 3 Jul 2019 15:17:47 -0700 (PDT) Received: from localhost ([::1]:41412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hinZM-0005Mr-Pr for importer@patchew.org; Wed, 03 Jul 2019 18:17:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46274) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1hinFF-0005ws-NY for qemu-devel@nongnu.org; Wed, 03 Jul 2019 17:56:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hinFD-0004Jv-Nm for qemu-devel@nongnu.org; Wed, 03 Jul 2019 17:56:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43304) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hinEw-00047a-6h; Wed, 03 Jul 2019 17:56:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75C08C01F28C; Wed, 3 Jul 2019 21:56:33 +0000 (UTC) Received: from probe.redhat.com (ovpn-123-117.rdu2.redhat.com [10.10.123.117]) by smtp.corp.redhat.com (Postfix) with ESMTP id E8C595235E; Wed, 3 Jul 2019 21:56:28 +0000 (UTC) From: John Snow To: qemu-block@nongnu.org, qemu-devel@nongnu.org Date: Wed, 3 Jul 2019 17:55:33 -0400 Message-Id: <20190703215542.16123-10-jsnow@redhat.com> In-Reply-To: <20190703215542.16123-1-jsnow@redhat.com> References: <20190703215542.16123-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 03 Jul 2019 21:56:33 +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 v2 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 , Markus Armbruster , "Dr. David Alan Gilbert" , Stefan Hajnoczi , Wen Congyang , Max Reitz 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 --- block/dirty-bitmap.c | 51 +++++++++++++++++++++++++++++++++------ include/block/block_int.h | 3 +++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 95a9c2a5d8..b0f76826b3 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -810,11 +810,15 @@ bool bdrv_dirty_bitmap_next_dirty_area(BdrvDirtyBitma= p *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) { - bool ret; - qemu_mutex_lock(dest->mutex); if (src->mutex !=3D dest->mutex) { qemu_mutex_lock(src->mutex); @@ -833,6 +837,37 @@ void bdrv_merge_dirty_bitmap(BdrvDirtyBitmap *dest, co= nst BdrvDirtyBitmap *src, goto out; } =20 + assert(bdrv_dirty_bitmap_merge_internal(dest, src, backup, false)); + +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; + + 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 +875,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