From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50094) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtbmO-00008j-BR for qemu-devel@nongnu.org; Wed, 26 Nov 2014 07:33:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XtbmI-0002Cd-76 for qemu-devel@nongnu.org; Wed, 26 Nov 2014 07:33:08 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52546) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XtbmH-0002CY-UT for qemu-devel@nongnu.org; Wed, 26 Nov 2014 07:33:02 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sAQCX1sc024490 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 26 Nov 2014 07:33:01 -0500 Message-ID: <5475C87A.6080200@redhat.com> Date: Wed, 26 Nov 2014 13:32:58 +0100 From: Max Reitz MIME-Version: 1.0 References: <1416944800-17919-1-git-send-email-jsnow@redhat.com> <1416944800-17919-5-git-send-email-jsnow@redhat.com> In-Reply-To: <1416944800-17919-5-git-send-email-jsnow@redhat.com> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [2.3 PATCH v7 04/10] hbitmap: Add hbitmap_copy List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow , qemu-devel@nongnu.org Cc: Fam Zheng On 2014-11-25 at 20:46, John Snow wrote: > From: Fam Zheng > > This makes a deep copy of an HBitmap. > > Signed-off-by: Fam Zheng > Signed-off-by: John Snow > --- > include/qemu/hbitmap.h | 8 ++++++++ > util/hbitmap.c | 16 ++++++++++++++++ > 2 files changed, 24 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 b3060e6..eddc05b 100644 > --- a/util/hbitmap.c > +++ b/util/hbitmap.c > @@ -395,3 +395,19 @@ 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; > + uint64_t size; > + HBitmap *hb = g_memdup(bitmap, sizeof(HBitmap)); > + > + size = bitmap->size; > + for (i = HBITMAP_LEVELS; i >= 0; i--) { Should be HBITMAP_LEVELS - 1. Max > + size = MAX((size + BITS_PER_LONG - 1) >> BITS_PER_LEVEL, 1); > + hb->levels[i] = g_memdup(bitmap->levels[i], > + size * sizeof(unsigned long)); > + } > + > + return hb; > +}