From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43367) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xpgk2-0003ZX-4Q for qemu-devel@nongnu.org; Sat, 15 Nov 2014 12:02:35 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xpgjx-00069h-2g for qemu-devel@nongnu.org; Sat, 15 Nov 2014 12:02:30 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42894) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xpgjw-00069I-Sk for qemu-devel@nongnu.org; Sat, 15 Nov 2014 12:02:25 -0500 Message-ID: <54678719.40208@redhat.com> Date: Sat, 15 Nov 2014 10:02:17 -0700 From: Eric Blake MIME-Version: 1.0 References: <1415970374-16811-1-git-send-email-mreitz@redhat.com> <1415970374-16811-8-git-send-email-mreitz@redhat.com> In-Reply-To: <1415970374-16811-8-git-send-email-mreitz@redhat.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="bGB6it5PApRCc9JSUalpAsBp8cwWsJt18" Subject: Re: [Qemu-devel] [PATCH v2 07/21] qcow2: Helper function for refcount modification List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz , qemu-devel@nongnu.org Cc: Kevin Wolf , Peter Lieven , Stefan Hajnoczi This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --bGB6it5PApRCc9JSUalpAsBp8cwWsJt18 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On 11/14/2014 06:06 AM, Max Reitz wrote: > Since refcounts do not always have to be a uint16_t, all refcount block= s > and arrays in memory should not have a specific type (thus they become > pointers to void) and for accessing them, two helper functions are used= > (a getter and a setter). Those functions are called indirectly through > function pointers in the BDRVQcowState so they may later be exchanged > for different refcount orders. >=20 > Signed-off-by: Max Reitz > --- > block/qcow2-refcount.c | 128 ++++++++++++++++++++++++++++++-----------= -------- > block/qcow2.h | 8 ++++ > 2 files changed, 87 insertions(+), 49 deletions(-) >=20 > @@ -1216,7 +1249,7 @@ enum { > * error occurred. > */ > static int check_refcounts_l2(BlockDriverState *bs, BdrvCheckResult *r= es, > - uint16_t **refcount_table, int64_t *refcount_table_size, int64_t l= 2_offset, > + void **refcount_table, int64_t *refcount_table_size, int64_t l2_of= fset, > int flags) > { Might be worth fixing the indentation here in addition to all the other places you adjusted. But that's minor. > @@ -1933,17 +1967,13 @@ write_refblocks: > goto fail; > } > =20 > - on_disk_refblock =3D qemu_blockalign0(bs->file, s->cluster_siz= e); > - for (i =3D 0; i < s->refcount_block_size && > - refblock_start + i < *nb_clusters; i++) > - { > - on_disk_refblock[i] =3D > - cpu_to_be16((*refcount_table)[refblock_start + i]); > - } > + /* The size of *refcount_table is always cluster-aligned, ther= efore the > + * write operation will not overflow */ > + on_disk_refblock =3D (void *)((uintptr_t)*refcount_table + > + (refblock_index << s->refcount_blo= ck_bits)); Here is where you are relying on the guarantee that you added in 6/21, which is why I ask for that one to mention it. Nice reduction of a bounce buffer, by the way :) Worth mentioning in the commit message as an intentional part of this commit? > @@ -2087,7 +2117,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, B= drvCheckResult *res, > /* Because the old reftable has been exchanged for a new one t= he > * references have to be recalculated */ > rebuild =3D false; > - memset(refcount_table, 0, nb_clusters * sizeof(uint16_t)); > + memset(refcount_table, 0, nb_clusters * s->refcount_bits / 8);= Phew; we're safe that this won't overflow; and good that you do the * first (if you did the /8 first, it would fail for sub-byte refcounts). Reviewed-by: Eric Blake --=20 Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --bGB6it5PApRCc9JSUalpAsBp8cwWsJt18 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 iQEcBAEBCAAGBQJUZ4cZAAoJEKeha0olJ0NqObsH/ih4JF3kj0yR+CAKCr1IhnmU 8vQC64DeAJigXUoLp5EddE7PrG8fnaNv+1Af0wFfiucJF9S3F/syeCoHQAy9SQXS aL76UlKPJgsg5X647JrBNButvMWlfl7LFvXI/ev42vlziZhCIYkmwvlTnuR5lRXw 9+zxLMbfCKI1JyhSg1rCXEUF77kjDPC/YydvzeGCYB7BjUVsfhzIZ4TFj9LI2/Mm /VNP5FSbld80exEYheCLZGON7k6jIBqa/XWKfcpyI5mHqG6tlh3ciFwen1Pw5iTh AXXXRb++lyo0JRaEHzNE3MTVq4RP40NilR2ODC4OvWebdySit98PnFkoVwNo2fE= =79fl -----END PGP SIGNATURE----- --bGB6it5PApRCc9JSUalpAsBp8cwWsJt18--