From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34361) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YdfJR-000587-4C for qemu-devel@nongnu.org; Thu, 02 Apr 2015 09:37:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YdfJQ-0002ug-5j for qemu-devel@nongnu.org; Thu, 02 Apr 2015 09:37:37 -0400 Date: Thu, 2 Apr 2015 14:37:24 +0100 From: Stefan Hajnoczi Message-ID: <20150402133724.GJ25244@stefanha-thinkpad.redhat.com> References: <1426879023-18151-1-git-send-email-jsnow@redhat.com> <1426879023-18151-16-git-send-email-jsnow@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="q5r20fdKX+PFtYHw" Content-Disposition: inline In-Reply-To: <1426879023-18151-16-git-send-email-jsnow@redhat.com> Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v4 15/20] block: Resize bitmaps on bdrv_truncate List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: John Snow Cc: famz@redhat.com, qemu-block@nongnu.org, qemu-devel@nongnu.org, armbru@redhat.com, vsementsov@parallels.com, stefanha@redhat.com, mreitz@redhat.com --q5r20fdKX+PFtYHw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Fri, Mar 20, 2015 at 03:16:58PM -0400, John Snow wrote: > +void hbitmap_truncate(HBitmap *hb, uint64_t size) > +{ > + bool shrink; > + unsigned i; > + uint64_t num_elements = size; > + uint64_t old; > + > + /* Size comes in as logical elements, adjust for granularity. */ > + size = (size + (1ULL << hb->granularity) - 1) >> hb->granularity; > + assert(size <= ((uint64_t)1 << HBITMAP_LOG_MAX_SIZE)); > + shrink = size < hb->size; > + > + /* bit sizes are identical; nothing to do. */ > + if (size == hb->size) { > + return; > + } > + > + /* If we're losing bits, let's clear those bits before we invalidate all of > + * our invariants. This helps keep the bitcount consistent, and will prevent > + * us from carrying around garbage bits beyond the end of the map. > + * > + * Because clearing bits past the end of map might reset bits we care about > + * within the array, record the current value of the last bit we're keeping. > + */ > + if (shrink) { > + bool set = hbitmap_get(hb, num_elements - 1); > + uint64_t fix_count = (hb->size << hb->granularity) - num_elements; > + > + assert(fix_count); > + hbitmap_reset(hb, num_elements, fix_count); > + if (set) { > + hbitmap_set(hb, num_elements - 1, 1); > + } Why is it necessary to set the last bit (if it was set)? The comment isn't clear to me. --q5r20fdKX+PFtYHw Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAEBAgAGBQJVHUYUAAoJEJykq7OBq3PIAjMH/jWMD8K+bvARKICTg5sQHo9l GLV8W5zwj8jnkzziZAU8LRZv9juhocEg4++LFi5wJp2SeTMlIcT1uOty0Zod8HNn watNB37TlYDXrfUGuAnjuRAuho3tINP5eAqiyL5pSBiPNYdBRnZ9YohU9wxmyED9 O4nPRmQ9GexjDWwR8OJ7/di7T1BexHwPnKbrDHpBr1Et2whxoBZUu6vjQ+EDVf1p bfRSuCIGq17Z/EDPOIKUeOzw0EInWLS65b4d3UKzRoFMGohpNojajEahnXTh/bGy VKPWdpVxPSzNhAqcYin0nI++mDwnzl7WoaCqKJpL0pUiIrBbXrkkcTLop+DWoMQ= =RAIO -----END PGP SIGNATURE----- --q5r20fdKX+PFtYHw--