Skip to contentSkip to conversation

btrfs: factor out fixup worker check and use it in extent_writepage_io()

PATCH New David Sterba 1 participant 1 message Aug 22, 2025 Btrfs file system

lore
Share & tools
lore

David Sterba

author maintainer
#0 lore raw

PATCH 1/1 btrfs: factor out fixup worker check and use it in extent_writepage_io()

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.

---

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(-)
fs/btrfs/extent_io.c +29 -9
index 426a6791a0b221..92dc75f051a3ae 100644
@@ -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)
Signature · 1 line
2.50.1