From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47279) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WihPq-0003vR-Fa for qemu-devel@nongnu.org; Fri, 09 May 2014 05:48:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WihPi-0007ns-KS for qemu-devel@nongnu.org; Fri, 09 May 2014 05:48:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:12864) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WihPi-0007nZ-Cz for qemu-devel@nongnu.org; Fri, 09 May 2014 05:48:22 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s499mLfJ004087 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 9 May 2014 05:48:21 -0400 From: Markus Armbruster Date: Fri, 9 May 2014 11:48:14 +0200 Message-Id: <1399628898-3241-2-git-send-email-armbru@redhat.com> In-Reply-To: <1399628898-3241-1-git-send-email-armbru@redhat.com> References: <1399628898-3241-1-git-send-email-armbru@redhat.com> Subject: [Qemu-devel] [PATCH 1/5] raw-posix: Fix raw_getlength() to always return -errno on error List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, stefanha@redhat.com We got a merry mix of -1 and -errno here. Signed-off-by: Markus Armbruster --- block/raw-posix.c | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index 3ce026d..9bf06e5 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1094,12 +1094,12 @@ static int64_t raw_getlength(BlockDriverState *bs) struct stat st; if (fstat(fd, &st)) - return -1; + return -errno; if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { struct disklabel dl; 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 @@ -1113,7 +1113,7 @@ static int64_t raw_getlength(BlockDriverState *bs) struct stat st; if (fstat(fd, &st)) - return -1; + return -errno; if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { struct dkwedge_info dkw; @@ -1123,7 +1123,7 @@ static int64_t raw_getlength(BlockDriverState *bs) struct disklabel dl; if (ioctl(fd, DIOCGDINFO, &dl)) - return -1; + return -errno; return (uint64_t)dl.d_secsize * dl.d_partitions[DISKPART(st.st_rdev)].p_size; } @@ -1136,6 +1136,7 @@ static int64_t raw_getlength(BlockDriverState *bs) BDRVRawState *s = bs->opaque; struct dk_minfo minfo; int ret; + int64_t size; ret = fd_open(bs); if (ret < 0) { @@ -1154,7 +1155,11 @@ static int64_t raw_getlength(BlockDriverState *bs) * There are reports that lseek on some devices fails, but * irc discussion said that contingency on contingency was overkill. */ - return lseek(s->fd, 0, SEEK_END); + size = lseek(s->fd, 0, SEEK_END); + if (size < 0) { + return -errno; + } + return size; } #elif defined(CONFIG_BSD) static int64_t raw_getlength(BlockDriverState *bs) @@ -1192,6 +1197,9 @@ again: size = LONG_LONG_MAX; #else size = lseek(fd, 0LL, SEEK_END); + if (size < 0) { + return -errno; + } #endif #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) switch(s->type) { @@ -1208,6 +1216,9 @@ again: #endif } else { size = lseek(fd, 0, SEEK_END); + if (size < 0) { + return -errno; + } } return size; } @@ -1216,13 +1227,18 @@ static int64_t raw_getlength(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; int ret; + int64_t size; ret = fd_open(bs); if (ret < 0) { return ret; } - return lseek(s->fd, 0, SEEK_END); + size = lseek(s->fd, 0, SEEK_END); + if (size < 0) { + return -errno; + } + return size; } #endif -- 1.8.1.4