Skip to content

Commit

Permalink
file-posix: Handle EINVAL fallocate return value
Browse files Browse the repository at this point in the history
The `detect-zeroes=unmap` option may issue unaligned
`FALLOC_FL_PUNCH_HOLE` requests, raw block devices can (and will) return
`EINVAL`, qemu should then write the zeroes to the blockdev instead of
issuing an `IO_ERROR`.

The problem can be reprodced like this:

$ qemu-io -c 'write -P 0 42 1234' --image-opts driver=host_device,filename=/dev/loop0,detect-zeroes=unmap
write failed: Invalid argument

Signed-off-by: Antoine Damhet <[email protected]>
Message-Id: <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
xdbob authored and kevmw committed Jul 21, 2020
1 parent 90218a9 commit bae127d
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion block/file-posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -1698,7 +1698,11 @@ static int handle_aiocb_write_zeroes_unmap(void *opaque)
#ifdef CONFIG_FALLOCATE_PUNCH_HOLE
int ret = do_fallocate(s->fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
aiocb->aio_offset, aiocb->aio_nbytes);
if (ret != -ENOTSUP) {
switch (ret) {
case -ENOTSUP:
case -EINVAL:
break;
default:
return ret;
}
#endif
Expand Down

0 comments on commit bae127d

Please sign in to comment.