diff options
3 files changed, 17 insertions, 24 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go index 3a6c35b..1d5ba14 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/btrees/rebuilt_btrees.go @@ -102,7 +102,7 @@ type RebuiltTrees struct { // static sb btrfstree.Superblock graph pkggraph.Graph - keyIO keyio.Handle + keyIO *keyio.Handle // static callbacks cbAddedItem func(ctx context.Context, tree btrfsprim.ObjID, key btrfsprim.Key) @@ -116,7 +116,7 @@ type RebuiltTrees struct { // NewRebuiltTrees returns a new RebuiltTrees instance. All of the // callbacks must be non-nil. func NewRebuiltTrees( - sb btrfstree.Superblock, graph pkggraph.Graph, keyIO keyio.Handle, + sb btrfstree.Superblock, graph pkggraph.Graph, keyIO *keyio.Handle, cbAddedItem func(ctx context.Context, tree btrfsprim.ObjID, key btrfsprim.Key), cbLookupRoot func(ctx context.Context, tree btrfsprim.ObjID) (offset btrfsprim.Generation, item btrfsitem.Root, ok bool), cbLookupUUID func(ctx context.Context, uuid btrfsprim.UUID) (id btrfsprim.ObjID, ok bool), diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go index 180edab..fecf5e6 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/rebuild.go @@ -34,7 +34,7 @@ type rebuilder struct { graph graph.Graph csums containers.RBTree[containers.NativeOrdered[btrfsvol.LogicalAddr], btrfsinspect.SysExtentCSum] - keyIO keyio.Handle + keyIO *keyio.Handle curKey keyio.KeyAndTree queue []keyio.KeyAndTree @@ -42,7 +42,7 @@ type rebuilder struct { } func RebuildNodes(ctx context.Context, fs *btrfs.FS, nodeScanResults btrfsinspect.ScanDevicesResult) (map[btrfsprim.ObjID]containers.Set[btrfsvol.LogicalAddr], error) { - scanData, err := ScanDevices(ctx, fs, nodeScanResults) // ScanDevices does its own logging + nodeGraph, keyIO, err := ScanDevices(ctx, fs, nodeScanResults) // ScanDevices does its own logging if err != nil { return nil, err } @@ -63,11 +63,11 @@ func RebuildNodes(ctx context.Context, fs *btrfs.FS, nodeScanResults btrfsinspec o := &rebuilder{ sb: *sb, - graph: *scanData.nodeGraph, + graph: nodeGraph, csums: *csums, - keyIO: *scanData.keyIO, + keyIO: keyIO, } - o.rebuilt = btrees.NewRebuiltTrees(*sb, *scanData.nodeGraph, *scanData.keyIO, + o.rebuilt = btrees.NewRebuiltTrees(*sb, nodeGraph, keyIO, o.cbAddedItem, o.cbLookupRoot, o.cbLookupUUID) if err := o.rebuild(ctx); err != nil { return nil, err diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go index 8c519fc..93d3e0c 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/scan.go @@ -21,11 +21,6 @@ import ( "git.lukeshu.com/btrfs-progs-ng/lib/textui" ) -type scanResult struct { - nodeGraph *graph.Graph - keyIO *keyio.Handle -} - type scanStats struct { N, D int } @@ -36,12 +31,12 @@ func (s scanStats) String() string { s.N, s.D) } -func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.ScanDevicesResult) (*scanResult, error) { +func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.ScanDevicesResult) (graph.Graph, *keyio.Handle, error) { dlog.Infof(ctx, "Reading node data from FS...") sb, err := fs.Superblock() if err != nil { - return nil, err + return graph.Graph{}, nil, err } total := countNodes(scanResults) @@ -51,10 +46,8 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.Sca progressWriter.Set(scanStats{N: done, D: total}) } - ret := &scanResult{ - nodeGraph: graph.New(*sb), - } - ret.keyIO = keyio.NewHandle(fs, *sb, ret.nodeGraph) + nodeGraph := graph.New(*sb) + keyIO := keyio.NewHandle(fs, *sb, nodeGraph) progress(done, total) for _, devResults := range scanResults { @@ -63,11 +56,11 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.Sca LAddr: containers.Optional[btrfsvol.LogicalAddr]{OK: true, Val: laddr}, }) if err != nil { - return nil, err + return graph.Graph{}, nil, err } - ret.nodeGraph.InsertNode(nodeRef) - ret.keyIO.InsertNode(nodeRef) + nodeGraph.InsertNode(nodeRef) + keyIO.InsertNode(nodeRef) done++ progress(done, total) @@ -81,11 +74,11 @@ func ScanDevices(ctx context.Context, fs *btrfs.FS, scanResults btrfsinspect.Sca progressWriter = textui.NewProgress[scanStats](ctx, dlog.LogLevelInfo, 1*time.Second) dlog.Infof(ctx, "Checking keypointers for dead-ends...") - if err := ret.nodeGraph.FinalCheck(fs, *sb, progress); err != nil { - return nil, err + if err := nodeGraph.FinalCheck(fs, *sb, progress); err != nil { + return graph.Graph{}, nil, err } progressWriter.Done() dlog.Info(ctx, "... done checking keypointers") - return ret, nil + return *nodeGraph, keyIO, nil } |