From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46901) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwEDr-0003IE-9X for qemu-devel@nongnu.org; Wed, 03 Dec 2014 13:00:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XwEDk-0007QP-Tl for qemu-devel@nongnu.org; Wed, 03 Dec 2014 13:00:19 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51162) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwEDk-0007Q0-Ka for qemu-devel@nongnu.org; Wed, 03 Dec 2014 13:00:12 -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 sB3I0ADk007501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 3 Dec 2014 13:00:11 -0500 Message-ID: <547F4FA4.8000105@redhat.com> Date: Wed, 03 Dec 2014 11:00:04 -0700 From: Eric Blake MIME-Version: 1.0 References: <1417613866-25890-1-git-send-email-mreitz@redhat.com> <1417613866-25890-10-git-send-email-mreitz@redhat.com> In-Reply-To: <1417613866-25890-10-git-send-email-mreitz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="coDNTPXcOVmSETM6Ef7NQtgiUSIVhX2oi" Subject: Re: [Qemu-devel] [PATCH v4 09/26] qcow2: Helper for refcount array reallocation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --coDNTPXcOVmSETM6Ef7NQtgiUSIVhX2oi Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 12/03/2014 06:37 AM, Max Reitz wrote: > Add a helper function for reallocating a refcount array, independent of= > the refcount order. The newly allocated space is zeroed and the functio= n > handles failed reallocations gracefully. >=20 > The helper function will always align the buffer size to a cluster > boundary; if storing the refcounts in such an array in big endian byte > order, this makes it possible to write parts of the array directly as > refcount blocks into the image file. >=20 > Signed-off-by: Max Reitz > --- > block/qcow2-refcount.c | 137 +++++++++++++++++++++++++++++++----------= -------- > 1 file changed, 88 insertions(+), 49 deletions(-) >=20 > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index 152ca22..8bb5167 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -1130,6 +1130,70 @@ fail: > /* refcount checking functions */ > =20 > =20 > +static size_t refcount_array_byte_size(BDRVQcowState *s, uint64_t entr= ies) > +{ > + if (s->refcount_order < 3) { > + /* sub-byte width */ > + int shift =3D 3 - s->refcount_order; > + return (entries + (1 << shift) - 1) >> shift; Bikeshedding: Should this use DIV_ROUND_UP(entries, 1 << shift)? Either way, Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --coDNTPXcOVmSETM6Ef7NQtgiUSIVhX2oi Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 Comment: Public key at http://people.redhat.com/eblake/eblake.gpg iQEcBAEBCAAGBQJUf0+kAAoJEKeha0olJ0NqIOUH/jYxaL/cz5qN3DJ8CmUu1Bpd y//qzKf853ubC/IVFoFuwy/xDaib3BMc3GnCFP74NLLCCyZNVRuG3VumcSQi9bFY bay+hhS3P7NT3+kod21ADniI5qvBlrnEzXgZNr1jVJ3+vQBE9pt8Jtm3GPwcgdCM g586ila4E4KWBgdbMBUr6sV93zYim4JxfHx1+SEi0MIeQLGy/yNaxthb4wooxz/B q5uYpOl/pNqQmGd3W4l3IsQJEboyFTU10CI9ew/YvFFC109FRi2PtVwOiN+pLYM8 Ye7BUqbbTwPALjBgXHf0cegBy+xNn6iBs6qvWK0fwYG7nKD2xcNHAqiotHKIAgM= =4bw/ -----END PGP SIGNATURE----- --coDNTPXcOVmSETM6Ef7NQtgiUSIVhX2oi--