From nobody Tue Nov 11 22:33:48 2025 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=1565997644; cv=none; d=zoho.com; s=zohoarc; b=EePbCDU8SQToCtqeFFshiIXtEbXUDxO3kj3tMLxWbW0Dy716Ph8nop7sEoqmI2x+Ht71UeEAJrEhSxJdzRDRt6vjg5dD2lIZ27L/Cb6rNr1KMz+pFB4ZVPrm/aCrk2+Vq+kOFnYJvI+W/h8mlo7D8btRS1fyJLgKX/E729jStFI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1565997644; 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=19Df0IRpptohRw5w8NxZ+vepVNT36dlUpUqsuQk0WQc=; b=R8kkTw84YkPOZQge9vQ2j/WzbtOIjpJ4vkLOKpEOAykOMS4yl3aXvRT8BSkXiCvnDcEE3eCn0DF/As3NdUx5DjpDNdeGQYPUkHuHWci7lifB5GVC2YFD44i4R0vBOg3rvFxBr/OIu7lOwXYovLoWOkY5/eAQBwf2KWOwBr+WEvI= 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 1565997644098928.7683915331601; Fri, 16 Aug 2019 16:20:44 -0700 (PDT) Received: from localhost ([::1]:33126 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hylWU-0005mi-MN for importer@patchew.org; Fri, 16 Aug 2019 19:20:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46212) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1hylPc-0006HZ-DW for qemu-devel@nongnu.org; Fri, 16 Aug 2019 19:13:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1hylPa-0005lq-E8 for qemu-devel@nongnu.org; Fri, 16 Aug 2019 19:13:36 -0400 Received: from mx1.redhat.com ([209.132.183.28]:36006) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1hylPX-0005gY-3a; Fri, 16 Aug 2019 19:13:31 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 551A53DFCD; Fri, 16 Aug 2019 23:13:30 +0000 (UTC) Received: from probe.bos.redhat.com (dhcp-17-187.bos.redhat.com [10.18.17.187]) by smtp.corp.redhat.com (Postfix) with ESMTP id A173919C6A; Fri, 16 Aug 2019 23:13:29 +0000 (UTC) From: John Snow To: qemu-devel@nongnu.org Date: Fri, 16 Aug 2019 19:12:51 -0400 Message-Id: <20190816231318.8650-10-jsnow@redhat.com> In-Reply-To: <20190816231318.8650-1-jsnow@redhat.com> References: <20190816231318.8650-1-jsnow@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 16 Aug 2019 23:13:30 +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] [PULL 09/36] 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: peter.maydell@linaro.org, jsnow@redhat.com, qemu-stable@nongnu.org, qemu-block@nongnu.org, 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 Reviewed-by: Max Reitz Message-id: 20190709232550.10724-10-jsnow@redhat.com Signed-off-by: John Snow --- 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 95a9c2a5d8a..7881fea684b 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 80953ac8aeb..aa697f1f694 100644 --- a/include/block/block_int.h +++ b/include/block/block_int.h @@ -1253,6 +1253,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