From 39dfaa5af4b628eee55b4aa583abf72ef5833f32 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 2 Jan 2023 18:52:27 -0700 Subject: rebuildnodes/btrees: Enhance logging around failure to add a tree --- lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/forrest.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/btrfsprogs') diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/forrest.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/forrest.go index 6f0ac96..3ed27b6 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/forrest.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/forrest.go @@ -115,12 +115,13 @@ func (ts *RebuiltForrest) addTree(ctx context.Context, treeID btrfsprim.ObjID, s ts.trees.Store(treeID, nil) } }() - if slices.Contains(treeID, stack) { - return false - } stack = append(stack, treeID) ctx = dlog.WithField(ctx, "btrfsinspect.rebuild-nodes.rebuild.add-tree", stack) dlog.Info(ctx, "adding tree...") + if slices.Contains(treeID, stack[:len(stack)-1]) { + dlog.Errorf(ctx, "failed to add tree: loop detected: %v", stack) + return false + } tree := &RebuiltTree{ ID: treeID, @@ -140,10 +141,12 @@ func (ts *RebuiltForrest) addTree(ctx context.Context, treeID btrfsprim.ObjID, s root = ts.sb.BlockGroupRoot default: if !ts.addTree(ctx, btrfsprim.ROOT_TREE_OBJECTID, stack) { + dlog.Error(ctx, "failed to add tree: add ROOT_TREE") return false } rootOff, rootItem, ok := ts.cbLookupRoot(ctx, treeID) if !ok { + dlog.Error(ctx, "failed to add tree: lookup ROOT_ITEM") return false } root = rootItem.ByteNr @@ -155,9 +158,11 @@ func (ts *RebuiltForrest) addTree(ctx context.Context, treeID btrfsprim.ObjID, s } parentID, ok := ts.cbLookupUUID(ctx, rootItem.ParentUUID) if !ok { + dlog.Error(ctx, "failed to add tree: lookup UUID") return false } if !ts.addTree(ctx, parentID, stack) { + dlog.Error(ctx, "failed to add tree: add parent tree") return false } tree.Parent, _ = ts.trees.Load(parentID) -- cgit v1.2.3-54-g00ecf