diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-02 03:30:54 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-17 22:50:57 -0600 |
commit | 432fcca3deb80e7faa362e508604238ce295053d (patch) | |
tree | 25be708d5c98fcd3d57bed0f1c78f38aeb56ebb4 | |
parent | 5afa6e03b8d6162b15e7edaa013e644f1931aaf9 (diff) |
lib: feat: Add ScanDevices
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildmappings/blockgroups.go | 6 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/scandevices.go | 28 |
2 files changed, 30 insertions, 4 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildmappings/blockgroups.go b/lib/btrfsprogs/btrfsinspect/rebuildmappings/blockgroups.go index 15df6da..2621c44 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildmappings/blockgroups.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildmappings/blockgroups.go @@ -16,8 +16,6 @@ import ( "git.lukeshu.com/btrfs-progs-ng/lib/maps" ) -type NodeScanResults = map[btrfsvol.DeviceID]btrfsinspect.ScanOneDeviceResult - type BlockGroup struct { LAddr btrfsvol.LogicalAddr Size btrfsvol.AddrDelta @@ -30,7 +28,7 @@ func ReadNodeScanResults(fs *btrfs.FS, filename string) (map[btrfsvol.LogicalAdd return nil, err } - var scanResults NodeScanResults + var scanResults btrfsinspect.ScanDevicesResult if err := json.Unmarshal(scanResultsBytes, &scanResults); err != nil { return nil, err } @@ -43,7 +41,7 @@ func ReadNodeScanResults(fs *btrfs.FS, filename string) (map[btrfsvol.LogicalAdd return bgTree, nil } -func ReduceScanResults(fs *btrfs.FS, scanResults NodeScanResults) (map[btrfsvol.LogicalAddr]BlockGroup, error) { +func ReduceScanResults(fs *btrfs.FS, scanResults btrfsinspect.ScanDevicesResult) (map[btrfsvol.LogicalAddr]BlockGroup, error) { // Reduce bgSet := make(map[BlockGroup]struct{}) for _, found := range scanResults { diff --git a/lib/btrfsprogs/btrfsinspect/scandevices.go b/lib/btrfsprogs/btrfsinspect/scandevices.go index c590d81..e28d35e 100644 --- a/lib/btrfsprogs/btrfsinspect/scandevices.go +++ b/lib/btrfsprogs/btrfsinspect/scandevices.go @@ -8,7 +8,9 @@ import ( "context" "errors" "fmt" + "sync" + "github.com/datawire/dlib/dgroup" "github.com/datawire/dlib/dlog" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs" @@ -18,6 +20,32 @@ import ( "git.lukeshu.com/btrfs-progs-ng/lib/slices" ) +type ScanDevicesResult map[btrfsvol.DeviceID]ScanOneDeviceResult + +func ScanDevices(ctx context.Context, fs *btrfs.FS, sb btrfs.Superblock) (ScanDevicesResult, error) { + grp := dgroup.NewGroup(ctx, dgroup.GroupConfig{}) + var mu sync.Mutex + result := make(map[btrfsvol.DeviceID]ScanOneDeviceResult) + for id, dev := range fs.LV.PhysicalVolumes() { + id := id + dev := dev + grp.Go(dev.Name(), func(ctx context.Context) error { + devResult, err := ScanOneDevice(ctx, dev, sb) + if err != nil { + return err + } + mu.Lock() + result[id] = devResult + mu.Unlock() + return nil + }) + } + if err := grp.Wait(); err != nil { + return nil, err + } + return result, nil +} + type ScanOneDeviceResult struct { Checksums SumRun[btrfsvol.PhysicalAddr] FoundNodes map[btrfsvol.LogicalAddr][]btrfsvol.PhysicalAddr |