summaryrefslogtreecommitdiff
path: root/cmd/btrfs-rec/inspect/rebuildtrees/scan.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/btrfs-rec/inspect/rebuildtrees/scan.go')
-rw-r--r--cmd/btrfs-rec/inspect/rebuildtrees/scan.go40
1 files changed, 18 insertions, 22 deletions
diff --git a/cmd/btrfs-rec/inspect/rebuildtrees/scan.go b/cmd/btrfs-rec/inspect/rebuildtrees/scan.go
index 2995a2e..ba56c5b 100644
--- a/cmd/btrfs-rec/inspect/rebuildtrees/scan.go
+++ b/cmd/btrfs-rec/inspect/rebuildtrees/scan.go
@@ -10,17 +10,15 @@ import (
"github.com/datawire/dlib/dlog"
- "git.lukeshu.com/btrfs-progs-ng/cmd/btrfs-rec/inspect/rebuildmappings"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfstree"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfsutil"
"git.lukeshu.com/btrfs-progs-ng/lib/containers"
- "git.lukeshu.com/btrfs-progs-ng/lib/maps"
"git.lukeshu.com/btrfs-progs-ng/lib/textui"
)
-func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults rebuildmappings.ScanDevicesResult) (btrfstree.Superblock, btrfsutil.Graph, *btrfsutil.KeyIO, error) {
+func ScanDevices(ctx context.Context, fs *btrfs.FS, nodeList []btrfsvol.LogicalAddr) (btrfstree.Superblock, btrfsutil.Graph, *btrfsutil.KeyIO, error) {
dlog.Info(ctx, "Reading superblock...")
sb, err := fs.Superblock()
if err != nil {
@@ -30,7 +28,7 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults rebuildmappings.
dlog.Infof(ctx, "Reading node data from FS...")
var stats textui.Portion[int]
- stats.D = countNodes(scanResults)
+ stats.D = len(nodeList)
progressWriter := textui.NewProgress[textui.Portion[int]](
dlog.WithField(ctx, "btrfs.inspect.rebuild-trees.read.substep", "read-nodes"),
dlog.LogLevelInfo, textui.Tunable(1*time.Second))
@@ -39,27 +37,25 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults rebuildmappings.
keyIO := btrfsutil.NewKeyIO(fs, *sb)
progressWriter.Set(stats)
- for _, devResults := range scanResults {
- for _, laddr := range maps.SortedKeys(devResults.FoundNodes) {
- if err := ctx.Err(); err != nil {
- return btrfstree.Superblock{}, btrfsutil.Graph{}, nil, err
- }
- nodeRef, err := btrfstree.ReadNode[btrfsvol.LogicalAddr](fs, *sb, laddr, btrfstree.NodeExpectations{
- LAddr: containers.Optional[btrfsvol.LogicalAddr]{OK: true, Val: laddr},
- })
- if err != nil {
- btrfstree.FreeNodeRef(nodeRef)
- return btrfstree.Superblock{}, btrfsutil.Graph{}, nil, err
- }
+ for _, laddr := range nodeList {
+ if err := ctx.Err(); err != nil {
+ return btrfstree.Superblock{}, btrfsutil.Graph{}, nil, err
+ }
+ nodeRef, err := btrfstree.ReadNode[btrfsvol.LogicalAddr](fs, *sb, laddr, btrfstree.NodeExpectations{
+ LAddr: containers.Optional[btrfsvol.LogicalAddr]{OK: true, Val: laddr},
+ })
+ if err != nil {
+ btrfstree.FreeNodeRef(nodeRef)
+ return btrfstree.Superblock{}, btrfsutil.Graph{}, nil, err
+ }
- nodeGraph.InsertNode(nodeRef)
- keyIO.InsertNode(nodeRef)
+ nodeGraph.InsertNode(nodeRef)
+ keyIO.InsertNode(nodeRef)
- btrfstree.FreeNodeRef(nodeRef)
+ btrfstree.FreeNodeRef(nodeRef)
- stats.N++
- progressWriter.Set(stats)
- }
+ stats.N++
+ progressWriter.Set(stats)
}
if stats.N != stats.D {
panic("should not happen")