diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2018-04-04 14:00:07 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2018-04-04 14:00:07 +0100 |
commit | fd69ad866b62ca8ed4337ffee83b6d82a4e99282 (patch) | |
tree | e4f79a4b282a69d09f28ed79ee7305b1d83f1da4 /block | |
parent | e5efa1f5f2d32cbfbf18ba84300736503985b593 (diff) | |
parent | 9c1386d3ff76c5983529884e3d8420df958c5a29 (diff) |
Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
Block layer patches
# gpg: Signature made Tue 03 Apr 2018 16:48:53 BST
# gpg: using RSA key 7F09B272C88F2FD6
# gpg: Good signature from "Kevin Wolf <kwolf@redhat.com>"
# Primary key fingerprint: DC3D EB15 9A9A F95D 3D74 56FE 7F09 B272 C88F 2FD6
* remotes/kevin/tags/for-upstream:
iotests: Test abnormally large size in compressed cluster descriptor
qemu-iotests: Use ppc64 qemu_arch on ppc64le host
iotests: Test preallocated truncate of 2G image
block/file-posix: Fix fully preallocated truncate
iotests: fix 208 for luks format
iotests: Update 186 after commit ac64273c66ab136c44043259162
iotests: Update 051 and 186 after commit 1454509726719e0933c
block: handle invalid lseek returns gracefully
gluster: Fix blockdev-add with server.N.type=unix
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'block')
-rw-r--r-- | block/file-posix.c | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/block/file-posix.c b/block/file-posix.c index d7fb772c14..3794c0007a 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1701,6 +1701,7 @@ static int raw_regular_truncate(int fd, int64_t offset, PreallocMode prealloc, case PREALLOC_MODE_FULL: { int64_t num = 0, left = offset - current_length; + off_t seek_result; /* * Knowing the final size from the beginning could allow the file @@ -1715,8 +1716,8 @@ static int raw_regular_truncate(int fd, int64_t offset, PreallocMode prealloc, buf = g_malloc0(65536); - result = lseek(fd, current_length, SEEK_SET); - if (result < 0) { + seek_result = lseek(fd, current_length, SEEK_SET); + if (seek_result < 0) { result = -errno; error_setg_errno(errp, -result, "Failed to seek to the old end of file"); @@ -2114,7 +2115,12 @@ static int find_allocation(BlockDriverState *bs, off_t start, if (offs < 0) { return -errno; /* D3 or D4 */ } - assert(offs >= start); + + if (offs < start) { + /* This is not a valid return by lseek(). We are safe to just return + * -EIO in this case, and we'll treat it like D4. */ + return -EIO; + } if (offs > start) { /* D2: in hole, next data at offs */ @@ -2146,7 +2152,12 @@ static int find_allocation(BlockDriverState *bs, off_t start, if (offs < 0) { return -errno; /* D1 and (H3 or H4) */ } - assert(offs >= start); + + if (offs < start) { + /* This is not a valid return by lseek(). We are safe to just return + * -EIO in this case, and we'll treat it like H4. */ + return -EIO; + } if (offs > start) { /* |