From nobody Fri Nov 7 02:12:27 2025 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; dkim=fail; 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; dmarc=fail(p=none dis=none) header.from=163.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1546423380873961.1595817541723; Wed, 2 Jan 2019 02:03:00 -0800 (PST) Received: from localhost ([127.0.0.1]:43384 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gedMO-0006UF-F5 for importer@patchew.org; Wed, 02 Jan 2019 05:02:48 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gedLO-0005uu-Rz for qemu-devel@nongnu.org; Wed, 02 Jan 2019 05:01:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gedLN-0007iI-P6 for qemu-devel@nongnu.org; Wed, 02 Jan 2019 05:01:46 -0500 Received: from m50-138.163.com ([123.125.50.138]:32822) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gedLF-0007PP-L5; Wed, 02 Jan 2019 05:01:39 -0500 Received: from localhost.localdomain (unknown [111.202.166.3]) by smtp1 (Coremail) with SMTP id C9GowAAHHQ3siyxcytNMDQ--.80S3; Wed, 02 Jan 2019 18:01:25 +0800 (CST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id; bh=Gwl9jH1rphgbKKmzKx RbVOXuohTdZ3ilQbpnpd8fEME=; b=Kcy0JkjvJkSJ4X0+wM1SzBZsig5Nx7AzHA gMEjgyInnnZfTRtB9GpdIcg2r1sPBD+9mP/nzJEoQFh9BNsNIr39luS61LAJluIs +dVZAOYlKwnHnUUGayz7D8mcOG7VM/vEhqK9Qh1mUfULsuo4WlcfbXxmFSmT61HX E64ABbhSw= From: mahaocong To: qemu-block@nongnu.org Date: Wed, 2 Jan 2019 18:01:13 +0800 Message-Id: <20190102100113.24621-1-mahaocong_work@163.com> X-Mailer: git-send-email 2.14.3 (Apple Git-98) X-CM-TRANSID: C9GowAAHHQ3siyxcytNMDQ--.80S3 X-Coremail-Antispam: 1Uf129KBjvJXoWxZFyDZr17uw48XF13tw18Xwb_yoW5ZFW8pF 1qyrn5Kry5Kr13Xr1fCry7ZF45trs5KwnxGryfW3WFkF1UXrn3Wr4kCFy8Aw4rGrnxJFs0 vFs8Gry8CF1SqrJanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jdyCLUUUUU= X-Originating-IP: [111.202.166.3] X-CM-SenderInfo: 5pdkt05frqwspzruyqqrwthudrp/xtbB0BYwClUMGbB0EgAAsq X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 123.125.50.138 Subject: [Qemu-devel] [PATCH v1] add new function to copy 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: fam@euphon.net, kwolf@redhat.com, mahaocong , qemu-devel@nongnu.org, mreitz@redhat.com, jsnow@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: mahaocong This patch adds new function to copy the hbitmap from an exist dirty-bitmap= to another. The destination bitmap should have the same size and granularity w= ith the source bitmap, or the copy will fail. Signed-off-by: mahaocong --- block/dirty-bitmap.c | 14 ++++++++++++++ include/block/dirty-bitmap.h | 3 +++ include/qemu/hbitmap.h | 2 ++ util/hbitmap.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 47 insertions(+) diff --git a/block/dirty-bitmap.c b/block/dirty-bitmap.c index 89fd1d7f8b..4445182e2a 100644 --- a/block/dirty-bitmap.c +++ b/block/dirty-bitmap.c @@ -348,6 +348,20 @@ BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriver= State *bs, return ret; } =20 +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BdrvDirtyBitmap *src, + BdrvDirtyBitmap *dest, + Error **errp) +{ + qemu_mutex_lock(src->mutex); + if (!hbitmap_copy(dest->bitmap, src->bitmap)) { + error_setg(errp, "Error: copy src bitmap failed"); + return NULL; + } + qemu_mutex_unlock(src->mutex); + + return dest; +} + /** * Truncates _all_ bitmaps attached to a BDS. * Called with BQL taken. diff --git a/include/block/dirty-bitmap.h b/include/block/dirty-bitmap.h index 8f38a3dec1..ae2e82f44b 100644 --- a/include/block/dirty-bitmap.h +++ b/include/block/dirty-bitmap.h @@ -21,6 +21,9 @@ BdrvDirtyBitmap *bdrv_dirty_bitmap_abdicate(BlockDriverSt= ate *bs, BdrvDirtyBitmap *bdrv_reclaim_dirty_bitmap(BlockDriverState *bs, BdrvDirtyBitmap *bitmap, Error **errp); +BdrvDirtyBitmap *bdrv_copy_dirty_bitmap(BdrvDirtyBitmap *src, + BdrvDirtyBitmap *dest, + Error **errp); void bdrv_dirty_bitmap_enable_successor(BdrvDirtyBitmap *bitmap); BdrvDirtyBitmap *bdrv_find_dirty_bitmap(BlockDriverState *bs, const char *name); diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index a7cb780592..6de3b4eb7e 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -91,6 +91,8 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b, HB= itmap *result); */ bool hbitmap_can_merge(const HBitmap *a, const HBitmap *b); =20 +bool hbitmap_copy(HBitmap *dst, const HBitmap *src); + /** * hbitmap_empty: * @hb: HBitmap to operate on. diff --git a/util/hbitmap.c b/util/hbitmap.c index 8d402c59d9..7ae2fc270c 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -765,6 +765,34 @@ bool hbitmap_merge(const HBitmap *a, const HBitmap *b,= HBitmap *result) return true; } =20 +/* + * Copy HBitmaps form src to dst. + * + * @return true if the copy was successful, + * false if it was not attempted. + */ +bool hbitmap_copy(HBitmap *dst, const HBitmap *src) +{ + int i; + + if ((dst->size !=3D src->size) || (dst->granularity !=3D src->granular= ity)) { + return false; + } + + if (hbitmap_count(src) =3D=3D 0) { + return true; + } + + for (i =3D HBITMAP_LEVELS - 1; i >=3D 0; i--) { + memcpy(dst->levels[i], src->levels[i], + src->sizes[i] * sizeof(unsigned long)); + } + + dst->count =3D src->count; + return true; +} + + HBitmap *hbitmap_create_meta(HBitmap *hb, int chunk_size) { assert(!(chunk_size & (chunk_size - 1))); --=20 2.14.1