public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] btrfs: fix unnecessary UUID tree rescan on mount
@ 2026-04-02  6:43 Dave Chen
  2026-04-02 15:00 ` Filipe Manana
  2026-04-07  3:36 ` [PATCH v2] btrfs: use BTRFS_FS_UPDATE_UUID_TREE_GEN flag for UUID tree rescan check Dave Chen
  0 siblings, 2 replies; 5+ messages in thread
From: Dave Chen @ 2026-04-02  6:43 UTC (permalink / raw)
  To: linux-btrfs, dsterba; +Cc: cccheng, robbieko, Dave Chen

The UUID tree rescan check in open_ctree() compares
fs_info->generation with the superblock's uuid_tree_generation.
This comparison can produce false positives because
fs_info->generation is bumped at transaction start time in
join_transaction(), while uuid_tree_generation is only updated at
commit time via update_super_roots().

Between the early BTRFS_FS_UPDATE_UUID_TREE_GEN flag check and the
late rescan decision, mount operations such as orphan cleanup start
transactions without committing them. This advances
fs_info->generation past uuid_tree_generation, triggering an
unnecessary full UUID tree rescan on every mount that recovers
file orphans from an unclean shutdown.

Fix this by using the BTRFS_FS_UPDATE_UUID_TREE_GEN flag directly,
which was already set earlier when the generations were known to
match, and is not invalidated by subsequent transaction starts.

Fixes: 70f80175472 ("Btrfs: check UUID tree during mount if required")
Signed-off-by: Dave Chen <davechen@synology.com>
Signed-off-by: Robbie Ko <robbieko@synology.com>
---
 fs/btrfs/disk-io.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 1b0eb246b7147..70357b12508d0 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -3674,7 +3674,7 @@ int __cold open_ctree(struct super_block *sb, struct btrfs_fs_devices *fs_device
 
 	if (fs_info->uuid_root &&
 	    (btrfs_test_opt(fs_info, RESCAN_UUID_TREE) ||
-	     fs_info->generation != btrfs_super_uuid_tree_generation(disk_super))) {
+	     !test_bit(BTRFS_FS_UPDATE_UUID_TREE_GEN, &fs_info->flags))) {
 		btrfs_info(fs_info, "checking UUID tree");
 		ret = btrfs_check_uuid_tree(fs_info);
 		if (ret) {
-- 
2.43.0


Disclaimer: The contents of this e-mail message and any attachments are confidential and are intended solely for addressee. The information may also be legally privileged. This transmission is sent in trust, for the sole purpose of delivery to the intended recipient. If you have received this transmission in error, any use, reproduction or dissemination of this transmission is strictly prohibited. If you are not the intended recipient, please immediately notify the sender by reply e-mail or phone and delete this message and its attachments, if any.

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-04-07 11:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-02  6:43 [PATCH] btrfs: fix unnecessary UUID tree rescan on mount Dave Chen
2026-04-02 15:00 ` Filipe Manana
2026-04-07  3:18   ` Dave Chen
2026-04-07  3:36 ` [PATCH v2] btrfs: use BTRFS_FS_UPDATE_UUID_TREE_GEN flag for UUID tree rescan check Dave Chen
2026-04-07 11:24   ` Filipe Manana

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox