]> git.hungrycats.org Git - linux/commitdiff
btrfs: remove btrfs_disk_cache_state
authorTal Zussman <tz2294@columbia.edu>
Thu, 15 Oct 2026 14:43:23 +0000 (10:43 -0400)
committerDavid Sterba <dsterba@suse.com>
Fri, 16 Oct 2026 17:06:56 +0000 (19:06 +0200)
With neither the writer nor the loader left, nothing acts on
disk_cache_state. Remove it, the need_clear handling when reading block
groups, and the enum. While at it, drop the unused cache_generation
field from struct btrfs_block_group.

lookup_free_space_inode() converted old style space inodes by clearing
disk_cache_state so the cache would be rewritten with the new inode
flags. Without that it only sets flags on the in-memory inode, which
every remaining caller truncates or deletes right after, so drop the
conversion too.

Assisted-by: LLM
Signed-off-by: Tal Zussman <tz2294@columbia.edu>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/block-group.c
fs/btrfs/block-group.h
fs/btrfs/disk-io.c
fs/btrfs/free-space-cache.c

index a11685440e3c7a84bdc95d17262a6d14eaa31999..9a98e291769ca6a32d4e931abca89cdb4ed92b00 100644 (file)
@@ -2496,8 +2496,7 @@ static int check_chunk_block_group_mappings(struct btrfs_fs_info *fs_info)
 
 static int read_one_block_group(struct btrfs_fs_info *info,
                                struct btrfs_block_group_item_v2 *bgi,
-                               const struct btrfs_key *key,
-                               bool need_clear)
+                               const struct btrfs_key *key)
 {
        struct btrfs_block_group *cache;
        const bool mixed = btrfs_fs_incompat(info, MIXED_GROUPS);
@@ -2523,20 +2522,6 @@ static int read_one_block_group(struct btrfs_fs_info *info,
 
        btrfs_set_free_space_tree_thresholds(cache);
 
-       if (need_clear) {
-               /*
-                * When we mount with old space cache, we need to
-                * set BTRFS_DC_CLEAR and set dirty flag.
-                *
-                * a) Setting 'BTRFS_DC_CLEAR' makes sure that we
-                *    truncate the old free space cache inode and
-                *    setup a new one.
-                * b) Setting 'dirty flag' makes sure that we flush
-                *    the new space cache info onto disk.
-                */
-               if (btrfs_test_opt(info, SPACE_CACHE))
-                       cache->disk_cache_state = BTRFS_DC_CLEAR;
-       }
        if (!mixed && ((cache->flags & BTRFS_BLOCK_GROUP_METADATA) &&
            (cache->flags & BTRFS_BLOCK_GROUP_DATA))) {
                        btrfs_err(info,
@@ -2677,8 +2662,6 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
        struct btrfs_block_group *cache;
        struct btrfs_space_info *space_info;
        struct btrfs_key key;
-       bool need_clear = false;
-       u64 cache_gen;
 
        /*
         * Either no extent root (with ibadroots rescue option) or we have
@@ -2699,13 +2682,6 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
        if (!path)
                return -ENOMEM;
 
-       cache_gen = btrfs_super_cache_generation(info->super_copy);
-       if (btrfs_test_opt(info, SPACE_CACHE) &&
-           btrfs_super_generation(info->super_copy) != cache_gen)
-               need_clear = true;
-       if (btrfs_test_opt(info, CLEAR_CACHE))
-               need_clear = true;
-
        while (1) {
                struct btrfs_block_group_item_v2 bgi;
                struct extent_buffer *leaf;
@@ -2734,7 +2710,7 @@ int btrfs_read_block_groups(struct btrfs_fs_info *info)
 
                btrfs_item_key_to_cpu(leaf, &key, slot);
                btrfs_release_path(path);
-               ret = read_one_block_group(info, &bgi, &key, need_clear);
+               ret = read_one_block_group(info, &bgi, &key);
                if (ret < 0)
                        goto error;
                key.objectid += key.offset;
@@ -3597,10 +3573,6 @@ int btrfs_update_block_group(struct btrfs_trans_handle *trans,
        spin_lock(&space_info->lock);
        spin_lock(&cache->lock);
 
-       if (btrfs_test_opt(info, SPACE_CACHE) &&
-           cache->disk_cache_state < BTRFS_DC_CLEAR)
-               cache->disk_cache_state = BTRFS_DC_CLEAR;
-
        old_val = cache->used;
        if (alloc) {
                old_val += num_bytes;
index f7346a0170fc467aa43446741bfc187b3b7b0eec..d567ed822e55dae25243b4706f13cc1d0c4a6825 100644 (file)
@@ -20,13 +20,6 @@ struct btrfs_fs_info;
 struct btrfs_inode;
 struct btrfs_trans_handle;
 
-enum btrfs_disk_cache_state {
-       BTRFS_DC_WRITTEN,
-       BTRFS_DC_ERROR,
-       BTRFS_DC_CLEAR,
-       BTRFS_DC_SETUP,
-};
-
 enum btrfs_block_group_size_class {
        /* Unset */
        BTRFS_BG_SZ_NONE,
@@ -131,7 +124,6 @@ struct btrfs_block_group {
        u64 delalloc_bytes;
        u64 bytes_super;
        u64 flags;
-       u64 cache_generation;
        u64 global_root_id;
        u64 remap_bytes;
        u32 identity_remap_count;
@@ -171,8 +163,6 @@ struct btrfs_block_group {
        unsigned long full_stripe_len;
        unsigned long runtime_flags;
 
-       enum btrfs_disk_cache_state disk_cache_state;
-
        /* Cache tracking stuff */
        enum btrfs_caching_type cached;
        struct btrfs_caching_control *caching_ctl;
index c3986b56b3c5d2566b1797f68a6dc9b03e8a027e..1c332b7622364791224a87f5c0b4f1b3d5f5b399 100644 (file)
@@ -4883,10 +4883,6 @@ void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *cur_trans,
                                         dirty_list);
 
                list_del_init(&cache->dirty_list);
-               spin_lock(&cache->lock);
-               cache->disk_cache_state = BTRFS_DC_ERROR;
-               spin_unlock(&cache->lock);
-
                spin_unlock(&cur_trans->dirty_bgs_lock);
                btrfs_put_block_group(cache);
                btrfs_dec_delayed_refs_rsv_bg_updates(fs_info);
index 1e2fc2884d07aacfc98be06006ace3b77a7898eb..e82216ebd5d0998082331ce7e6651bc6c30ebbfc 100644 (file)
@@ -124,7 +124,6 @@ struct inode *lookup_free_space_inode(struct btrfs_block_group *block_group,
 {
        struct btrfs_fs_info *fs_info = block_group->fs_info;
        struct inode *inode = NULL;
-       u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW;
 
        spin_lock(&block_group->lock);
        if (block_group->inode)
@@ -139,13 +138,6 @@ struct inode *lookup_free_space_inode(struct btrfs_block_group *block_group,
                return inode;
 
        spin_lock(&block_group->lock);
-       if (!((BTRFS_I(inode)->flags & flags) == flags)) {
-               btrfs_info(fs_info, "Old style space inode found, converting.");
-               BTRFS_I(inode)->flags |= BTRFS_INODE_NODATASUM |
-                       BTRFS_INODE_NODATACOW;
-               block_group->disk_cache_state = BTRFS_DC_CLEAR;
-       }
-
        if (!test_and_set_bit(BLOCK_GROUP_FLAG_IREF, &block_group->runtime_flags))
                block_group->inode = BTRFS_I(igrab(inode));
        spin_unlock(&block_group->lock);