summaryrefslogtreecommitdiff
path: root/fs
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-12-15 17:29:26 -0800
commitb5d915ddad3466713db3baed9dc3ee3e11044605 (patch)
tree5377ce4ef702d5b6a10788627a3b71d5396b4d65 /fs
parenta21246ea33b8f47e9dff9596ed4654a5825ac4ed (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')
-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 c8c15c3c3147..e68d69022550 100644
--- a/fs/xfs/xfs_aops.c
+++ b/fs/xfs/xfs_aops.c
@@ -470,12 +470,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
@@ -484,7 +513,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);
}