[PATCH v3 08/17] btrfs: remove btrfs_disk_cache_state
From: Tal Zussman
Date: Thu Sep 17 2026 - 00:01:17 EST
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: Claude:claude-fable-5-1
Signed-off-by: Tal Zussman <tz2294@xxxxxxxxxxxx>
---
fs/btrfs/block-group.c | 32 ++------------------------------
fs/btrfs/block-group.h | 10 ----------
fs/btrfs/disk-io.c | 4 ----
fs/btrfs/free-space-cache.c | 8 --------
4 files changed, 2 insertions(+), 52 deletions(-)
diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 972909b52a39..7c5f80f4aa79 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2454,8 +2454,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);
@@ -2481,20 +2480,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,
@@ -2635,8 +2620,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
@@ -2657,13 +2640,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;
@@ -2692,7 +2668,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;
@@ -3555,10 +3531,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;
diff --git a/fs/btrfs/block-group.h b/fs/btrfs/block-group.h
index 939d4bfbd4b4..eac794a053cd 100644
--- a/fs/btrfs/block-group.h
+++ b/fs/btrfs/block-group.h
@@ -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;
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index f256a91f58b4..881d95080709 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -4864,10 +4864,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);
diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c
index a25c4db561b4..3ba9ed4a39d0 100644
--- a/fs/btrfs/free-space-cache.c
+++ b/fs/btrfs/free-space-cache.c
@@ -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);
--
2.39.5