public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers
@ 2026-02-09 11:07 fdmanana
  2026-02-09 11:07 ` [PATCH 1/2] btrfs: use the helper extent_buffer_uptodate() everywhere fdmanana
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fdmanana @ 2026-02-09 11:07 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

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(-)

-- 
2.47.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] btrfs: use the helper extent_buffer_uptodate() everywhere
  2026-02-09 11:07 [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers fdmanana
@ 2026-02-09 11:07 ` fdmanana
  2026-02-09 11:07 ` [PATCH 2/2] btrfs: remove redundant extent_buffer_uptodate() checks after read_tree_block() fdmanana
  2026-02-09 20:57 ` [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers Boris Burkov
  2 siblings, 0 replies; 4+ messages in thread
From: fdmanana @ 2026-02-09 11:07 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

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.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/extent_io.c | 6 +++---
 fs/btrfs/extent_io.h | 2 +-
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 3df399dc8856..11faecb66109 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -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;
 }
diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h
index 73571d5d3d5a..6409dda947f1 100644
--- a/fs/btrfs/extent_io.h
+++ b/fs/btrfs/extent_io.h
@@ -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);
 }
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] btrfs: remove redundant extent_buffer_uptodate() checks after read_tree_block()
  2026-02-09 11:07 [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers fdmanana
  2026-02-09 11:07 ` [PATCH 1/2] btrfs: use the helper extent_buffer_uptodate() everywhere fdmanana
@ 2026-02-09 11:07 ` fdmanana
  2026-02-09 20:57 ` [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers Boris Burkov
  2 siblings, 0 replies; 4+ messages in thread
From: fdmanana @ 2026-02-09 11:07 UTC (permalink / raw)
  To: linux-btrfs

From: Filipe Manana <fdmanana@suse.com>

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.

Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 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(-)

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 7921a926f676..8a119c505e32 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -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);
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index 7267b2502665..f2c925e90a87 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -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);
 }
 
 /*
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index c7b1f779e252..597d78d2dfe1 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -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);
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index f189bf09ce6a..15f7c0de513f 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -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)
diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c
index 6030214e413a..aaa47b63ffb1 100644
--- a/fs/btrfs/qgroup.c
+++ b/fs/btrfs/qgroup.c
@@ -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);
diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 64d140bea1fb..1da892af9a44 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -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
diff --git a/fs/btrfs/tree-mod-log.c b/fs/btrfs/tree-mod-log.c
index 9e8cb3b7c064..d9f4bd2c17f1 100644
--- a/fs/btrfs/tree-mod-log.c
+++ b/fs/btrfs/tree-mod-log.c
@@ -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;
 
-- 
2.47.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers
  2026-02-09 11:07 [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers fdmanana
  2026-02-09 11:07 ` [PATCH 1/2] btrfs: use the helper extent_buffer_uptodate() everywhere fdmanana
  2026-02-09 11:07 ` [PATCH 2/2] btrfs: remove redundant extent_buffer_uptodate() checks after read_tree_block() fdmanana
@ 2026-02-09 20:57 ` Boris Burkov
  2 siblings, 0 replies; 4+ messages in thread
From: Boris Burkov @ 2026-02-09 20:57 UTC (permalink / raw)
  To: fdmanana; +Cc: linux-btrfs

On Mon, Feb 09, 2026 at 11:07:09AM +0000, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> Details in the change logs.

Reviewed-by: Boris Burkov <boris@bur.io>

> 
> 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(-)
> 
> -- 
> 2.47.2
> 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-09 20:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-09 11:07 [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers fdmanana
2026-02-09 11:07 ` [PATCH 1/2] btrfs: use the helper extent_buffer_uptodate() everywhere fdmanana
2026-02-09 11:07 ` [PATCH 2/2] btrfs: remove redundant extent_buffer_uptodate() checks after read_tree_block() fdmanana
2026-02-09 20:57 ` [PATCH 0/2] btrfs: remove stale code in read_tree_block() callers Boris Burkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox