diff options
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes')
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildnodes/s1_uuidmap.go | 11 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildnodes/visualizenodes.go | 19 |
2 files changed, 17 insertions, 13 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s1_uuidmap.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s1_uuidmap.go index caccfb9..3ca195a 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/s1_uuidmap.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/s1_uuidmap.go @@ -81,11 +81,18 @@ func newFullAncestorLister(uuidMap uuidMap, treeAncestors map[btrfsprim.ObjID]co } func (fa fullAncestorLister) GetFullAncestors(child btrfsprim.ObjID) containers.Set[btrfsprim.ObjID] { - if memoized := fa.memos[child]; memoized != nil { + if memoized, ok := fa.memos[child]; ok { + if memoized == nil { + panic(fmt.Errorf("loop involving tree %v", child)) + } return memoized } + fa.memos[child] = nil + ret := make(containers.Set[btrfsprim.ObjID]) - fa.memos[child] = ret + defer func() { + fa.memos[child] = ret + }() // Try to use '.uuidMap' instead of '.treeAncestors' if possible. knownAncestors := make(containers.Set[btrfsprim.ObjID]) diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/visualizenodes.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/visualizenodes.go index 3096b46..3ab0881 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/visualizenodes.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/visualizenodes.go @@ -90,22 +90,12 @@ func VisualizeNodes(ctx context.Context, out io.Writer, fs *btrfs.FS, nodeScanRe // Node var treeID btrfsprim.ObjID - var cliqueID btrfsprim.ObjID var nodeStr string if err != nil && (errors.Is(err, btrfstree.ErrNotANode) || errors.As(err, new(*btrfstree.IOError))) { treeID = 0 - func() { - defer func() { - if r := recover(); r != nil { - panic(fmt.Errorf("path=%#v (%s): %v", path, path, r)) - } - }() - cliqueID = getCliqueID(cliques, path.Node(-1).FromTree) - }() nodeStr = fmt.Sprintf(`n%d [shape=star color=red label="%v"]`, addr, addr) } else { treeID = nodeRef.Data.Head.Owner - cliqueID = getCliqueID(cliques, treeID) var buf strings.Builder fmt.Fprintf(&buf, `n%d [shape=record label="%v\ngen=%v\nlvl=%v|{`, addr, @@ -157,6 +147,13 @@ func VisualizeNodes(ctx context.Context, out io.Writer, fs *btrfs.FS, nodeScanRe } else { edge.WriteString(`"]`) } + cliqueID := getCliqueID(cliques, path[0].FromTree) + if treeID != 0 && getCliqueID(cliques, treeID) != cliqueID { + panic(fmt.Errorf("tree %v is not in clique %v", treeID, maps.SortedKeys(*cliques[cliqueID]))) + } + if !cliques[cliqueID].Has(cliqueID) { + panic(fmt.Errorf("clique %v does not contain supposed-member %v", maps.SortedKeys(*cliques[cliqueID]), cliqueID)) + } if _, ok := edges[cliqueID]; !ok { edges[cliqueID] = make(containers.Set[string]) } @@ -211,7 +208,7 @@ func VisualizeNodes(ctx context.Context, out io.Writer, fs *btrfs.FS, nodeScanRe return err } - if _, err := fmt.Fprintf(buf, "digraph clique%d {\n", cliqueID); err != nil { + if _, err := fmt.Fprintf(buf, "strict digraph clique%d {\n", cliqueID); err != nil { return err } clique := cliques[cliqueID] |