From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:41775) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoTRJ-0003ls-Rn for qemu-devel@nongnu.org; Thu, 05 Dec 2013 02:33:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoTRD-0002hL-Gm for qemu-devel@nongnu.org; Thu, 05 Dec 2013 02:33:37 -0500 Received: from mx1.redhat.com ([209.132.183.28]:5658) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoTRD-0002hF-8H for qemu-devel@nongnu.org; Thu, 05 Dec 2013 02:33:31 -0500 Message-ID: <52A02C3E.3010203@redhat.com> Date: Thu, 05 Dec 2013 15:33:18 +0800 From: Fam Zheng MIME-Version: 1.0 References: <1386225154-21638-1-git-send-email-hutao@cn.fujitsu.com> In-Reply-To: <1386225154-21638-1-git-send-email-hutao@cn.fujitsu.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH] qcow2: use start_of_cluster() and offset_into_cluster() everywhere List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hu Tao , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi On 2013=E5=B9=B412=E6=9C=8805=E6=97=A5 14:32, Hu Tao wrote: > Signed-off-by: Hu Tao > --- > block/qcow2-cluster.c | 2 +- > block/qcow2-refcount.c | 22 +++++++++++----------- > 2 files changed, 12 insertions(+), 12 deletions(-) > > diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c > index 791083a..b54ad3c 100644 > --- a/block/qcow2-cluster.c > +++ b/block/qcow2-cluster.c > @@ -1401,7 +1401,7 @@ int qcow2_discard_clusters(BlockDriverState *bs, = uint64_t offset, > > /* Round start up and end down */ > offset =3D align_offset(offset, s->cluster_size); > - end_offset &=3D ~(s->cluster_size - 1); > + end_offset =3D start_of_cluster(s, end_offset); > > if (offset > end_offset) { > return 0; > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index 1ff43d0..c974abe 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -515,8 +515,8 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount(= BlockDriverState *bs, > s->l2_table_cache); > } > > - start =3D offset & ~(s->cluster_size - 1); > - last =3D (offset + length - 1) & ~(s->cluster_size - 1); > + start =3D start_of_cluster(s, offset); > + last =3D start_of_cluster(s, offset + length - 1); > for(cluster_offset =3D start; cluster_offset <=3D last; > cluster_offset +=3D s->cluster_size) > { > @@ -724,7 +724,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int= size) > } > redo: > free_in_cluster =3D s->cluster_size - > - (s->free_byte_offset & (s->cluster_size - 1)); > + offset_into_cluster(s, s->free_byte_offset); > if (size <=3D free_in_cluster) { > /* enough space in current cluster */ > offset =3D s->free_byte_offset; > @@ -732,7 +732,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int= size) > free_in_cluster -=3D size; > if (free_in_cluster =3D=3D 0) > s->free_byte_offset =3D 0; > - if ((offset & (s->cluster_size - 1)) !=3D 0) > + if (offset_into_cluster(s, offset) !=3D 0) > qcow2_update_cluster_refcount(bs, offset >> s->cluster_bi= ts, 1, > QCOW2_DISCARD_NEVER); > } else { > @@ -740,7 +740,7 @@ int64_t qcow2_alloc_bytes(BlockDriverState *bs, int= size) > if (offset < 0) { > return offset; > } > - cluster_offset =3D s->free_byte_offset & ~(s->cluster_size - 1= ); > + cluster_offset =3D start_of_cluster(s, s->free_byte_offset); > if ((cluster_offset + s->cluster_size) =3D=3D offset) { > /* we are lucky: contiguous data */ > offset =3D s->free_byte_offset; > @@ -1010,8 +1010,8 @@ static void inc_refcounts(BlockDriverState *bs, > if (size <=3D 0) > return; > > - start =3D offset & ~(s->cluster_size - 1); > - last =3D (offset + size - 1) & ~(s->cluster_size - 1); > + start =3D start_of_cluster(s, offset); > + last =3D start_of_cluster(s, offset + size - 1); > for(cluster_offset =3D start; cluster_offset <=3D last; > cluster_offset +=3D s->cluster_size) { > k =3D cluster_offset >> s->cluster_bits; > @@ -1122,7 +1122,7 @@ static int check_refcounts_l2(BlockDriverState *b= s, BdrvCheckResult *res, > offset, s->cluster_size); > > /* Correct offsets are cluster aligned */ > - if (offset & (s->cluster_size - 1)) { > + if (offset_into_cluster(s, offset)) { > fprintf(stderr, "ERROR offset=3D%" PRIx64 ": Cluster = is not " > "properly aligned; L2 entry corrupted.\n", offset= ); > res->corruptions++; > @@ -1194,7 +1194,7 @@ static int check_refcounts_l1(BlockDriverState *b= s, > l2_offset, s->cluster_size); > > /* L2 tables are cluster aligned */ > - if (l2_offset & (s->cluster_size - 1)) { > + if (offset_into_cluster(s, l2_offset)) { > fprintf(stderr, "ERROR l2_offset=3D%" PRIx64 ": Table= is not " > "cluster aligned; L1 entry corrupted\n", l2_offse= t); > res->corruptions++; > @@ -1423,7 +1423,7 @@ static int64_t realloc_refcount_block(BlockDriver= State *bs, int reftable_index, > } > > /* update refcount table */ > - assert(!(new_offset & (s->cluster_size - 1))); > + assert(!offset_into_cluster(s, new_offset)); > s->refcount_table[reftable_index] =3D new_offset; > ret =3D write_reftable_entry(bs, reftable_index); > if (ret < 0) { > @@ -1507,7 +1507,7 @@ int qcow2_check_refcounts(BlockDriverState *bs, B= drvCheckResult *res, > cluster =3D offset >> s->cluster_bits; > > /* Refcount blocks are cluster aligned */ > - if (offset & (s->cluster_size - 1)) { > + if (offset_into_cluster(s, offset)) { > fprintf(stderr, "ERROR refcount block %" PRId64 " is not = " > "cluster aligned; refcount table entry corrupted\n", = i); > res->corruptions++; > The conversion looks good to me, and covers all the existing=20 "s->cluster_size - 1" appearances in qcow2. Reviewed-by: Fam Zheng