From: Qu Wenruo Date: Wed, 11 Feb 2026 21:14:21 +0000 (+1030) Subject: btrfs: remove out-of-date comments in btree_writepages() X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e677ccac5a7b84db4894c723efb2dd2d1607046f;p=thirdparty%2Fkernel%2Flinux.git btrfs: remove out-of-date comments in btree_writepages() There is a lengthy comment introduced in commit b3ff8f1d380e ("btrfs: Don't submit any btree write bio if the fs has errors") and commit c9583ada8cc4 ("btrfs: avoid double clean up when submit_one_bio() failed"), explaining two things: - Why we don't want to submit metadata write if the fs has errors - Why we re-set @ret to 0 if it's positive However it's no longer uptodate by the following reasons: - We have better checks nowadays Commit 2618849f31e7 ("btrfs: ensure no dirty metadata is written back for an fs with errors") has introduced better checks, that if the fs is in an error state, metadata writes will not result in any bio but instead complete immediately. That covers all metadata writes better. - Mentioned incorrect function name The commit c9583ada8cc4 ("btrfs: avoid double clean up when submit_one_bio() failed") introduced this ret > 0 handling, but at that time the function name submit_extent_page() was already incorrect. It was submit_eb_page() that could return >0 at that time, and submit_extent_page() could only return 0 or <0 for errors, never >0. Later commit b35397d1d325 ("btrfs: convert submit_extent_page() to use a folio") changed "submit_extent_page()" to "submit_extent_folio()" in the comment, but it doesn't make any difference since the function name is wrong from day 1. Finally commit 5e121ae687b8 ("btrfs: use buffer xarray for extent buffer writeback operations") completely reworked how metadata writeback works, and removed submit_eb_page(), leaving only the wrong function name in the comment. Furthermore the function submit_extent_folio() still exists in the latest code base, but is never utilized for metadata writeback, causing more confusion. Just remove the lengthy comment, and replace the "if (ret > 0)" check with an ASSERT(), since only btrfs_check_meta_write_pointer() can modify @ret and it returns 0 or <0 for errors. Reviewed-by: Filipe Manana Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 942cc95a0375c..cfafe05aa6f70 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -2396,38 +2396,12 @@ retry: index = 0; goto retry; } + /* - * If something went wrong, don't allow any metadata write bio to be - * submitted. - * - * This would prevent use-after-free if we had dirty pages not - * cleaned up, which can still happen by fuzzed images. - * - * - Bad extent tree - * Allowing existing tree block to be allocated for other trees. - * - * - Log tree operations - * Exiting tree blocks get allocated to log tree, bumps its - * generation, then get cleaned in tree re-balance. - * Such tree block will not be written back, since it's clean, - * thus no WRITTEN flag set. - * And after log writes back, this tree block is not traced by - * any dirty extent_io_tree. - * - * - Offending tree block gets re-dirtied from its original owner - * Since it has bumped generation, no WRITTEN flag, it can be - * reused without COWing. This tree block will not be traced - * by btrfs_transaction::dirty_pages. - * - * Now such dirty tree block will not be cleaned by any dirty - * extent io tree. Thus we don't want to submit such wild eb - * if the fs already has error. - * - * We can get ret > 0 from submit_extent_folio() indicating how many ebs - * were submitted. Reset it to 0 to avoid false alerts for the caller. + * Only btrfs_check_meta_write_pointer() can update @ret, + * and it only returns 0 or errors. */ - if (ret > 0) - ret = 0; + ASSERT(ret <= 0); if (!ret && BTRFS_FS_ERROR(fs_info)) ret = -EROFS;