diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-09 20:04:15 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-08-17 22:50:57 -0600 |
commit | 0a299e78d476aeedf64a424d1f0e0d959a15ba6b (patch) | |
tree | a2c6bd0590194f72669f0843a1e20510d364c84b | |
parent | 432fcca3deb80e7faa362e508604238ce295053d (diff) |
lib: feat: ScanOneDevice: Optimize a bit
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/scandevices.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/scandevices.go b/lib/btrfsprogs/btrfsinspect/scandevices.go index e28d35e..19774d3 100644 --- a/lib/btrfsprogs/btrfsinspect/scandevices.go +++ b/lib/btrfsprogs/btrfsinspect/scandevices.go @@ -13,11 +13,11 @@ import ( "github.com/datawire/dlib/dgroup" "github.com/datawire/dlib/dlog" + "git.lukeshu.com/btrfs-progs-ng/lib/binstruct" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsitem" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" "git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsutil" - "git.lukeshu.com/btrfs-progs-ng/lib/slices" ) type ScanDevicesResult map[btrfsvol.DeviceID]ScanOneDeviceResult @@ -77,6 +77,8 @@ func ScanOneDevice(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock) FoundNodes: make(map[btrfsvol.LogicalAddr][]btrfsvol.PhysicalAddr), } + sbSize := btrfsvol.PhysicalAddr(binstruct.StaticSize(btrfs.Superblock{})) + devSize := dev.Size() if sb.NodeSize < sb.SectorSize { return result, fmt.Errorf("node_size(%v) < sector_size(%v)", @@ -107,6 +109,7 @@ func ScanOneDevice(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock) } } + var minNextNode btrfsvol.PhysicalAddr for i := 0; i < numSums; i++ { if ctx.Err() != nil { return result, ctx.Err() @@ -120,7 +123,17 @@ func ScanOneDevice(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock) } copy(sums[i*csumSize:], sum[:csumSize]) - if !slices.Contains(pos, btrfs.SuperblockAddrs) { + checkForNode := pos >= minNextNode + if checkForNode { + for _, sbAddr := range btrfs.SuperblockAddrs { + if sbAddr <= pos && pos < sbAddr+sbSize { + checkForNode = false + break + } + } + } + + if checkForNode { nodeRef, err := btrfs.ReadNode[btrfsvol.PhysicalAddr](dev, sb, pos, nil) if err != nil { if !errors.Is(err, btrfs.ErrNotANode) { @@ -184,6 +197,7 @@ func ScanOneDevice(ctx context.Context, dev *btrfs.Device, sb btrfs.Superblock) }) } } + minNextNode = pos + btrfsvol.PhysicalAddr(sb.NodeSize) } } } |