From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38140) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOPWy-0006zI-0N for qemu-devel@nongnu.org; Mon, 01 Sep 2014 07:12:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOPWr-0005O6-2Q for qemu-devel@nongnu.org; Mon, 01 Sep 2014 07:12:15 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:41676 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOPWq-0005Nu-Rp for qemu-devel@nongnu.org; Mon, 01 Sep 2014 07:12:08 -0400 Date: Mon, 1 Sep 2014 13:11:21 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140901111119.GO15537@irqsave.net> References: <1409568798-2292-1-git-send-email-junmuzi@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1409568798-2292-1-git-send-email-junmuzi@gmail.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v2] qcow2: add update refcount table realization for update_refcount List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jun Li Cc: kwolf@redhat.com, juli@redhat.com, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com The Monday 01 Sep 2014 =E0 18:52:48 (+0800), Jun Li wrote : > When every item of refcount block is NULL, free refcount block and rese= t the > corresponding item of refcount table with NULL. >=20 > Signed-off-by: Jun Li > --- >=20 > The v2 do following change to modify some potential issue. >=20 > +------- Here should start from "0". > | > for (k =3D 0; k < refcount_block_entries; k++) { > if (refcount_block[k] !=3D cpu_to_be16(0)) { > ... | | > } | | > } | +---- Using "0" is more sa= fe. > | > +-------- This should be "k" not "++k". > --- > block/qcow2-refcount.c | 31 +++++++++++++++++++++++++++++++ > 1 file changed, 31 insertions(+) >=20 > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index 43665b8..63f36e6 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -586,6 +586,37 @@ static int QEMU_WARN_UNUSED_RESULT update_refcount= (BlockDriverState *bs, > if (refcount =3D=3D 0 && s->discard_passthrough[type]) { > update_refcount_discard(bs, cluster_offset, s->cluster_siz= e); > } > + > + /* When refcount block is NULL, update refcount table */ > + if (block_index =3D=3D 0) { > + int k =3D block_index; > + int refcount_block_entries =3D s->cluster_size / sizeof(ui= nt16_t); > + for (k =3D 0; k < refcount_block_entries; k++) { > + if (refcount_block[k] !=3D cpu_to_be16(0)) { > + break; > + } > + } > + > + if (k =3D=3D refcount_block_entries) { > + qemu_vfree(refcount_block); > + /* update refcount table */ > + unsigned int refcount_table_index; > + uint64_t data64 =3D cpu_to_be64(0); > + refcount_table_index =3D cluster_index >> (s->cluster_= bits - > + REFCOUNT_SHIFT); > + ret =3D bdrv_pwrite_sync(bs->file, > + s->refcount_table_offset + > + refcount_table_index * > + sizeof(uint64_t), > + &data64, sizeof(data64)); > + if (ret < 0) { > + goto fail; > + } > + > + s->refcount_table[refcount_table_index] =3D data64; Shouldn't the in memory version be be in cpu order ? like s->refcount_table[refcount_table_index] =3D 0; Best regards Beno=EEt=20 > + > + } > + } > } > =20 > ret =3D 0; > --=20 > 1.9.3 >=20 >=20