From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOHCq-0003CX-WD for qemu-devel@nongnu.org; Wed, 18 Feb 2015 21:51:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YOHCm-0006WT-03 for qemu-devel@nongnu.org; Wed, 18 Feb 2015 21:51:12 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41232) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YOHCl-0006WH-Nz for qemu-devel@nongnu.org; Wed, 18 Feb 2015 21:51:07 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t1J2p6la031412 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 18 Feb 2015 21:51:06 -0500 Message-ID: <54E54F99.4030301@redhat.com> Date: Wed, 18 Feb 2015 19:51:05 -0700 From: Eric Blake MIME-Version: 1.0 References: <1424299260-1763-1-git-send-email-mreitz@redhat.com> <1424299260-1763-2-git-send-email-mreitz@redhat.com> In-Reply-To: <1424299260-1763-2-git-send-email-mreitz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="M4tdvoPna9EJcsjMvUNJ3wmCVQBdfJTqR" Subject: Re: [Qemu-devel] [PATCH v7 11/25] qcow2: refcount_order parameter for qcow2_create2 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) --M4tdvoPna9EJcsjMvUNJ3wmCVQBdfJTqR Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 02/18/2015 03:40 PM, Max Reitz wrote: > Add a refcount_order parameter to qcow2_create2(), use that value for > the image header and for calculating the size required for > preallocation. >=20 > For now, always pass 4. >=20 > This addition requires changes to the calculation of the file size for > the "full" and "falloc" preallocation modes. That in turn is a nice > opportunity to add a comment about that calculation not necessarily > being exact (and that being intentional). >=20 > Signed-off-by: Max Reitz > --- > block/qcow2.c | 47 ++++++++++++++++++++++++++++++++++++----------- > 1 file changed, 36 insertions(+), 11 deletions(-) >=20 > @@ -2010,6 +2022,8 @@ static int qcow2_create(const char *filename, Qem= uOpts *opts, Error **errp) > size_t cluster_size =3D DEFAULT_CLUSTER_SIZE; > PreallocMode prealloc; > int version =3D 3; > + uint64_t refcount_bits =3D 16; > + int refcount_order; > Error *local_err =3D NULL; > int ret; > =20 > @@ -2064,8 +2078,19 @@ static int qcow2_create(const char *filename, Qe= muOpts *opts, Error **errp) > goto finish; > } > =20 > + if (version < 3 && refcount_bits !=3D 16) { > + error_setg(errp, "Different refcount widths than 16 bits requi= re " > + "compatibility level 1.1 or above (use compat=3D1.1= or " > + "greater)"); > + ret =3D -EINVAL; > + goto finish; > + } > + > + refcount_order =3D ffs(refcount_bits) - 1; ffs() doesn't work on uint64_t (it gives the wrong answer for 0x100000000, for example); you want to use ffsll(). But ffsll() isn't portable. But we have include/qemu/host-utils.h that gives us ctz64() which is what we want (where ctz=3D=3Dffs-1 other than for the special ca= se of 0). So this should be: refcount_order =3D ctz64(refcount_bits); With that change, Reviewed-by: Eric Blake (Hmm, that means that at least qcow2.c:qcow2_create2() has a bug for calling ffs(size_t), and we probably ought to eradicate other uses of ffs from the tree - but as a separate followup). --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --M4tdvoPna9EJcsjMvUNJ3wmCVQBdfJTqR 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 Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/ iQEcBAEBCAAGBQJU5U+ZAAoJEKeha0olJ0NqDrYIAIhALNdQZsPcmjLFuZqWe5Xf LWi7Za3cdJgXXTJenoRHsCTNX0LU/XLiMQOlTnhHM/bh9z+Y2y+P+uxukL4LJcVh gZt7HApBJ+GtPls2BYHjowCM36tGb5EfMbBRPDSl8q7WWdbtVpZa2l0q55QXz/nC cO8xepA5w7awM3CTMpIJ9W2oJmEI/T9DZ7qP2EIgdYryNZIHPSwIFsFF+CV4ba/+ SGRzWCp0juVdBCCzjoLmsmrkBdLCheqsp47GVWCAmL1+6yI1FznbE8OVCJIMfNqC MsED4kkM1G1fthUm+f82ReD20z+99xODBpPV9EvJFEXOG0EHMulzs4NhP6PFZg8= =WJDG -----END PGP SIGNATURE----- --M4tdvoPna9EJcsjMvUNJ3wmCVQBdfJTqR--