All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs: kill BUG_ON in do_relocation
@ 2016-09-14 16:27 Liu Bo
  2016-09-14 17:13 ` Josef Bacik
  2016-09-23 21:05 ` [PATCH v2] " Liu Bo
  0 siblings, 2 replies; 15+ messages in thread
From: Liu Bo @ 2016-09-14 16:27 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

While updating btree, we try to push items between sibling
nodes/leaves in order to keep height as low as possible.
But we don't memset the original places with zero when
pushing items so that we could end up leaving stale content
in nodes/leaves.  One may read the above stale content by
increasing btree blocks' @nritems.

One case I've come across is that in fs tree, a leaf has two
parent nodes, hence running balance ends up with processing
this leaf with two parent nodes, but it can only reach the
valid parent node through btrfs_search_slot, so it'd be like,

do_relocation
    for P in all parent nodes of block A:
        if !P->eb:
            btrfs_search_slot(key);   --> get path from P to A.
        if lowest:
            BUG_ON(A->bytenr != bytenr of A recorded in P);
        btrfs_cow_block(P, A);   --> change A's bytenr in P.

After btrfs_cow_block, P has the new bytenr of A, but with the
same @key, we get the same path again, and get panic by BUG_ON.

Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/relocation.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
index 680e234..bce8fea 100644
--- a/fs/btrfs/relocation.c
+++ b/fs/btrfs/relocation.c
@@ -2723,7 +2723,14 @@ static int do_relocation(struct btrfs_trans_handle *trans,
 
 		bytenr = btrfs_node_blockptr(upper->eb, slot);
 		if (lowest) {
-			BUG_ON(bytenr != node->bytenr);
+			if (bytenr != node->bytenr) {
+				btrfs_err(root->fs_info,
+		"lowest leaf/node mismatch: bytenr %llu node->bytenr %llu slot %d upper %llu",
+					  bytenr, node->bytenr, slot,
+					  upper->eb->start);
+				err = -EEXIST;
+				goto next;
+			}
 		} else {
 			if (node->eb->start == bytenr)
 				goto next;
-- 
2.5.5

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-

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

end of thread, other threads:[~2016-10-11 14:25 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-14 16:27 [PATCH] Btrfs: kill BUG_ON in do_relocation Liu Bo
2016-09-14 17:13 ` Josef Bacik
2016-09-14 17:29   ` Chris Mason
2016-09-14 17:31     ` Josef Bacik
2016-09-14 18:19       ` Liu Bo
2016-09-15 19:01         ` Liu Bo
2016-09-15 18:58           ` Chris Mason
2016-09-19 18:01             ` David Sterba
2016-09-19 23:11               ` Liu Bo
2016-09-20  8:03                 ` David Sterba
2016-09-20 17:59                   ` Liu Bo
2016-09-21  8:14                     ` David Sterba
2016-09-14 18:16   ` Liu Bo
2016-09-23 21:05 ` [PATCH v2] " Liu Bo
2016-10-11 14:25   ` David Sterba

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.