From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43234) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrTZZ-0007F8-AA for qemu-devel@nongnu.org; Mon, 02 Jun 2014 10:50:55 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrTZT-0006DX-Bm for qemu-devel@nongnu.org; Mon, 02 Jun 2014 10:50:49 -0400 Received: from lputeaux-656-01-25-125.w80-12.abo.wanadoo.fr ([80.12.84.125]:38619 helo=paradis.irqsave.net) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrTZT-0006DE-1h for qemu-devel@nongnu.org; Mon, 02 Jun 2014 10:50:43 -0400 Date: Mon, 2 Jun 2014 16:50:41 +0200 From: =?iso-8859-1?Q?Beno=EEt?= Canet Message-ID: <20140602145040.GA8181@irqsave.net> References: <1401473631-10724-1-git-send-email-armbru@redhat.com> <1401473631-10724-2-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-2-git-send-email-armbru@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH v3 01/10] raw-posix: Fix raw_getlength() to always return -errno on error 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:42 (+0200), Markus Armbruster wrote : > We got a merry mix of -1 and -errno here. >=20 > Signed-off-by: Markus Armbruster > Reviewed-by: Eric Blake > --- > block/raw-posix.c | 28 ++++++++++++++++++++++------ > 1 file changed, 22 insertions(+), 6 deletions(-) >=20 > diff --git a/block/raw-posix.c b/block/raw-posix.c > index 6586a0c..9221de5 100644 > --- a/block/raw-posix.c > +++ b/block/raw-posix.c > @@ -1097,12 +1097,12 @@ static int64_t raw_getlength(BlockDriverState *= bs) > struct stat st; > =20 > if (fstat(fd, &st)) > - return -1; > + return -errno; > if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { > struct disklabel dl; > =20 > if (ioctl(fd, DIOCGDINFO, &dl)) > - return -1; > + return -errno; > return (uint64_t)dl.d_secsize * > dl.d_partitions[DISKPART(st.st_rdev)].p_size; > } else > @@ -1116,7 +1116,7 @@ static int64_t raw_getlength(BlockDriverState *bs= ) > struct stat st; > =20 > if (fstat(fd, &st)) > - return -1; > + return -errno; > if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { > struct dkwedge_info dkw; > =20 > @@ -1126,7 +1126,7 @@ static int64_t raw_getlength(BlockDriverState *bs= ) > struct disklabel dl; > =20 > if (ioctl(fd, DIOCGDINFO, &dl)) > - return -1; > + return -errno; > return (uint64_t)dl.d_secsize * > dl.d_partitions[DISKPART(st.st_rdev)].p_size; > } > @@ -1139,6 +1139,7 @@ static int64_t raw_getlength(BlockDriverState *bs= ) > BDRVRawState *s =3D bs->opaque; > struct dk_minfo minfo; > int ret; > + int64_t size; > =20 > ret =3D fd_open(bs); > if (ret < 0) { > @@ -1157,7 +1158,11 @@ static int64_t raw_getlength(BlockDriverState *b= s) > * There are reports that lseek on some devices fails, but > * irc discussion said that contingency on contingency was overkil= l. > */ > - return lseek(s->fd, 0, SEEK_END); > + size =3D lseek(s->fd, 0, SEEK_END); > + if (size < 0) { > + return -errno; > + } > + return size; > } > #elif defined(CONFIG_BSD) > static int64_t raw_getlength(BlockDriverState *bs) > @@ -1195,6 +1200,9 @@ again: > size =3D LONG_LONG_MAX; > #else > size =3D lseek(fd, 0LL, SEEK_END); > + if (size < 0) { > + return -errno; > + } > #endif > #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) > switch(s->type) { > @@ -1211,6 +1219,9 @@ again: > #endif > } else { > size =3D lseek(fd, 0, SEEK_END); > + if (size < 0) { > + return -errno; > + } > } > return size; > } > @@ -1219,13 +1230,18 @@ static int64_t raw_getlength(BlockDriverState *= bs) > { > BDRVRawState *s =3D bs->opaque; > int ret; > + int64_t size; > =20 > ret =3D fd_open(bs); > if (ret < 0) { > return ret; > } > =20 > - return lseek(s->fd, 0, SEEK_END); > + size =3D lseek(s->fd, 0, SEEK_END); > + if (size < 0) { > + return -errno; > + } > + return size; > } > #endif > =20 > --=20 > 1.9.3 >=20 >=20 Reviewed-by: Benoit Canet