summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/rebuildnodes/treeancestors.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/treeancestors.go')
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/treeancestors.go41
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/treeancestors.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/treeancestors.go
index c396a13..42228ae 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/treeancestors.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/treeancestors.go
@@ -4,6 +4,7 @@
package rebuildnodes
+/*
import (
"context"
@@ -33,3 +34,43 @@ func getTreeAncestors(ctx context.Context, scanData scanResult) map[btrfsprim.Ob
return treeAncestors
}
+
+func (m uuidMap) considerAncestors(ctx context.Context, treeAncestors map[btrfsprim.ObjID]containers.Set[btrfsprim.ObjID]) {
+ if missing := m.missingRootItems(); len(missing) == 0 {
+ return
+ } else {
+ dlog.Infof(ctx, "Rebuilding %d root items...", len(missing))
+ }
+
+ fa := newFullAncestorLister(m, treeAncestors)
+
+ for _, missingRoot := range maps.SortedKeys(m.missingRootItems()) {
+ if _, ok := m.TreeParent[missingRoot]; ok {
+ // This one is incomplete because it doesn't have a UUID, not
+ // because it doesn't have a parent.
+ continue
+ }
+ potentialParents := make(containers.Set[btrfsprim.ObjID])
+ potentialParents.InsertFrom(fa.GetFullAncestors(missingRoot))
+ for _, ancestor := range maps.SortedKeys(fa.GetFullAncestors(missingRoot)) {
+ potentialParents.DeleteFrom(fa.GetFullAncestors(ancestor))
+ }
+ if len(potentialParents) == 1 {
+ parent := potentialParents.TakeOne()
+ dlog.Infof(ctx, "... the parent of %v is %v", missingRoot, parent)
+ parentUUID, ok := m.ObjID2UUID[parent]
+ if !ok {
+ dlog.Errorf(ctx, "... but can't synthesize a root item because UUID of %v is unknown", parent)
+ continue
+ }
+ m.TreeParent[missingRoot] = parentUUID
+ }
+ }
+
+ if missing := m.missingRootItems(); len(missing) > 0 {
+ dlog.Errorf(ctx, "... could not rebuild root items for %d trees: %v", len(missing), maps.SortedKeys(missing))
+ } else {
+ dlog.Info(ctx, "... rebuilt all root items")
+ }
+}
+*/