From: Andrey Shinkevich Date: Tue, 27 Aug 2019 13:52:53 +0000 (+0300) Subject: block: workaround for unaligned byte range in fallocate() X-Git-Tag: v4.2.0-rc0~117^2~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=294682cc3a7c5b3d1b2d45b686e2d8523750ce64;p=thirdparty%2Fqemu.git block: workaround for unaligned byte range in fallocate() Revert the commit 118f99442d 'block/io.c: fix for the allocation failure' and use better error handling for file systems that do not support fallocate() for an unaligned byte range. Allow falling back to pwrite in case fallocate() returns EINVAL. Suggested-by: Kevin Wolf Suggested-by: Eric Blake Signed-off-by: Andrey Shinkevich Reviewed-by: Eric Blake Reviewed-by: Denis V. Lunev Message-Id: <1566913973-15490-1-git-send-email-andrey.shinkevich@virtuozzo.com> Signed-off-by: Eric Blake --- diff --git a/block/file-posix.c b/block/file-posix.c index 71f168ee2f1..87c5a4ccbdc 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1588,6 +1588,13 @@ static int handle_aiocb_write_zeroes(void *opaque) if (s->has_write_zeroes) { int ret = do_fallocate(s->fd, FALLOC_FL_ZERO_RANGE, aiocb->aio_offset, aiocb->aio_nbytes); + if (ret == -EINVAL) { + /* + * Allow falling back to pwrite for file systems that + * do not support fallocate() for an unaligned byte range. + */ + return -ENOTSUP; + } if (ret == 0 || ret != -ENOTSUP) { return ret; } diff --git a/block/io.c b/block/io.c index 0fa10831edb..16a598fd085 100644 --- a/block/io.c +++ b/block/io.c @@ -1746,7 +1746,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, assert(!bs->supported_zero_flags); } - if (ret < 0 && !(flags & BDRV_REQ_NO_FALLBACK)) { + if (ret == -ENOTSUP && !(flags & BDRV_REQ_NO_FALLBACK)) { /* Fall back to bounce buffer if write zeroes is unsupported */ BdrvRequestFlags write_flags = flags & ~BDRV_REQ_ZERO_WRITE;