Skip to contentSkip to conversation

btrfs: don't clobber errors in add_remap_tree_entries()

PATCH In review Mark Harmstone 2 participants 2 messages Apr 8 – Apr 13 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: don't clobber errors in add_remap_tree_entries()

From: Mark Harmstone <[email protected]>

In add_remap_tree_entries(), we only process a certain number of entries at a time, meaning we may need to loop.

But because we weren't checking the return value of btrfs_insert_empty_items() within the loop, this meant that if the last iteration of the loop succeeded but a previous iteration failed, we were erroneously returning 0.

Fix this by breaking the loop early if btrfs_insert_empty_items() fails.

Fixes b56f35560b82 ("btrfs: handle setting up relocation of block group with remap-tree")
---
 fs/btrfs/relocation.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/relocation.c +1 -1
index ad433b7ca919aa..a7cf5d9cf1de0d 100644
@@ -3876,7 +3876,7 @@ static int add_remap_tree_entries(struct btrfs_trans_handle *trans, struct btrfs
 		ret = btrfs_insert_empty_items(trans, fs_info->remap_root, path, &batch);
 		btrfs_release_path(path);
 
-		if (num_entries <= max_items)
+		if (ret || num_entries <= max_items)
 			break;
 
 		num_entries -= max_items;
Signature · 1 line
2.52.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Mark Harmstone

From: Mark Harmstone <[email protected]>

In add_remap_tree_entries(), we only process a certain number of entries at a time, meaning we may need to loop.

But because we weren't checking the return value of btrfs_insert_empty_items() within the loop, this meant that if the last iteration of the loop succeeded but a previous iteration failed, we were erroneously returning 0.

Quoted 4 lines

Fix this by breaking the loop early if btrfs_insert_empty_items() fails.

Fixes b56f35560b82 ("btrfs: handle setting up relocation of block group with remap-tree")