Received: from eggs.gnu.org ([2001:4830:134:3::10]:48120) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrVQT-0005n6-O6 for qemu-devel@nongnu.org; Mon, 02 Jun 2014 12:49:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrVQN-0001CV-LP for qemu-devel@nongnu.org; Mon, 02 Jun 2014 12:49:33 -0400 Received: from oxygen.pond.sub.org ([2a01:4f8:201:233:1::3]:47159) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrVQN-0001C2-9h for qemu-devel@nongnu.org; Mon, 02 Jun 2014 12:49:27 -0400 From: Markus Armbruster References: <1401473631-10724-1-git-send-email-armbru@redhat.com> <1401473631-10724-11-git-send-email-armbru@redhat.com> <20140602152216.GJ8181@irqsave.net> Date: Mon, 02 Jun 2014 18:49:24 +0200 In-Reply-To: <20140602152216.GJ8181@irqsave.net> (=?utf-8?Q?=22Beno=C3=AEt?= Canet"'s message of "Mon, 2 Jun 2014 17:22:17 +0200") Message-ID: <87wqczxnmz.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 10/10] block: Avoid bdrv_get_geometry() where errors should be detected List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?utf-8?Q?Beno=C3=AEt?= Canet Cc: kwolf@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, mreitz@redhat.com Beno=C3=AEt Canet writes: > The Friday 30 May 2014 =C3=A0 20:13:51 (+0200), Markus Armbruster wrote : >> bdrv_get_geometry() hides errors. Use bdrv_nb_sectors() or >> bdrv_getlength() instead where that's obviously inappropriate. >>=20 >> Signed-off-by: Markus Armbruster >> Reviewed-by: Eric Blake >> Reviewed-by: Max Reitz >> --- >> block.c | 11 ++++++++--- >> block/qapi.c | 14 ++++++++++---- >> qemu-img.c | 59 +++++++++++++++++++++++++++++++++++++++++++++--------= ------ >> 3 files changed, 63 insertions(+), 21 deletions(-) >>=20 >> diff --git a/block.c b/block.c >> index 41837b4..94f8b87 100644 >> --- a/block.c >> +++ b/block.c >> @@ -5573,7 +5573,7 @@ void bdrv_img_create(const char *filename, const c= har *fmt, >> if (size && size->value.n =3D=3D -1) { >> if (backing_file && backing_file->value.s) { >> BlockDriverState *bs; >> - uint64_t size; >> + int64_t size; >> char buf[32]; >> int back_flags; >>=20=20 >> @@ -5592,8 +5592,13 @@ void bdrv_img_create(const char *filename, const = char *fmt, >> local_err =3D NULL; >> goto out; >> } >> - bdrv_get_geometry(bs, &size); >> - size *=3D 512; >> + size =3D bdrv_getlength(bs); >> + if (size < 0) { >> + error_setg_errno(errp, -size, "Could not get size of '%= s'", >> + backing_file->value.s); >> + bdrv_unref(bs); >> + goto out; >> + } >>=20=20 >> snprintf(buf, sizeof(buf), "%" PRId64, size); >> set_option_parameter(param, BLOCK_OPT_SIZE, buf); >> diff --git a/block/qapi.c b/block/qapi.c >> index 75f44f1..ae6488a 100644 >> --- a/block/qapi.c >> +++ b/block/qapi.c >> @@ -165,19 +165,25 @@ void bdrv_query_image_info(BlockDriverState *bs, >> ImageInfo **p_info, >> Error **errp) >> { >> - uint64_t total_sectors; >> + int64_t size; >> const char *backing_filename; >> char backing_filename2[1024]; >> BlockDriverInfo bdi; >> int ret; >> Error *err =3D NULL; >> - ImageInfo *info =3D g_new0(ImageInfo, 1); >> + ImageInfo *info; >>=20=20 >> - bdrv_get_geometry(bs, &total_sectors); >> + size =3D bdrv_getlength(bs); >> + if (size < 0) { >> + error_setg_errno(errp, -size, "Can't get size of device '%s'", >> + bdrv_get_device_name(bs)); >> + return; >> + } >>=20=20 >> + info =3D g_new0(ImageInfo, 1); >> info->filename =3D g_strdup(bs->filename); >> info->format =3D g_strdup(bdrv_get_format_name(bs)); >> - info->virtual_size =3D total_sectors * 512; >> + info->virtual_size =3D size; >> info->actual_size =3D bdrv_get_allocated_file_size(bs); >> info->has_actual_size =3D info->actual_size >=3D 0; >> if (bdrv_is_encrypted(bs)) { >> diff --git a/qemu-img.c b/qemu-img.c >> index 2cb56c5..fca58bc 100644 >> --- a/qemu-img.c >> +++ b/qemu-img.c >> @@ -959,7 +959,6 @@ static int img_compare(int argc, char **argv) >> int64_t sector_num =3D 0; >> int64_t nb_sectors; >> int c, pnum; >> - uint64_t bs_sectors; >> uint64_t progress_base; >>=20=20 >> for (;;) { >> @@ -1021,10 +1020,18 @@ static int img_compare(int argc, char **argv) >>=20=20 >> buf1 =3D qemu_blockalign(bs1, IO_BUF_SIZE); >> buf2 =3D qemu_blockalign(bs2, IO_BUF_SIZE); >> - bdrv_get_geometry(bs1, &bs_sectors); >> - total_sectors1 =3D bs_sectors; >> - bdrv_get_geometry(bs2, &bs_sectors); >> - total_sectors2 =3D bs_sectors; >> + total_sectors1 =3D bdrv_nb_sectors(bs1); >> + if (total_sectors1 < 0) { >> + error_report("Can't get size of %s: %s", >> + filename1, strerror(-total_sectors1)); >> + goto out; >> + } >> + total_sectors2 =3D bdrv_nb_sectors(bs2); >> + if (total_sectors2 < 0) { >> + error_report("Can't get size of %s: %s", >> + filename2, strerror(-total_sectors2)); >> + goto out; >> + } > Would setting ret be useful beforie goto out ?=20 Yes, to a value > 1. But which one? We use 2, 3 and 4, but their documented only as ">1 - Error occured". >> total_sectors =3D MIN(total_sectors1, total_sectors2); >> progress_base =3D MAX(total_sectors1, total_sectors2); >>=20=20 [...] Thanks!