]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
btrfs: use BTRFS_FS_UPDATE_UUID_TREE_GEN flag for UUID tree rescan check
authorDave Chen <davechen@synology.com>
Tue, 7 Apr 2026 03:36:24 +0000 (11:36 +0800)
committerDavid Sterba <dsterba@suse.com>
Tue, 7 Apr 2026 17:43:06 +0000 (19:43 +0200)
The UUID tree rescan check in open_ctree() compares
fs_info->generation with the superblock's uuid_tree_generation.
This comparison is not reliable 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 file orphan cleanup
from an unclean shutdown start transactions without committing
them. This advances fs_info->generation past uuid_tree_generation
and produces a false-positive mismatch.

Use the BTRFS_FS_UPDATE_UUID_TREE_GEN flag directly instead. The
flag was already set earlier in open_ctree() when the generations
were known to match, and accurately represents "UUID tree is up to
date" without being affected by subsequent transaction starts.

Reviewed-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Dave Chen <davechen@synology.com>
Signed-off-by: Robbie Ko <robbieko@synology.com>
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/disk-io.c

index b8ac3275d8f8ab6ca01f96fe86dee4dfb01901bb..8a11be02eeb9bebe76aa7a51f013890477c2e823 100644 (file)
@@ -3660,7 +3660,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) {