From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39307) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOPdM-0000zN-7J for qemu-devel@nongnu.org; Mon, 01 Sep 2014 07:18:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOPdG-0007IA-1P for qemu-devel@nongnu.org; Mon, 01 Sep 2014 07:18:52 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:41882 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOPdF-0007I6-Ny for qemu-devel@nongnu.org; Mon, 01 Sep 2014 07:18:45 -0400 Date: Mon, 1 Sep 2014 13:17:58 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140901111758.GP15537@irqsave.net> References: <1409348727-17183-1-git-send-email-mreitz@redhat.com> <1409348727-17183-2-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1409348727-17183-2-git-send-email-mreitz@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/2] qcow2: Drop REFCOUNT_SHIFT List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: Kevin Wolf , Jun Li , juli@redhat.com, qemu-devel@nongnu.org, Stefan Hajnoczi The Friday 29 Aug 2014 =E0 23:45:26 (+0200), Max Reitz wrote : > With BDRVQcowState.refcount_block_bits, we don't need REFCOUNT_SHIFT > anymore. >=20 > Signed-off-by: Max Reitz > --- > block/qcow2-refcount.c | 32 ++++++++++++++------------------ > block/qcow2.c | 2 +- > block/qcow2.h | 2 -- > 3 files changed, 15 insertions(+), 21 deletions(-) >=20 > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index 29136ee..cd6f5a0 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -102,7 +102,7 @@ static int get_refcount(BlockDriverState *bs, int64= _t cluster_index) > uint16_t *refcount_block; > uint16_t refcount; > =20 > - refcount_table_index =3D cluster_index >> (s->cluster_bits - REFCO= UNT_SHIFT); > + refcount_table_index =3D cluster_index >> s->refcount_block_bits; > if (refcount_table_index >=3D s->refcount_table_size) > return 0; > refcount_block_offset =3D > @@ -116,8 +116,7 @@ static int get_refcount(BlockDriverState *bs, int64= _t cluster_index) > return ret; > } > =20 > - block_index =3D cluster_index & > - ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1); > + block_index =3D cluster_index & (s->refcount_block_size - 1); > refcount =3D be16_to_cpu(refcount_block[block_index]); > =20 > ret =3D qcow2_cache_put(bs, s->refcount_block_cache, > @@ -152,8 +151,8 @@ static unsigned int next_refcount_table_size(BDRVQc= owState *s, > static int in_same_refcount_block(BDRVQcowState *s, uint64_t offset_a, > uint64_t offset_b) > { > - uint64_t block_a =3D offset_a >> (2 * s->cluster_bits - REFCOUNT_S= HIFT); > - uint64_t block_b =3D offset_b >> (2 * s->cluster_bits - REFCOUNT_S= HIFT); > + uint64_t block_a =3D offset_a >> (s->cluster_bits + s->refcount_bl= ock_bits); > + uint64_t block_b =3D offset_b >> (s->cluster_bits + s->refcount_bl= ock_bits); > =20 > return (block_a =3D=3D block_b); > } > @@ -174,7 +173,7 @@ static int alloc_refcount_block(BlockDriverState *b= s, > BLKDBG_EVENT(bs->file, BLKDBG_REFBLOCK_ALLOC); > =20 > /* Find the refcount block for the given cluster */ > - refcount_table_index =3D cluster_index >> (s->cluster_bits - REFCO= UNT_SHIFT); > + refcount_table_index =3D cluster_index >> s->refcount_block_bits; > =20 > if (refcount_table_index < s->refcount_table_size) { > =20 > @@ -243,7 +242,7 @@ static int alloc_refcount_block(BlockDriverState *b= s, > =20 > /* The block describes itself, need to update the cache */ > int block_index =3D (new_block >> s->cluster_bits) & > - ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1); > + (s->refcount_block_size - 1); > (*refcount_block)[block_index] =3D cpu_to_be16(1); > } else { > /* Described somewhere else. This can recurse at most twice be= fore we > @@ -315,8 +314,7 @@ static int alloc_refcount_block(BlockDriverState *b= s, > BLKDBG_EVENT(bs->file, BLKDBG_REFTABLE_GROW); > =20 > /* Calculate the number of refcount blocks needed so far */ > - uint64_t refcount_block_clusters =3D 1 << (s->cluster_bits - REFCO= UNT_SHIFT); > - uint64_t blocks_used =3D DIV_ROUND_UP(cluster_index, refcount_bloc= k_clusters); > + uint64_t blocks_used =3D DIV_ROUND_UP(cluster_index, s->refcount_b= lock_size); > =20 > if (blocks_used > QCOW_MAX_REFTABLE_SIZE / sizeof(uint64_t)) { > return -EFBIG; > @@ -330,14 +328,14 @@ static int alloc_refcount_block(BlockDriverState = *bs, > uint64_t table_clusters =3D > size_to_clusters(s, table_size * sizeof(uint64_t)); > blocks_clusters =3D 1 + > - ((table_clusters + refcount_block_clusters - 1) > - / refcount_block_clusters); > + ((table_clusters + s->refcount_block_size - 1) > + / s->refcount_block_size); > uint64_t meta_clusters =3D table_clusters + blocks_clusters; > =20 > last_table_size =3D table_size; > table_size =3D next_refcount_table_size(s, blocks_used + > - ((meta_clusters + refcount_block_clusters - 1) > - / refcount_block_clusters)); > + ((meta_clusters + s->refcount_block_size - 1) > + / s->refcount_block_size)); > =20 > } while (last_table_size !=3D table_size); > =20 > @@ -347,7 +345,7 @@ static int alloc_refcount_block(BlockDriverState *b= s, > #endif > =20 > /* Create the new refcount table and blocks */ > - uint64_t meta_offset =3D (blocks_used * refcount_block_clusters) * > + uint64_t meta_offset =3D (blocks_used * s->refcount_block_size) * > s->cluster_size; > uint64_t table_offset =3D meta_offset + blocks_clusters * s->clust= er_size; > uint64_t *new_table =3D g_try_new0(uint64_t, table_size); > @@ -546,8 +544,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(= BlockDriverState *bs, > { > int block_index, refcount; > int64_t cluster_index =3D cluster_offset >> s->cluster_bits; > - int64_t table_index =3D > - cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT); > + int64_t table_index =3D cluster_index >> s->refcount_block_bit= s; > =20 > /* Load the refcount block and allocate it if needed */ > if (table_index !=3D old_table_index) { > @@ -569,8 +566,7 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(= BlockDriverState *bs, > qcow2_cache_entry_mark_dirty(s->refcount_block_cache, refcount= _block); > =20 > /* we can update the count and save it */ > - block_index =3D cluster_index & > - ((1 << (s->cluster_bits - REFCOUNT_SHIFT)) - 1); > + block_index =3D cluster_index & (s->refcount_block_size - 1); > =20 > refcount =3D be16_to_cpu(refcount_block[block_index]); > refcount +=3D addend; > diff --git a/block/qcow2.c b/block/qcow2.c > index 82bca88..cdbcb81 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -1799,7 +1799,7 @@ static int qcow2_create2(const char *filename, in= t64_t total_size, > .l1_size =3D cpu_to_be32(0), > .refcount_table_offset =3D cpu_to_be64(cluster_size), > .refcount_table_clusters =3D cpu_to_be32(1), > - .refcount_order =3D cpu_to_be32(3 + REFCOUNT_SHIFT= ), > + .refcount_order =3D cpu_to_be32(4), > .header_length =3D cpu_to_be32(sizeof(*header)), > }; > =20 > diff --git a/block/qcow2.h b/block/qcow2.h > index 7c01fb7..5b099cb 100644 > --- a/block/qcow2.h > +++ b/block/qcow2.h > @@ -59,8 +59,6 @@ > /* The cluster reads as all zeros */ > #define QCOW_OFLAG_ZERO (1ULL << 0) > =20 > -#define REFCOUNT_SHIFT 1 /* refcount size is 2 bytes */ > - > #define MIN_CLUSTER_BITS 9 > #define MAX_CLUSTER_BITS 21 > =20 > --=20 > 2.1.0 >=20 >=20 Putting Jun Li in copy because he just wrote a patch using it.