Skip to content

Commit 0e4656a

Browse files
committed
Merge tag 'iomap-5.9-merge-5' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux
Pull iomap updates from Darrick Wong: "The most notable changes are: - iomap no longer invalidates the page cache when performing a direct read, since doing so is unnecessary and the old directio code doesn't do that either. - iomap embraced the use of returning ENOTBLK from a direct write to trigger falling back to a buffered write since ext4 already did this and btrfs wants it for their port. - iomap falls back to buffered writes if we're doing a direct write and the page cache invalidation after the flush fails; this was necessary to handle a corner case in the btrfs port. - Remove email virus scanner detritus that was accidentally included in yesterday's pull request. Clearly I need(ed) to update my git branch checker scripts. :(" * tag 'iomap-5.9-merge-5' of git://git.kernel.org/pub/scm/fs/xfs/xfs-linux: iomap: fall back to buffered writes for invalidation failures xfs: use ENOTBLK for direct I/O to buffered I/O fallback iomap: Only invalidate page cache pages on direct IO writes iomap: Make sure iomap_end is called after iomap_begin
2 parents eb65405 + 60263d5 commit 0e4656a

File tree

7 files changed

+44
-27
lines changed

7 files changed

+44
-27
lines changed

fs/ext4/file.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ static ssize_t ext4_dio_write_iter(struct kiocb *iocb, struct iov_iter *from)
544544
iomap_ops = &ext4_iomap_overwrite_ops;
545545
ret = iomap_dio_rw(iocb, from, iomap_ops, &ext4_dio_write_ops,
546546
is_sync_kiocb(iocb) || unaligned_io || extend);
547+
if (ret == -ENOTBLK)
548+
ret = 0;
547549

548550
if (extend)
549551
ret = ext4_handle_inode_extension(inode, offset, ret, count);

fs/gfs2/file.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,8 @@ static ssize_t gfs2_file_direct_write(struct kiocb *iocb, struct iov_iter *from)
835835

836836
ret = iomap_dio_rw(iocb, from, &gfs2_iomap_ops, NULL,
837837
is_sync_kiocb(iocb));
838-
838+
if (ret == -ENOTBLK)
839+
ret = 0;
839840
out:
840841
gfs2_glock_dq(&gh);
841842
out_uninit:

fs/iomap/apply.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,14 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,
4646
ret = ops->iomap_begin(inode, pos, length, flags, &iomap, &srcmap);
4747
if (ret)
4848
return ret;
49-
if (WARN_ON(iomap.offset > pos))
50-
return -EIO;
51-
if (WARN_ON(iomap.length == 0))
52-
return -EIO;
49+
if (WARN_ON(iomap.offset > pos)) {
50+
written = -EIO;
51+
goto out;
52+
}
53+
if (WARN_ON(iomap.length == 0)) {
54+
written = -EIO;
55+
goto out;
56+
}
5357

5458
trace_iomap_apply_dstmap(inode, &iomap);
5559
if (srcmap.type != IOMAP_HOLE)
@@ -80,6 +84,7 @@ iomap_apply(struct inode *inode, loff_t pos, loff_t length, unsigned flags,
8084
written = actor(inode, pos, length, data, &iomap,
8185
srcmap.type != IOMAP_HOLE ? &srcmap : &iomap);
8286

87+
out:
8388
/*
8489
* Now the data has been copied, commit the range we've copied. This
8590
* should not fail unless the filesystem has had a fatal error.

fs/iomap/direct-io.c

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <linux/backing-dev.h>
1111
#include <linux/uio.h>
1212
#include <linux/task_io_accounting_ops.h>
13+
#include "trace.h"
1314

1415
#include "../internal.h"
1516

@@ -401,6 +402,9 @@ iomap_dio_actor(struct inode *inode, loff_t pos, loff_t length,
401402
* can be mapped into multiple disjoint IOs and only a subset of the IOs issued
402403
* may be pure data writes. In that case, we still need to do a full data sync
403404
* completion.
405+
*
406+
* Returns -ENOTBLK In case of a page invalidation invalidation failure for
407+
* writes. The callers needs to fall back to buffered I/O in this case.
404408
*/
405409
ssize_t
406410
iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
@@ -475,23 +479,24 @@ iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
475479
if (ret)
476480
goto out_free_dio;
477481

478-
/*
479-
* Try to invalidate cache pages for the range we're direct
480-
* writing. If this invalidation fails, tough, the write will
481-
* still work, but racing two incompatible write paths is a
482-
* pretty crazy thing to do, so we don't support it 100%.
483-
*/
484-
ret = invalidate_inode_pages2_range(mapping,
485-
pos >> PAGE_SHIFT, end >> PAGE_SHIFT);
486-
if (ret)
487-
dio_warn_stale_pagecache(iocb->ki_filp);
488-
ret = 0;
489-
490-
if (iov_iter_rw(iter) == WRITE && !wait_for_completion &&
491-
!inode->i_sb->s_dio_done_wq) {
492-
ret = sb_init_dio_done_wq(inode->i_sb);
493-
if (ret < 0)
482+
if (iov_iter_rw(iter) == WRITE) {
483+
/*
484+
* Try to invalidate cache pages for the range we are writing.
485+
* If this invalidation fails, let the caller fall back to
486+
* buffered I/O.
487+
*/
488+
if (invalidate_inode_pages2_range(mapping, pos >> PAGE_SHIFT,
489+
end >> PAGE_SHIFT)) {
490+
trace_iomap_dio_invalidate_fail(inode, pos, count);
491+
ret = -ENOTBLK;
494492
goto out_free_dio;
493+
}
494+
495+
if (!wait_for_completion && !inode->i_sb->s_dio_done_wq) {
496+
ret = sb_init_dio_done_wq(inode->i_sb);
497+
if (ret < 0)
498+
goto out_free_dio;
499+
}
495500
}
496501

497502
inode_dio_begin(inode);

fs/iomap/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ DEFINE_EVENT(iomap_range_class, name, \
7474
DEFINE_RANGE_EVENT(iomap_writepage);
7575
DEFINE_RANGE_EVENT(iomap_releasepage);
7676
DEFINE_RANGE_EVENT(iomap_invalidatepage);
77+
DEFINE_RANGE_EVENT(iomap_dio_invalidate_fail);
7778

7879
#define IOMAP_TYPE_STRINGS \
7980
{ IOMAP_HOLE, "HOLE" }, \

fs/xfs/xfs_file.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ xfs_file_dio_aio_write(
505505
*/
506506
if (xfs_is_cow_inode(ip)) {
507507
trace_xfs_reflink_bounce_dio_write(ip, iocb->ki_pos, count);
508-
return -EREMCHG;
508+
return -ENOTBLK;
509509
}
510510
iolock = XFS_IOLOCK_EXCL;
511511
} else {
@@ -553,8 +553,8 @@ xfs_file_dio_aio_write(
553553
xfs_iunlock(ip, iolock);
554554

555555
/*
556-
* No fallback to buffered IO on errors for XFS, direct IO will either
557-
* complete fully or fail.
556+
* No fallback to buffered IO after short writes for XFS, direct I/O
557+
* will either complete fully or return an error.
558558
*/
559559
ASSERT(ret < 0 || ret == count);
560560
return ret;
@@ -714,7 +714,7 @@ xfs_file_write_iter(
714714
* allow an operation to fall back to buffered mode.
715715
*/
716716
ret = xfs_file_dio_aio_write(iocb, from);
717-
if (ret != -EREMCHG)
717+
if (ret != -ENOTBLK)
718718
return ret;
719719
}
720720

fs/zonefs/super.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,11 @@ static ssize_t zonefs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)
786786
if (iocb->ki_pos >= ZONEFS_I(inode)->i_max_size)
787787
return -EFBIG;
788788

789-
if (iocb->ki_flags & IOCB_DIRECT)
790-
return zonefs_file_dio_write(iocb, from);
789+
if (iocb->ki_flags & IOCB_DIRECT) {
790+
ssize_t ret = zonefs_file_dio_write(iocb, from);
791+
if (ret != -ENOTBLK)
792+
return ret;
793+
}
791794

792795
return zonefs_file_buffered_write(iocb, from);
793796
}

0 commit comments

Comments
 (0)