From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:48983) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrTvk-0004H0-If for qemu-devel@nongnu.org; Mon, 02 Jun 2014 11:13:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrTve-0005sV-JS for qemu-devel@nongnu.org; Mon, 02 Jun 2014 11:13:44 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:38644 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrTve-0005sQ-Ax for qemu-devel@nongnu.org; Mon, 02 Jun 2014 11:13:38 -0400 Date: Mon, 2 Jun 2014 17:13:36 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140602151336.GI8181@irqsave.net> References: <1401473631-10724-1-git-send-email-armbru@redhat.com> <1401473631-10724-10-git-send-email-armbru@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1401473631-10724-10-git-send-email-armbru@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 09/10] qemu-img: Make img_convert() get image size just once per image List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Markus Armbruster Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com The Friday 30 May 2014 =E0 20:13:50 (+0200), Markus Armbruster wrote : > Chiefly so I don't have to do the error checking in quadruplicate in > the next commit. Moreover, replacing the frequently updated > bs_sectors by an array assigned just once makes the code easier to > understand. >=20 > Signed-off-by: Markus Armbruster > Reviewed-by: Max Reitz > --- > qemu-img.c | 32 ++++++++++++++++---------------- > 1 file changed, 16 insertions(+), 16 deletions(-) >=20 > diff --git a/qemu-img.c b/qemu-img.c > index 8d996ba..2cb56c5 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -1186,7 +1186,7 @@ static int img_convert(int argc, char **argv) > BlockDriver *drv, *proto_drv; > BlockDriverState **bs =3D NULL, *out_bs =3D NULL; > int64_t total_sectors, nb_sectors, sector_num, bs_offset; > - uint64_t bs_sectors; > + uint64_t *bs_sectors =3D NULL; > uint8_t * buf =3D NULL; > size_t bufsectors =3D IO_BUF_SIZE / BDRV_SECTOR_SIZE; > const uint8_t *buf1; > @@ -1326,7 +1326,8 @@ static int img_convert(int argc, char **argv) > =20 > qemu_progress_print(0, 100); > =20 > - bs =3D g_malloc0(bs_n * sizeof(BlockDriverState *)); > + bs =3D g_new0(BlockDriverState *, bs_n); > + bs_sectors =3D g_new(uint64_t, bs_n); > =20 > total_sectors =3D 0; > for (bs_i =3D 0; bs_i < bs_n; bs_i++) { > @@ -1340,8 +1341,8 @@ static int img_convert(int argc, char **argv) > ret =3D -1; > goto out; > } > - bdrv_get_geometry(bs[bs_i], &bs_sectors); > - total_sectors +=3D bs_sectors; > + bdrv_get_geometry(bs[bs_i], &bs_sectors[bs_i]); > + total_sectors +=3D bs_sectors[bs_i]; > } > =20 > if (sn_opts) { > @@ -1465,7 +1466,6 @@ static int img_convert(int argc, char **argv) > =20 > bs_i =3D 0; > bs_offset =3D 0; > - bdrv_get_geometry(bs[0], &bs_sectors); > =20 > /* increase bufsectors from the default 4096 (2M) if opt_transfer_= length > * or discard_alignment of the out_bs is greater. Limit to 32768 (= 16MB) > @@ -1532,19 +1532,19 @@ static int img_convert(int argc, char **argv) > buf2 =3D buf; > while (remainder > 0) { > int nlow; > - while (bs_num =3D=3D bs_sectors) { > + while (bs_num =3D=3D bs_sectors[bs_i]) { > + bs_offset +=3D bs_sectors[bs_i]; > bs_i++; > assert (bs_i < bs_n); > - bs_offset +=3D bs_sectors; > - bdrv_get_geometry(bs[bs_i], &bs_sectors); > bs_num =3D 0; > /* printf("changing part: sector_num=3D%" PRId64 "= , " > "bs_i=3D%d, bs_offset=3D%" PRId64 ", bs_sectors= =3D%" PRId64 > - "\n", sector_num, bs_i, bs_offset, bs_sectors);= */ > + "\n", sector_num, bs_i, bs_offset, bs_sectors[b= s_i]); */ > } > - assert (bs_num < bs_sectors); > + assert (bs_num < bs_sectors[bs_i]); > =20 > - nlow =3D (remainder > bs_sectors - bs_num) ? bs_sector= s - bs_num : remainder; > + nlow =3D remainder > bs_sectors[bs_i] - bs_num > + ? bs_sectors[bs_i] - bs_num : remainder; > =20 > ret =3D bdrv_read(bs[bs_i], bs_num, buf2, nlow); > if (ret < 0) { > @@ -1605,14 +1605,13 @@ restart: > break; > } > =20 > - while (sector_num - bs_offset >=3D bs_sectors) { > + while (sector_num - bs_offset >=3D bs_sectors[bs_i]) { > + bs_offset +=3D bs_sectors[bs_i]; > bs_i ++; > assert (bs_i < bs_n); > - bs_offset +=3D bs_sectors; > - bdrv_get_geometry(bs[bs_i], &bs_sectors); > /* printf("changing part: sector_num=3D%" PRId64 ", bs= _i=3D%d, " > "bs_offset=3D%" PRId64 ", bs_sectors=3D%" PRId64 "\n= ", > - sector_num, bs_i, bs_offset, bs_sectors); */ > + sector_num, bs_i, bs_offset, bs_sectors[bs_i]); */ > } > =20 > if ((out_baseimg || has_zero_init) && > @@ -1665,7 +1664,7 @@ restart: > } > } > =20 > - n =3D MIN(n, bs_sectors - (sector_num - bs_offset)); > + n =3D MIN(n, bs_sectors[bs_i] - (sector_num - bs_offset)); > =20 > sectors_read +=3D n; > if (count_allocated_sectors) { > @@ -1723,6 +1722,7 @@ out: > } > g_free(bs); > } > + g_free(bs_sectors); > fail_getopt: > g_free(options); > =20 > --=20 > 1.9.3 >=20 >=20 Reviewed-by: Benoit Canet