diff mbox series

[SRU,B,5/6] btrfs: Fix wrong first_key parameter in replace_path

Message ID 20210707044037.37992-6-matthew.ruffell@canonical.com
State New
Headers show
Series btrfs: Automatic balance returns -EUCLEAN and leads to forced readonly filesystem | expand

Commit Message

Matthew Ruffell July 7, 2021, 4:40 a.m. UTC
From: Qu Wenruo <wqu@suse.com>

BugLink: https://bugs.launchpad.net/bugs/1934709

Commit 581c1760415c ("btrfs: Validate child tree block's level and first
key") introduced new @first_key parameter for read_tree_block(), however
caller in replace_path() is parasing wrong key to read_tree_block().

It should use parameter @first_key other than @key.

Normally it won't expose problem as @key is normally initialzied to the
same value of @first_key we expect.
However in relocation recovery case, @key can be set to (0, 0, 0), and
since no valid key in relocation tree can be (0, 0, 0), it will cause
read_tree_block() to return -EUCLEAN and interrupt relocation recovery.

Fix it by setting @first_key correctly.

Fixes: 581c1760415c ("btrfs: Validate child tree block's level and first key")
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
(cherry picked from commit 17515f1b764df36271f3166c714f5a78301fbaa7)
Signed-off-by: Matthew Ruffell <matthew.ruffell@canonical.com>
---
 fs/btrfs/relocation.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index aaa33186648b..ff953b345cb0 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1855,7 +1855,7 @@  int replace_path(struct btrfs_trans_handle *trans,
 		old_bytenr = btrfs_node_blockptr(parent, slot);
 		blocksize = fs_info->nodesize;
 		old_ptr_gen = btrfs_node_ptr_generation(parent, slot);
-		btrfs_node_key_to_cpu(parent, &key, slot);
+		btrfs_node_key_to_cpu(parent, &first_key, slot);
 
 		if (level <= max_level) {
 			eb = path->nodes[level];