From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45187) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNchD-0003oM-P3 for qemu-devel@nongnu.org; Wed, 12 Mar 2014 02:31:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNch7-0000SX-Cg for qemu-devel@nongnu.org; Wed, 12 Mar 2014 02:31:19 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6076) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNch7-0000ST-5L for qemu-devel@nongnu.org; Wed, 12 Mar 2014 02:31:13 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2C6VCDH012693 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 12 Mar 2014 02:31:12 -0400 From: Fam Zheng Date: Wed, 12 Mar 2014 14:31:00 +0800 Message-Id: <1394605864-32237-6-git-send-email-famz@redhat.com> In-Reply-To: <1394605864-32237-1-git-send-email-famz@redhat.com> References: <1394605864-32237-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v2 5/9] hbitmap: Add hbitmap_copy List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com This makes a deep copy of an HBitmap. Signed-off-by: Fam Zheng --- include/qemu/hbitmap.h | 8 ++++++++ util/hbitmap.c | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/qemu/hbitmap.h b/include/qemu/hbitmap.h index 550d7ce..b645cfc 100644 --- a/include/qemu/hbitmap.h +++ b/include/qemu/hbitmap.h @@ -65,6 +65,14 @@ struct HBitmapIter { HBitmap *hbitmap_alloc(uint64_t size, int granularity); /** + * hbitmap_copy: + * @bitmap: The original bitmap to copy. + * + * Copy a HBitmap. + */ +HBitmap *hbitmap_copy(const HBitmap *bitmap); + +/** * hbitmap_empty: * @hb: HBitmap to operate on. * diff --git a/util/hbitmap.c b/util/hbitmap.c index d936831..cf670c7 100644 --- a/util/hbitmap.c +++ b/util/hbitmap.c @@ -400,3 +400,16 @@ HBitmap *hbitmap_alloc(uint64_t size, int granularity) hb->levels[0][0] |= 1UL << (BITS_PER_LONG - 1); return hb; } + +HBitmap *hbitmap_copy(const HBitmap *bitmap) +{ + int i; + HBitmap *hb = g_memdup(bitmap, sizeof(struct HBitmap)); + + for (i = HBITMAP_LEVELS; i-- > 0; ) { + hb->levels[i] = g_memdup(bitmap->levels[i], + bitmap->size * sizeof(unsigned long)); + } + + return hb; +} -- 1.9.0