* [PATCH] btrfs: factor out fixup worker check and use it in extent_writepage_io()
@ 2025-08-22 11:57 David Sterba
0 siblings, 0 replies; only message in thread
From: David Sterba @ 2025-08-22 11:57 UTC (permalink / raw)
To: linux-btrfs; +Cc: wqu, David Sterba
The whole cow fixup machinery is under experimental build but all we
care about is the check that that a folio is properly set up for IO.
This has uncovered some bugs so keep it but make it standalone and
independent of the fixup worker. The detection and report is copied from
btrfs_writepage_cow_fixup() and simplified.
Signed-off-by: David Sterba <dsterba@suse.com>
---
RFC, the fixup worker cleanups can be done on top of that.
fs/btrfs/extent_io.c | 38 +++++++++++++++++++++++++++++---------
1 file changed, 29 insertions(+), 9 deletions(-)
diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 426a6791a0b221..92dc75f051a3ae 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1642,6 +1642,32 @@ static int submit_one_sector(struct btrfs_inode *inode,
return 0;
}
+/*
+ * Check that the folio has been set up for IO and its range has an ordered
+ * extent.
+ *
+ * Historical note: this used to be fixup worker that handled pages/folios
+ * dirtied out-of-band outside of the filesystem and restarted the whole
+ * process again. This cannot happen anymore since 5.8 and get_user_pages()
+ * update. This check is to catch bugs.
+ *
+ * Return: true if the check fails and folio is dirty
+ */
+static bool btrfs_check_folio_for_writepage(struct folio *folio)
+{
+ struct btrfs_inode *inode = folio_to_inode(folio);
+
+ /* This folio has ordered extent covering it already */
+ if (folio_test_ordered(folio))
+ return false;
+
+ DEBUG_WARN();
+ btrfs_err_rl(inode->root->fs_info,
+"root %lld ino %llu folio %llu is marked dirty without notifying the fs",
+ btrfs_root_id(inode->root), btrfs_ino(inode), folio_pos(folio));
+ return true;
+}
+
/*
* Helper for extent_writepage(). This calls the writepage start hooks,
* and does the loop to map the page into extents and bios.
@@ -1669,18 +1695,12 @@ static noinline_for_stack int extent_writepage_io(struct btrfs_inode *inode,
ASSERT(start >= folio_start &&
start + len <= folio_start + folio_size(folio));
- ret = btrfs_writepage_cow_fixup(folio);
- if (ret == -EAGAIN) {
- /* Fixup worker will requeue */
- folio_redirty_for_writepage(bio_ctrl->wbc, folio);
- folio_unlock(folio);
- return 1;
- }
- if (ret < 0) {
+ ret = btrfs_check_folio_for_writepage(folio);
+ if (ret) {
btrfs_folio_clear_dirty(fs_info, folio, start, len);
btrfs_folio_set_writeback(fs_info, folio, start, len);
btrfs_folio_clear_writeback(fs_info, folio, start, len);
- return ret;
+ return -EUCLEAN;
}
for (cur = start; cur < start + len; cur += fs_info->sectorsize)
--
2.50.1
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-08-22 11:58 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-22 11:57 [PATCH] btrfs: factor out fixup worker check and use it in extent_writepage_io() David Sterba
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).