Skip to contentSkip to conversation

btrfs: remove stale code in read_tree_block() callers

PATCH In review [email protected] 2 participants 4 messages Feb 9 Btrfs file system

lore
Share & tools
lore
#0 lore raw

cover btrfs: remove stale code in read_tree_block() callers

From: Filipe Manana <[email protected]>

Details in the change logs.

Filipe Manana (2):
btrfs: use the helper extent_buffer_uptodate() everywhere
btrfs: remove redundant extent_buffer_uptodate() checks after read_tree_block()

 fs/btrfs/backref.c      | 10 ----------
 fs/btrfs/ctree.c        | 13 ++-----------
 fs/btrfs/disk-io.c      | 10 ----------
 fs/btrfs/extent_io.c    |  6 +++---
 fs/btrfs/extent_io.h    |  2 +-
 fs/btrfs/print-tree.c   |  4 ----
 fs/btrfs/qgroup.c       |  4 ----
 fs/btrfs/relocation.c   |  5 +----
 fs/btrfs/tree-mod-log.c |  8 +++-----
 9 files changed, 10 insertions(+), 52 deletions(-)
Signature · 1 line
2.47.2
#1 lore raw

PATCH 1/2 btrfs: use the helper extent_buffer_uptodate() everywhere

From: Filipe Manana <[email protected]>

Instead of open coding testing the uptodate bit on the extent buffer's flags, use the existing helper extent_buffer_uptodate() (which is even shorter to type). Also change the helper's return value from int to bool, since we always use it in a boolean context.

---
 fs/btrfs/extent_io.c | 6 +++---
 fs/btrfs/extent_io.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)
fs/btrfs/extent_io.c +3 -3
index 3df399dc8856..11faecb66109 100644
@@ -3858,7 +3858,7 @@ int read_extent_buffer_pages_nowait(struct extent_buffer *eb, int mirror_num,
 	struct btrfs_fs_info *fs_info = eb->fs_info;
 	struct btrfs_bio *bbio;
 
-	if (test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags))
+	if (extent_buffer_uptodate(eb))
 		return 0;
 
 	/*
@@ -3879,7 +3879,7 @@ int read_extent_buffer_pages_nowait(struct extent_buffer *eb, int mirror_num,
 	 * started and finished reading the same eb.  In this case, UPTODATE
 	 * will now be set, and we shouldn't read it in again.
 	 */
-	if (unlikely(test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags))) {
+	if (unlikely(extent_buffer_uptodate(eb))) {
 		clear_extent_buffer_reading(eb);
 		return 0;
 	}
@@ -3916,7 +3916,7 @@ int read_extent_buffer_pages(struct extent_buffer *eb, int mirror_num,
 		return ret;
 
 	wait_on_bit_io(&eb->bflags, EXTENT_BUFFER_READING, TASK_UNINTERRUPTIBLE);
-	if (unlikely(!test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags)))
+	if (unlikely(!extent_buffer_uptodate(eb)))
 		return -EIO;
 	return 0;
 }
fs/btrfs/extent_io.h +1 -1
index 73571d5d3d5a..6409dda947f1 100644
@@ -298,7 +298,7 @@ static inline int __pure num_extent_folios(const struct extent_buffer *eb)
 	return num_extent_pages(eb);
 }
 
-static inline int extent_buffer_uptodate(const struct extent_buffer *eb)
+static inline bool extent_buffer_uptodate(const struct extent_buffer *eb)
 {
 	return test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags);
 }
Signature · 1 line
2.47.2
#2 lore raw

PATCH 2/2 btrfs: remove redundant extent_buffer_uptodate() checks after read_tree_block()

In reply to [email protected]

From: Filipe Manana <[email protected]>

We have several places that call extent_buffer_uptodate() after reading a tree block with read_tree_block(), but that is redundant since we already call extent_buffer_uptodate() in the call chain of read_tree_block():

read_tree_block()
btrfs_read_extent_buffer()
read_extent_buffer_pages()
returns -EIO if extent_buffer_uptodate() returns false

So remove those redundant checks.

---
 fs/btrfs/backref.c      | 10 ----------
 fs/btrfs/ctree.c        | 13 ++-----------
 fs/btrfs/disk-io.c      | 10 ----------
 fs/btrfs/print-tree.c   |  4 ----
 fs/btrfs/qgroup.c       |  4 ----
 fs/btrfs/relocation.c   |  5 +----
 fs/btrfs/tree-mod-log.c |  8 +++-----
 7 files changed, 6 insertions(+), 48 deletions(-)
fs/btrfs/backref.c +0 -10
index 7921a926f676..8a119c505e32 100644
@@ -858,11 +858,6 @@ static int add_missing_keys(struct btrfs_fs_info *fs_info,
 			free_pref(ref);
 			return PTR_ERR(eb);
 		}
-		if (unlikely(!extent_buffer_uptodate(eb))) {
-			free_pref(ref);
-			free_extent_buffer(eb);
-			return -EIO;
-		}
 
 		if (lock)
 			btrfs_tree_read_lock(eb);
@@ -1620,11 +1615,6 @@ static int find_parent_nodes(struct btrfs_backref_walk_ctx *ctx,
 					ret = PTR_ERR(eb);
 					goto out;
 				}
-				if (unlikely(!extent_buffer_uptodate(eb))) {
-					free_extent_buffer(eb);
-					ret = -EIO;
-					goto out;
-				}
 
 				if (!path->skip_locking)
 					btrfs_tree_read_lock(eb);
fs/btrfs/ctree.c +2 -11
index 7267b2502665..f2c925e90a87 100644
@@ -822,7 +822,6 @@ struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent,
 {
 	int level = btrfs_header_level(parent);
 	struct btrfs_tree_parent_check check = { 0 };
-	struct extent_buffer *eb;
 
 	if (slot < 0 || slot >= btrfs_header_nritems(parent))
 		return ERR_PTR(-ENOENT);
@@ -835,16 +834,8 @@ struct extent_buffer *btrfs_read_node_slot(struct extent_buffer *parent,
 	check.has_first_key = true;
 	btrfs_node_key_to_cpu(parent, &check.first_key, slot);
 
-	eb = read_tree_block(parent->fs_info, btrfs_node_blockptr(parent, slot),
-			     &check);
-	if (IS_ERR(eb))
-		return eb;
-	if (unlikely(!extent_buffer_uptodate(eb))) {
-		free_extent_buffer(eb);
-		return ERR_PTR(-EIO);
-	}
-
-	return eb;
+	return read_tree_block(parent->fs_info, btrfs_node_blockptr(parent, slot),
+			       &check);
 }
 
 /*
fs/btrfs/disk-io.c +0 -10
index c7b1f779e252..597d78d2dfe1 100644
@@ -2024,11 +2024,6 @@ static int btrfs_replay_log(struct btrfs_fs_info *fs_info,
 		btrfs_put_root(log_tree_root);
 		return ret;
 	}
-	if (unlikely(!extent_buffer_uptodate(log_tree_root->node))) {
-		btrfs_err(fs_info, "failed to read log tree");
-		btrfs_put_root(log_tree_root);
-		return -EIO;
-	}
 
 	/* returns with log_tree_root freed on success */
 	ret = btrfs_recover_log_trees(log_tree_root);
@@ -2628,11 +2623,6 @@ static int load_super_root(struct btrfs_root *root, u64 bytenr, u64 gen, int lev
 		root->node = NULL;
 		return ret;
 	}
-	if (unlikely(!extent_buffer_uptodate(root->node))) {
-		free_extent_buffer(root->node);
-		root->node = NULL;
-		return -EIO;
-	}
 
 	btrfs_set_root_node(&root->root_item, root->node);
 	root->commit_root = btrfs_root_node(root);
fs/btrfs/print-tree.c +0 -4
index f189bf09ce6a..15f7c0de513f 100644
@@ -616,10 +616,6 @@ void btrfs_print_tree(const struct extent_buffer *c, bool follow)
 		next = read_tree_block(fs_info, btrfs_node_blockptr(c, i), &check);
 		if (IS_ERR(next))
 			continue;
-		if (!extent_buffer_uptodate(next)) {
-			free_extent_buffer(next);
-			continue;
-		}
 
 		if (btrfs_is_leaf(next) &&
 		   level != 1)
fs/btrfs/qgroup.c +0 -4
index 6030214e413a..aaa47b63ffb1 100644
@@ -4884,10 +4884,6 @@ int btrfs_qgroup_trace_subtree_after_cow(struct btrfs_trans_handle *trans,
 		reloc_eb = NULL;
 		goto free_out;
 	}
-	if (unlikely(!extent_buffer_uptodate(reloc_eb))) {
-		ret = -EIO;
-		goto free_out;
-	}
 
 	ret = qgroup_trace_subtree_swap(trans, reloc_eb, subvol_eb,
 			block->last_snapshot, block->trace_leaf);
fs/btrfs/relocation.c +1 -4
index 64d140bea1fb..1da892af9a44 100644
@@ -2440,10 +2440,7 @@ static int get_tree_block_key(struct btrfs_fs_info *fs_info,
 	eb = read_tree_block(fs_info, block->bytenr, &check);
 	if (IS_ERR(eb))
 		return PTR_ERR(eb);
-	if (unlikely(!extent_buffer_uptodate(eb))) {
-		free_extent_buffer(eb);
-		return -EIO;
-	}
+
 	if (block->level == 0)
 		btrfs_item_key_to_cpu(eb, &block->key, 0);
 	else
fs/btrfs/tree-mod-log.c +3 -5
index 9e8cb3b7c064..d9f4bd2c17f1 100644
@@ -1043,12 +1043,10 @@ struct extent_buffer *btrfs_get_old_root(struct btrfs_root *root, u64 time_seq)
 		check.owner_root = btrfs_root_id(root);
 
 		old = read_tree_block(fs_info, logical, &check);
-		if (WARN_ON(IS_ERR(old) || !extent_buffer_uptodate(old))) {
-			if (!IS_ERR(old))
-				free_extent_buffer(old);
+		if (WARN_ON(IS_ERR(old))) {
 			btrfs_warn(fs_info,
-				   "failed to read tree block %llu from get_old_root",
-				   logical);
+				   "failed to read tree block %llu from get_old_root: %ld",
+				   logical, PTR_ERR(old));
 		} else {
 			struct tree_mod_elem *tm2;
 
Signature · 1 line
2.47.2
Reviewed-by on the v1 series
#3 lore raw
In reply to [email protected]
Quoted 3 lines · On Mon, Feb 09, 2026 at 11:07:09AM +0000, [email protected] wrote:

From: Filipe Manana <[email protected]>

Details in the change logs.

Quoted 19 lines

Filipe Manana (2):
btrfs: use the helper extent_buffer_uptodate() everywhere
btrfs: remove redundant extent_buffer_uptodate() checks after read_tree_block()

 fs/btrfs/backref.c      | 10 ----------
 fs/btrfs/ctree.c        | 13 ++-----------
 fs/btrfs/disk-io.c      | 10 ----------
 fs/btrfs/extent_io.c    |  6 +++---
 fs/btrfs/extent_io.h    |  2 +-
 fs/btrfs/print-tree.c   |  4 ----
 fs/btrfs/qgroup.c       |  4 ----
 fs/btrfs/relocation.c   |  5 +----
 fs/btrfs/tree-mod-log.c |  8 +++-----
 9 files changed, 10 insertions(+), 52 deletions(-)
Signature · 1 line
2.47.2