block: workaround for unaligned byte range in fallocate()
PATCH 1/1 block: workaround for unaligned byte range in fallocate()
Revert the commit 118f99442d 'block/io.c: fix for the allocation failure' and make better error handling for the file systems that do not support fallocate() for the unaligned byte range. Allow falling back to pwrite in case fallocate() returns EINVAL.
---
Discussed in email thread with the message ID <1554474244-553661-1-git-send-email-andrey.shinkevich@virtuozzo.com>
block/file-posix.c | 7 +++++++ block/io.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)
block/file-posix.c +7 -0
@@ -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 unaligned byte range. +*/ +return -ENOTSUP ; + }if (ret ==0 || ret != -ENOTSUP ) {return ret; }
block/io.c +1 -1
@@ -1558,7 +1558,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 ;
Signature · 1 line
1.8.3.1
Quoted 24 lines · Andrey Shinkevich
Revert the commit
118f99442d'block/io.c: fix for the allocation failure' and make better error handling for the file systems that do not supportfallocate()for the unaligned byte range. Allow falling back to pwrite in casefallocate()returns EINVAL.Suggested-by Kevin Wolf <[email protected]>Suggested-by Eric Blake <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>---
Discussed in email thread with the message ID <1554474244-553661-1-git-send-email-andrey.shinkevich@virtuozzo.com>block/file-posix.c | 7 +++++++ block/io.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)block/file-posix.c +0
-0@@ -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);
block/file-posix.c static int handle_aiocb_write_zeroes(void *opaque) · line 1600
Quoted 10 lines
block/file-posix.c +7
-0+if (ret == -EINVAL ) { +/* +* Allow falling back to pwrite for file systems that +* do not support fallocate() for unaligned byte range. +*/ +return -ENOTSUP ; + }if (ret ==0 || ret != -ENOTSUP ) {return ret; }
Hmm stop, you've done exactly what Den was afraid of:
the next line
s->has_write_zeroes = false;
will disable write_zeroes forever.
Something like
block/file-posix.c +4 -2
@@ -1588,10 +1588,12 @@ 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 ==0 || ret != -ENOTSUP ) { +if (ret ==0 || (ret != -ENOTSUP && ret != -EINVAL )) {return ret; } - s->has_write_zeroes = false; +if (ret == -ENOTSUP ) { + s->has_write_zeroes = false; + } }#endif
will work better. So, handle ENOTSUP as "disable write_zeros forever", and EINVAL as "don't disable, but fallback to writing zeros". And we need same handling for following do_fallocate() calls too (otherwise they again fails with EINVAL which will break the whole thing).
Quoted 14 lines
block/io.c +1
-1@@ -1558,7 +1558,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 ;
Signature · 2 lines
Best regards, Vladimir
Quoted 63 lines · Vladimir Sementsov-Ogievskiy
Quoted 24 lines · Andrey Shinkevich
Revert the commit
118f99442d'block/io.c: fix for the allocation failure' and make better error handling for the file systems that do not supportfallocate()for the unaligned byte range. Allow falling back to pwrite in casefallocate()returns EINVAL.Suggested-by Kevin Wolf <[email protected]>Suggested-by Eric Blake <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>---
Discussed in email thread with the message ID <1554474244-553661-1-git-send-email-andrey.shinkevich@virtuozzo.com>
block/file-posix.c| 7 +++++++
block/io.c | 2 +-2 files changed, 8 insertions(+), 1 deletion(-)block/file-posix.c +0
-0@@ -1588,6 +1588,13 @@ static int j(void *opaque) if (s->has_write_zeroes) { int ret = do_fallocate(s->fd, FALLOC_FL_ZERO_RANGE, aiocb->aio_offset, aiocb->aio_nbytes);block/file-posix.c static int j(void *opaque) · line 1600
Quoted 10 lines
block/file-posix.c +7
-0+ if (ret == -EINVAL) { + /* + * Allow falling back to pwrite for file systems that + * do not support fallocate() for unaligned byte range. + */ + return -ENOTSUP; + } if (ret == 0 || ret != -ENOTSUP) { return ret; }Hmm stop, you've done exactly what Den was afraid of:
the next line
s->has_write_zeroes= false;will disable
write_zeroesforever.Something like
block/file-posix.c +4
-2@@ -1588,10 +1588,12 @@ 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 == 0 || ret != -ENOTSUP) { + if (ret == 0 || (ret != -ENOTSUP && ret != -EINVAL)) { return ret; } - s->has_write_zeroes = false; + if (ret == -ENOTSUP) { + s->has_write_zeroes = false; + } } #endif
Quoted 4 lines
will work better. So, handle ENOTSUP as "disable
write_zerosforever", and EINVAL as "don't disable, but fallback to writing zeros". And we need same handling for followingdo_fallocate()calls too (otherwise they again fails with EINVAL which will break the whole thing).
Oops, sorry, I misread your patch, it's OK.
Still we may want to handle other do_fallocate() calls in same manner, or may be just:
@@ -1558,7 +1558,13 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,
assert(!bs->supported_zero_flags);
}- if (ret < 0 && !(flags & BDRV_REQ_NO_FALLBACK)) {
+ /*
+ * We are sure that our arguments make sense, so consider "invalid
+ * argument" in same manner as "not supported".
+ */
+ if ((ret == -ENOTSUP || ret == -EINVAL) &&
+ !(flags & BDRV_REQ_NO_FALLBACK))
+ {
/* Fall back to bounce buffer if write zeroes is unsupported */
BdrvRequestFlags write_flags = flags & ~BDRV_REQ_ZERO_WRITE;Signature · 2 lines
Best regards, Vladimir
Quoted 2 lines · Andrey Shinkevich
Revert the commit
118f99442d'block/io.c: fix for the allocation failure' and make better error handling for the file systems that do not support
s/make/use/
Quoted 1 line
fallocate()for the unaligned byte range. Allow falling back to pwrite
s/the/an/
Quoted 18 lines
in case
fallocate()returns EINVAL.Suggested-by Kevin Wolf <[email protected]>Suggested-by Eric Blake <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>---
Discussed in email thread with the message ID <1554474244-553661-1-git-send-email-andrey.shinkevich@virtuozzo.com>block/file-posix.c | 7 +++++++ block/io.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)block/file-posix.c +0
-0
block/file-posix.c static int handle_aiocb_write_zeroes(void *opaque) · line 1594
Quoted 7 lines
block/file-posix.c +4
-0@@ -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 unaligned byte range.
s/for/for an/
Quoted 12 lines
block/file-posix.c +3
-0+*/ +return -ENOTSUP ; + }if (ret ==0 || ret != -ENOTSUP ) {return ret; }block/io.c +0
-0
block/io.c static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, · line 1564
Quoted 8 lines
block/io.c +1
-1@@ -1558,7 +1558,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 ;
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org
Quoted 52 lines · Eric Blake
Quoted 2 lines · Andrey Shinkevich
Revert the commit
118f99442d'block/io.c: fix for the allocation failure' and make better error handling for the file systems that do not supports/make/use/
Quoted 1 line
fallocate()for the unaligned byte range. Allow falling back to pwrites/the/an/
Quoted 18 lines
in case
fallocate()returns EINVAL.Suggested-by Kevin Wolf <[email protected]>Suggested-by Eric Blake <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>---
Discussed in email thread with the message ID <1554474244-553661-1-git-send-email-andrey.shinkevich@virtuozzo.com>block/file-posix.c | 7 +++++++ block/io.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)block/file-posix.c +0
-0block/file-posix.c static int handle_aiocb_write_zeroes(void *opaque) · line 1594
Quoted 7 lines
block/file-posix.c +4
-0@@ -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 unaligned byte range. s/for/for an/
Quoted 14 lines
block/file-posix.c +3
-0+*/ +return -ENOTSUP ; + }if (ret ==0 || ret != -ENOTSUP ) {return ret; }block/io.c +0
-0@@ -1558,7 +1558,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,assert (!bs->supported_zero_flags); }
Quoted 9 lines
block/io.c static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, · line 1564
Quoted 6 lines
block/io.c +1
-1-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 ;Reviewed-by Eric Blake <[email protected]>
Thank you Eric!
Also, I would prefer "make the finer error handling" because the word 'better' has a wide sense.
I have prepared the v2 with your corrections and am waiting for Denis Lunev's response. He is coming back to work from his vacation on Tuesday.
Andrey
Signature · 2 lines
With the best regards, Andrey Shinkevich
Denis V. Lunev
Reviewed-byQuoted 49 lines · Eric Blake
Quoted 2 lines · Andrey Shinkevich
Revert the commit
118f99442d'block/io.c: fix for the allocation failure' and make better error handling for the file systems that do not supports/make/use/
Quoted 1 line
fallocate()for the unaligned byte range. Allow falling back to pwrites/the/an/
Quoted 18 lines
in case
fallocate()returns EINVAL.Suggested-by Kevin Wolf <[email protected]>Suggested-by Eric Blake <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>---
Discussed in email thread with the message ID <1554474244-553661-1-git-send-email-andrey.shinkevich@virtuozzo.com>block/file-posix.c | 7 +++++++ block/io.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)block/file-posix.c +0
-0block/file-posix.c static int handle_aiocb_write_zeroes(void *opaque) · line 1594
Quoted 7 lines
block/file-posix.c +4
-0@@ -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 unaligned byte range. s/for/for an/
Quoted 14 lines
block/file-posix.c +3
-0+*/ +return -ENOTSUP ; + }if (ret ==0 || ret != -ENOTSUP ) {return ret; }block/io.c +0
-0@@ -1558,7 +1558,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,assert (!bs->supported_zero_flags); }
Quoted 8 lines
block/io.c static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, · line 1564
Quoted 6 lines
block/io.c +1
-1-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 ;Reviewed-by Eric Blake <[email protected]>
Quoted 52 lines · Eric Blake
Quoted 2 lines · Andrey Shinkevich
Revert the commit
118f99442d'block/io.c: fix for the allocation failure' and make better error handling for the file systems that do not supports/make/use/
Quoted 1 line
fallocate()for the unaligned byte range. Allow falling back to pwrites/the/an/
Quoted 18 lines
in case
fallocate()returns EINVAL.Suggested-by Kevin Wolf <[email protected]>Suggested-by Eric Blake <[email protected]>Signed-off-by Andrey Shinkevich <[email protected]>---
Discussed in email thread with the message ID <1554474244-553661-1-git-send-email-andrey.shinkevich@virtuozzo.com>block/file-posix.c | 7 +++++++ block/io.c | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-)block/file-posix.c +0
-0block/file-posix.c static int handle_aiocb_write_zeroes(void *opaque) · line 1594
Quoted 7 lines
block/file-posix.c +4
-0@@ -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 unaligned byte range. s/for/for an/
Quoted 14 lines
block/file-posix.c +3
-0+*/ +return -ENOTSUP ; + }if (ret ==0 || ret != -ENOTSUP ) {return ret; }block/io.c +0
-0@@ -1558,7 +1558,7 @@ static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs,assert (!bs->supported_zero_flags); }
Quoted 9 lines
block/io.c static int coroutine_fn bdrv_co_do_pwrite_zeroes(BlockDriverState *bs, · line 1564
Quoted 6 lines
block/io.c +1
-1-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 ;Reviewed-by Eric Blake <[email protected]>
Eric,
If you are good to take this patch to your branch with your corrections, please let us know. Otherwise, I will send the v2 with your corrections.
Signature · 2 lines
With the best regards, Andrey Shinkevich
Quoted 10 lines · Andrey Shinkevich
Quoted 7 lines
Quoted 4 lines
Reviewed-by Eric Blake <[email protected]>Eric,
If you are good to take this patch to your branch with your corrections, please let us know. Otherwise, I will send the v2 with your corrections.
Since I based my fast-zero patches on top of this, I'm fine making the corrections locally and queuing this patch through my NBD tree.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org