Consolidate DIO behavior on unaligned EOF read
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest2 patches 3 repliesIn review
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | direct-io: defer alignment check until after EOF checkfs/ | +18 | 1 reply | |
| 2/2 | f2fs: Return EOF on unaligned end of file DIO readfs/ | +3 | 2 replies |
Reviews trailers per patch
1 of 2 patches has a Reviewed-by or Acked-by.
| Patch | Chao Yu |
|---|---|
| 1/2 | |
| 2/2 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH 0/2] Consolidate DIO behavior on unaligned EOF read
When issuing a DIO read past EOF on a file that doesn't end on a block boundary, behavior varies among filesystems. Most filesystems (including the ones using iomap for DIO) will return EOF, but the old generic DIO mechanism changed behavior accidently after commit 9fe55eea7e4b ("Fix race when checking i_size on direct i/o read") and started returning -EINVAL.
This can be observed with a simple read over a file that doesn't end on a block boundary, forcing the last read to be unaligned.
while (done < total) {
ssize_t delta = pread(fd, buf + done, total - done, off + done); if (!delta)
break;
...
}
On the final read, delta will be 0 on most filesystems, including ext4, xfs and btrfs, but it started being -EINVAL after said commit, for filesystems using do_blockdev_direct_IO.
BTRFS, even though relying on this generic code, doesn't have this issue, because it does the verification beforehand, on check_direct_IO. Finally, f2fs requires a specific fix, since it checks for alignment before calling the generic code.
It is arguable whether filesystems should actually return EOF or -EINVAL, but since the original ABI returned 0 and so does most filesystems and original DIO code, it seems reasonable to consolidate on that. Therefore, this patchset fixes the filesystems returning EINVAL to return EOF.
I ran smoke tests over f2fs, and didn't observe regressions.
Gabriel Krisman Bertazi (1):
f2fs: Return EOF on unaligned end of file DIO read
Jamie Liu (1):
direct-io: defer alignment check until after EOF check
fs/direct-io.c | 31 ++++++++++++++++++------------- fs/f2fs/data.c | 3 +++ 2 files changed, 21 insertions(+), 13 deletions(-)
Signature · 1 line
2.28.0