From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56333) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WO5xA-0003VM-4G for qemu-devel@nongnu.org; Thu, 13 Mar 2014 09:45:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WO5x4-00056r-0p for qemu-devel@nongnu.org; Thu, 13 Mar 2014 09:45:44 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:56122 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WO5x3-00056Z-RT for qemu-devel@nongnu.org; Thu, 13 Mar 2014 09:45:37 -0400 Date: Thu, 13 Mar 2014 14:45:36 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140313134536.GE4534@irqsave.net> References: <1394605864-32237-1-git-send-email-famz@redhat.com> <1394605864-32237-6-git-send-email-famz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1394605864-32237-6-git-send-email-famz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2 5/9] hbitmap: Add hbitmap_copy List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Fam Zheng Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com The Wednesday 12 Mar 2014 =E0 14:31:00 (+0800), Fam Zheng wrote : > 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 granular= ity) > hb->levels[0][0] |=3D 1UL << (BITS_PER_LONG - 1); > return hb; > } > + > +HBitmap *hbitmap_copy(const HBitmap *bitmap) > +{ > + int i; > + HBitmap *hb =3D g_memdup(bitmap, sizeof(struct HBitmap)); > + > + for (i =3D HBITMAP_LEVELS; i-- > 0; ) { > + hb->levels[i] =3D g_memdup(bitmap->levels[i], > + bitmap->size * sizeof(unsigned long))= ; This feel wrong: struct HBitmap { /* Number of total bits in the bottom level. */ uint64_t size; The comment about size imply that size apply only to the bottom level. Moreover the bitmaps are progressivelly less coarse so I think the size y= ou use should goes down as you go up to the top. Best regards Beno=EEt > + } > + > + return hb; > +} > -- > 1.9.0 > >