From: Dave Chen Date: Tue, 7 Apr 2026 03:36:24 +0000 (+0800) Subject: btrfs: use BTRFS_FS_UPDATE_UUID_TREE_GEN flag for UUID tree rescan check X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e70e3f858e084aee34a2206e5f4dd49a47673f6a;p=thirdparty%2Fkernel%2Flinux.git btrfs: use BTRFS_FS_UPDATE_UUID_TREE_GEN flag for UUID tree rescan check 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 Signed-off-by: Dave Chen Signed-off-by: Robbie Ko Signed-off-by: Filipe Manana Signed-off-by: David Sterba --- diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b8ac3275d8f8a..8a11be02eeb9b 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -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) {