]> git.hungrycats.org Git - linux/commitdiff
btrfs: stop enabling the v1 space cache from the on-disk state
authorTal Zussman <tz2294@columbia.edu>
Thu, 17 Sep 2026 03:59:57 +0000 (23:59 -0400)
committerDavid Sterba <dsterba@suse.com>
Thu, 17 Sep 2026 17:49:47 +0000 (19:49 +0200)
Since commit 545e560a5b0f ("btrfs: disable v1 space cache") the mount
options can no longer request the v1 space cache, but a filesystem with
an active v1 cache and no free space tree still enables it from
cache_generation, and remount does the same. Drop both, so SPACE_CACHE
can never be set.

btrfs_start_pre_rw_mount() then sees the on-disk cache as active but
unwanted and cleans it up, as -o nospace_cache does today. That covers
the read-only to read-write remount as well, so drop the toggle in
btrfs_remount_cleanup(), which would otherwise start a transaction on
remounts of a read-only filesystem with an old cache.

The cleanup is now unconditional, and the first read-write mount fails
if it fails, as it did with -o nospace_cache. This also lets an old
filesystem mount without options when the page size is larger than the
sector size, which btrfs_check_features() rejected once SPACE_CACHE was
set from the superblock.

Assisted-by: Claude:claude-fable-5-1
Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/super.c

index 464129b1b0d4cb8ce624038b5dbd46ca78fac98a..77443ded6db39306a6ba300e49e6c5cefd10812e 100644 (file)
@@ -759,12 +759,12 @@ void btrfs_set_free_space_cache_settings(struct btrfs_fs_info *fs_info)
 
        /*
         * At this point we don't have explicit options set by the user, set
-        * them ourselves based on the state of the file system.
+        * them ourselves based on the state of the file system. An existing
+        * v1 space cache is no longer used and gets cleaned up once the
+        * filesystem is mounted read-write.
         */
        if (btrfs_fs_compat_ro(fs_info, FREE_SPACE_TREE))
                btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
-       else if (btrfs_free_space_cache_v1_active(fs_info))
-               btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE);
 }
 
 static void set_device_specific_options(struct btrfs_fs_info *fs_info)
@@ -1264,8 +1264,6 @@ static inline void btrfs_remount_begin(struct btrfs_fs_info *fs_info,
 static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info,
                                         unsigned long long old_opts)
 {
-       const bool cache_opt = btrfs_test_opt(fs_info, SPACE_CACHE);
-
        /*
         * We need to cleanup all defraggable inodes if the autodefragment is
         * close or the filesystem is read only.
@@ -1282,10 +1280,6 @@ static inline void btrfs_remount_cleanup(struct btrfs_fs_info *fs_info,
        else if (btrfs_raw_test_opt(old_opts, DISCARD_ASYNC) &&
                 !btrfs_test_opt(fs_info, DISCARD_ASYNC))
                btrfs_discard_cleanup(fs_info);
-
-       /* If we toggled space cache */
-       if (cache_opt != btrfs_free_space_cache_v1_active(fs_info))
-               btrfs_set_free_space_cache_v1_active(fs_info, cache_opt);
 }
 
 static int btrfs_remount_rw(struct btrfs_fs_info *fs_info)
@@ -1535,10 +1529,6 @@ static int btrfs_reconfigure(struct fs_context *fc)
                        btrfs_set_opt(fs_info->mount_opt, FREE_SPACE_TREE);
                        btrfs_clear_opt(fs_info->mount_opt, SPACE_CACHE);
                }
-               if (btrfs_free_space_cache_v1_active(fs_info)) {
-                       btrfs_clear_opt(fs_info->mount_opt, FREE_SPACE_TREE);
-                       btrfs_set_opt(fs_info->mount_opt, SPACE_CACHE);
-               }
        }
 
        ret = 0;