linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] Consolidate DIO behavior on unaligned EOF read
@ 2020-08-19 20:07 Gabriel Krisman Bertazi
  2020-08-19 20:07 ` [PATCH 1/2] direct-io: defer alignment check until after EOF check Gabriel Krisman Bertazi
  2020-08-19 20:07 ` [PATCH 2/2] f2fs: Return EOF on unaligned end of file DIO read Gabriel Krisman Bertazi
  0 siblings, 2 replies; 6+ messages in thread
From: Gabriel Krisman Bertazi @ 2020-08-19 20:07 UTC (permalink / raw)
  To: viro, jaegeuk, chao
  Cc: linux-fsdevel, linux-f2fs-devel, Gabriel Krisman Bertazi, kernel

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(-)

-- 
2.28.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-08-26 14:29 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19 20:07 [PATCH 0/2] Consolidate DIO behavior on unaligned EOF read Gabriel Krisman Bertazi
2020-08-19 20:07 ` [PATCH 1/2] direct-io: defer alignment check until after EOF check Gabriel Krisman Bertazi
2020-08-26 14:28   ` Jan Kara
2020-08-19 20:07 ` [PATCH 2/2] f2fs: Return EOF on unaligned end of file DIO read Gabriel Krisman Bertazi
2020-08-20 16:13   ` Jaegeuk Kim
2020-08-21  1:37   ` Chao Yu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).