summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/rebuildnodes
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-08-29 19:38:28 -0600
committerLuke Shumaker <lukeshu@lukeshu.com>2022-08-30 21:29:15 -0600
commit709553bb19fcd5abf0a2839a18d2dd0c66554dd2 (patch)
tree4c6dc0cf2c0c66615c07808e3a93f537af31ed64 /lib/btrfsprogs/btrfsinspect/rebuildnodes
parentb6a7ab5f6c1fe993271242021c3ed4050733fdf2 (diff)
wip
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes')
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go2
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go2
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/uuidmap.go36
3 files changed, 22 insertions, 18 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go
index 5afa783..7ccccea 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuildnodes.go
@@ -27,7 +27,7 @@ import (
)
func RebuildNodes(ctx context.Context, fs *btrfs.FS, nodeScanResults btrfsinspect.ScanDevicesResult) (map[btrfsvol.LogicalAddr]*RebuiltNode, error) {
- uuidMap, err := buildTreeUUIDMap(ctx, fs, nodeScanResults)
+ uuidMap, err := buildUUIDMap(ctx, fs, nodeScanResults)
if err != nil {
return nil, err
}
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go
index 37db791..d2f0798 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuilttrees.go
@@ -17,7 +17,7 @@ import (
type RebuiltTrees struct {
inner *btrfs.FS
- uuidMap treeUUIDMap
+ uuidMap uuidMap
nodes map[btrfsvol.LogicalAddr]*RebuiltNode
}
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/uuidmap.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/uuidmap.go
index 95bb3b1..606f8f9 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/uuidmap.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/uuidmap.go
@@ -21,7 +21,7 @@ import (
"git.lukeshu.com/btrfs-progs-ng/lib/maps"
)
-type treeUUIDMap struct {
+type uuidMap struct {
ObjID2UUID map[btrfsprim.ObjID]btrfsprim.UUID
UUID2ObjID map[btrfsprim.UUID]btrfsprim.ObjID
TreeParent map[btrfsprim.ObjID]btrfsprim.UUID
@@ -35,12 +35,12 @@ func maybeSet[K, V comparable](name string, m map[K]V, k K, v V) error {
return nil
}
-func buildTreeUUIDMap(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.ScanDevicesResult) (treeUUIDMap, error) {
- dlog.Infof(ctx, "Building table of tree ObjID←→UUID...")
+func buildUUIDMap(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.ScanDevicesResult) (uuidMap, error) {
+ dlog.Infof(ctx, "Building table of ObjID←→UUID...")
sb, err := fs.Superblock()
if err != nil {
- return treeUUIDMap{}, nil
+ return uuidMap{}, nil
}
lastPct := -1
@@ -55,12 +55,12 @@ func buildTreeUUIDMap(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspec
}
}
- ret := treeUUIDMap{
+ ret := uuidMap{
ObjID2UUID: make(map[btrfsprim.ObjID]btrfsprim.UUID),
UUID2ObjID: make(map[btrfsprim.UUID]btrfsprim.ObjID),
TreeParent: make(map[btrfsprim.ObjID]btrfsprim.UUID),
}
- treeIDs := make(map[btrfsprim.ObjID]struct{})
+ seenTreeIDs := make(map[btrfsprim.ObjID]struct{})
progress()
for _, devResults := range scanResults {
@@ -69,35 +69,35 @@ func buildTreeUUIDMap(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspec
LAddr: containers.Optional[btrfsvol.LogicalAddr]{OK: true, Val: laddr},
})
if err != nil {
- return treeUUIDMap{}, nil
+ return uuidMap{}, nil
}
for _, item := range nodeRef.Data.BodyLeaf {
switch itemBody := item.Body.(type) {
case btrfsitem.Root:
if err := maybeSet("ObjID2UUID", ret.ObjID2UUID, item.Key.ObjectID, itemBody.UUID); err != nil {
- return treeUUIDMap{}, err
+ return uuidMap{}, err
}
if itemBody.UUID != (btrfsprim.UUID{}) {
if err := maybeSet("UUID2ObjID", ret.UUID2ObjID, itemBody.UUID, item.Key.ObjectID); err != nil {
- return treeUUIDMap{}, err
+ return uuidMap{}, err
}
}
if err := maybeSet("ParentUUID", ret.TreeParent, item.Key.ObjectID, itemBody.ParentUUID); err != nil {
- return treeUUIDMap{}, err
+ return uuidMap{}, err
}
case btrfsitem.UUIDMap:
var uuid btrfsprim.UUID
binary.BigEndian.PutUint64(uuid[:8], uint64(item.Key.ObjectID))
binary.BigEndian.PutUint64(uuid[8:], uint64(item.Key.Offset))
if err := maybeSet("ObjID2UUID", ret.ObjID2UUID, itemBody.ObjID, uuid); err != nil {
- return treeUUIDMap{}, err
+ return uuidMap{}, err
}
if err := maybeSet("UUID2ObjID", ret.UUID2ObjID, uuid, itemBody.ObjID); err != nil {
- return treeUUIDMap{}, err
+ return uuidMap{}, err
}
}
}
- treeIDs[nodeRef.Data.Head.Owner] = struct{}{}
+ seenTreeIDs[nodeRef.Data.Head.Owner] = struct{}{}
done++
progress()
}
@@ -105,15 +105,19 @@ func buildTreeUUIDMap(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspec
progress()
missing := make(map[btrfsprim.ObjID]struct{})
- for treeID := range treeIDs {
+ for treeID := range seenTreeIDs {
if _, ok := ret.ObjID2UUID[treeID]; !ok {
missing[treeID] = struct{}{}
+ continue
+ }
+ if _, ok := ret.TreeParent[treeID]; !ok && treeID >= btrfsprim.FIRST_FREE_OBJECTID && treeID <= btrfsprim.LAST_FREE_OBJECTID {
+ missing[treeID] = struct{}{}
}
}
if len(missing) > 0 {
- return treeUUIDMap{}, fmt.Errorf("could not find root items for trees %v", maps.SortedKeys(missing))
+ dlog.Errorf(ctx, "... could not find root items for trees %v", maps.SortedKeys(missing))
}
- dlog.Info(ctx, ".. done building table")
+ dlog.Info(ctx, "... done building table")
return ret, nil
}