diff mbox

[01/11] btrfs-progs: lowmem check: Fix regression which screws up extent allocator

Message ID 20171122090325.29458-2-wqu@suse.com
State New, archived
Headers show

Commit Message

Qu Wenruo Nov. 22, 2017, 9:03 a.m. UTC
Commit 723427d7e6b7 ("btrfs-progs: check: change the way lowmem mode traverses
metadata") introduces a regression which could make some fsck self test
case to fail.

For fsck test case 004-no-dir-item, btrfs check --mode=lowmem --repair
can cause BUG_ON() with ret = -17 (-EEXIST) when committing transaction.

The problem happens with the following backtrace:


The bug is triggered by that, extent allocator considers range [29360128,
29376512) is free and allocate it.
However when inserting EXTENT_ITEM, btrfs finds there is already one
tree block (fs tree root), returning -EEXIST and causing later BUG_ON().

The cause is in repair mode, lowmem check always pins all metadata
However pinned metadata blocks will be unpin when transaction commits,
and will be marked as *FREE* space.

So later extent allocator will consider such range free and allocate
them wrongly.

Don't pin metadata blocks without valid reason or preparation (like
discard all free space cache to re-calculate free space on next write).

Fixes: 723427d7e6b7 ("btrfs-progs: check: change the way lowmem mode traverses metadata")
Signed-off-by: Qu Wenruo <wqu@suse.com>
 cmds-check.c | 10 ----------
 1 file changed, 10 deletions(-)
diff mbox


diff --git a/cmds-check.c b/cmds-check.c
index a93ac2c88a38..644ee084cb8e 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -6623,8 +6623,6 @@  out:
 	return ret;
-static int pin_metadata_blocks(struct btrfs_fs_info *fs_info);
  * Iterate all items in the tree and call check_inode_item() to check.
@@ -13306,8 +13304,6 @@  out:
 	return err;
-static int pin_metadata_blocks(struct btrfs_fs_info *fs_info);
  * Low memory usage version check_chunks_and_extents.
@@ -13326,12 +13322,6 @@  static int check_chunks_and_extents_v2(struct btrfs_fs_info *fs_info)
 	root = fs_info->fs_root;
 	if (repair) {
-		/* pin every tree block to avoid extent overwrite */
-		ret = pin_metadata_blocks(fs_info);
-		if (ret) {
-			error("failed to pin metadata blocks");
-			return ret;
-		}
 		trans = btrfs_start_transaction(fs_info->extent_root, 1);
 		if (IS_ERR(trans)) {
 			error("failed to start transaction before check");