All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v6 00/52]
@ 2020-12-08 16:23 Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 01/52] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Josef Bacik
                   ` (52 more replies)
  0 siblings, 53 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

v5->v6:
- Reworked "btrfs: handle errors from select_reloc_root()" because Zygo reported
  hitting an ASSERT(ret != -ENOENT) during his testing.  This was because I
  changed select_reloc_root() to return -ENOENT if we happened to race with
  somebody else who failed to init the reloc root, however we had an ASSERT() to
  check for this because it indicated corruption.  I modified that patch to move
  the ASSERT() to where the problem actually is, so select_reloc_root() can
  return whatever error and it'll pass it along.  I also removed Qu's
  reviewed-by for the patch because of the change.

v4->v5:
- Dropped "btrfs: fix error handling in commit_fs_roots" as it was merged.
- Fixed an ASSERT() that happened during relocation recovery that Zygo reported,
  I moved the error condition out of another condition which broke recovery if
  we had deleted subvols pending with relocation.

v3->v4:
- Squashed the __add_reloc_root error handling patches in
  btrfs_recover_relocation as they were small and in the same function.
- Squashed the record_root_in_trans failure handling patches for
  select_reloc_root as they were small and in the same function.
- Added a new patch to address an existing error handling problem with subvol
  creation.
- Fixed up the various cases that Qu noticed where I got things wrong, cleaning
  up a leaked root extent ref, a leaked inode item, and where I accidentally
  stopped dealing with errors from btrfs_drop_subtree.
- Reworked a bunch of the ASSERT()'s to do ASSERT(0) in their respective if
  statements.
- Added reviewed-bys.

v2->v3:
- A lot of extra patches fixing various things that I encountered while
  debugging the corruption problem that was uncovered by these patches.
- Fixed the panic that Zygo was seeing and other issues.
- Fixed up the comments from Nikolay and Filipe.

A slight note, the first set of patches could probably be taken now, and in fact

  btrfs: fix error handling in commit_fs_roots

Was sent earlier this week and is very important and needs to be reviewed and
merged ASAP.  The following are safe and could be merged outside of the rest of
this series

  btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
  btrfs: fix lockdep splat in btrfs_recover_relocation
  btrfs: keep track of the root owner for relocation reads
  btrfs: noinline btrfs_should_cancel_balance
  btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node
  btrfs: pass down the tree block level through ref-verify
  btrfs: make sure owner is set in ref-verify
  btrfs: don't clear ret in btrfs_start_dirty_block_groups

The rest obviously are all around the actual error handling.

v1->v2:
- fixed a bug where I accidentally dropped reading flags in relocate_block_group
  when I dropped the extra checks that we handle in the tree checker.

--- Original message ---
Hello,

Relocation is the last place that is not able to handle errors at all, which
results in all sorts of lovely panics if you encounter corruptions or IO errors.
I'm going to start cleaning up relocation, but before I move code around I want
the error handling to be somewhat sane, so I'm not changing behavior and error
handling at the same time.

These patches are purely about error handling, there is no behavior changing
other than returning errors up the chain properly.  There is a lot of room for
follow up cleanups, which will happen next.  However I wanted to get this series
done today and out so we could get it merged ASAP, and then the follow up
cleanups can happen later as they are less important and less critical.

The only exception to the above is the patch to add the error injection sites
for btrfs_cow_block and btrfs_search_slot, and a lockdep fix that I discovered
while running my tests, those are the first two patches in the series.

I tested this with my error injection stress test, where I keep track of all
stack traces that have been tested and only inject errors when we have a new
stack trace, which means I should have covered all of the various error
conditions.  With this patchset I'm no longer panicing while stressing the error
conditions.  Thanks,

Josef

Josef Bacik (52):
  btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
  btrfs: modify the new_root highest_objectid under a ref count
  btrfs: fix lockdep splat in btrfs_recover_relocation
  btrfs: keep track of the root owner for relocation reads
  btrfs: noinline btrfs_should_cancel_balance
  btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node
  btrfs: pass down the tree block level through ref-verify
  btrfs: make sure owner is set in ref-verify
  btrfs: don't clear ret in btrfs_start_dirty_block_groups
  btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation
  btrfs: convert BUG_ON()'s in relocate_tree_block
  btrfs: return an error from btrfs_record_root_in_trans
  btrfs: handle errors from select_reloc_root()
  btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors
  btrfs: check record_root_in_trans related failures in
    select_reloc_root
  btrfs: do proper error handling in record_reloc_root_in_trans
  btrfs: handle btrfs_record_root_in_trans failure in
    btrfs_rename_exchange
  btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename
  btrfs: handle btrfs_record_root_in_trans failure in
    btrfs_delete_subvolume
  btrfs: handle btrfs_record_root_in_trans failure in
    btrfs_recover_log_trees
  btrfs: handle btrfs_record_root_in_trans failure in create_subvol
  btrfs: btrfs: handle btrfs_record_root_in_trans failure in
    relocate_tree_block
  btrfs: handle btrfs_record_root_in_trans failure in start_transaction
  btrfs: handle record_root_in_trans failure in qgroup_account_snapshot
  btrfs: handle record_root_in_trans failure in
    btrfs_record_root_in_trans
  btrfs: handle record_root_in_trans failure in create_pending_snapshot
  btrfs: do not panic in __add_reloc_root
  btrfs: have proper error handling in btrfs_init_reloc_root
  btrfs: do proper error handling in create_reloc_root
  btrfs: validate ->reloc_root after recording root in trans
  btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots
  btrfs: change insert_dirty_subvol to return errors
  btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol
  btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge
  btrfs: do proper error handling in btrfs_update_reloc_root
  btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s
  btrfs: handle btrfs_cow_block errors in replace_path
  btrfs: handle btrfs_search_slot failure in replace_path
  btrfs: handle errors in reference count manipulation in replace_path
  btrfs: handle extent reference errors in do_relocation
  btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly
  btrfs: remove the extent item sanity checks in relocate_block_group
  btrfs: do proper error handling in create_reloc_inode
  btrfs: handle __add_reloc_root failures in btrfs_recover_relocation
  btrfs: cleanup error handling in prepare_to_merge
  btrfs: handle extent corruption with select_one_root properly
  btrfs: do proper error handling in merge_reloc_roots
  btrfs: check return value of btrfs_commit_transaction in relocation
  btrfs: do not WARN_ON() if we can't find the reloc root
  btrfs: print the actual offset in btrfs_root_name
  btrfs: fix reloc root leak with 0 ref reloc roots on recovery
  btrfs: splice remaining dirty_bg's onto the transaction dirty bg list

 fs/btrfs/backref.c      |   9 +-
 fs/btrfs/block-group.c  |   6 +-
 fs/btrfs/ctree.c        |   2 +
 fs/btrfs/disk-io.c      |   2 +-
 fs/btrfs/inode.c        |  20 +-
 fs/btrfs/ioctl.c        |  17 +-
 fs/btrfs/print-tree.c   |  10 +-
 fs/btrfs/print-tree.h   |   2 +-
 fs/btrfs/ref-verify.c   |  43 ++--
 fs/btrfs/relocation.c   | 474 +++++++++++++++++++++++++++++++---------
 fs/btrfs/transaction.c  |  37 +++-
 fs/btrfs/tree-checker.c |   5 +
 fs/btrfs/tree-log.c     |   8 +-
 fs/btrfs/volumes.c      |   2 +
 14 files changed, 477 insertions(+), 160 deletions(-)

-- 
2.26.2


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

* [PATCH v6 01/52] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 02/52] btrfs: modify the new_root highest_objectid under a ref count Josef Bacik
                   ` (51 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo, Johannes Thumshirn

The following patches are going to address error handling in relocation,
in order to test those patches I need to be able to inject errors in
btrfs_search_slot and btrfs_cow_block, as we call both of these pretty
often in different cases during relocation.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ctree.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
index cc89b63d65a4..56e132d825a2 100644
--- a/fs/btrfs/ctree.c
+++ b/fs/btrfs/ctree.c
@@ -1494,6 +1494,7 @@ noinline int btrfs_cow_block(struct btrfs_trans_handle *trans,
 
 	return ret;
 }
+ALLOW_ERROR_INJECTION(btrfs_cow_block, ERRNO);
 
 /*
  * helper function for defrag to decide if two blocks pointed to by a
@@ -2821,6 +2822,7 @@ int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 		btrfs_release_path(p);
 	return ret;
 }
+ALLOW_ERROR_INJECTION(btrfs_search_slot, ERRNO);
 
 /*
  * Like btrfs_search_slot, this looks for a key in the given tree. It uses the
-- 
2.26.2


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

* [PATCH v6 02/52] btrfs: modify the new_root highest_objectid under a ref count
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 01/52] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 03/52] btrfs: fix lockdep splat in btrfs_recover_relocation Josef Bacik
                   ` (50 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Qu pointed out a bug in one of my error handling patches, which made me
notice that we modify the new_root->highest_objectid _after_ we've
dropped the ref to the new_root.  This could lead to a possible UAF, fix
this by modifying the ->highest_objectid before we drop our reference to
the new_root.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ioctl.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index dde49a791f3e..af8d01659562 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -717,6 +717,12 @@ static noinline int create_subvol(struct inode *dir,
 	btrfs_record_root_in_trans(trans, new_root);
 
 	ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid);
+	if (!ret) {
+		mutex_lock(&new_root->objectid_mutex);
+		new_root->highest_objectid = new_dirid;
+		mutex_unlock(&new_root->objectid_mutex);
+	}
+
 	btrfs_put_root(new_root);
 	if (ret) {
 		/* We potentially lose an unused inode item here */
@@ -724,10 +730,6 @@ static noinline int create_subvol(struct inode *dir,
 		goto fail;
 	}
 
-	mutex_lock(&new_root->objectid_mutex);
-	new_root->highest_objectid = new_dirid;
-	mutex_unlock(&new_root->objectid_mutex);
-
 	/*
 	 * insert the directory item
 	 */
-- 
2.26.2


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

* [PATCH v6 03/52] btrfs: fix lockdep splat in btrfs_recover_relocation
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 01/52] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 02/52] btrfs: modify the new_root highest_objectid under a ref count Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 04/52] btrfs: keep track of the root owner for relocation reads Josef Bacik
                   ` (49 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo, Johannes Thumshirn

While testing the error paths of relocation I hit the following lockdep
splat

======================================================
WARNING: possible circular locking dependency detected
5.10.0-rc6+ #217 Not tainted
------------------------------------------------------
mount/779 is trying to acquire lock:
ffffa0e676945418 (&fs_info->balance_mutex){+.+.}-{3:3}, at: btrfs_recover_balance+0x2f0/0x340

but task is already holding lock:
ffffa0e60ee31da8 (btrfs-root-00){++++}-{3:3}, at: __btrfs_tree_read_lock+0x27/0x100

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (btrfs-root-00){++++}-{3:3}:
       down_read_nested+0x43/0x130
       __btrfs_tree_read_lock+0x27/0x100
       btrfs_read_lock_root_node+0x31/0x40
       btrfs_search_slot+0x462/0x8f0
       btrfs_update_root+0x55/0x2b0
       btrfs_drop_snapshot+0x398/0x750
       clean_dirty_subvols+0xdf/0x120
       btrfs_recover_relocation+0x534/0x5a0
       btrfs_start_pre_rw_mount+0xcb/0x170
       open_ctree+0x151f/0x1726
       btrfs_mount_root.cold+0x12/0xea
       legacy_get_tree+0x30/0x50
       vfs_get_tree+0x28/0xc0
       vfs_kern_mount.part.0+0x71/0xb0
       btrfs_mount+0x10d/0x380
       legacy_get_tree+0x30/0x50
       vfs_get_tree+0x28/0xc0
       path_mount+0x433/0xc10
       __x64_sys_mount+0xe3/0x120
       do_syscall_64+0x33/0x40
       entry_SYSCALL_64_after_hwframe+0x44/0xa9

-> #1 (sb_internal#2){.+.+}-{0:0}:
       start_transaction+0x444/0x700
       insert_balance_item.isra.0+0x37/0x320
       btrfs_balance+0x354/0xf40
       btrfs_ioctl_balance+0x2cf/0x380
       __x64_sys_ioctl+0x83/0xb0
       do_syscall_64+0x33/0x40
       entry_SYSCALL_64_after_hwframe+0x44/0xa9

-> #0 (&fs_info->balance_mutex){+.+.}-{3:3}:
       __lock_acquire+0x1120/0x1e10
       lock_acquire+0x116/0x370
       __mutex_lock+0x7e/0x7b0
       btrfs_recover_balance+0x2f0/0x340
       open_ctree+0x1095/0x1726
       btrfs_mount_root.cold+0x12/0xea
       legacy_get_tree+0x30/0x50
       vfs_get_tree+0x28/0xc0
       vfs_kern_mount.part.0+0x71/0xb0
       btrfs_mount+0x10d/0x380
       legacy_get_tree+0x30/0x50
       vfs_get_tree+0x28/0xc0
       path_mount+0x433/0xc10
       __x64_sys_mount+0xe3/0x120
       do_syscall_64+0x33/0x40
       entry_SYSCALL_64_after_hwframe+0x44/0xa9

other info that might help us debug this:

Chain exists of:
  &fs_info->balance_mutex --> sb_internal#2 --> btrfs-root-00

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(btrfs-root-00);
                               lock(sb_internal#2);
                               lock(btrfs-root-00);
  lock(&fs_info->balance_mutex);

 *** DEADLOCK ***

2 locks held by mount/779:
 #0: ffffa0e60dc040e0 (&type->s_umount_key#47/1){+.+.}-{3:3}, at: alloc_super+0xb5/0x380
 #1: ffffa0e60ee31da8 (btrfs-root-00){++++}-{3:3}, at: __btrfs_tree_read_lock+0x27/0x100

stack backtrace:
CPU: 0 PID: 779 Comm: mount Not tainted 5.10.0-rc6+ #217
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
Call Trace:
 dump_stack+0x8b/0xb0
 check_noncircular+0xcf/0xf0
 ? trace_call_bpf+0x139/0x260
 __lock_acquire+0x1120/0x1e10
 lock_acquire+0x116/0x370
 ? btrfs_recover_balance+0x2f0/0x340
 __mutex_lock+0x7e/0x7b0
 ? btrfs_recover_balance+0x2f0/0x340
 ? btrfs_recover_balance+0x2f0/0x340
 ? rcu_read_lock_sched_held+0x3f/0x80
 ? kmem_cache_alloc_trace+0x2c4/0x2f0
 ? btrfs_get_64+0x5e/0x100
 btrfs_recover_balance+0x2f0/0x340
 open_ctree+0x1095/0x1726
 btrfs_mount_root.cold+0x12/0xea
 ? rcu_read_lock_sched_held+0x3f/0x80
 legacy_get_tree+0x30/0x50
 vfs_get_tree+0x28/0xc0
 vfs_kern_mount.part.0+0x71/0xb0
 btrfs_mount+0x10d/0x380
 ? __kmalloc_track_caller+0x2f2/0x320
 legacy_get_tree+0x30/0x50
 vfs_get_tree+0x28/0xc0
 ? capable+0x3a/0x60
 path_mount+0x433/0xc10
 __x64_sys_mount+0xe3/0x120
 do_syscall_64+0x33/0x40
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

This is thankfully straightforward to fix, simply release the path
before we setup the reloc_ctl.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/volumes.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 7930e1c78c45..49ba941f0314 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -4318,6 +4318,8 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
 		btrfs_warn(fs_info,
 	"balance: cannot set exclusive op status, resume manually");
 
+	btrfs_release_path(path);
+
 	mutex_lock(&fs_info->balance_mutex);
 	BUG_ON(fs_info->balance_ctl);
 	spin_lock(&fs_info->balance_lock);
-- 
2.26.2


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

* [PATCH v6 04/52] btrfs: keep track of the root owner for relocation reads
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (2 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 03/52] btrfs: fix lockdep splat in btrfs_recover_relocation Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 05/52] btrfs: noinline btrfs_should_cancel_balance Josef Bacik
                   ` (48 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

While testing the error paths in relocation, I hit the following lockdep
splat

======================================================
WARNING: possible circular locking dependency detected
5.10.0-rc3+ #206 Not tainted
------------------------------------------------------
btrfs-balance/1571 is trying to acquire lock:
ffff8cdbcc8f77d0 (&head_ref->mutex){+.+.}-{3:3}, at: btrfs_lookup_extent_info+0x156/0x3b0

but task is already holding lock:
ffff8cdbc54adbf8 (btrfs-tree-00){++++}-{3:3}, at: __btrfs_tree_lock+0x27/0x100

which lock already depends on the new lock.

the existing dependency chain (in reverse order) is:

-> #2 (btrfs-tree-00){++++}-{3:3}:
       down_write_nested+0x43/0x80
       __btrfs_tree_lock+0x27/0x100
       btrfs_search_slot+0x248/0x890
       relocate_tree_blocks+0x490/0x650
       relocate_block_group+0x1ba/0x5d0
       kretprobe_trampoline+0x0/0x50

-> #1 (btrfs-csum-01){++++}-{3:3}:
       down_read_nested+0x43/0x130
       __btrfs_tree_read_lock+0x27/0x100
       btrfs_read_lock_root_node+0x31/0x40
       btrfs_search_slot+0x5ab/0x890
       btrfs_del_csums+0x10b/0x3c0
       __btrfs_free_extent+0x49d/0x8e0
       __btrfs_run_delayed_refs+0x283/0x11f0
       btrfs_run_delayed_refs+0x86/0x220
       btrfs_start_dirty_block_groups+0x2ba/0x520
       kretprobe_trampoline+0x0/0x50

-> #0 (&head_ref->mutex){+.+.}-{3:3}:
       __lock_acquire+0x1167/0x2150
       lock_acquire+0x116/0x3e0
       __mutex_lock+0x7e/0x7b0
       btrfs_lookup_extent_info+0x156/0x3b0
       walk_down_proc+0x1c3/0x280
       walk_down_tree+0x64/0xe0
       btrfs_drop_subtree+0x182/0x260
       do_relocation+0x52e/0x660
       relocate_tree_blocks+0x2ae/0x650
       relocate_block_group+0x1ba/0x5d0
       kretprobe_trampoline+0x0/0x50

other info that might help us debug this:

Chain exists of:
  &head_ref->mutex --> btrfs-csum-01 --> btrfs-tree-00

 Possible unsafe locking scenario:

       CPU0                    CPU1
       ----                    ----
  lock(btrfs-tree-00);
                               lock(btrfs-csum-01);
                               lock(btrfs-tree-00);
  lock(&head_ref->mutex);

 *** DEADLOCK ***

5 locks held by btrfs-balance/1571:
 #0: ffff8cdb89749ff8 (&fs_info->delete_unused_bgs_mutex){+.+.}-{3:3}, at: btrfs_balance+0x563/0xf40
 #1: ffff8cdb89748838 (&fs_info->cleaner_mutex){+.+.}-{3:3}, at: btrfs_relocate_block_group+0x156/0x300
 #2: ffff8cdbc2c16650 (sb_internal#2){.+.+}-{0:0}, at: start_transaction+0x413/0x5c0
 #3: ffff8cdbc135f538 (btrfs-treloc-01){+.+.}-{3:3}, at: __btrfs_tree_lock+0x27/0x100
 #4: ffff8cdbc54adbf8 (btrfs-tree-00){++++}-{3:3}, at: __btrfs_tree_lock+0x27/0x100

stack backtrace:
CPU: 1 PID: 1571 Comm: btrfs-balance Not tainted 5.10.0-rc3+ #206
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
Call Trace:
 dump_stack+0x8b/0xb0
 check_noncircular+0xcf/0xf0
 ? trace_call_bpf+0x139/0x260
 __lock_acquire+0x1167/0x2150
 lock_acquire+0x116/0x3e0
 ? btrfs_lookup_extent_info+0x156/0x3b0
 __mutex_lock+0x7e/0x7b0
 ? btrfs_lookup_extent_info+0x156/0x3b0
 ? btrfs_lookup_extent_info+0x156/0x3b0
 ? release_extent_buffer+0x124/0x170
 ? _raw_spin_unlock+0x1f/0x30
 ? release_extent_buffer+0x124/0x170
 btrfs_lookup_extent_info+0x156/0x3b0
 walk_down_proc+0x1c3/0x280
 walk_down_tree+0x64/0xe0
 btrfs_drop_subtree+0x182/0x260
 do_relocation+0x52e/0x660
 relocate_tree_blocks+0x2ae/0x650
 ? add_tree_block+0x149/0x1b0
 relocate_block_group+0x1ba/0x5d0
 elfcorehdr_read+0x40/0x40
 ? elfcorehdr_read+0x40/0x40
 ? btrfs_balance+0x796/0xf40
 ? __kthread_parkme+0x66/0x90
 ? btrfs_balance+0xf40/0xf40
 ? balance_kthread+0x37/0x50
 ? kthread+0x137/0x150
 ? __kthread_bind_mask+0x60/0x60
 ? ret_from_fork+0x1f/0x30

As you can see this is bogus, we never take another tree's lock under
the csum lock.  This happens because sometimes we have to read tree
blocks from disk without knowing which root they belong to during
relocation.  We defaulted to an owner of 0, which translates to an fs
tree.  This is fine as all fs trees have the same class, but obviously
isn't fine if the block belongs to a cow only tree.

Thankfully cow only trees only have their owners root as a reference to
them, and since we already look up the extent information during
relocation, go ahead and check and see if this block might belong to a
cow only tree, and if so save the owner in the struct tree_block.  This
allows us to read_tree_block with the proper owner, which gets rid of
this lockdep splat.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 47 ++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 44 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 19b7db8b2117..2b30e39e922a 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -98,6 +98,7 @@ struct tree_block {
 		u64 bytenr;
 	}; /* Use rb_simple_node for search/insert */
 	struct btrfs_key key;
+	u64 owner;
 	unsigned int level:8;
 	unsigned int key_ready:1;
 };
@@ -2393,8 +2394,8 @@ static int get_tree_block_key(struct btrfs_fs_info *fs_info,
 {
 	struct extent_buffer *eb;
 
-	eb = read_tree_block(fs_info, block->bytenr, 0, block->key.offset,
-			     block->level, NULL);
+	eb = read_tree_block(fs_info, block->bytenr, block->owner,
+			     block->key.offset, block->level, NULL);
 	if (IS_ERR(eb)) {
 		return PTR_ERR(eb);
 	} else if (!extent_buffer_uptodate(eb)) {
@@ -2493,7 +2494,8 @@ int relocate_tree_blocks(struct btrfs_trans_handle *trans,
 	/* Kick in readahead for tree blocks with missing keys */
 	rbtree_postorder_for_each_entry_safe(block, next, blocks, rb_node) {
 		if (!block->key_ready)
-			btrfs_readahead_tree_block(fs_info, block->bytenr, 0, 0,
+			btrfs_readahead_tree_block(fs_info, block->bytenr,
+						   block->owner, 0,
 						   block->level);
 	}
 
@@ -2801,21 +2803,59 @@ static int add_tree_block(struct reloc_control *rc,
 	u32 item_size;
 	int level = -1;
 	u64 generation;
+	u64 owner = 0;
 
 	eb =  path->nodes[0];
 	item_size = btrfs_item_size_nr(eb, path->slots[0]);
 
 	if (extent_key->type == BTRFS_METADATA_ITEM_KEY ||
 	    item_size >= sizeof(*ei) + sizeof(*bi)) {
+		unsigned long ptr = 0, end;
+
 		ei = btrfs_item_ptr(eb, path->slots[0],
 				struct btrfs_extent_item);
+		end = (unsigned long)ei + item_size;
 		if (extent_key->type == BTRFS_EXTENT_ITEM_KEY) {
 			bi = (struct btrfs_tree_block_info *)(ei + 1);
 			level = btrfs_tree_block_level(eb, bi);
+			ptr = (unsigned long)(bi + 1);
 		} else {
 			level = (int)extent_key->offset;
+			ptr = (unsigned long)(ei + 1);
 		}
 		generation = btrfs_extent_generation(eb, ei);
+
+		/*
+		 * We're reading random blocks without knowing their owner ahead
+		 * of time.  This is ok most of the time, as all reloc roots and
+		 * fs roots have the same lock type.  However normal trees do
+		 * not, and the only way to know ahead of time is to read the
+		 * inline ref offset.  We know it's an fs root if
+		 *
+		 * 1. There's more than one ref.
+		 * 2. There's a SHARED_DATA_REF_KEY set.
+		 * 3. FULL_BACKREF is set on the flags.
+		 *
+		 * Otherwise it's safe to assume that the ref offset == the
+		 * owner of this block, so we can use that when calling
+		 * read_tree_block.
+		 */
+		if (btrfs_extent_refs(eb, ei) == 1 &&
+		    !(btrfs_extent_flags(eb, ei) &
+		      BTRFS_BLOCK_FLAG_FULL_BACKREF) &&
+		    ptr < end) {
+			struct btrfs_extent_inline_ref *iref;
+			int type;
+
+			iref = (struct btrfs_extent_inline_ref *)ptr;
+			type = btrfs_get_extent_inline_ref_type(eb, iref,
+							BTRFS_REF_TYPE_BLOCK);
+			if (type == BTRFS_REF_TYPE_INVALID)
+				return -EINVAL;
+			if (type == BTRFS_TREE_BLOCK_REF_KEY)
+				owner = btrfs_extent_inline_ref_offset(eb,
+								       iref);
+		}
 	} else if (unlikely(item_size == sizeof(struct btrfs_extent_item_v0))) {
 		btrfs_print_v0_err(eb->fs_info);
 		btrfs_handle_fs_error(eb->fs_info, -EINVAL, NULL);
@@ -2837,6 +2877,7 @@ static int add_tree_block(struct reloc_control *rc,
 	block->key.offset = generation;
 	block->level = level;
 	block->key_ready = 0;
+	block->owner = owner;
 
 	rb_node = rb_simple_insert(blocks, block->bytenr, &block->rb_node);
 	if (rb_node)
-- 
2.26.2


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

* [PATCH v6 05/52] btrfs: noinline btrfs_should_cancel_balance
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (3 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 04/52] btrfs: keep track of the root owner for relocation reads Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 06/52] btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node Josef Bacik
                   ` (47 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo, Johannes Thumshirn

I was attempting to reproduce a problem that Zygo hit, but my error
injection wasn't firing for a few of the common calls to
btrfs_should_cancel_balance.  This is because the compiler decided to
inline it at these spots.  Keep this from happening by explicitly
noinline'ing the function so that error injection will always work.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 2b30e39e922a..ce935139d87b 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2617,7 +2617,7 @@ int setup_extent_mapping(struct inode *inode, u64 start, u64 end,
 /*
  * Allow error injection to test balance cancellation
  */
-int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info)
+noinline int btrfs_should_cancel_balance(struct btrfs_fs_info *fs_info)
 {
 	return atomic_read(&fs_info->balance_cancel_req) ||
 		fatal_signal_pending(current);
-- 
2.26.2


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

* [PATCH v6 06/52] btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (4 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 05/52] btrfs: noinline btrfs_should_cancel_balance Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 07/52] btrfs: pass down the tree block level through ref-verify Josef Bacik
                   ` (46 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

Zygo reported the following panic when testing my error handling patches
for relocation

------------[ cut here ]------------
kernel BUG at fs/btrfs/backref.c:2545!
invalid opcode: 0000 [#1] SMP KASAN PTI CPU: 3 PID: 8472 Comm: btrfs Tainted: G        W 14
Hardware name: QEMU Standard PC (i440FX + PIIX,

Call Trace:
 btrfs_backref_error_cleanup+0x4df/0x530
 build_backref_tree+0x1a5/0x700
 ? _raw_spin_unlock+0x22/0x30
 ? release_extent_buffer+0x225/0x280
 ? free_extent_buffer.part.52+0xd7/0x140
 relocate_tree_blocks+0x2a6/0xb60
 ? kasan_unpoison_shadow+0x35/0x50
 ? do_relocation+0xc10/0xc10
 ? kasan_kmalloc+0x9/0x10
 ? kmem_cache_alloc_trace+0x6a3/0xcb0
 ? free_extent_buffer.part.52+0xd7/0x140
 ? rb_insert_color+0x342/0x360
 ? add_tree_block.isra.36+0x236/0x2b0
 relocate_block_group+0x2eb/0x780
 ? merge_reloc_roots+0x470/0x470
 btrfs_relocate_block_group+0x26e/0x4c0
 btrfs_relocate_chunk+0x52/0x120
 btrfs_balance+0xe2e/0x18f0
 ? pvclock_clocksource_read+0xeb/0x190
 ? btrfs_relocate_chunk+0x120/0x120
 ? lock_contended+0x620/0x6e0
 ? do_raw_spin_lock+0x1e0/0x1e0
 ? do_raw_spin_unlock+0xa8/0x140
 btrfs_ioctl_balance+0x1f9/0x460
 btrfs_ioctl+0x24c8/0x4380
 ? __kasan_check_read+0x11/0x20
 ? check_chain_key+0x1f4/0x2f0
 ? __asan_loadN+0xf/0x20
 ? btrfs_ioctl_get_supported_features+0x30/0x30
 ? kvm_sched_clock_read+0x18/0x30
 ? check_chain_key+0x1f4/0x2f0
 ? lock_downgrade+0x3f0/0x3f0
 ? handle_mm_fault+0xad6/0x2150
 ? do_vfs_ioctl+0xfc/0x9d0
 ? ioctl_file_clone+0xe0/0xe0
 ? check_flags.part.50+0x6c/0x1e0
 ? check_flags.part.50+0x6c/0x1e0
 ? check_flags+0x26/0x30
 ? lock_is_held_type+0xc3/0xf0
 ? syscall_enter_from_user_mode+0x1b/0x60
 ? do_syscall_64+0x13/0x80
 ? rcu_read_lock_sched_held+0xa1/0xd0
 ? __kasan_check_read+0x11/0x20
 ? __fget_light+0xae/0x110
 __x64_sys_ioctl+0xc3/0x100
 do_syscall_64+0x37/0x80
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

This occurs because of this check

if (RB_EMPTY_NODE(&upper->rb_node))
	BUG_ON(!list_empty(&node->upper));

As we are dropping the backref node, if we discover that our upper node
in the edge we just cleaned up isn't linked into the cache that we are
now done with this node, thus the BUG_ON().

However this is an erroneous assumption, as we will look up all the
references for a node first, and then process the pending edges.  All of
the 'upper' nodes in our pending edges won't be in the cache's rb_tree
yet, because they haven't been processed.  We could very well have many
edges still left to cleanup on this node.

The fact is we simply do not need this check, we can just process all of
the edges only for this node, because below this check we do the
following

if (list_empty(&upper->lower)) {
	list_add_tail(&upper->lower, &cache->leaves);
	upper->lowest = 1;
}

If the upper node truly isn't used yet, then we add it to the
cache->leaves list to be cleaned up later.  If it is still used then the
last child node that has it linked into its node will add it to the
leaves list and then it will be cleaned up.

Fix this problem by dropping this logic altogether.  With this fix I no
longer see the panic when testing with error injection in the backref
code.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/backref.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 02d7d7b2563b..56f7c840031e 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2541,13 +2541,6 @@ void btrfs_backref_cleanup_node(struct btrfs_backref_cache *cache,
 		list_del(&edge->list[UPPER]);
 		btrfs_backref_free_edge(cache, edge);
 
-		if (RB_EMPTY_NODE(&upper->rb_node)) {
-			BUG_ON(!list_empty(&node->upper));
-			btrfs_backref_drop_node(cache, node);
-			node = upper;
-			node->lowest = 1;
-			continue;
-		}
 		/*
 		 * Add the node to leaf node list if no other child block
 		 * cached.
-- 
2.26.2


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

* [PATCH v6 07/52] btrfs: pass down the tree block level through ref-verify
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (5 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 06/52] btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 08/52] btrfs: make sure owner is set in ref-verify Josef Bacik
                   ` (45 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

I noticed that sometimes I would have the wrong level printed out with
ref-verify while testing some error injection related problems.  This is
because we only get the level from the main extent item, but our
references could go off the current leaf into another, and at that point
we lose our level.  Fix this by keeping track of the last tree block
level that we found, the same way we keep track of our bytenr and
num_bytes, in case we happen to wander into another leaf while still
processing the references for a bytenr.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ref-verify.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index 4b9b6c52a83b..409b02566b25 100644
--- a/fs/btrfs/ref-verify.c
+++ b/fs/btrfs/ref-verify.c
@@ -495,14 +495,15 @@ static int process_extent_item(struct btrfs_fs_info *fs_info,
 }
 
 static int process_leaf(struct btrfs_root *root,
-			struct btrfs_path *path, u64 *bytenr, u64 *num_bytes)
+			struct btrfs_path *path, u64 *bytenr, u64 *num_bytes,
+			int *tree_block_level)
 {
 	struct btrfs_fs_info *fs_info = root->fs_info;
 	struct extent_buffer *leaf = path->nodes[0];
 	struct btrfs_extent_data_ref *dref;
 	struct btrfs_shared_data_ref *sref;
 	u32 count;
-	int i = 0, tree_block_level = 0, ret = 0;
+	int i = 0, ret = 0;
 	struct btrfs_key key;
 	int nritems = btrfs_header_nritems(leaf);
 
@@ -515,15 +516,15 @@ static int process_leaf(struct btrfs_root *root,
 		case BTRFS_METADATA_ITEM_KEY:
 			*bytenr = key.objectid;
 			ret = process_extent_item(fs_info, path, &key, i,
-						  &tree_block_level);
+						  tree_block_level);
 			break;
 		case BTRFS_TREE_BLOCK_REF_KEY:
 			ret = add_tree_block(fs_info, key.offset, 0,
-					     key.objectid, tree_block_level);
+					     key.objectid, *tree_block_level);
 			break;
 		case BTRFS_SHARED_BLOCK_REF_KEY:
 			ret = add_tree_block(fs_info, 0, key.offset,
-					     key.objectid, tree_block_level);
+					     key.objectid, *tree_block_level);
 			break;
 		case BTRFS_EXTENT_DATA_REF_KEY:
 			dref = btrfs_item_ptr(leaf, i,
@@ -549,7 +550,8 @@ static int process_leaf(struct btrfs_root *root,
 
 /* Walk down to the leaf from the given level */
 static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
-			  int level, u64 *bytenr, u64 *num_bytes)
+			  int level, u64 *bytenr, u64 *num_bytes,
+			  int *tree_block_level)
 {
 	struct extent_buffer *eb;
 	int ret = 0;
@@ -565,7 +567,8 @@ static int walk_down_tree(struct btrfs_root *root, struct btrfs_path *path,
 			path->slots[level-1] = 0;
 			path->locks[level-1] = BTRFS_READ_LOCK;
 		} else {
-			ret = process_leaf(root, path, bytenr, num_bytes);
+			ret = process_leaf(root, path, bytenr, num_bytes,
+					   tree_block_level);
 			if (ret)
 				break;
 		}
@@ -974,6 +977,7 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)
 {
 	struct btrfs_path *path;
 	struct extent_buffer *eb;
+	int tree_block_level = 0;
 	u64 bytenr = 0, num_bytes = 0;
 	int ret, level;
 
@@ -998,7 +1002,7 @@ int btrfs_build_ref_tree(struct btrfs_fs_info *fs_info)
 		 * different leaf from the original extent item.
 		 */
 		ret = walk_down_tree(fs_info->extent_root, path, level,
-				     &bytenr, &num_bytes);
+				     &bytenr, &num_bytes, &tree_block_level);
 		if (ret)
 			break;
 		ret = walk_up_tree(path, &level);
-- 
2.26.2


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

* [PATCH v6 08/52] btrfs: make sure owner is set in ref-verify
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (6 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 07/52] btrfs: pass down the tree block level through ref-verify Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 09/52] btrfs: don't clear ret in btrfs_start_dirty_block_groups Josef Bacik
                   ` (44 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

I noticed that shared ref entries in ref-verify didn't have the proper
owner set, which caused me to think there was something seriously wrong.
However the problem is if we have a parent we simply weren't filling out
the owner part of the reference, even though we have it.  Fix this by
making sure we set all the proper fields when we modify a reference,
this way we'll have the proper owner if a problem happens and we don't
waste time thinking we're updating the wrong level.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ref-verify.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/fs/btrfs/ref-verify.c b/fs/btrfs/ref-verify.c
index 409b02566b25..2b490becbe67 100644
--- a/fs/btrfs/ref-verify.c
+++ b/fs/btrfs/ref-verify.c
@@ -669,18 +669,18 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
 	u64 bytenr = generic_ref->bytenr;
 	u64 num_bytes = generic_ref->len;
 	u64 parent = generic_ref->parent;
-	u64 ref_root;
-	u64 owner;
-	u64 offset;
+	u64 ref_root = 0;
+	u64 owner = 0;
+	u64 offset = 0;
 
 	if (!btrfs_test_opt(fs_info, REF_VERIFY))
 		return 0;
 
 	if (generic_ref->type == BTRFS_REF_METADATA) {
-		ref_root = generic_ref->tree_ref.root;
+		if (!parent)
+			ref_root = generic_ref->tree_ref.root;
 		owner = generic_ref->tree_ref.level;
-		offset = 0;
-	} else {
+	} else if (!parent) {
 		ref_root = generic_ref->data_ref.ref_root;
 		owner = generic_ref->data_ref.ino;
 		offset = generic_ref->data_ref.offset;
@@ -696,13 +696,10 @@ int btrfs_ref_tree_mod(struct btrfs_fs_info *fs_info,
 		goto out;
 	}
 
-	if (parent) {
-		ref->parent = parent;
-	} else {
-		ref->root_objectid = ref_root;
-		ref->owner = owner;
-		ref->offset = offset;
-	}
+	ref->parent = parent;
+	ref->owner = owner;
+	ref->root_objectid = ref_root;
+	ref->offset = offset;
 	ref->num_refs = (action == BTRFS_DROP_DELAYED_REF) ? -1 : 1;
 
 	memcpy(&ra->ref, ref, sizeof(struct ref_entry));
-- 
2.26.2


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

* [PATCH v6 09/52] btrfs: don't clear ret in btrfs_start_dirty_block_groups
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (7 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 08/52] btrfs: make sure owner is set in ref-verify Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 10/52] btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation Josef Bacik
                   ` (43 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo, Johannes Thumshirn

If we fail to update a block group item in the loop we'll break, however
we'll do btrfs_run_delayed_refs and lose our error value in ret, and
thus not clean up properly.  Fix this by only running the delayed refs
if there was no failure.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/block-group.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 52f2198d44c9..0886e81e5540 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2669,7 +2669,8 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans)
 	 * Go through delayed refs for all the stuff we've just kicked off
 	 * and then loop back (just once)
 	 */
-	ret = btrfs_run_delayed_refs(trans, 0);
+	if (!ret)
+		ret = btrfs_run_delayed_refs(trans, 0);
 	if (!ret && loops == 0) {
 		loops++;
 		spin_lock(&cur_trans->dirty_bgs_lock);
-- 
2.26.2


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

* [PATCH v6 10/52] btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (8 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 09/52] btrfs: don't clear ret in btrfs_start_dirty_block_groups Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 11/52] btrfs: convert BUG_ON()'s in relocate_tree_block Josef Bacik
                   ` (42 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

A few of these are checking for correctness, and won't be triggered by
corrupted file systems, so convert them to ASSERT() instead of BUG_ON()
and add a comment explaining their existence.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index ce935139d87b..d0ce771a2a8d 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2183,7 +2183,11 @@ static int do_relocation(struct btrfs_trans_handle *trans,
 	int slot;
 	int ret = 0;
 
-	BUG_ON(lowest && node->eb);
+	/*
+	 * If we are lowest then this is the first time we're processing this
+	 * block, and thus shouldn't have an eb associated with it yet.
+	 */
+	ASSERT(!lowest || !node->eb);
 
 	path->lowest_level = node->level + 1;
 	rc->backref_cache.path[node->level] = node;
@@ -2268,7 +2272,11 @@ static int do_relocation(struct btrfs_trans_handle *trans,
 			free_extent_buffer(eb);
 			if (ret < 0)
 				goto next;
-			BUG_ON(node->eb != eb);
+			/*
+			 * We've just cow'ed this block, it should have updated
+			 * the correct backref node entry.
+			 */
+			ASSERT(node->eb == eb);
 		} else {
 			btrfs_set_node_blockptr(upper->eb, slot,
 						node->eb->start);
@@ -2304,7 +2312,12 @@ static int do_relocation(struct btrfs_trans_handle *trans,
 	}
 
 	path->lowest_level = 0;
-	BUG_ON(ret == -ENOSPC);
+
+	/*
+	 * We should have allocated all of our space in the block rsv and thus
+	 * shouldn't ENOSPC.
+	 */
+	ASSERT(ret != -ENOSPC);
 	return ret;
 }
 
-- 
2.26.2


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

* [PATCH v6 11/52] btrfs: convert BUG_ON()'s in relocate_tree_block
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (9 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 10/52] btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 12/52] btrfs: return an error from btrfs_record_root_in_trans Josef Bacik
                   ` (41 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

We have a couple of BUG_ON()'s in relocate_tree_block() that can be
tripped if we have file system corruption.  Convert these to ASSERT()'s
so developers still get yelled at when they break the backref code, but
error out nicely for users so the whole box doesn't go down.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index d0ce771a2a8d..4333ee329290 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2456,8 +2456,28 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans,
 
 	if (root) {
 		if (test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) {
-			BUG_ON(node->new_bytenr);
-			BUG_ON(!list_empty(&node->list));
+			/*
+			 * This block was the root block of a root, and this is
+			 * the first time we're processing the block and thus it
+			 * should not have had the ->new_bytenr modified and
+			 * should have not been included on the changed list.
+			 *
+			 * However in the case of corruption we could have
+			 * multiple refs pointing to the same block improperly,
+			 * and thus we would trip over these checks.  ASSERT()
+			 * for the developer case, because it could indicate a
+			 * bug in the backref code, however error out for a
+			 * normal user in the case of corruption.
+			 */
+			ASSERT(node->new_bytenr == 0);
+			ASSERT(list_empty(&node->list));
+			if (node->new_bytenr || !list_empty(&node->list)) {
+				btrfs_err(root->fs_info,
+				  "bytenr %llu has improper references to it",
+					  node->bytenr);
+				ret = -EUCLEAN;
+				goto out;
+			}
 			btrfs_record_root_in_trans(trans, root);
 			root = root->reloc_root;
 			node->new_bytenr = root->node->start;
-- 
2.26.2


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

* [PATCH v6 12/52] btrfs: return an error from btrfs_record_root_in_trans
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (10 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 11/52] btrfs: convert BUG_ON()'s in relocate_tree_block Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 13/52] btrfs: handle errors from select_reloc_root() Josef Bacik
                   ` (40 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo, Johannes Thumshirn

We can create a reloc root when we record the root in the trans, which
can fail for all sorts of different reasons.  Propagate this error up
the chain of callers.  Future patches will fix the callers of
btrfs_record_root_in_trans() to handle the error.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/transaction.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index e51ff63c8408..5cc368fede19 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -400,6 +400,7 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans,
 			       int force)
 {
 	struct btrfs_fs_info *fs_info = root->fs_info;
+	int ret = 0;
 
 	if ((test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
 	    root->last_trans < trans->transid) || force) {
@@ -448,11 +449,11 @@ static int record_root_in_trans(struct btrfs_trans_handle *trans,
 		 * lock.  smp_wmb() makes sure that all the writes above are
 		 * done before we pop in the zero below
 		 */
-		btrfs_init_reloc_root(trans, root);
+		ret = btrfs_init_reloc_root(trans, root);
 		smp_mb__before_atomic();
 		clear_bit(BTRFS_ROOT_IN_TRANS_SETUP, &root->state);
 	}
-	return 0;
+	return ret;
 }
 
 
-- 
2.26.2


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

* [PATCH v6 13/52] btrfs: handle errors from select_reloc_root()
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (11 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 12/52] btrfs: return an error from btrfs_record_root_in_trans Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 14/52] btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors Josef Bacik
                   ` (39 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Currently select_reloc_root() doesn't return an error, but followup
patches will make it possible for it to return an error.  We do have
proper error recovery in do_relocation however, so handle the
possibility of select_reloc_root() having an error properly instead of
BUG_ON(!root).  I've also adjusted select_reloc_root() to return
ERR_PTR(-ENOENT) if we don't find a root, instead of NULL, to make the
error case easier to deal with.  I've replaced the BUG_ON(!root) with an
ASSERT(0) for this case as it indicates we messed up the backref walking
code, but it could also indicate corruption.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 4333ee329290..9a5293efe695 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2026,8 +2026,14 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans,
 		if (!next || next->level <= node->level)
 			break;
 	}
-	if (!root)
-		return NULL;
+	if (!root) {
+		/*
+		 * This can happen if there's fs corruption or if there's a bug
+		 * in the backref lookup code.
+		 */
+		ASSERT(0);
+		return ERR_PTR(-ENOENT);
+	}
 
 	next = node;
 	/* setup backref node path for btrfs_reloc_cow_block */
@@ -2198,7 +2204,10 @@ static int do_relocation(struct btrfs_trans_handle *trans,
 
 		upper = edge->node[UPPER];
 		root = select_reloc_root(trans, rc, upper, edges);
-		BUG_ON(!root);
+		if (IS_ERR(root)) {
+			ret = PTR_ERR(root);
+			goto next;
+		}
 
 		if (upper->eb && !upper->locked) {
 			if (!lowest) {
-- 
2.26.2


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

* [PATCH v6 14/52] btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (12 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 13/52] btrfs: handle errors from select_reloc_root() Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 15/52] btrfs: check record_root_in_trans related failures in select_reloc_root Josef Bacik
                   ` (38 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We have several BUG_ON()'s in select_reloc_root() that can be tripped if
you have extent tree corruption.  Convert these to ASSERT()'s, because
if we hit it during testing it really is bad, or could indicate a
problem with the backref walking code.

However if users hit these problems it generally indicates corruption,
I've hit a few machines in the fleet that trip over these with clearly
corrupted extent trees, so be nice and spit out an error message and
return an error instead of bringing the whole box down.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 47 +++++++++++++++++++++++++++++++++++++++----
 1 file changed, 43 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 9a5293efe695..0d4c4e250a89 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1996,8 +1996,33 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans,
 		cond_resched();
 		next = walk_up_backref(next, edges, &index);
 		root = next->root;
-		BUG_ON(!root);
-		BUG_ON(!test_bit(BTRFS_ROOT_SHAREABLE, &root->state));
+
+		/*
+		 * If there is no root, then our references for this block are
+		 * incomplete, as we should be able to walk all the way up to a
+		 * block that is owned by a root.
+		 *
+		 * This path is only for SHAREABLE roots, so if we come upon a
+		 * non-SHAREABLE root then we have backrefs that resolve
+		 * improperly.
+		 *
+		 * Both of these cases indicate file system corruption, or a bug
+		 * in the backref walking code.
+		 */
+		if (!root) {
+			ASSERT(0);
+			btrfs_err(trans->fs_info,
+		"bytenr %llu doesn't have a backref path ending in a root",
+				  node->bytenr);
+			return ERR_PTR(-EUCLEAN);
+		}
+		if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state)) {
+			ASSERT(0);
+			btrfs_err(trans->fs_info,
+"bytenr %llu has multiple refs with one ending in a non shareable root",
+				  node->bytenr);
+			return ERR_PTR(-EUCLEAN);
+		}
 
 		if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
 			record_reloc_root_in_trans(trans, root);
@@ -2008,8 +2033,22 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans,
 		root = root->reloc_root;
 
 		if (next->new_bytenr != root->node->start) {
-			BUG_ON(next->new_bytenr);
-			BUG_ON(!list_empty(&next->list));
+			/*
+			 * We just created the reloc root, so we shouldn't have
+			 * ->new_bytenr set and this shouldn't be in the changed
+			 *  list.  If it is then we have multiple roots pointing
+			 *  at the same bytenr which indicates corruption, or
+			 *  we've made a mistake in the backref walking code.
+			 */
+			ASSERT(next->new_bytenr == 0);
+			ASSERT(list_empty(&next->list));
+			if (next->new_bytenr || !list_empty(&next->list)) {
+				btrfs_err(trans->fs_info,
+"bytenr %llu possibly has multiple roots pointing at the same bytenr %llu",
+					  node->bytenr, next->bytenr);
+				return ERR_PTR(-EUCLEAN);
+			}
+
 			next->new_bytenr = root->node->start;
 			btrfs_put_root(next->root);
 			next->root = btrfs_grab_root(root);
-- 
2.26.2


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

* [PATCH v6 15/52] btrfs: check record_root_in_trans related failures in select_reloc_root
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (13 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 14/52] btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 16/52] btrfs: do proper error handling in record_reloc_root_in_trans Josef Bacik
                   ` (37 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

We will record the fs root or the reloc root in the trans in
select_reloc_root.  These will actually return errors in the following
patches, so check their return value here and return it up the stack.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 0d4c4e250a89..fd00517fb0f6 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1990,6 +1990,7 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans,
 	struct btrfs_backref_node *next;
 	struct btrfs_root *root;
 	int index = 0;
+	int ret;
 
 	next = node;
 	while (1) {
@@ -2025,11 +2026,15 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans,
 		}
 
 		if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
-			record_reloc_root_in_trans(trans, root);
+			ret = record_reloc_root_in_trans(trans, root);
+			if (ret)
+				return ERR_PTR(ret);
 			break;
 		}
 
-		btrfs_record_root_in_trans(trans, root);
+		ret = btrfs_record_root_in_trans(trans, root);
+		if (ret)
+			return ERR_PTR(ret);
 		root = root->reloc_root;
 
 		if (next->new_bytenr != root->node->start) {
-- 
2.26.2


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

* [PATCH v6 16/52] btrfs: do proper error handling in record_reloc_root_in_trans
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (14 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 15/52] btrfs: check record_root_in_trans related failures in select_reloc_root Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 17/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename_exchange Josef Bacik
                   ` (36 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

Generally speaking this shouldn't ever fail, the corresponding fs root
for the reloc root will already be in memory, so we won't get -ENOMEM
here.

However if there is no corresponding root for the reloc root then we
could get -ENOMEM when we try to allocate it or we could get -ENOENT
when we look it up and see that it doesn't exist.

Convert these BUG_ON()'s into ASSERT()'s + proper error handling for the
case of corruption.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 23 +++++++++++++++++++++--
 1 file changed, 21 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index fd00517fb0f6..bc676c11a2f4 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1973,8 +1973,27 @@ static int record_reloc_root_in_trans(struct btrfs_trans_handle *trans,
 		return 0;
 
 	root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset, false);
-	BUG_ON(IS_ERR(root));
-	BUG_ON(root->reloc_root != reloc_root);
+
+	/*
+	 * This should succeed, since we can't have a reloc root without having
+	 * already looked up the actual root and created the reloc root for this
+	 * root.
+	 *
+	 * However if there's some sort of corruption where we have a ref to a
+	 * reloc root without a corresponding root this could return -ENOENT.
+	 */
+	if (IS_ERR(root)) {
+		ASSERT(0);
+		return PTR_ERR(root);
+	}
+	if (root->reloc_root != reloc_root) {
+		ASSERT(0);
+		btrfs_err(fs_info,
+			  "root %llu has two reloc roots associated with it",
+			  reloc_root->root_key.offset);
+		btrfs_put_root(root);
+		return -EUCLEAN;
+	}
 	ret = btrfs_record_root_in_trans(trans, root);
 	btrfs_put_root(root);
 
-- 
2.26.2


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

* [PATCH v6 17/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename_exchange
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (15 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 16/52] btrfs: do proper error handling in record_reloc_root_in_trans Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 18/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename Josef Bacik
                   ` (35 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

btrfs_record_root_in_trans will return errors in the future, so handle
the error properly in btrfs_rename_exchange.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 070716650df8..2f8bb8405ac6 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -8897,8 +8897,11 @@ static int btrfs_rename_exchange(struct inode *old_dir,
 		goto out_notrans;
 	}
 
-	if (dest != root)
-		btrfs_record_root_in_trans(trans, dest);
+	if (dest != root) {
+		ret = btrfs_record_root_in_trans(trans, dest);
+		if (ret)
+			goto out_fail;
+	}
 
 	/*
 	 * We need to find a free sequence number both in the source and
-- 
2.26.2


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

* [PATCH v6 18/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (16 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 17/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename_exchange Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 19/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_delete_subvolume Josef Bacik
                   ` (34 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

btrfs_record_root_in_trans will return errors in the future, so handle
the error properly in btrfs_rename.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/inode.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 2f8bb8405ac6..bcbae8b460c0 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -9205,8 +9205,11 @@ static int btrfs_rename(struct inode *old_dir, struct dentry *old_dentry,
 		goto out_notrans;
 	}
 
-	if (dest != root)
-		btrfs_record_root_in_trans(trans, dest);
+	if (dest != root) {
+		ret = btrfs_record_root_in_trans(trans, dest);
+		if (ret)
+			goto out_fail;
+	}
 
 	ret = btrfs_set_inode_index(BTRFS_I(new_dir), &index);
 	if (ret)
-- 
2.26.2


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

* [PATCH v6 19/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_delete_subvolume
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (17 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 18/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 20/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_recover_log_trees Josef Bacik
                   ` (33 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

btrfs_record_root_in_trans will return errors in the future, so handle
the error properly in btrfs_delete_subvolume.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/inode.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index bcbae8b460c0..7a8d89e1b73f 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -4175,7 +4175,11 @@ int btrfs_delete_subvolume(struct inode *dir, struct dentry *dentry)
 		goto out_end_trans;
 	}
 
-	btrfs_record_root_in_trans(trans, dest);
+	ret = btrfs_record_root_in_trans(trans, dest);
+	if (ret) {
+		btrfs_abort_transaction(trans, ret);
+		goto out_end_trans;
+	}
 
 	memset(&dest->root_item.drop_progress, 0,
 		sizeof(dest->root_item.drop_progress));
-- 
2.26.2


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

* [PATCH v6 20/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_recover_log_trees
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (18 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 19/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_delete_subvolume Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 21/52] btrfs: handle btrfs_record_root_in_trans failure in create_subvol Josef Bacik
                   ` (32 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

btrfs_record_root_in_trans will return errors in the future, so handle
the error properly in btrfs_recover_log_trees.

This appears tricky, however we have a reference count on the
destination root, so if this fails we need to continue on in the loop to
make sure the properly cleanup is done.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/tree-log.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
index 254c2ee43aae..77adeb3c988d 100644
--- a/fs/btrfs/tree-log.c
+++ b/fs/btrfs/tree-log.c
@@ -6286,8 +6286,12 @@ int btrfs_recover_log_trees(struct btrfs_root *log_root_tree)
 		}
 
 		wc.replay_dest->log_root = log;
-		btrfs_record_root_in_trans(trans, wc.replay_dest);
-		ret = walk_log_tree(trans, log, &wc);
+		ret = btrfs_record_root_in_trans(trans, wc.replay_dest);
+		if (ret)
+			btrfs_handle_fs_error(fs_info, ret,
+				"Couldn't record the root in the transaction.");
+		else
+			ret = walk_log_tree(trans, log, &wc);
 
 		if (!ret && wc.stage == LOG_WALK_REPLAY_ALL) {
 			ret = fixup_inode_link_counts(trans, wc.replay_dest,
-- 
2.26.2


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

* [PATCH v6 21/52] btrfs: handle btrfs_record_root_in_trans failure in create_subvol
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (19 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 20/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_recover_log_trees Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 22/52] btrfs: btrfs: handle btrfs_record_root_in_trans failure in relocate_tree_block Josef Bacik
                   ` (31 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

btrfs_record_root_in_trans will return errors in the future, so handle
the error properly in create_subvol.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/ioctl.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index af8d01659562..2d0782f7e0e0 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -714,7 +714,12 @@ static noinline int create_subvol(struct inode *dir,
 	/* Freeing will be done in btrfs_put_root() of new_root */
 	anon_dev = 0;
 
-	btrfs_record_root_in_trans(trans, new_root);
+	ret = btrfs_record_root_in_trans(trans, new_root);
+	if (ret) {
+		btrfs_put_root(new_root);
+		btrfs_abort_transaction(trans, ret);
+		goto fail;
+	}
 
 	ret = btrfs_create_subvol_root(trans, new_root, root, new_dirid);
 	if (!ret) {
-- 
2.26.2


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

* [PATCH v6 22/52] btrfs: btrfs: handle btrfs_record_root_in_trans failure in relocate_tree_block
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (20 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 21/52] btrfs: handle btrfs_record_root_in_trans failure in create_subvol Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 23/52] btrfs: handle btrfs_record_root_in_trans failure in start_transaction Josef Bacik
                   ` (30 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

btrfs_record_root_in_trans will return errors in the future, so handle
the error properly in relocate_tree_block.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index bc676c11a2f4..a0453d67749a 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2550,7 +2550,9 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans,
 				ret = -EUCLEAN;
 				goto out;
 			}
-			btrfs_record_root_in_trans(trans, root);
+			ret = btrfs_record_root_in_trans(trans, root);
+			if (ret)
+				goto out;
 			root = root->reloc_root;
 			node->new_bytenr = root->node->start;
 			btrfs_put_root(node->root);
-- 
2.26.2


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

* [PATCH v6 23/52] btrfs: handle btrfs_record_root_in_trans failure in start_transaction
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (21 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 22/52] btrfs: btrfs: handle btrfs_record_root_in_trans failure in relocate_tree_block Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 24/52] btrfs: handle record_root_in_trans failure in qgroup_account_snapshot Josef Bacik
                   ` (29 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

btrfs_record_root_in_trans will return errors in the future, so handle
the error properly in start_transaction.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/transaction.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 5cc368fede19..df9b9c1a8831 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -734,7 +734,11 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
 	 * Thus it need to be called after current->journal_info initialized,
 	 * or we can deadlock.
 	 */
-	btrfs_record_root_in_trans(h, root);
+	ret = btrfs_record_root_in_trans(h, root);
+	if (ret) {
+		btrfs_end_transaction(h);
+		return ERR_PTR(ret);
+	}
 
 	return h;
 
-- 
2.26.2


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

* [PATCH v6 24/52] btrfs: handle record_root_in_trans failure in qgroup_account_snapshot
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (22 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 23/52] btrfs: handle btrfs_record_root_in_trans failure in start_transaction Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 25/52] btrfs: handle record_root_in_trans failure in btrfs_record_root_in_trans Josef Bacik
                   ` (28 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

record_root_in_trans can fail currently, so handle this failure
properly.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/transaction.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index df9b9c1a8831..77feead2a324 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1435,7 +1435,9 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
 	 * recorded root will never be updated again, causing an outdated root
 	 * item.
 	 */
-	record_root_in_trans(trans, src, 1);
+	ret = record_root_in_trans(trans, src, 1);
+	if (ret)
+		return ret;
 
 	/*
 	 * We are going to commit transaction, see btrfs_commit_transaction()
@@ -1487,7 +1489,7 @@ static int qgroup_account_snapshot(struct btrfs_trans_handle *trans,
 	 * insert_dir_item()
 	 */
 	if (!ret)
-		record_root_in_trans(trans, parent, 1);
+		ret = record_root_in_trans(trans, parent, 1);
 	return ret;
 }
 
-- 
2.26.2


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

* [PATCH v6 25/52] btrfs: handle record_root_in_trans failure in btrfs_record_root_in_trans
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (23 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 24/52] btrfs: handle record_root_in_trans failure in qgroup_account_snapshot Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 26/52] btrfs: handle record_root_in_trans failure in create_pending_snapshot Josef Bacik
                   ` (27 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

record_root_in_trans can fail currently, handle this failure properly.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/transaction.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 77feead2a324..7404d88e6201 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -480,6 +480,7 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
 			       struct btrfs_root *root)
 {
 	struct btrfs_fs_info *fs_info = root->fs_info;
+	int ret;
 
 	if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
 		return 0;
@@ -494,10 +495,10 @@ int btrfs_record_root_in_trans(struct btrfs_trans_handle *trans,
 		return 0;
 
 	mutex_lock(&fs_info->reloc_mutex);
-	record_root_in_trans(trans, root, 0);
+	ret = record_root_in_trans(trans, root, 0);
 	mutex_unlock(&fs_info->reloc_mutex);
 
-	return 0;
+	return ret;
 }
 
 static inline int is_transaction_blocked(struct btrfs_transaction *trans)
-- 
2.26.2


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

* [PATCH v6 26/52] btrfs: handle record_root_in_trans failure in create_pending_snapshot
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (24 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 25/52] btrfs: handle record_root_in_trans failure in btrfs_record_root_in_trans Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 27/52] btrfs: do not panic in __add_reloc_root Josef Bacik
                   ` (26 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

record_root_in_trans can currently fail, so handle this failure
properly.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/transaction.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 7404d88e6201..375aa2bed36d 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1567,8 +1567,9 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 	dentry = pending->dentry;
 	parent_inode = pending->dir;
 	parent_root = BTRFS_I(parent_inode)->root;
-	record_root_in_trans(trans, parent_root, 0);
-
+	ret = record_root_in_trans(trans, parent_root, 0);
+	if (ret)
+		goto fail;
 	cur_time = current_time(parent_inode);
 
 	/*
@@ -1604,7 +1605,11 @@ static noinline int create_pending_snapshot(struct btrfs_trans_handle *trans,
 		goto fail;
 	}
 
-	record_root_in_trans(trans, root, 0);
+	ret = record_root_in_trans(trans, root, 0);
+	if (ret) {
+		btrfs_abort_transaction(trans, ret);
+		goto fail;
+	}
 	btrfs_set_root_last_snapshot(&root->root_item, trans->transid);
 	memcpy(new_root_item, &root->root_item, sizeof(*new_root_item));
 	btrfs_check_and_init_root_item(new_root_item);
-- 
2.26.2


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

* [PATCH v6 27/52] btrfs: do not panic in __add_reloc_root
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (25 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 26/52] btrfs: handle record_root_in_trans failure in create_pending_snapshot Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 28/52] btrfs: have proper error handling in btrfs_init_reloc_root Josef Bacik
                   ` (25 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

If we have a duplicate entry for a reloc root then we could have fs
corruption that resulted in a double allocation.  This shouldn't happen
generally so leave an ASSERT() for this case, but return an error
instead of panicing in the normal user case.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index a0453d67749a..36323cd08bc8 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -638,9 +638,11 @@ static int __must_check __add_reloc_root(struct btrfs_root *root)
 				   node->bytenr, &node->rb_node);
 	spin_unlock(&rc->reloc_root_tree.lock);
 	if (rb_node) {
-		btrfs_panic(fs_info, -EEXIST,
+		ASSERT(0);
+		btrfs_err(fs_info,
 			    "Duplicate root found for start=%llu while inserting into relocation tree",
 			    node->bytenr);
+		return -EEXIST;
 	}
 
 	list_add_tail(&root->root_list, &rc->reloc_roots);
-- 
2.26.2


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

* [PATCH v6 28/52] btrfs: have proper error handling in btrfs_init_reloc_root
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (26 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 27/52] btrfs: do not panic in __add_reloc_root Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 29/52] btrfs: do proper error handling in create_reloc_root Josef Bacik
                   ` (24 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

create_reloc_root will return errors in the future, and __add_reloc_root
can return -ENOMEM or -EEXIST, so handle these errors properly.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 36323cd08bc8..692a24ec7d83 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -860,9 +860,14 @@ int btrfs_init_reloc_root(struct btrfs_trans_handle *trans,
 	reloc_root = create_reloc_root(trans, root, root->root_key.objectid);
 	if (clear_rsv)
 		trans->block_rsv = rsv;
+	if (IS_ERR(reloc_root))
+		return PTR_ERR(reloc_root);
 
 	ret = __add_reloc_root(reloc_root);
-	BUG_ON(ret < 0);
+	if (ret) {
+		btrfs_put_root(reloc_root);
+		return ret;
+	}
 	root->reloc_root = btrfs_grab_root(reloc_root);
 	return 0;
 }
-- 
2.26.2


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

* [PATCH v6 29/52] btrfs: do proper error handling in create_reloc_root
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (27 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 28/52] btrfs: have proper error handling in btrfs_init_reloc_root Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 30/52] btrfs: validate ->reloc_root after recording root in trans Josef Bacik
                   ` (23 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

We do memory allocations here, read blocks from disk, all sorts of
operations that could easily fail at any given point.  Instead of
panicing the box, simply return the error back up the chain, all callers
at this point have proper error handling.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 692a24ec7d83..b7a8a5b44a16 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -737,10 +737,11 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans,
 	struct extent_buffer *eb;
 	struct btrfs_root_item *root_item;
 	struct btrfs_key root_key;
-	int ret;
+	int ret = 0;
 
 	root_item = kmalloc(sizeof(*root_item), GFP_NOFS);
-	BUG_ON(!root_item);
+	if (!root_item)
+		return ERR_PTR(-ENOMEM);
 
 	root_key.objectid = BTRFS_TREE_RELOC_OBJECTID;
 	root_key.type = BTRFS_ROOT_ITEM_KEY;
@@ -752,7 +753,9 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans,
 		/* called by btrfs_init_reloc_root */
 		ret = btrfs_copy_root(trans, root, root->commit_root, &eb,
 				      BTRFS_TREE_RELOC_OBJECTID);
-		BUG_ON(ret);
+		if (ret)
+			goto fail;
+
 		/*
 		 * Set the last_snapshot field to the generation of the commit
 		 * root - like this ctree.c:btrfs_block_can_be_shared() behaves
@@ -773,7 +776,8 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans,
 		 */
 		ret = btrfs_copy_root(trans, root, root->node, &eb,
 				      BTRFS_TREE_RELOC_OBJECTID);
-		BUG_ON(ret);
+		if (ret)
+			goto fail;
 	}
 
 	memcpy(root_item, &root->root_item, sizeof(*root_item));
@@ -793,14 +797,20 @@ static struct btrfs_root *create_reloc_root(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_insert_root(trans, fs_info->tree_root,
 				&root_key, root_item);
-	BUG_ON(ret);
+	if (ret)
+		goto fail;
+
 	kfree(root_item);
 
 	reloc_root = btrfs_read_tree_root(fs_info->tree_root, &root_key);
-	BUG_ON(IS_ERR(reloc_root));
+	if (IS_ERR(reloc_root))
+		return reloc_root;
 	set_bit(BTRFS_ROOT_SHAREABLE, &reloc_root->state);
 	reloc_root->last_trans = trans->transid;
 	return reloc_root;
+fail:
+	kfree(root_item);
+	return ERR_PTR(ret);
 }
 
 /*
-- 
2.26.2


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

* [PATCH v6 30/52] btrfs: validate ->reloc_root after recording root in trans
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (28 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 29/52] btrfs: do proper error handling in create_reloc_root Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 31/52] btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots Josef Bacik
                   ` (22 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Zygo Blaxell

If we fail to setup a ->reloc_root in a different thread that path will
error out, however it still leaves root->reloc_root NULL but would still
appear set up in the transaction.  Subsequent calls to
btrfs_record_root_in_transaction would succeed without attempting to
create the reloc root, as the transid has already been update.  Handle
this case by making sure we have a root->reloc_root set after a
btrfs_record_root_in_transaction call so we don't end up deref'ing a
NULL pointer.

Reported-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b7a8a5b44a16..ac5350dfb33a 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2073,6 +2073,13 @@ struct btrfs_root *select_reloc_root(struct btrfs_trans_handle *trans,
 			return ERR_PTR(ret);
 		root = root->reloc_root;
 
+		/*
+		 * We could have raced with another thread which failed, so
+		 * ->reloc_root may not be set, return -ENOENT in this case.
+		 */
+		if (!root)
+			return ERR_PTR(-ENOENT);
+
 		if (next->new_bytenr != root->node->start) {
 			/*
 			 * We just created the reloc root, so we shouldn't have
@@ -2570,6 +2577,14 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans,
 			ret = btrfs_record_root_in_trans(trans, root);
 			if (ret)
 				goto out;
+			/*
+			 * Another thread could have failed, need to check if we
+			 * have ->reloc_root actually set.
+			 */
+			if (!root->reloc_root) {
+				ret = -ENOENT;
+				goto out;
+			}
 			root = root->reloc_root;
 			node->new_bytenr = root->node->start;
 			btrfs_put_root(node->root);
-- 
2.26.2


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

* [PATCH v6 31/52] btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (29 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 30/52] btrfs: validate ->reloc_root after recording root in trans Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 32/52] btrfs: change insert_dirty_subvol to return errors Josef Bacik
                   ` (21 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

btrfs_update_reloc_root will will return errors in the future, so handle
the error properly in commit_fs_roots.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/transaction.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c
index 375aa2bed36d..dd60590685c0 100644
--- a/fs/btrfs/transaction.c
+++ b/fs/btrfs/transaction.c
@@ -1343,7 +1343,9 @@ static noinline int commit_fs_roots(struct btrfs_trans_handle *trans)
 			spin_unlock(&fs_info->fs_roots_radix_lock);
 
 			btrfs_free_log(trans, root);
-			btrfs_update_reloc_root(trans, root);
+			err = btrfs_update_reloc_root(trans, root);
+			if (err)
+				return err;
 
 			/* see comments in should_cow_block() */
 			clear_bit(BTRFS_ROOT_FORCE_COW, &root->state);
-- 
2.26.2


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

* [PATCH v6 32/52] btrfs: change insert_dirty_subvol to return errors
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (30 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 31/52] btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 33/52] btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol Josef Bacik
                   ` (20 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

This will be able to return errors in the future, so change it to return
an error and handle the error appropriately.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index ac5350dfb33a..17bb2bb9a507 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1556,9 +1556,9 @@ static int find_next_key(struct btrfs_path *path, int level,
 /*
  * Insert current subvolume into reloc_control::dirty_subvol_roots
  */
-static void insert_dirty_subvol(struct btrfs_trans_handle *trans,
-				struct reloc_control *rc,
-				struct btrfs_root *root)
+static int insert_dirty_subvol(struct btrfs_trans_handle *trans,
+			       struct reloc_control *rc,
+			       struct btrfs_root *root)
 {
 	struct btrfs_root *reloc_root = root->reloc_root;
 	struct btrfs_root_item *reloc_root_item;
@@ -1578,6 +1578,7 @@ static void insert_dirty_subvol(struct btrfs_trans_handle *trans,
 		btrfs_grab_root(root);
 		list_add_tail(&root->reloc_dirty_list, &rc->dirty_subvol_roots);
 	}
+	return 0;
 }
 
 static int clean_dirty_subvols(struct reloc_control *rc)
@@ -1779,8 +1780,11 @@ static noinline_for_stack int merge_reloc_root(struct reloc_control *rc,
 out:
 	btrfs_free_path(path);
 
-	if (ret == 0)
-		insert_dirty_subvol(trans, rc, root);
+	if (ret == 0) {
+		ret = insert_dirty_subvol(trans, rc, root);
+		if (ret)
+			btrfs_abort_transaction(trans, ret);
+	}
 
 	if (trans)
 		btrfs_end_transaction_throttle(trans);
-- 
2.26.2


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

* [PATCH v6 33/52] btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (31 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 32/52] btrfs: change insert_dirty_subvol to return errors Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 34/52] btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge Josef Bacik
                   ` (19 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

btrfs_update_reloc_root will will return errors in the future, so handle
the error properly in insert_dirty_subvol.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 17bb2bb9a507..916f9ebedc8b 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1562,6 +1562,7 @@ static int insert_dirty_subvol(struct btrfs_trans_handle *trans,
 {
 	struct btrfs_root *reloc_root = root->reloc_root;
 	struct btrfs_root_item *reloc_root_item;
+	int ret;
 
 	/* @root must be a subvolume tree root with a valid reloc tree */
 	ASSERT(root->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID);
@@ -1572,7 +1573,9 @@ static int insert_dirty_subvol(struct btrfs_trans_handle *trans,
 		sizeof(reloc_root_item->drop_progress));
 	btrfs_set_root_drop_level(reloc_root_item, 0);
 	btrfs_set_root_refs(reloc_root_item, 0);
-	btrfs_update_reloc_root(trans, root);
+	ret = btrfs_update_reloc_root(trans, root);
+	if (ret)
+		return ret;
 
 	if (list_empty(&root->reloc_dirty_list)) {
 		btrfs_grab_root(root);
-- 
2.26.2


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

* [PATCH v6 34/52] btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (32 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 33/52] btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 35/52] btrfs: do proper error handling in btrfs_update_reloc_root Josef Bacik
                   ` (18 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

btrfs_update_reloc_root will will return errors in the future, so handle
an error properly in prepare_to_merge.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 916f9ebedc8b..c99f50969e24 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1860,10 +1860,21 @@ int prepare_to_merge(struct reloc_control *rc, int err)
 		 */
 		if (!err)
 			btrfs_set_root_refs(&reloc_root->root_item, 1);
-		btrfs_update_reloc_root(trans, root);
+		ret = btrfs_update_reloc_root(trans, root);
 
+		/*
+		 * Even if we have an error we need this reloc root back on our
+		 * list so we can clean up properly.
+		 */
 		list_add(&reloc_root->root_list, &reloc_roots);
 		btrfs_put_root(root);
+
+		if (ret) {
+			btrfs_abort_transaction(trans, ret);
+			if (!err)
+				err = ret;
+			break;
+		}
 	}
 
 	list_splice(&reloc_roots, &rc->reloc_roots);
-- 
2.26.2


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

* [PATCH v6 35/52] btrfs: do proper error handling in btrfs_update_reloc_root
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (33 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 34/52] btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 36/52] btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s Josef Bacik
                   ` (17 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

We call btrfs_update_root in btrfs_update_reloc_root, which can fail for
all sorts of reasons, including IO errors.  Instead of panicing the box
lets return the error, now that all callers properly handle those
errors.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index c99f50969e24..49caecd897d4 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -894,7 +894,7 @@ int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
 	int ret;
 
 	if (!have_reloc_root(root))
-		goto out;
+		return 0;
 
 	reloc_root = root->reloc_root;
 	root_item = &reloc_root->root_item;
@@ -927,10 +927,8 @@ int btrfs_update_reloc_root(struct btrfs_trans_handle *trans,
 
 	ret = btrfs_update_root(trans, fs_info->tree_root,
 				&reloc_root->root_key, root_item);
-	BUG_ON(ret);
 	btrfs_put_root(reloc_root);
-out:
-	return 0;
+	return ret;
 }
 
 /*
-- 
2.26.2


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

* [PATCH v6 36/52] btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (34 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 35/52] btrfs: do proper error handling in btrfs_update_reloc_root Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 37/52] btrfs: handle btrfs_cow_block errors in replace_path Josef Bacik
                   ` (16 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

A few BUG_ON()'s in replace_path are purely to keep us from making
logical mistakes, so replace them with ASSERT()'s.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 49caecd897d4..1f1dfa9c74be 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1202,8 +1202,8 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
 	int ret;
 	int slot;
 
-	BUG_ON(src->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID);
-	BUG_ON(dest->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID);
+	ASSERT(src->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID);
+	ASSERT(dest->root_key.objectid != BTRFS_TREE_RELOC_OBJECTID);
 
 	last_snapshot = btrfs_root_last_snapshot(&src->root_item);
 again:
@@ -1234,7 +1234,7 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
 	parent = eb;
 	while (1) {
 		level = btrfs_header_level(parent);
-		BUG_ON(level < lowest_level);
+		ASSERT(level >= lowest_level);
 
 		ret = btrfs_bin_search(parent, &key, &slot);
 		if (ret < 0)
-- 
2.26.2


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

* [PATCH v6 37/52] btrfs: handle btrfs_cow_block errors in replace_path
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (35 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 36/52] btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 38/52] btrfs: handle btrfs_search_slot failure " Josef Bacik
                   ` (15 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

If we error out cow'ing the root node when doing a replace_path then we
simply unlock and free the buffer and return the error.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 1f1dfa9c74be..8d683056fd9e 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1222,7 +1222,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
 	if (cow) {
 		ret = btrfs_cow_block(trans, dest, eb, NULL, 0, &eb,
 				      BTRFS_NESTING_COW);
-		BUG_ON(ret);
+		if (ret) {
+			btrfs_tree_unlock(eb);
+			free_extent_buffer(eb);
+			return ret;
+		}
 	}
 
 	if (next_key) {
@@ -1282,7 +1286,11 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
 				ret = btrfs_cow_block(trans, dest, eb, parent,
 						      slot, &eb,
 						      BTRFS_NESTING_COW);
-				BUG_ON(ret);
+				if (ret) {
+					btrfs_tree_unlock(eb);
+					free_extent_buffer(eb);
+					break;
+				}
 			}
 
 			btrfs_tree_unlock(parent);
-- 
2.26.2


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

* [PATCH v6 38/52] btrfs: handle btrfs_search_slot failure in replace_path
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (36 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 37/52] btrfs: handle btrfs_cow_block errors in replace_path Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 39/52] btrfs: handle errors in reference count manipulation " Josef Bacik
                   ` (14 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

This can fail for any number of reasons, why bring the whole box down
with it?

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 8d683056fd9e..01085952059b 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1314,7 +1314,8 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
 		path->lowest_level = level;
 		ret = btrfs_search_slot(trans, src, &key, path, 0, 1);
 		path->lowest_level = 0;
-		BUG_ON(ret);
+		if (ret)
+			break;
 
 		/*
 		 * Info qgroup to trace both subtrees.
-- 
2.26.2


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

* [PATCH v6 39/52] btrfs: handle errors in reference count manipulation in replace_path
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (37 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 38/52] btrfs: handle btrfs_search_slot failure " Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 40/52] btrfs: handle extent reference errors in do_relocation Josef Bacik
                   ` (13 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

If any of the reference count manipulation stuff fails in replace_path
we need to abort the transaction, as we've modified the blocks already.
We can simply break at this point and everything will be cleaned up.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 20 ++++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 01085952059b..5ddd9e6e354c 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1355,27 +1355,39 @@ int replace_path(struct btrfs_trans_handle *trans, struct reloc_control *rc,
 		ref.skip_qgroup = true;
 		btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid);
 		ret = btrfs_inc_extent_ref(trans, &ref);
-		BUG_ON(ret);
+		if (ret) {
+			btrfs_abort_transaction(trans, ret);
+			break;
+		}
 		btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, new_bytenr,
 				       blocksize, 0);
 		ref.skip_qgroup = true;
 		btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid);
 		ret = btrfs_inc_extent_ref(trans, &ref);
-		BUG_ON(ret);
+		if (ret) {
+			btrfs_abort_transaction(trans, ret);
+			break;
+		}
 
 		btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, new_bytenr,
 				       blocksize, path->nodes[level]->start);
 		btrfs_init_tree_ref(&ref, level - 1, src->root_key.objectid);
 		ref.skip_qgroup = true;
 		ret = btrfs_free_extent(trans, &ref);
-		BUG_ON(ret);
+		if (ret) {
+			btrfs_abort_transaction(trans, ret);
+			break;
+		}
 
 		btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, old_bytenr,
 				       blocksize, 0);
 		btrfs_init_tree_ref(&ref, level - 1, dest->root_key.objectid);
 		ref.skip_qgroup = true;
 		ret = btrfs_free_extent(trans, &ref);
-		BUG_ON(ret);
+		if (ret) {
+			btrfs_abort_transaction(trans, ret);
+			break;
+		}
 
 		btrfs_unlock_up_safe(path, 0);
 
-- 
2.26.2


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

* [PATCH v6 40/52] btrfs: handle extent reference errors in do_relocation
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (38 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 39/52] btrfs: handle errors in reference count manipulation " Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 41/52] btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly Josef Bacik
                   ` (12 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We can already deal with errors appropriately from do_relocation, simply
handle any errors that come from changing the refs at this point
cleanly.  We have to abort the transaction if we fail here as we've
modified metadata at this point.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 5ddd9e6e354c..1097d1b3c492 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2424,10 +2424,11 @@ static int do_relocation(struct btrfs_trans_handle *trans,
 			btrfs_init_tree_ref(&ref, node->level,
 					    btrfs_header_owner(upper->eb));
 			ret = btrfs_inc_extent_ref(trans, &ref);
-			BUG_ON(ret);
-
-			ret = btrfs_drop_subtree(trans, root, eb, upper->eb);
-			BUG_ON(ret);
+			if (!ret)
+				ret = btrfs_drop_subtree(trans, root, eb,
+							 upper->eb);
+			if (ret)
+				btrfs_abort_transaction(trans, ret);
 		}
 next:
 		if (!upper->pending)
-- 
2.26.2


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

* [PATCH v6 41/52] btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (39 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 40/52] btrfs: handle extent reference errors in do_relocation Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 42/52] btrfs: remove the extent item sanity checks in relocate_block_group Josef Bacik
                   ` (11 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

We need to validate that a data extent item does not have the
FULL_BACKREF flag set on it's flags.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/tree-checker.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/fs/btrfs/tree-checker.c b/fs/btrfs/tree-checker.c
index 028e733e42f3..39714aeb9b36 100644
--- a/fs/btrfs/tree-checker.c
+++ b/fs/btrfs/tree-checker.c
@@ -1283,6 +1283,11 @@ static int check_extent_item(struct extent_buffer *leaf,
 				   key->offset, fs_info->sectorsize);
 			return -EUCLEAN;
 		}
+		if (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF) {
+			extent_err(leaf, slot,
+			"invalid extent flag, data has full backref set");
+			return -EUCLEAN;
+		}
 	}
 	ptr = (unsigned long)(struct btrfs_extent_item *)(ei + 1);
 
-- 
2.26.2


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

* [PATCH v6 42/52] btrfs: remove the extent item sanity checks in relocate_block_group
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (40 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 41/52] btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 43/52] btrfs: do proper error handling in create_reloc_inode Josef Bacik
                   ` (10 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

These checks are all taken care of for us by the tree checker code.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 29 +----------------------------
 1 file changed, 1 insertion(+), 28 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 1097d1b3c492..328a78399ddb 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3361,20 +3361,6 @@ static void unset_reloc_control(struct reloc_control *rc)
 	mutex_unlock(&fs_info->reloc_mutex);
 }
 
-static int check_extent_flags(u64 flags)
-{
-	if ((flags & BTRFS_EXTENT_FLAG_DATA) &&
-	    (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK))
-		return 1;
-	if (!(flags & BTRFS_EXTENT_FLAG_DATA) &&
-	    !(flags & BTRFS_EXTENT_FLAG_TREE_BLOCK))
-		return 1;
-	if ((flags & BTRFS_EXTENT_FLAG_DATA) &&
-	    (flags & BTRFS_BLOCK_FLAG_FULL_BACKREF))
-		return 1;
-	return 0;
-}
-
 static noinline_for_stack
 int prepare_to_relocate(struct reloc_control *rc)
 {
@@ -3426,7 +3412,6 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
 	struct btrfs_path *path;
 	struct btrfs_extent_item *ei;
 	u64 flags;
-	u32 item_size;
 	int ret;
 	int err = 0;
 	int progress = 0;
@@ -3475,19 +3460,7 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
 
 		ei = btrfs_item_ptr(path->nodes[0], path->slots[0],
 				    struct btrfs_extent_item);
-		item_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
-		if (item_size >= sizeof(*ei)) {
-			flags = btrfs_extent_flags(path->nodes[0], ei);
-			ret = check_extent_flags(flags);
-			BUG_ON(ret);
-		} else if (unlikely(item_size == sizeof(struct btrfs_extent_item_v0))) {
-			err = -EINVAL;
-			btrfs_print_v0_err(trans->fs_info);
-			btrfs_abort_transaction(trans, err);
-			break;
-		} else {
-			BUG();
-		}
+		flags = btrfs_extent_flags(path->nodes[0], ei);
 
 		if (flags & BTRFS_EXTENT_FLAG_TREE_BLOCK) {
 			ret = add_tree_block(rc, &key, path, &blocks);
-- 
2.26.2


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

* [PATCH v6 43/52] btrfs: do proper error handling in create_reloc_inode
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (41 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 42/52] btrfs: remove the extent item sanity checks in relocate_block_group Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 44/52] btrfs: handle __add_reloc_root failures in btrfs_recover_relocation Josef Bacik
                   ` (9 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We already handle some errors in this function, and the callers do the
correct error handling, so clean up the rest of the function to do the
appropriate error handling.

There's a little extra work that needs to be done here, as we create the
inode item before we create the orphan item.  We could potentially add
the orphan item, but if we failed to create the inode item we would have
to abort the transaction.  Instead add a helper to delete the inode item
we created in the case that we're unable to look up the inode (this
would likely be caused by an ENOMEM), which if it succeeds means we can
avoid a transaction abort in this particular error case.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 39 +++++++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 328a78399ddb..b5d644a87dcf 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -3599,6 +3599,35 @@ static int __insert_orphan_inode(struct btrfs_trans_handle *trans,
 	return ret;
 }
 
+static void delete_orphan_inode(struct btrfs_trans_handle *trans,
+				struct btrfs_root *root, u64 objectid)
+{
+	struct btrfs_path *path;
+	struct btrfs_key key;
+	int ret = 0;
+
+	path = btrfs_alloc_path();
+	if (!path) {
+		ret = -ENOMEM;
+		goto out;
+	}
+
+	key.objectid = objectid;
+	key.type = BTRFS_INODE_ITEM_KEY;
+	key.offset = 0;
+	ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
+	if (ret) {
+		if (ret > 0)
+			ret = -ENOENT;
+		goto out;
+	}
+	ret = btrfs_del_item(trans, root, path);
+out:
+	if (ret)
+		btrfs_abort_transaction(trans, ret);
+	btrfs_free_path(path);
+}
+
 /*
  * helper to create inode for data relocation.
  * the inode is in data relocation tree and its link count is 0
@@ -3625,10 +3654,16 @@ struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info,
 		goto out;
 
 	err = __insert_orphan_inode(trans, root, objectid);
-	BUG_ON(err);
+	if (err)
+		goto out;
 
 	inode = btrfs_iget(fs_info->sb, objectid, root);
-	BUG_ON(IS_ERR(inode));
+	if (IS_ERR(inode)) {
+		delete_orphan_inode(trans, root, objectid);
+		err = PTR_ERR(inode);
+		inode = NULL;
+		goto out;
+	}
 	BTRFS_I(inode)->index_cnt = group->start;
 
 	err = btrfs_orphan_add(trans, BTRFS_I(inode));
-- 
2.26.2


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

* [PATCH v6 44/52] btrfs: handle __add_reloc_root failures in btrfs_recover_relocation
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (42 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 43/52] btrfs: do proper error handling in create_reloc_inode Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 45/52] btrfs: cleanup error handling in prepare_to_merge Josef Bacik
                   ` (8 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

We can already handle errors appropriately from this function, deal with
an error coming from __add_reloc_root appropriately.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b5d644a87dcf..af9008a71ff4 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -4005,7 +4005,12 @@ int btrfs_recover_relocation(struct btrfs_root *root)
 		}
 
 		err = __add_reloc_root(reloc_root);
-		BUG_ON(err < 0); /* -ENOMEM or logic error */
+		if (err) {
+			list_add_tail(&reloc_root->root_list, &reloc_roots);
+			btrfs_put_root(fs_root);
+			btrfs_end_transaction(trans);
+			goto out_unset;
+		}
 		fs_root->reloc_root = btrfs_grab_root(reloc_root);
 		btrfs_put_root(fs_root);
 	}
@@ -4220,7 +4225,10 @@ int btrfs_reloc_post_snapshot(struct btrfs_trans_handle *trans,
 		return PTR_ERR(reloc_root);
 
 	ret = __add_reloc_root(reloc_root);
-	BUG_ON(ret < 0);
+	if (ret) {
+		btrfs_put_root(reloc_root);
+		return ret;
+	}
 	new_root->reloc_root = btrfs_grab_root(reloc_root);
 
 	if (rc->create_reloc_tree)
-- 
2.26.2


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

* [PATCH v6 45/52] btrfs: cleanup error handling in prepare_to_merge
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (43 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 44/52] btrfs: handle __add_reloc_root failures in btrfs_recover_relocation Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 46/52] btrfs: handle extent corruption with select_one_root properly Josef Bacik
                   ` (7 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

This probably can't happen even with a corrupt file system, because we
would have failed much earlier on than here.  However there's no reason
we can't just check and bail out as appropriate, so do that and convert
the correctness BUG_ON() to an ASSERT().

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index af9008a71ff4..b824ef069ac5 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1870,8 +1870,14 @@ int prepare_to_merge(struct reloc_control *rc, int err)
 
 		root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
 				false);
-		BUG_ON(IS_ERR(root));
-		BUG_ON(root->reloc_root != reloc_root);
+		if (IS_ERR(root)) {
+			list_add(&reloc_root->root_list, &reloc_roots);
+			btrfs_abort_transaction(trans, (int)PTR_ERR(root));
+			if (!err)
+				err = PTR_ERR(root);
+			break;
+		}
+		ASSERT(root->reloc_root == reloc_root);
 
 		/*
 		 * set reference count to 1, so btrfs_recover_relocation
-- 
2.26.2


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

* [PATCH v6 46/52] btrfs: handle extent corruption with select_one_root properly
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (44 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 45/52] btrfs: cleanup error handling in prepare_to_merge Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 47/52] btrfs: do proper error handling in merge_reloc_roots Josef Bacik
                   ` (6 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

In corruption cases we could have paths from a block up to no root at
all, and thus we'll BUG_ON(!root) in select_one_root.  Handle this by
adding an ASSERT() for developers, and returning an error for normal
users.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index b824ef069ac5..9a59adaf178c 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2199,7 +2199,17 @@ struct btrfs_root *select_one_root(struct btrfs_backref_node *node)
 		cond_resched();
 		next = walk_up_backref(next, edges, &index);
 		root = next->root;
-		BUG_ON(!root);
+
+		/*
+		 * This can occur if we have incomplete extent refs leading all
+		 * the way up a particular path, in this case return -EUCLEAN.
+		 * However leave as an ASSERT() for developers, because it could
+		 * indicate a bug in the backref code.
+		 */
+		if (!root) {
+			ASSERT(0);
+			return ERR_PTR(-EUCLEAN);
+		}
 
 		/* No other choice for non-shareable tree */
 		if (!test_bit(BTRFS_ROOT_SHAREABLE, &root->state))
@@ -2589,8 +2599,12 @@ static int relocate_tree_block(struct btrfs_trans_handle *trans,
 
 	BUG_ON(node->processed);
 	root = select_one_root(node);
-	if (root == ERR_PTR(-ENOENT)) {
-		update_processed_blocks(rc, node);
+	if (IS_ERR(root)) {
+		ret = PTR_ERR(root);
+		if (ret == -ENOENT) {
+			ret = 0;
+			update_processed_blocks(rc, node);
+		}
 		goto out;
 	}
 
-- 
2.26.2


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

* [PATCH v6 47/52] btrfs: do proper error handling in merge_reloc_roots
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (45 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 46/52] btrfs: handle extent corruption with select_one_root properly Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 48/52] btrfs: check return value of btrfs_commit_transaction in relocation Josef Bacik
                   ` (5 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

We have a BUG_ON() if we get an error back from btrfs_get_fs_root().
This honestly should never fail, as at this point we have a solid
coordination of fs root to reloc root, and these roots will all be in
memory.  But in the name of killing BUG_ON()'s remove these and handle
the error condition properly, ASSERT()'ing for developers.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 9a59adaf178c..066d06575dbc 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1950,8 +1950,29 @@ void merge_reloc_roots(struct reloc_control *rc)
 		root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
 					 false);
 		if (btrfs_root_refs(&reloc_root->root_item) > 0) {
-			BUG_ON(IS_ERR(root));
-			BUG_ON(root->reloc_root != reloc_root);
+			if (IS_ERR(root)) {
+				/*
+				 * For recovery we read the fs roots on mount,
+				 * and if we didn't find the root then we marked
+				 * the reloc root as a garbage root.  For normal
+				 * relocation obviously the root should exist in
+				 * memory.  However there's no reason we can't
+				 * handle the error properly here just in case.
+				 */
+				ASSERT(0);
+				ret = PTR_ERR(root);
+				goto out;
+			}
+			if (root->reloc_root != reloc_root) {
+				/*
+				 * This is actually impossible without something
+				 * going really wrong (like weird race condition
+				 * or cosmic rays).
+				 */
+				ASSERT(0);
+				ret = -EINVAL;
+				goto out;
+			}
 			ret = merge_reloc_root(rc, root);
 			btrfs_put_root(root);
 			if (ret) {
-- 
2.26.2


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

* [PATCH v6 48/52] btrfs: check return value of btrfs_commit_transaction in relocation
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (46 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 47/52] btrfs: do proper error handling in merge_reloc_roots Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 49/52] btrfs: do not WARN_ON() if we can't find the reloc root Josef Bacik
                   ` (4 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

There's a few places where we don't check the return value of
btrfs_commit_transaction in relocation.c.  Thankfully all these places
have straightforward error handling, so simply change all of the sites
at once.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 066d06575dbc..3ecb09c5d65f 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -1905,7 +1905,7 @@ int prepare_to_merge(struct reloc_control *rc, int err)
 	list_splice(&reloc_roots, &rc->reloc_roots);
 
 	if (!err)
-		btrfs_commit_transaction(trans);
+		err = btrfs_commit_transaction(trans);
 	else
 		btrfs_end_transaction(trans);
 	return err;
@@ -3440,8 +3440,7 @@ int prepare_to_relocate(struct reloc_control *rc)
 		 */
 		return PTR_ERR(trans);
 	}
-	btrfs_commit_transaction(trans);
-	return 0;
+	return btrfs_commit_transaction(trans);
 }
 
 static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
@@ -3600,7 +3599,9 @@ static noinline_for_stack int relocate_block_group(struct reloc_control *rc)
 		err = PTR_ERR(trans);
 		goto out_free;
 	}
-	btrfs_commit_transaction(trans);
+	ret = btrfs_commit_transaction(trans);
+	if (ret && !err)
+		err = ret;
 out_free:
 	ret = clean_dirty_subvols(rc);
 	if (ret < 0 && !err)
-- 
2.26.2


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

* [PATCH v6 49/52] btrfs: do not WARN_ON() if we can't find the reloc root
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (47 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 48/52] btrfs: check return value of btrfs_commit_transaction in relocation Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 50/52] btrfs: print the actual offset in btrfs_root_name Josef Bacik
                   ` (3 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Zygo Blaxell

Any number of things could have gone wrong, like ENOMEM or EIO, so don't
WARN_ON() if we're unable to find the reloc root in the backref code.

Reported-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/backref.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c
index 56f7c840031e..525815d2914b 100644
--- a/fs/btrfs/backref.c
+++ b/fs/btrfs/backref.c
@@ -2617,7 +2617,7 @@ static int handle_direct_tree_backref(struct btrfs_backref_cache *cache,
 		/* Only reloc backref cache cares about a specific root */
 		if (cache->is_reloc) {
 			root = find_reloc_root(cache->fs_info, cur->bytenr);
-			if (WARN_ON(!root))
+			if (!root)
 				return -ENOENT;
 			cur->root = root;
 		} else {
-- 
2.26.2


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

* [PATCH v6 50/52] btrfs: print the actual offset in btrfs_root_name
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (48 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 49/52] btrfs: do not WARN_ON() if we can't find the reloc root Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 51/52] btrfs: fix reloc root leak with 0 ref reloc roots on recovery Josef Bacik
                   ` (2 subsequent siblings)
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

We're supposed to print the root_key.offset in btrfs_root_name in the
case of a reloc root, not the objectid.  Fix this helper to take the key
so we have access to the offset when we need it.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/disk-io.c    |  2 +-
 fs/btrfs/print-tree.c | 10 +++++-----
 fs/btrfs/print-tree.h |  2 +-
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 765deefda92b..0eeadf624dfb 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -1457,7 +1457,7 @@ void btrfs_check_leaked_roots(struct btrfs_fs_info *fs_info)
 		root = list_first_entry(&fs_info->allocated_roots,
 					struct btrfs_root, leak_list);
 		btrfs_err(fs_info, "leaked root %s refcount %d",
-			  btrfs_root_name(root->root_key.objectid, buf),
+			  btrfs_root_name(&root->root_key, buf),
 			  refcount_read(&root->refs));
 		while (refcount_read(&root->refs) > 1)
 			btrfs_put_root(root);
diff --git a/fs/btrfs/print-tree.c b/fs/btrfs/print-tree.c
index fe5e0026129d..b8137dbf6a3a 100644
--- a/fs/btrfs/print-tree.c
+++ b/fs/btrfs/print-tree.c
@@ -26,22 +26,22 @@ static const struct root_name_map root_map[] = {
 	{ BTRFS_DATA_RELOC_TREE_OBJECTID,	"DATA_RELOC_TREE"	},
 };
 
-const char *btrfs_root_name(u64 objectid, char *buf)
+const char *btrfs_root_name(struct btrfs_key *key, char *buf)
 {
 	int i;
 
-	if (objectid == BTRFS_TREE_RELOC_OBJECTID) {
+	if (key->objectid == BTRFS_TREE_RELOC_OBJECTID) {
 		snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN,
-			 "TREE_RELOC offset=%llu", objectid);
+			 "TREE_RELOC offset=%llu", key->offset);
 		return buf;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(root_map); i++) {
-		if (root_map[i].id == objectid)
+		if (root_map[i].id == key->objectid)
 			return root_map[i].name;
 	}
 
-	snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN, "%llu", objectid);
+	snprintf(buf, BTRFS_ROOT_NAME_BUF_LEN, "%llu", key->objectid);
 	return buf;
 }
 
diff --git a/fs/btrfs/print-tree.h b/fs/btrfs/print-tree.h
index 78b99385a503..802628dd1a6e 100644
--- a/fs/btrfs/print-tree.h
+++ b/fs/btrfs/print-tree.h
@@ -11,6 +11,6 @@
 
 void btrfs_print_leaf(struct extent_buffer *l);
 void btrfs_print_tree(struct extent_buffer *c, bool follow);
-const char *btrfs_root_name(u64 objectid, char *buf);
+const char *btrfs_root_name(struct btrfs_key *key, char *buf);
 
 #endif
-- 
2.26.2


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

* [PATCH v6 51/52] btrfs: fix reloc root leak with 0 ref reloc roots on recovery
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (49 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 50/52] btrfs: print the actual offset in btrfs_root_name Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 16:23 ` [PATCH v6 52/52] btrfs: splice remaining dirty_bg's onto the transaction dirty bg list Josef Bacik
  2020-12-08 19:46 ` [PATCH v6 00/52] Zygo Blaxell
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team

When recovering a relocation, if we run into a reloc root that has 0
refs we simply add it to the reloc_control->reloc_roots list, and then
clean it up later.  The problem with this is __del_reloc_root() doesn't
do anything if the root isn't in the radix tree, which in this case it
won't be because we never call __add_reloc_root() on the reloc_root.

This exit condition simply isn't correct really.  During normal
operation we can remove ourselves from the rb tree and then we're meant
to clean up later at merge_reloc_roots() time, and this happens
correctly.  During recovery we're depending on free_reloc_roots() to
drop our references, but we're short-circuiting.

Fix this by continuing to check if we're on the list and dropping
ourselves from the reloc_control root list and dropping our reference
appropriately.  Change the corresponding BUG_ON() to an ASSERT() that
does the correct thing if we aren't in the rb tree.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/relocation.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 3ecb09c5d65f..9f16e9932595 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -671,9 +671,7 @@ static void __del_reloc_root(struct btrfs_root *root)
 			RB_CLEAR_NODE(&node->rb_node);
 		}
 		spin_unlock(&rc->reloc_root_tree.lock);
-		if (!node)
-			return;
-		BUG_ON((struct btrfs_root *)node->data != root);
+		ASSERT(!node || (struct btrfs_root *)node->data == root);
 	}
 
 	/*
-- 
2.26.2


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

* [PATCH v6 52/52] btrfs: splice remaining dirty_bg's onto the transaction dirty bg list
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (50 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 51/52] btrfs: fix reloc root leak with 0 ref reloc roots on recovery Josef Bacik
@ 2020-12-08 16:23 ` Josef Bacik
  2020-12-08 19:46 ` [PATCH v6 00/52] Zygo Blaxell
  52 siblings, 0 replies; 55+ messages in thread
From: Josef Bacik @ 2020-12-08 16:23 UTC (permalink / raw)
  To: linux-btrfs, kernel-team; +Cc: Qu Wenruo

While doing error injection testing with my relocation patches I hit the
following ASSERT()

assertion failed: list_empty(&block_group->dirty_list), in fs/btrfs/block-group.c:3356
------------[ cut here ]------------
kernel BUG at fs/btrfs/ctree.h:3357!
invalid opcode: 0000 [#1] SMP NOPTI
CPU: 0 PID: 24351 Comm: umount Tainted: G        W         5.10.0-rc3+ #193
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014
RIP: 0010:assertfail.constprop.0+0x18/0x1a
RSP: 0018:ffffa09b019c7e00 EFLAGS: 00010282
RAX: 0000000000000056 RBX: ffff8f6492c18000 RCX: 0000000000000000
RDX: ffff8f64fbc27c60 RSI: ffff8f64fbc19050 RDI: ffff8f64fbc19050
RBP: ffff8f6483bbdc00 R08: 0000000000000000 R09: 0000000000000000
R10: ffffa09b019c7c38 R11: ffffffff85d70928 R12: ffff8f6492c18100
R13: ffff8f6492c18148 R14: ffff8f6483bbdd70 R15: dead000000000100
FS:  00007fbfda4cdc40(0000) GS:ffff8f64fbc00000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 00007fbfda666fd0 CR3: 000000013cf66002 CR4: 0000000000370ef0
Call Trace:
 btrfs_free_block_groups.cold+0x55/0x55
 close_ctree+0x2c5/0x306
 ? fsnotify_destroy_marks+0x14/0x100
 generic_shutdown_super+0x6c/0x100
 kill_anon_super+0x14/0x30
 btrfs_kill_super+0x12/0x20
 deactivate_locked_super+0x36/0xa0
 cleanup_mnt+0x12d/0x190
 task_work_run+0x5c/0xa0
 exit_to_user_mode_prepare+0x1b1/0x1d0
 syscall_exit_to_user_mode+0x54/0x280
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

This happened because I injected an error in btrfs_cow_block() while
running the dirty block groups.  When we run the dirty block groups, we
splice the list onto a local list to process.  However if an error
occurs, we only cleanup the transactions dirty block group list, not any
pending block groups we have on our locally spliced list.  Fix this by
splicing the list back onto the transactions dirty block group list, so
any remaining block groups are cleaned up.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/block-group.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/btrfs/block-group.c b/fs/btrfs/block-group.c
index 0886e81e5540..5cfa52b1a3b8 100644
--- a/fs/btrfs/block-group.c
+++ b/fs/btrfs/block-group.c
@@ -2685,6 +2685,9 @@ int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans)
 		}
 		spin_unlock(&cur_trans->dirty_bgs_lock);
 	} else if (ret < 0) {
+		spin_lock(&cur_trans->dirty_bgs_lock);
+		list_splice_init(&dirty, &cur_trans->dirty_bgs);
+		spin_unlock(&cur_trans->dirty_bgs_lock);
 		btrfs_cleanup_dirty_bgs(cur_trans, fs_info);
 	}
 
-- 
2.26.2


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

* Re: [PATCH v6 00/52]
  2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
                   ` (51 preceding siblings ...)
  2020-12-08 16:23 ` [PATCH v6 52/52] btrfs: splice remaining dirty_bg's onto the transaction dirty bg list Josef Bacik
@ 2020-12-08 19:46 ` Zygo Blaxell
  2020-12-13 22:26   ` Zygo Blaxell
  52 siblings, 1 reply; 55+ messages in thread
From: Zygo Blaxell @ 2020-12-08 19:46 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Tue, Dec 08, 2020 at 11:23:07AM -0500, Josef Bacik wrote:
> v5->v6:
> - Reworked "btrfs: handle errors from select_reloc_root()" because Zygo reported
>   hitting an ASSERT(ret != -ENOENT) during his testing.  This was because I
>   changed select_reloc_root() to return -ENOENT if we happened to race with
>   somebody else who failed to init the reloc root, however we had an ASSERT() to
>   check for this because it indicated corruption.  I modified that patch to move
>   the ASSERT() to where the problem actually is, so select_reloc_root() can
>   return whatever error and it'll pass it along.  I also removed Qu's
>   reviewed-by for the patch because of the change.

Now it KASAN's:

	[Tue Dec  8 13:18:56 2020] BTRFS info (device dm-0): balance: start -mlimit=1 -slimit=1
	[Tue Dec  8 13:18:56 2020] BTRFS debug (device dm-0): cleaner removing 2383
	[Tue Dec  8 13:18:57 2020] BTRFS info (device dm-0): relocating block group 3262427168768 flags metadata|raid1
	[Tue Dec  8 13:19:51 2020] BTRFS debug (device dm-0): cleaner removing 2384
	[Tue Dec  8 13:22:21 2020] avg_delayed_ref_runtime = 3894835, time = 750151098700, count = 192601
	[Tue Dec  8 13:22:32 2020] ==================================================================
	[Tue Dec  8 13:22:32 2020] BUG: KASAN: use-after-free in btrfs_backref_cleanup_node+0x18a/0x420
	[Tue Dec  8 13:22:32 2020] Read of size 8 at addr ffff888112402950 by task btrfs/28836

	[Tue Dec  8 13:22:32 2020] CPU: 0 PID: 28836 Comm: btrfs Tainted: G        W         5.10.0-e35f27394290-for-next+ #23
	[Tue Dec  8 13:22:32 2020] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
	[Tue Dec  8 13:22:32 2020] Call Trace:
	[Tue Dec  8 13:22:32 2020]  dump_stack+0xbc/0xf9
	[Tue Dec  8 13:22:32 2020]  ? btrfs_backref_cleanup_node+0x18a/0x420
	[Tue Dec  8 13:22:32 2020]  print_address_description.constprop.8+0x21/0x210
	[Tue Dec  8 13:22:32 2020]  ? record_print_text.cold.34+0x11/0x11
	[Tue Dec  8 13:22:32 2020]  ? btrfs_backref_cleanup_node+0x18a/0x420
	[Tue Dec  8 13:22:32 2020]  ? btrfs_backref_cleanup_node+0x18a/0x420
	[Tue Dec  8 13:22:32 2020]  kasan_report.cold.10+0x20/0x37
	[Tue Dec  8 13:22:32 2020]  ? btrfs_backref_cleanup_node+0x18a/0x420
	[Tue Dec  8 13:22:32 2020]  __asan_load8+0x69/0x90
	[Tue Dec  8 13:22:32 2020]  btrfs_backref_cleanup_node+0x18a/0x420
	[Tue Dec  8 13:22:32 2020]  btrfs_backref_release_cache+0x83/0x1b0
	[Tue Dec  8 13:22:32 2020]  relocate_block_group+0x394/0x780
	[Tue Dec  8 13:22:32 2020]  ? merge_reloc_roots+0x4a0/0x4a0
	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_block_group+0x26e/0x4c0
	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_chunk+0x52/0x120
	[Tue Dec  8 13:22:32 2020]  btrfs_balance+0xe2e/0x1900
	[Tue Dec  8 13:22:32 2020]  ? check_flags.part.50+0x6c/0x1e0
	[Tue Dec  8 13:22:32 2020]  ? btrfs_relocate_chunk+0x120/0x120
	[Tue Dec  8 13:22:32 2020]  ? kmem_cache_alloc_trace+0xa06/0xcb0
	[Tue Dec  8 13:22:32 2020]  ? _copy_from_user+0x83/0xc0
	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl_balance+0x3a7/0x460
	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl+0x24c8/0x4360
	[Tue Dec  8 13:22:32 2020]  ? __kasan_check_read+0x11/0x20
	[Tue Dec  8 13:22:32 2020]  ? check_chain_key+0x1f4/0x2f0
	[Tue Dec  8 13:22:32 2020]  ? __asan_loadN+0xf/0x20
	[Tue Dec  8 13:22:32 2020]  ? btrfs_ioctl_get_supported_features+0x30/0x30
	[Tue Dec  8 13:22:32 2020]  ? kvm_sched_clock_read+0x18/0x30
	[Tue Dec  8 13:22:32 2020]  ? check_chain_key+0x1f4/0x2f0
	[Tue Dec  8 13:22:32 2020]  ? lock_downgrade+0x3f0/0x3f0
	[Tue Dec  8 13:22:32 2020]  ? handle_mm_fault+0xad6/0x2150
	[Tue Dec  8 13:22:32 2020]  ? do_vfs_ioctl+0xfc/0x9d0
	[Tue Dec  8 13:22:32 2020]  ? ioctl_file_clone+0xe0/0xe0
	[Tue Dec  8 13:22:32 2020]  ? check_flags.part.50+0x6c/0x1e0
	[Tue Dec  8 13:22:32 2020]  ? check_flags.part.50+0x6c/0x1e0
	[Tue Dec  8 13:22:32 2020]  ? check_flags+0x26/0x30
	[Tue Dec  8 13:22:32 2020]  ? lock_is_held_type+0xc3/0xf0
	[Tue Dec  8 13:22:32 2020]  ? syscall_enter_from_user_mode+0x1b/0x60
	[Tue Dec  8 13:22:32 2020]  ? do_syscall_64+0x13/0x80
	[Tue Dec  8 13:22:32 2020]  ? rcu_read_lock_sched_held+0xa1/0xd0
	[Tue Dec  8 13:22:32 2020]  ? __kasan_check_read+0x11/0x20
	[Tue Dec  8 13:22:32 2020]  ? __fget_light+0xae/0x110
	[Tue Dec  8 13:22:32 2020]  __x64_sys_ioctl+0xc3/0x100
	[Tue Dec  8 13:22:32 2020]  do_syscall_64+0x37/0x80
	[Tue Dec  8 13:22:32 2020]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
	[Tue Dec  8 13:22:32 2020] RIP: 0033:0x7f4c4bdfe427
	[Tue Dec  8 13:22:32 2020] Code: 00 00 90 48 8b 05 69 aa 0c 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 39 aa 0c 00 f7 d8 64 89 01 48
	[Tue Dec  8 13:22:32 2020] RSP: 002b:00007fff33ee6df8 EFLAGS: 00000202 ORIG_RAX: 0000000000000010
	[Tue Dec  8 13:22:32 2020] RAX: ffffffffffffffda RBX: 00007fff33ee6e98 RCX: 00007f4c4bdfe427
	[Tue Dec  8 13:22:32 2020] RDX: 00007fff33ee6e98 RSI: 00000000c4009420 RDI: 0000000000000003
	[Tue Dec  8 13:22:32 2020] RBP: 0000000000000003 R08: 0000000000000003 R09: 0000000000000078
	[Tue Dec  8 13:22:32 2020] R10: fffffffffffff59d R11: 0000000000000202 R12: 0000000000000001
	[Tue Dec  8 13:22:32 2020] R13: 0000000000000000 R14: 00007fff33ee8a34 R15: 0000000000000001

	[Tue Dec  8 13:22:32 2020] Allocated by task 28836:
	[Tue Dec  8 13:22:32 2020]  kasan_save_stack+0x21/0x50
	[Tue Dec  8 13:22:32 2020]  __kasan_kmalloc.constprop.18+0xbe/0xd0
	[Tue Dec  8 13:22:32 2020]  kasan_kmalloc+0x9/0x10
	[Tue Dec  8 13:22:32 2020]  kmem_cache_alloc_trace+0x410/0xcb0
	[Tue Dec  8 13:22:32 2020]  btrfs_backref_alloc_node+0x46/0xf0
	[Tue Dec  8 13:22:32 2020]  btrfs_backref_add_tree_node+0x60d/0x11d0
	[Tue Dec  8 13:22:32 2020]  build_backref_tree+0xc5/0x700
	[Tue Dec  8 13:22:32 2020]  relocate_tree_blocks+0x2be/0xb90
	[Tue Dec  8 13:22:32 2020]  relocate_block_group+0x2eb/0x780
	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_block_group+0x26e/0x4c0
	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_chunk+0x52/0x120
	[Tue Dec  8 13:22:32 2020]  btrfs_balance+0xe2e/0x1900
	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl_balance+0x3a7/0x460
	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl+0x24c8/0x4360
	[Tue Dec  8 13:22:32 2020]  __x64_sys_ioctl+0xc3/0x100
	[Tue Dec  8 13:22:32 2020]  do_syscall_64+0x37/0x80
	[Tue Dec  8 13:22:32 2020]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

	[Tue Dec  8 13:22:32 2020] Freed by task 28836:
	[Tue Dec  8 13:22:32 2020]  kasan_save_stack+0x21/0x50
	[Tue Dec  8 13:22:32 2020]  kasan_set_track+0x20/0x30
	[Tue Dec  8 13:22:32 2020]  kasan_set_free_info+0x1f/0x30
	[Tue Dec  8 13:22:32 2020]  __kasan_slab_free+0xf3/0x140
	[Tue Dec  8 13:22:32 2020]  kasan_slab_free+0xe/0x10
	[Tue Dec  8 13:22:32 2020]  kfree+0xde/0x200
	[Tue Dec  8 13:22:32 2020]  btrfs_backref_error_cleanup+0x452/0x530
	[Tue Dec  8 13:22:32 2020]  build_backref_tree+0x1a5/0x700
	[Tue Dec  8 13:22:32 2020]  relocate_tree_blocks+0x2be/0xb90
	[Tue Dec  8 13:22:32 2020]  relocate_block_group+0x2eb/0x780
	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_block_group+0x26e/0x4c0
	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_chunk+0x52/0x120
	[Tue Dec  8 13:22:32 2020]  btrfs_balance+0xe2e/0x1900
	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl_balance+0x3a7/0x460
	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl+0x24c8/0x4360
	[Tue Dec  8 13:22:32 2020]  __x64_sys_ioctl+0xc3/0x100
	[Tue Dec  8 13:22:32 2020]  do_syscall_64+0x37/0x80
	[Tue Dec  8 13:22:32 2020]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

	[Tue Dec  8 13:22:32 2020] The buggy address belongs to the object at ffff888112402900
				    which belongs to the cache kmalloc-128 of size 128
	[Tue Dec  8 13:22:32 2020] The buggy address is located 80 bytes inside of
				    128-byte region [ffff888112402900, ffff888112402980)
	[Tue Dec  8 13:22:32 2020] The buggy address belongs to the page:
	[Tue Dec  8 13:22:32 2020] page:0000000028b1cd08 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888131c810c0 pfn:0x112402
	[Tue Dec  8 13:22:32 2020] flags: 0x17ffe0000000200(slab)
	[Tue Dec  8 13:22:32 2020] raw: 017ffe0000000200 ffffea000424f308 ffffea0007d572c8 ffff888100040440
	[Tue Dec  8 13:22:32 2020] raw: ffff888131c810c0 ffff888112402000 0000000100000009 0000000000000000
	[Tue Dec  8 13:22:32 2020] page dumped because: kasan: bad access detected

	[Tue Dec  8 13:22:32 2020] Memory state around the buggy address:
	[Tue Dec  8 13:22:32 2020]  ffff888112402800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
	[Tue Dec  8 13:22:32 2020]  ffff888112402880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
	[Tue Dec  8 13:22:32 2020] >ffff888112402900: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
	[Tue Dec  8 13:22:33 2020]                                                  ^
	[Tue Dec  8 13:22:33 2020]  ffff888112402980: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
	[Tue Dec  8 13:22:33 2020]  ffff888112402a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
	[Tue Dec  8 13:22:33 2020] ==================================================================
	[Tue Dec  8 13:22:33 2020] Disabling lock debugging due to kernel taint

> v4->v5:
> - Dropped "btrfs: fix error handling in commit_fs_roots" as it was merged.
> - Fixed an ASSERT() that happened during relocation recovery that Zygo reported,
>   I moved the error condition out of another condition which broke recovery if
>   we had deleted subvols pending with relocation.
> 
> v3->v4:
> - Squashed the __add_reloc_root error handling patches in
>   btrfs_recover_relocation as they were small and in the same function.
> - Squashed the record_root_in_trans failure handling patches for
>   select_reloc_root as they were small and in the same function.
> - Added a new patch to address an existing error handling problem with subvol
>   creation.
> - Fixed up the various cases that Qu noticed where I got things wrong, cleaning
>   up a leaked root extent ref, a leaked inode item, and where I accidentally
>   stopped dealing with errors from btrfs_drop_subtree.
> - Reworked a bunch of the ASSERT()'s to do ASSERT(0) in their respective if
>   statements.
> - Added reviewed-bys.
> 
> v2->v3:
> - A lot of extra patches fixing various things that I encountered while
>   debugging the corruption problem that was uncovered by these patches.
> - Fixed the panic that Zygo was seeing and other issues.
> - Fixed up the comments from Nikolay and Filipe.
> 
> A slight note, the first set of patches could probably be taken now, and in fact
> 
>   btrfs: fix error handling in commit_fs_roots
> 
> Was sent earlier this week and is very important and needs to be reviewed and
> merged ASAP.  The following are safe and could be merged outside of the rest of
> this series
> 
>   btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
>   btrfs: fix lockdep splat in btrfs_recover_relocation
>   btrfs: keep track of the root owner for relocation reads
>   btrfs: noinline btrfs_should_cancel_balance
>   btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node
>   btrfs: pass down the tree block level through ref-verify
>   btrfs: make sure owner is set in ref-verify
>   btrfs: don't clear ret in btrfs_start_dirty_block_groups
> 
> The rest obviously are all around the actual error handling.
> 
> v1->v2:
> - fixed a bug where I accidentally dropped reading flags in relocate_block_group
>   when I dropped the extra checks that we handle in the tree checker.
> 
> --- Original message ---
> Hello,
> 
> Relocation is the last place that is not able to handle errors at all, which
> results in all sorts of lovely panics if you encounter corruptions or IO errors.
> I'm going to start cleaning up relocation, but before I move code around I want
> the error handling to be somewhat sane, so I'm not changing behavior and error
> handling at the same time.
> 
> These patches are purely about error handling, there is no behavior changing
> other than returning errors up the chain properly.  There is a lot of room for
> follow up cleanups, which will happen next.  However I wanted to get this series
> done today and out so we could get it merged ASAP, and then the follow up
> cleanups can happen later as they are less important and less critical.
> 
> The only exception to the above is the patch to add the error injection sites
> for btrfs_cow_block and btrfs_search_slot, and a lockdep fix that I discovered
> while running my tests, those are the first two patches in the series.
> 
> I tested this with my error injection stress test, where I keep track of all
> stack traces that have been tested and only inject errors when we have a new
> stack trace, which means I should have covered all of the various error
> conditions.  With this patchset I'm no longer panicing while stressing the error
> conditions.  Thanks,
> 
> Josef
> 
> Josef Bacik (52):
>   btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
>   btrfs: modify the new_root highest_objectid under a ref count
>   btrfs: fix lockdep splat in btrfs_recover_relocation
>   btrfs: keep track of the root owner for relocation reads
>   btrfs: noinline btrfs_should_cancel_balance
>   btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node
>   btrfs: pass down the tree block level through ref-verify
>   btrfs: make sure owner is set in ref-verify
>   btrfs: don't clear ret in btrfs_start_dirty_block_groups
>   btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation
>   btrfs: convert BUG_ON()'s in relocate_tree_block
>   btrfs: return an error from btrfs_record_root_in_trans
>   btrfs: handle errors from select_reloc_root()
>   btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors
>   btrfs: check record_root_in_trans related failures in
>     select_reloc_root
>   btrfs: do proper error handling in record_reloc_root_in_trans
>   btrfs: handle btrfs_record_root_in_trans failure in
>     btrfs_rename_exchange
>   btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename
>   btrfs: handle btrfs_record_root_in_trans failure in
>     btrfs_delete_subvolume
>   btrfs: handle btrfs_record_root_in_trans failure in
>     btrfs_recover_log_trees
>   btrfs: handle btrfs_record_root_in_trans failure in create_subvol
>   btrfs: btrfs: handle btrfs_record_root_in_trans failure in
>     relocate_tree_block
>   btrfs: handle btrfs_record_root_in_trans failure in start_transaction
>   btrfs: handle record_root_in_trans failure in qgroup_account_snapshot
>   btrfs: handle record_root_in_trans failure in
>     btrfs_record_root_in_trans
>   btrfs: handle record_root_in_trans failure in create_pending_snapshot
>   btrfs: do not panic in __add_reloc_root
>   btrfs: have proper error handling in btrfs_init_reloc_root
>   btrfs: do proper error handling in create_reloc_root
>   btrfs: validate ->reloc_root after recording root in trans
>   btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots
>   btrfs: change insert_dirty_subvol to return errors
>   btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol
>   btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge
>   btrfs: do proper error handling in btrfs_update_reloc_root
>   btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s
>   btrfs: handle btrfs_cow_block errors in replace_path
>   btrfs: handle btrfs_search_slot failure in replace_path
>   btrfs: handle errors in reference count manipulation in replace_path
>   btrfs: handle extent reference errors in do_relocation
>   btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly
>   btrfs: remove the extent item sanity checks in relocate_block_group
>   btrfs: do proper error handling in create_reloc_inode
>   btrfs: handle __add_reloc_root failures in btrfs_recover_relocation
>   btrfs: cleanup error handling in prepare_to_merge
>   btrfs: handle extent corruption with select_one_root properly
>   btrfs: do proper error handling in merge_reloc_roots
>   btrfs: check return value of btrfs_commit_transaction in relocation
>   btrfs: do not WARN_ON() if we can't find the reloc root
>   btrfs: print the actual offset in btrfs_root_name
>   btrfs: fix reloc root leak with 0 ref reloc roots on recovery
>   btrfs: splice remaining dirty_bg's onto the transaction dirty bg list
> 
>  fs/btrfs/backref.c      |   9 +-
>  fs/btrfs/block-group.c  |   6 +-
>  fs/btrfs/ctree.c        |   2 +
>  fs/btrfs/disk-io.c      |   2 +-
>  fs/btrfs/inode.c        |  20 +-
>  fs/btrfs/ioctl.c        |  17 +-
>  fs/btrfs/print-tree.c   |  10 +-
>  fs/btrfs/print-tree.h   |   2 +-
>  fs/btrfs/ref-verify.c   |  43 ++--
>  fs/btrfs/relocation.c   | 474 +++++++++++++++++++++++++++++++---------
>  fs/btrfs/transaction.c  |  37 +++-
>  fs/btrfs/tree-checker.c |   5 +
>  fs/btrfs/tree-log.c     |   8 +-
>  fs/btrfs/volumes.c      |   2 +
>  14 files changed, 477 insertions(+), 160 deletions(-)
> 
> -- 
> 2.26.2
> 

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

* Re: [PATCH v6 00/52]
  2020-12-08 19:46 ` [PATCH v6 00/52] Zygo Blaxell
@ 2020-12-13 22:26   ` Zygo Blaxell
  0 siblings, 0 replies; 55+ messages in thread
From: Zygo Blaxell @ 2020-12-13 22:26 UTC (permalink / raw)
  To: Josef Bacik; +Cc: linux-btrfs, kernel-team

On Tue, Dec 08, 2020 at 02:46:07PM -0500, Zygo Blaxell wrote:
> On Tue, Dec 08, 2020 at 11:23:07AM -0500, Josef Bacik wrote:
> > v5->v6:
> > - Reworked "btrfs: handle errors from select_reloc_root()" because Zygo reported
> >   hitting an ASSERT(ret != -ENOENT) during his testing.  This was because I
> >   changed select_reloc_root() to return -ENOENT if we happened to race with
> >   somebody else who failed to init the reloc root, however we had an ASSERT() to
> >   check for this because it indicated corruption.  I modified that patch to move
> >   the ASSERT() to where the problem actually is, so select_reloc_root() can
> >   return whatever error and it'll pass it along.  I also removed Qu's
> >   reviewed-by for the patch because of the change.
> 
> Now it KASAN's:
> 
> 	[Tue Dec  8 13:18:56 2020] BTRFS info (device dm-0): balance: start -mlimit=1 -slimit=1
> 	[Tue Dec  8 13:18:56 2020] BTRFS debug (device dm-0): cleaner removing 2383
> 	[Tue Dec  8 13:18:57 2020] BTRFS info (device dm-0): relocating block group 3262427168768 flags metadata|raid1
> 	[Tue Dec  8 13:19:51 2020] BTRFS debug (device dm-0): cleaner removing 2384
> 	[Tue Dec  8 13:22:21 2020] avg_delayed_ref_runtime = 3894835, time = 750151098700, count = 192601
> 	[Tue Dec  8 13:22:32 2020] ==================================================================
> 	[Tue Dec  8 13:22:32 2020] BUG: KASAN: use-after-free in btrfs_backref_cleanup_node+0x18a/0x420
> 	[Tue Dec  8 13:22:32 2020] Read of size 8 at addr ffff888112402950 by task btrfs/28836
> 
> 	[Tue Dec  8 13:22:32 2020] CPU: 0 PID: 28836 Comm: btrfs Tainted: G        W         5.10.0-e35f27394290-for-next+ #23
> 	[Tue Dec  8 13:22:32 2020] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
> 	[Tue Dec  8 13:22:32 2020] Call Trace:
> 	[Tue Dec  8 13:22:32 2020]  dump_stack+0xbc/0xf9
> 	[Tue Dec  8 13:22:32 2020]  ? btrfs_backref_cleanup_node+0x18a/0x420
> 	[Tue Dec  8 13:22:32 2020]  print_address_description.constprop.8+0x21/0x210
> 	[Tue Dec  8 13:22:32 2020]  ? record_print_text.cold.34+0x11/0x11
> 	[Tue Dec  8 13:22:32 2020]  ? btrfs_backref_cleanup_node+0x18a/0x420
> 	[Tue Dec  8 13:22:32 2020]  ? btrfs_backref_cleanup_node+0x18a/0x420
> 	[Tue Dec  8 13:22:32 2020]  kasan_report.cold.10+0x20/0x37
> 	[Tue Dec  8 13:22:32 2020]  ? btrfs_backref_cleanup_node+0x18a/0x420
> 	[Tue Dec  8 13:22:32 2020]  __asan_load8+0x69/0x90
> 	[Tue Dec  8 13:22:32 2020]  btrfs_backref_cleanup_node+0x18a/0x420
> 	[Tue Dec  8 13:22:32 2020]  btrfs_backref_release_cache+0x83/0x1b0
> 	[Tue Dec  8 13:22:32 2020]  relocate_block_group+0x394/0x780
> 	[Tue Dec  8 13:22:32 2020]  ? merge_reloc_roots+0x4a0/0x4a0
> 	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_block_group+0x26e/0x4c0
> 	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_chunk+0x52/0x120
> 	[Tue Dec  8 13:22:32 2020]  btrfs_balance+0xe2e/0x1900
> 	[Tue Dec  8 13:22:32 2020]  ? check_flags.part.50+0x6c/0x1e0
> 	[Tue Dec  8 13:22:32 2020]  ? btrfs_relocate_chunk+0x120/0x120
> 	[Tue Dec  8 13:22:32 2020]  ? kmem_cache_alloc_trace+0xa06/0xcb0
> 	[Tue Dec  8 13:22:32 2020]  ? _copy_from_user+0x83/0xc0
> 	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl_balance+0x3a7/0x460
> 	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl+0x24c8/0x4360
> 	[Tue Dec  8 13:22:32 2020]  ? __kasan_check_read+0x11/0x20
> 	[Tue Dec  8 13:22:32 2020]  ? check_chain_key+0x1f4/0x2f0
> 	[Tue Dec  8 13:22:32 2020]  ? __asan_loadN+0xf/0x20
> 	[Tue Dec  8 13:22:32 2020]  ? btrfs_ioctl_get_supported_features+0x30/0x30
> 	[Tue Dec  8 13:22:32 2020]  ? kvm_sched_clock_read+0x18/0x30
> 	[Tue Dec  8 13:22:32 2020]  ? check_chain_key+0x1f4/0x2f0
> 	[Tue Dec  8 13:22:32 2020]  ? lock_downgrade+0x3f0/0x3f0
> 	[Tue Dec  8 13:22:32 2020]  ? handle_mm_fault+0xad6/0x2150
> 	[Tue Dec  8 13:22:32 2020]  ? do_vfs_ioctl+0xfc/0x9d0
> 	[Tue Dec  8 13:22:32 2020]  ? ioctl_file_clone+0xe0/0xe0
> 	[Tue Dec  8 13:22:32 2020]  ? check_flags.part.50+0x6c/0x1e0
> 	[Tue Dec  8 13:22:32 2020]  ? check_flags.part.50+0x6c/0x1e0
> 	[Tue Dec  8 13:22:32 2020]  ? check_flags+0x26/0x30
> 	[Tue Dec  8 13:22:32 2020]  ? lock_is_held_type+0xc3/0xf0
> 	[Tue Dec  8 13:22:32 2020]  ? syscall_enter_from_user_mode+0x1b/0x60
> 	[Tue Dec  8 13:22:32 2020]  ? do_syscall_64+0x13/0x80
> 	[Tue Dec  8 13:22:32 2020]  ? rcu_read_lock_sched_held+0xa1/0xd0
> 	[Tue Dec  8 13:22:32 2020]  ? __kasan_check_read+0x11/0x20
> 	[Tue Dec  8 13:22:32 2020]  ? __fget_light+0xae/0x110
> 	[Tue Dec  8 13:22:32 2020]  __x64_sys_ioctl+0xc3/0x100
> 	[Tue Dec  8 13:22:32 2020]  do_syscall_64+0x37/0x80
> 	[Tue Dec  8 13:22:32 2020]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> 	[Tue Dec  8 13:22:32 2020] RIP: 0033:0x7f4c4bdfe427
> 	[Tue Dec  8 13:22:32 2020] Code: 00 00 90 48 8b 05 69 aa 0c 00 64 c7 00 26 00 00 00 48 c7 c0 ff ff ff ff c3 66 2e 0f 1f 84 00 00 00 00 00 b8 10 00 00 00 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 8b 0d 39 aa 0c 00 f7 d8 64 89 01 48
> 	[Tue Dec  8 13:22:32 2020] RSP: 002b:00007fff33ee6df8 EFLAGS: 00000202 ORIG_RAX: 0000000000000010
> 	[Tue Dec  8 13:22:32 2020] RAX: ffffffffffffffda RBX: 00007fff33ee6e98 RCX: 00007f4c4bdfe427
> 	[Tue Dec  8 13:22:32 2020] RDX: 00007fff33ee6e98 RSI: 00000000c4009420 RDI: 0000000000000003
> 	[Tue Dec  8 13:22:32 2020] RBP: 0000000000000003 R08: 0000000000000003 R09: 0000000000000078
> 	[Tue Dec  8 13:22:32 2020] R10: fffffffffffff59d R11: 0000000000000202 R12: 0000000000000001
> 	[Tue Dec  8 13:22:32 2020] R13: 0000000000000000 R14: 00007fff33ee8a34 R15: 0000000000000001
> 
> 	[Tue Dec  8 13:22:32 2020] Allocated by task 28836:
> 	[Tue Dec  8 13:22:32 2020]  kasan_save_stack+0x21/0x50
> 	[Tue Dec  8 13:22:32 2020]  __kasan_kmalloc.constprop.18+0xbe/0xd0
> 	[Tue Dec  8 13:22:32 2020]  kasan_kmalloc+0x9/0x10
> 	[Tue Dec  8 13:22:32 2020]  kmem_cache_alloc_trace+0x410/0xcb0
> 	[Tue Dec  8 13:22:32 2020]  btrfs_backref_alloc_node+0x46/0xf0
> 	[Tue Dec  8 13:22:32 2020]  btrfs_backref_add_tree_node+0x60d/0x11d0
> 	[Tue Dec  8 13:22:32 2020]  build_backref_tree+0xc5/0x700
> 	[Tue Dec  8 13:22:32 2020]  relocate_tree_blocks+0x2be/0xb90
> 	[Tue Dec  8 13:22:32 2020]  relocate_block_group+0x2eb/0x780
> 	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_block_group+0x26e/0x4c0
> 	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_chunk+0x52/0x120
> 	[Tue Dec  8 13:22:32 2020]  btrfs_balance+0xe2e/0x1900
> 	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl_balance+0x3a7/0x460
> 	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl+0x24c8/0x4360
> 	[Tue Dec  8 13:22:32 2020]  __x64_sys_ioctl+0xc3/0x100
> 	[Tue Dec  8 13:22:32 2020]  do_syscall_64+0x37/0x80
> 	[Tue Dec  8 13:22:32 2020]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> 
> 	[Tue Dec  8 13:22:32 2020] Freed by task 28836:
> 	[Tue Dec  8 13:22:32 2020]  kasan_save_stack+0x21/0x50
> 	[Tue Dec  8 13:22:32 2020]  kasan_set_track+0x20/0x30
> 	[Tue Dec  8 13:22:32 2020]  kasan_set_free_info+0x1f/0x30
> 	[Tue Dec  8 13:22:32 2020]  __kasan_slab_free+0xf3/0x140
> 	[Tue Dec  8 13:22:32 2020]  kasan_slab_free+0xe/0x10
> 	[Tue Dec  8 13:22:32 2020]  kfree+0xde/0x200
> 	[Tue Dec  8 13:22:32 2020]  btrfs_backref_error_cleanup+0x452/0x530
> 	[Tue Dec  8 13:22:32 2020]  build_backref_tree+0x1a5/0x700
> 	[Tue Dec  8 13:22:32 2020]  relocate_tree_blocks+0x2be/0xb90
> 	[Tue Dec  8 13:22:32 2020]  relocate_block_group+0x2eb/0x780
> 	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_block_group+0x26e/0x4c0
> 	[Tue Dec  8 13:22:32 2020]  btrfs_relocate_chunk+0x52/0x120
> 	[Tue Dec  8 13:22:32 2020]  btrfs_balance+0xe2e/0x1900
> 	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl_balance+0x3a7/0x460
> 	[Tue Dec  8 13:22:32 2020]  btrfs_ioctl+0x24c8/0x4360
> 	[Tue Dec  8 13:22:32 2020]  __x64_sys_ioctl+0xc3/0x100
> 	[Tue Dec  8 13:22:32 2020]  do_syscall_64+0x37/0x80
> 	[Tue Dec  8 13:22:32 2020]  entry_SYSCALL_64_after_hwframe+0x44/0xa9
> 
> 	[Tue Dec  8 13:22:32 2020] The buggy address belongs to the object at ffff888112402900
> 				    which belongs to the cache kmalloc-128 of size 128
> 	[Tue Dec  8 13:22:32 2020] The buggy address is located 80 bytes inside of
> 				    128-byte region [ffff888112402900, ffff888112402980)
> 	[Tue Dec  8 13:22:32 2020] The buggy address belongs to the page:
> 	[Tue Dec  8 13:22:32 2020] page:0000000028b1cd08 refcount:1 mapcount:0 mapping:0000000000000000 index:0xffff888131c810c0 pfn:0x112402
> 	[Tue Dec  8 13:22:32 2020] flags: 0x17ffe0000000200(slab)
> 	[Tue Dec  8 13:22:32 2020] raw: 017ffe0000000200 ffffea000424f308 ffffea0007d572c8 ffff888100040440
> 	[Tue Dec  8 13:22:32 2020] raw: ffff888131c810c0 ffff888112402000 0000000100000009 0000000000000000
> 	[Tue Dec  8 13:22:32 2020] page dumped because: kasan: bad access detected
> 
> 	[Tue Dec  8 13:22:32 2020] Memory state around the buggy address:
> 	[Tue Dec  8 13:22:32 2020]  ffff888112402800: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> 	[Tue Dec  8 13:22:32 2020]  ffff888112402880: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> 	[Tue Dec  8 13:22:32 2020] >ffff888112402900: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> 	[Tue Dec  8 13:22:33 2020]                                                  ^
> 	[Tue Dec  8 13:22:33 2020]  ffff888112402980: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
> 	[Tue Dec  8 13:22:33 2020]  ffff888112402a00: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
> 	[Tue Dec  8 13:22:33 2020] ==================================================================
> 	[Tue Dec  8 13:22:33 2020] Disabling lock debugging due to kernel taint

Same test filesystem has been stuck since Wed Dec 9.  I thought it was
just deleting snapshots slowly, but the subvols all gone now except for
one, and the filesystem has been full the whole time.  That might
explain the lack of KASANs...

5.9.14 is spitting this out every few seconds:

	[Sun Dec 13 16:46:30 2020] BTRFS error (device dm-0): Missing references.
	[Sun Dec 13 16:46:35 2020] BTRFS debug (device dm-0): cleaner removing 257
	[Sun Dec 13 16:46:35 2020] ------------[ cut here ]------------
	[Sun Dec 13 16:46:35 2020] WARNING: CPU: 2 PID: 4710 at fs/btrfs/extent-tree.c:265 btrfs_lookup_extent_info+0x596/0x5c0
	[Sun Dec 13 16:46:35 2020] Modules linked in:
	[Sun Dec 13 16:46:36 2020] CPU: 2 PID: 4710 Comm: btrfs-cleaner Tainted: G        W         5.9.14-7a5a46b56104+ #4
	[Sun Dec 13 16:46:36 2020] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.12.0-1 04/01/2014
	[Sun Dec 13 16:46:36 2020] RIP: 0010:btrfs_lookup_extent_info+0x596/0x5c0
	[Sun Dec 13 16:46:36 2020] Code: 48 89 85 50 ff ff ff e9 64 fb ff ff 48 8d 78 6a e8 cf 89 c9 ff 41 80 4e 6a 14 e9 6b fb ff ff 4d 85 ed 0f 85 ed fe ff ff 0f 0b <0f> 0b e9 21 ff ff ff b8 f4 ff ff ff e9 6e ff ff ff e8 e4 47 1a 01
	[Sun Dec 13 16:46:36 2020] RSP: 0018:ffffc900019a7920 EFLAGS: 00010246
	[Sun Dec 13 16:46:36 2020] RAX: 0000000000000001 RBX: ffff888093aed000 RCX: ffffffff981e0ecc
	[Sun Dec 13 16:46:36 2020] RDX: 0000000000000003 RSI: dffffc0000000000 RDI: ffff888093aed398
	[Sun Dec 13 16:46:36 2020] RBP: ffffc900019a7a00 R08: ffffed101275da74 R09: ffffed101275da74
	[Sun Dec 13 16:46:36 2020] R10: ffff888093aed39b R11: ffffed101275da73 R12: 0000000000000000
	[Sun Dec 13 16:46:36 2020] R13: 0000000000000000 R14: ffff888092276a50 R15: ffff888095be4930
	[Sun Dec 13 16:46:36 2020] FS:  0000000000000000(0000) GS:ffff8881f5a00000(0000) knlGS:0000000000000000
	[Sun Dec 13 16:46:36 2020] CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
	[Sun Dec 13 16:46:36 2020] CR2: 000055fd7c9109a8 CR3: 00000001f2084004 CR4: 0000000000170ee0
	[Sun Dec 13 16:46:36 2020] Call Trace:
	[Sun Dec 13 16:46:36 2020]  ? btrfs_lookup_data_extent+0x100/0x100
	[Sun Dec 13 16:46:36 2020]  ? _raw_write_unlock+0x22/0x30
	[Sun Dec 13 16:46:36 2020]  do_walk_down+0x2b0/0xc70
	[Sun Dec 13 16:46:36 2020]  ? walk_up_tree+0x310/0x310
	[Sun Dec 13 16:46:36 2020]  ? check_flags+0x26/0x30
	[Sun Dec 13 16:46:36 2020]  ? lock_is_held_type+0xc3/0xf0
	[Sun Dec 13 16:46:36 2020]  ? rcu_read_lock_sched_held+0xa1/0xd0
	[Sun Dec 13 16:46:36 2020]  ? rcu_read_lock_bh_held+0xb0/0xb0
	[Sun Dec 13 16:46:36 2020]  ? walk_down_proc+0x409/0x470
	[Sun Dec 13 16:46:36 2020]  walk_down_tree+0x1b4/0x220
	[Sun Dec 13 16:46:36 2020]  ? do_walk_down+0xc70/0xc70
	[Sun Dec 13 16:46:36 2020]  btrfs_drop_snapshot+0x441/0xd00
	[Sun Dec 13 16:46:36 2020]  ? btrfs_alloc_tree_block+0x520/0x520
	[Sun Dec 13 16:46:36 2020]  ? btrfs_clean_one_deleted_snapshot+0x1ef/0x210
	[Sun Dec 13 16:46:36 2020]  btrfs_clean_one_deleted_snapshot+0x197/0x210
	[Sun Dec 13 16:46:36 2020]  cleaner_kthread+0x2b5/0x330
	[Sun Dec 13 16:46:36 2020]  ? btree_submit_bio_start+0x20/0x20
	[Sun Dec 13 16:46:36 2020]  ? __kasan_check_read+0x11/0x20
	[Sun Dec 13 16:46:36 2020]  ? __kthread_parkme+0xd4/0xf0
	[Sun Dec 13 16:46:36 2020]  ? btree_submit_bio_start+0x20/0x20
	[Sun Dec 13 16:46:36 2020]  kthread+0x20c/0x230
	[Sun Dec 13 16:46:36 2020]  ? kthread_create_worker_on_cpu+0xc0/0xc0
	[Sun Dec 13 16:46:36 2020]  ret_from_fork+0x22/0x30
	[Sun Dec 13 16:46:36 2020] irq event stamp: 160085
	[Sun Dec 13 16:46:36 2020] hardirqs last  enabled at (160095): [<ffffffff981f0f22>] console_unlock+0x642/0x710
	[Sun Dec 13 16:46:36 2020] hardirqs last disabled at (160104): [<ffffffff981f0e0e>] console_unlock+0x52e/0x710
	[Sun Dec 13 16:46:36 2020] softirqs last  enabled at (159694): [<ffffffff99e0047f>] __do_softirq+0x47f/0x5d7
	[Sun Dec 13 16:46:36 2020] softirqs last disabled at (159607): [<ffffffff99c01102>] asm_call_irq_on_stack+0x12/0x20
	[Sun Dec 13 16:46:36 2020] ---[ end trace d1213a58ac962aed ]---

	+ btrfs fi usage .
	Overall:
	    Device size:                   2.00TiB
	    Device allocated:              2.00TiB
	    Device unallocated:            2.00MiB
	    Device missing:                  0.00B
	    Used:                          2.00TiB
	    Free (estimated):            516.00KiB      (min: 516.00KiB)
	    Data ratio:                       1.00
	    Metadata ratio:                   2.00
	    Global reserve:              512.00MiB      (used: 0.00B)
	    Multiple profiles:                  no

	Data,single: Size:1.94TiB, Used:1.94TiB (100.00%)
	   /dev/mapper/vgtester-tvdb    991.97GiB
	   /dev/mapper/vgtester-tvdc    991.97GiB

	Metadata,RAID1: Size:32.00GiB, Used:31.53GiB (98.53%)
	   /dev/mapper/vgtester-tvdb     32.00GiB
	   /dev/mapper/vgtester-tvdc     32.00GiB

	System,RAID1: Size:32.00MiB, Used:240.00KiB (0.73%)
	   /dev/mapper/vgtester-tvdb     32.00MiB
	   /dev/mapper/vgtester-tvdc     32.00MiB

	Unallocated:
	   /dev/mapper/vgtester-tvdb      1.00MiB
	   /dev/mapper/vgtester-tvdc      1.00MiB
	+ df .
	Filesystem                  1K-blocks       Used Available Use% Mounted on
	/dev/mapper/vgtester-tvdb 2147483648 2146952732       516 100% /media/testfs
	+ btrfs sub list -d .
	ID 257 gen 140782 top level 0 path DELETED

The filesystem is now empty except for the deleted subvol, but below
reserved limits.  Resizing the test devices larger doesn't help (it
does allow more data to be written to the FS, but doesn't help the
subvol get deleted).

> > v4->v5:
> > - Dropped "btrfs: fix error handling in commit_fs_roots" as it was merged.
> > - Fixed an ASSERT() that happened during relocation recovery that Zygo reported,
> >   I moved the error condition out of another condition which broke recovery if
> >   we had deleted subvols pending with relocation.
> > 
> > v3->v4:
> > - Squashed the __add_reloc_root error handling patches in
> >   btrfs_recover_relocation as they were small and in the same function.
> > - Squashed the record_root_in_trans failure handling patches for
> >   select_reloc_root as they were small and in the same function.
> > - Added a new patch to address an existing error handling problem with subvol
> >   creation.
> > - Fixed up the various cases that Qu noticed where I got things wrong, cleaning
> >   up a leaked root extent ref, a leaked inode item, and where I accidentally
> >   stopped dealing with errors from btrfs_drop_subtree.
> > - Reworked a bunch of the ASSERT()'s to do ASSERT(0) in their respective if
> >   statements.
> > - Added reviewed-bys.
> > 
> > v2->v3:
> > - A lot of extra patches fixing various things that I encountered while
> >   debugging the corruption problem that was uncovered by these patches.
> > - Fixed the panic that Zygo was seeing and other issues.
> > - Fixed up the comments from Nikolay and Filipe.
> > 
> > A slight note, the first set of patches could probably be taken now, and in fact
> > 
> >   btrfs: fix error handling in commit_fs_roots
> > 
> > Was sent earlier this week and is very important and needs to be reviewed and
> > merged ASAP.  The following are safe and could be merged outside of the rest of
> > this series
> > 
> >   btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
> >   btrfs: fix lockdep splat in btrfs_recover_relocation
> >   btrfs: keep track of the root owner for relocation reads
> >   btrfs: noinline btrfs_should_cancel_balance
> >   btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node
> >   btrfs: pass down the tree block level through ref-verify
> >   btrfs: make sure owner is set in ref-verify
> >   btrfs: don't clear ret in btrfs_start_dirty_block_groups
> > 
> > The rest obviously are all around the actual error handling.
> > 
> > v1->v2:
> > - fixed a bug where I accidentally dropped reading flags in relocate_block_group
> >   when I dropped the extra checks that we handle in the tree checker.
> > 
> > --- Original message ---
> > Hello,
> > 
> > Relocation is the last place that is not able to handle errors at all, which
> > results in all sorts of lovely panics if you encounter corruptions or IO errors.
> > I'm going to start cleaning up relocation, but before I move code around I want
> > the error handling to be somewhat sane, so I'm not changing behavior and error
> > handling at the same time.
> > 
> > These patches are purely about error handling, there is no behavior changing
> > other than returning errors up the chain properly.  There is a lot of room for
> > follow up cleanups, which will happen next.  However I wanted to get this series
> > done today and out so we could get it merged ASAP, and then the follow up
> > cleanups can happen later as they are less important and less critical.
> > 
> > The only exception to the above is the patch to add the error injection sites
> > for btrfs_cow_block and btrfs_search_slot, and a lockdep fix that I discovered
> > while running my tests, those are the first two patches in the series.
> > 
> > I tested this with my error injection stress test, where I keep track of all
> > stack traces that have been tested and only inject errors when we have a new
> > stack trace, which means I should have covered all of the various error
> > conditions.  With this patchset I'm no longer panicing while stressing the error
> > conditions.  Thanks,
> > 
> > Josef
> > 
> > Josef Bacik (52):
> >   btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block
> >   btrfs: modify the new_root highest_objectid under a ref count
> >   btrfs: fix lockdep splat in btrfs_recover_relocation
> >   btrfs: keep track of the root owner for relocation reads
> >   btrfs: noinline btrfs_should_cancel_balance
> >   btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node
> >   btrfs: pass down the tree block level through ref-verify
> >   btrfs: make sure owner is set in ref-verify
> >   btrfs: don't clear ret in btrfs_start_dirty_block_groups
> >   btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation
> >   btrfs: convert BUG_ON()'s in relocate_tree_block
> >   btrfs: return an error from btrfs_record_root_in_trans
> >   btrfs: handle errors from select_reloc_root()
> >   btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors
> >   btrfs: check record_root_in_trans related failures in
> >     select_reloc_root
> >   btrfs: do proper error handling in record_reloc_root_in_trans
> >   btrfs: handle btrfs_record_root_in_trans failure in
> >     btrfs_rename_exchange
> >   btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename
> >   btrfs: handle btrfs_record_root_in_trans failure in
> >     btrfs_delete_subvolume
> >   btrfs: handle btrfs_record_root_in_trans failure in
> >     btrfs_recover_log_trees
> >   btrfs: handle btrfs_record_root_in_trans failure in create_subvol
> >   btrfs: btrfs: handle btrfs_record_root_in_trans failure in
> >     relocate_tree_block
> >   btrfs: handle btrfs_record_root_in_trans failure in start_transaction
> >   btrfs: handle record_root_in_trans failure in qgroup_account_snapshot
> >   btrfs: handle record_root_in_trans failure in
> >     btrfs_record_root_in_trans
> >   btrfs: handle record_root_in_trans failure in create_pending_snapshot
> >   btrfs: do not panic in __add_reloc_root
> >   btrfs: have proper error handling in btrfs_init_reloc_root
> >   btrfs: do proper error handling in create_reloc_root
> >   btrfs: validate ->reloc_root after recording root in trans
> >   btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots
> >   btrfs: change insert_dirty_subvol to return errors
> >   btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol
> >   btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge
> >   btrfs: do proper error handling in btrfs_update_reloc_root
> >   btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s
> >   btrfs: handle btrfs_cow_block errors in replace_path
> >   btrfs: handle btrfs_search_slot failure in replace_path
> >   btrfs: handle errors in reference count manipulation in replace_path
> >   btrfs: handle extent reference errors in do_relocation
> >   btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly
> >   btrfs: remove the extent item sanity checks in relocate_block_group
> >   btrfs: do proper error handling in create_reloc_inode
> >   btrfs: handle __add_reloc_root failures in btrfs_recover_relocation
> >   btrfs: cleanup error handling in prepare_to_merge
> >   btrfs: handle extent corruption with select_one_root properly
> >   btrfs: do proper error handling in merge_reloc_roots
> >   btrfs: check return value of btrfs_commit_transaction in relocation
> >   btrfs: do not WARN_ON() if we can't find the reloc root
> >   btrfs: print the actual offset in btrfs_root_name
> >   btrfs: fix reloc root leak with 0 ref reloc roots on recovery
> >   btrfs: splice remaining dirty_bg's onto the transaction dirty bg list
> > 
> >  fs/btrfs/backref.c      |   9 +-
> >  fs/btrfs/block-group.c  |   6 +-
> >  fs/btrfs/ctree.c        |   2 +
> >  fs/btrfs/disk-io.c      |   2 +-
> >  fs/btrfs/inode.c        |  20 +-
> >  fs/btrfs/ioctl.c        |  17 +-
> >  fs/btrfs/print-tree.c   |  10 +-
> >  fs/btrfs/print-tree.h   |   2 +-
> >  fs/btrfs/ref-verify.c   |  43 ++--
> >  fs/btrfs/relocation.c   | 474 +++++++++++++++++++++++++++++++---------
> >  fs/btrfs/transaction.c  |  37 +++-
> >  fs/btrfs/tree-checker.c |   5 +
> >  fs/btrfs/tree-log.c     |   8 +-
> >  fs/btrfs/volumes.c      |   2 +
> >  14 files changed, 477 insertions(+), 160 deletions(-)
> > 
> > -- 
> > 2.26.2
> > 

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

end of thread, other threads:[~2020-12-13 22:27 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-08 16:23 [PATCH v6 00/52] Josef Bacik
2020-12-08 16:23 ` [PATCH v6 01/52] btrfs: allow error injection for btrfs_search_slot and btrfs_cow_block Josef Bacik
2020-12-08 16:23 ` [PATCH v6 02/52] btrfs: modify the new_root highest_objectid under a ref count Josef Bacik
2020-12-08 16:23 ` [PATCH v6 03/52] btrfs: fix lockdep splat in btrfs_recover_relocation Josef Bacik
2020-12-08 16:23 ` [PATCH v6 04/52] btrfs: keep track of the root owner for relocation reads Josef Bacik
2020-12-08 16:23 ` [PATCH v6 05/52] btrfs: noinline btrfs_should_cancel_balance Josef Bacik
2020-12-08 16:23 ` [PATCH v6 06/52] btrfs: do not cleanup upper nodes in btrfs_backref_cleanup_node Josef Bacik
2020-12-08 16:23 ` [PATCH v6 07/52] btrfs: pass down the tree block level through ref-verify Josef Bacik
2020-12-08 16:23 ` [PATCH v6 08/52] btrfs: make sure owner is set in ref-verify Josef Bacik
2020-12-08 16:23 ` [PATCH v6 09/52] btrfs: don't clear ret in btrfs_start_dirty_block_groups Josef Bacik
2020-12-08 16:23 ` [PATCH v6 10/52] btrfs: convert some BUG_ON()'s to ASSERT()'s in do_relocation Josef Bacik
2020-12-08 16:23 ` [PATCH v6 11/52] btrfs: convert BUG_ON()'s in relocate_tree_block Josef Bacik
2020-12-08 16:23 ` [PATCH v6 12/52] btrfs: return an error from btrfs_record_root_in_trans Josef Bacik
2020-12-08 16:23 ` [PATCH v6 13/52] btrfs: handle errors from select_reloc_root() Josef Bacik
2020-12-08 16:23 ` [PATCH v6 14/52] btrfs: convert BUG_ON()'s in select_reloc_root() to proper errors Josef Bacik
2020-12-08 16:23 ` [PATCH v6 15/52] btrfs: check record_root_in_trans related failures in select_reloc_root Josef Bacik
2020-12-08 16:23 ` [PATCH v6 16/52] btrfs: do proper error handling in record_reloc_root_in_trans Josef Bacik
2020-12-08 16:23 ` [PATCH v6 17/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename_exchange Josef Bacik
2020-12-08 16:23 ` [PATCH v6 18/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_rename Josef Bacik
2020-12-08 16:23 ` [PATCH v6 19/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_delete_subvolume Josef Bacik
2020-12-08 16:23 ` [PATCH v6 20/52] btrfs: handle btrfs_record_root_in_trans failure in btrfs_recover_log_trees Josef Bacik
2020-12-08 16:23 ` [PATCH v6 21/52] btrfs: handle btrfs_record_root_in_trans failure in create_subvol Josef Bacik
2020-12-08 16:23 ` [PATCH v6 22/52] btrfs: btrfs: handle btrfs_record_root_in_trans failure in relocate_tree_block Josef Bacik
2020-12-08 16:23 ` [PATCH v6 23/52] btrfs: handle btrfs_record_root_in_trans failure in start_transaction Josef Bacik
2020-12-08 16:23 ` [PATCH v6 24/52] btrfs: handle record_root_in_trans failure in qgroup_account_snapshot Josef Bacik
2020-12-08 16:23 ` [PATCH v6 25/52] btrfs: handle record_root_in_trans failure in btrfs_record_root_in_trans Josef Bacik
2020-12-08 16:23 ` [PATCH v6 26/52] btrfs: handle record_root_in_trans failure in create_pending_snapshot Josef Bacik
2020-12-08 16:23 ` [PATCH v6 27/52] btrfs: do not panic in __add_reloc_root Josef Bacik
2020-12-08 16:23 ` [PATCH v6 28/52] btrfs: have proper error handling in btrfs_init_reloc_root Josef Bacik
2020-12-08 16:23 ` [PATCH v6 29/52] btrfs: do proper error handling in create_reloc_root Josef Bacik
2020-12-08 16:23 ` [PATCH v6 30/52] btrfs: validate ->reloc_root after recording root in trans Josef Bacik
2020-12-08 16:23 ` [PATCH v6 31/52] btrfs: handle btrfs_update_reloc_root failure in commit_fs_roots Josef Bacik
2020-12-08 16:23 ` [PATCH v6 32/52] btrfs: change insert_dirty_subvol to return errors Josef Bacik
2020-12-08 16:23 ` [PATCH v6 33/52] btrfs: handle btrfs_update_reloc_root failure in insert_dirty_subvol Josef Bacik
2020-12-08 16:23 ` [PATCH v6 34/52] btrfs: handle btrfs_update_reloc_root failure in prepare_to_merge Josef Bacik
2020-12-08 16:23 ` [PATCH v6 35/52] btrfs: do proper error handling in btrfs_update_reloc_root Josef Bacik
2020-12-08 16:23 ` [PATCH v6 36/52] btrfs: convert logic BUG_ON()'s in replace_path to ASSERT()'s Josef Bacik
2020-12-08 16:23 ` [PATCH v6 37/52] btrfs: handle btrfs_cow_block errors in replace_path Josef Bacik
2020-12-08 16:23 ` [PATCH v6 38/52] btrfs: handle btrfs_search_slot failure " Josef Bacik
2020-12-08 16:23 ` [PATCH v6 39/52] btrfs: handle errors in reference count manipulation " Josef Bacik
2020-12-08 16:23 ` [PATCH v6 40/52] btrfs: handle extent reference errors in do_relocation Josef Bacik
2020-12-08 16:23 ` [PATCH v6 41/52] btrfs: check for BTRFS_BLOCK_FLAG_FULL_BACKREF being set improperly Josef Bacik
2020-12-08 16:23 ` [PATCH v6 42/52] btrfs: remove the extent item sanity checks in relocate_block_group Josef Bacik
2020-12-08 16:23 ` [PATCH v6 43/52] btrfs: do proper error handling in create_reloc_inode Josef Bacik
2020-12-08 16:23 ` [PATCH v6 44/52] btrfs: handle __add_reloc_root failures in btrfs_recover_relocation Josef Bacik
2020-12-08 16:23 ` [PATCH v6 45/52] btrfs: cleanup error handling in prepare_to_merge Josef Bacik
2020-12-08 16:23 ` [PATCH v6 46/52] btrfs: handle extent corruption with select_one_root properly Josef Bacik
2020-12-08 16:23 ` [PATCH v6 47/52] btrfs: do proper error handling in merge_reloc_roots Josef Bacik
2020-12-08 16:23 ` [PATCH v6 48/52] btrfs: check return value of btrfs_commit_transaction in relocation Josef Bacik
2020-12-08 16:23 ` [PATCH v6 49/52] btrfs: do not WARN_ON() if we can't find the reloc root Josef Bacik
2020-12-08 16:23 ` [PATCH v6 50/52] btrfs: print the actual offset in btrfs_root_name Josef Bacik
2020-12-08 16:23 ` [PATCH v6 51/52] btrfs: fix reloc root leak with 0 ref reloc roots on recovery Josef Bacik
2020-12-08 16:23 ` [PATCH v6 52/52] btrfs: splice remaining dirty_bg's onto the transaction dirty bg list Josef Bacik
2020-12-08 19:46 ` [PATCH v6 00/52] Zygo Blaxell
2020-12-13 22:26   ` Zygo Blaxell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.