From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49818) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7H9T-0005k6-Ik for qemu-devel@nongnu.org; Sat, 25 Jan 2014 23:17:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W7H9O-0001UR-UV for qemu-devel@nongnu.org; Sat, 25 Jan 2014 23:16:55 -0500 Received: from paradis.irqsave.net ([62.212.105.220]:48348) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W7H9O-0001UH-Co for qemu-devel@nongnu.org; Sat, 25 Jan 2014 23:16:50 -0500 Date: Sun, 26 Jan 2014 05:16:49 +0100 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140126041649.GC2958@irqsave.net> References: <1951774efa04da5c770f13ca014366b2ac7d0120.1390705440.git.hutao@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1951774efa04da5c770f13ca014366b2ac7d0120.1390705440.git.hutao@cn.fujitsu.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v5 3/4] qcow2: check for NULL l2meta List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hu Tao Cc: Kevin Wolf , =?iso-8859-1?Q?Beno=EEt?= Canet , qemu-devel@nongnu.org Le Sunday 26 Jan 2014 =E0 11:12:39 (+0800), Hu Tao a =E9crit : > In the case of a metadata preallocation with a large cluster size, > qcow2_alloc_cluster_offset() can allocate nothing and returns a > NULL l2meta. This patch checks for it and link2 l2 with only valid > l2meta. >=20 > Replace 9 and 512 with BDRV_SECTOR_BITS, BDRV_SECTOR_SIZE > respectively while at the function. >=20 > Reviewed-by: Max Reitz > Signed-off-by: Hu Tao > --- > block/qcow2.c | 31 ++++++++++++++++--------------- > 1 file changed, 16 insertions(+), 15 deletions(-) >=20 > diff --git a/block/qcow2.c b/block/qcow2.c > index effdd56..bfdbfa1 100644 > --- a/block/qcow2.c > +++ b/block/qcow2.c > @@ -1396,34 +1396,34 @@ static int preallocate(BlockDriverState *bs) > int ret; > QCowL2Meta *meta; > =20 > - nb_sectors =3D bdrv_getlength(bs) >> 9; > + nb_sectors =3D bdrv_getlength(bs) >> BDRV_SECTOR_BITS; > offset =3D 0; > =20 > while (nb_sectors) { > - num =3D MIN(nb_sectors, INT_MAX >> 9); > + num =3D MIN(nb_sectors, INT_MAX >> BDRV_SECTOR_BITS); > ret =3D qcow2_alloc_cluster_offset(bs, offset, &num, > &host_offset, &meta); > if (ret < 0) { > return ret; > } > =20 > - ret =3D qcow2_alloc_cluster_link_l2(bs, meta); > - if (ret < 0) { > - qcow2_free_any_clusters(bs, meta->alloc_offset, meta->nb_c= lusters, > - QCOW2_DISCARD_NEVER); > - return ret; > - } > - > - /* There are no dependent requests, but we need to remove our = request > - * from the list of in-flight requests */ > if (meta !=3D NULL) { > + ret =3D qcow2_alloc_cluster_link_l2(bs, meta); > + if (ret < 0) { > + qcow2_free_any_clusters(bs, meta->alloc_offset, > + meta->nb_clusters, QCOW2_DISCA= RD_NEVER); > + return ret; > + } > + > + /* There are no dependent requests, but we need to remove = our > + * request from the list of in-flight requests */ > QLIST_REMOVE(meta, next_in_flight); > } > =20 > /* TODO Preallocate data if requested */ > =20 > nb_sectors -=3D num; > - offset +=3D num << 9; > + offset +=3D num << BDRV_SECTOR_BITS; > } > =20 > /* > @@ -1432,9 +1432,10 @@ static int preallocate(BlockDriverState *bs) > * EOF). Extend the image to the last allocated sector. > */ > if (host_offset !=3D 0) { > - uint8_t buf[512]; > - memset(buf, 0, 512); > - ret =3D bdrv_write(bs->file, (host_offset >> 9) + num - 1, buf= , 1); > + uint8_t buf[BDRV_SECTOR_SIZE]; > + memset(buf, 0, BDRV_SECTOR_SIZE); > + ret =3D bdrv_write(bs->file, (host_offset >> BDRV_SECTOR_BITS)= + num - 1, > + buf, 1); > if (ret < 0) { > return ret; > } > --=20 > 1.8.5.2.229.g4448466 >=20 >=20 Reviewed-by: Benoit Canet