[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL for-2.1 06/11] raw-posix: Fix raw_getlength() to alwa
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL for-2.1 06/11] raw-posix: Fix raw_getlength() to always return -errno on error |
Date: |
Mon, 7 Jul 2014 14:28:33 +0200 |
From: Markus Armbruster <address@hidden>
We got a merry mix of -1 and -errno here.
Signed-off-by: Markus Armbruster <address@hidden>
Reviewed-by: Eric Blake <address@hidden>
Reviewed-by: Benoit Canet <address@hidden>
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
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 825a0c8..fa005b3 100644
--- a/block/raw-posix.c
+++ b/block/raw-posix.c
@@ -1133,12 +1133,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
@@ -1152,7 +1152,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;
@@ -1162,7 +1162,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;
}
@@ -1175,6 +1175,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) {
@@ -1193,7 +1194,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)
@@ -1231,6 +1236,9 @@ again:
size = LLONG_MAX;
#else
size = lseek(fd, 0LL, SEEK_END);
+ if (size < 0) {
+ return -errno;
+ }
#endif
#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
switch(s->type) {
@@ -1247,6 +1255,9 @@ again:
#endif
} else {
size = lseek(fd, 0, SEEK_END);
+ if (size < 0) {
+ return -errno;
+ }
}
return size;
}
@@ -1255,13 +1266,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.9.3
- [Qemu-devel] [PULL for-2.1 00/11] Block patches, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 01/11] Fix nocow typos in manpage, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 04/11] ahci.c: mask unused flags when reading size PRDT DBC, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 02/11] mirror: Fix qiov size for short requests, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 03/11] MAINTAINERS: add Stefan Hajnoczi to IDE maintainers, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 05/11] qemu-iotests: Disable Quorum testing in 041 when Quorum is not builtin, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 06/11] raw-posix: Fix raw_getlength() to always return -errno on error,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL for-2.1 07/11] ahci: map memory via device's address space instead of address_space_memory, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 08/11] block: block: introduce APIs for submitting IO as a batch, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 09/11] linux-aio: implement io plug, unplug and flush io queue, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 10/11] dataplane: submit I/O as a batch, Stefan Hajnoczi, 2014/07/07
- [Qemu-devel] [PULL for-2.1 11/11] qmp: show QOM properties in device-list-properties, Stefan Hajnoczi, 2014/07/07
- Re: [Qemu-devel] [PULL for-2.1 00/11] Block patches, Peter Maydell, 2014/07/07