summaryrefslogtreecommitdiff
path: root/fs/xfs/xfs_aops.c
diff options
context:
space:
mode:
authorDarrick J. Wong <djwong@kernel.org>2021-09-01 11:19:51 -0700
committerDarrick J. Wong <djwong@kernel.org>2021-10-22 16:41:12 -0700
commit45aef4a545ba0ff76a423c5fbe9b7833d93f0b84 (patch)
tree954d782ccf9f413a29706bb0424c23ccc7793db4 /fs/xfs/xfs_aops.c
parentac5be15a06fe9f73d92fabbd7bef32131d666094 (diff)
xfs: extend writeback requests to handle rt cow correctly
If we have shared realtime files and the rt extent size is larger than a single fs block, we need to extend writeback requests to be aligned to rt extent size granularity because we cannot share partial rt extents. The front end should have set us up for this by dirtying the relevant ranges. Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Diffstat (limited to 'fs/xfs/xfs_aops.c')
-rw-r--r--fs/xfs/xfs_aops.c40
1 files changed, 36 insertions, 4 deletions
diff --git a/fs/xfs/xfs_aops.c b/fs/xfs/xfs_aops.c
index 34fc6148032a..b0f093ab6efe 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -461,12 +461,41 @@ static const struct iomap_writeback_ops xfs_writeback_ops = {
.discard_page = xfs_discard_page,
};
+/*
+ * Extend the writeback range to allocation unit granularity and alignment.
+ * This is a requirement for blocksize > pagesize scenarios such as realtime
+ * copy on write, since we can only share full rt extents.
+ */
+static void
+xfs_vm_writepage_extend(
+ struct xfs_inode *ip,
+ struct writeback_control *wbc)
+{
+ unsigned int bsize = xfs_inode_alloc_unitsize(ip);
+ long long int pages_to_write;
+
+ wbc->range_start = rounddown_64(wbc->range_start, bsize);
+ if (wbc->range_end != LLONG_MAX)
+ wbc->range_end = roundup_64(wbc->range_end, bsize);
+
+ if (wbc->nr_to_write == LONG_MAX)
+ return;
+
+ pages_to_write = roundup_64(wbc->range_end - wbc->range_start,
+ PAGE_SIZE);
+ if (pages_to_write >= LONG_MAX)
+ pages_to_write = LONG_MAX;
+ if (wbc->nr_to_write < pages_to_write)
+ wbc->nr_to_write = pages_to_write;
+}
+
STATIC int
xfs_vm_writepages(
- struct address_space *mapping,
- struct writeback_control *wbc)
+ struct address_space *mapping,
+ struct writeback_control *wbc)
{
- struct xfs_writepage_ctx wpc = { };
+ struct xfs_writepage_ctx wpc = { };
+ struct xfs_inode *ip = XFS_I(mapping->host);
/*
* Writing back data in a transaction context can result in recursive
@@ -475,7 +504,10 @@ xfs_vm_writepages(
if (WARN_ON_ONCE(current->journal_info))
return 0;
- xfs_iflags_clear(XFS_I(mapping->host), XFS_ITRUNCATED);
+ if (xfs_inode_needs_cow_around(ip))
+ xfs_vm_writepage_extend(ip, wbc);
+
+ xfs_iflags_clear(ip, XFS_ITRUNCATED);
return iomap_writepages(mapping, wbc, &wpc.ctx, &xfs_writeback_ops);
}