diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-03 19:10:08 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-04 20:53:06 -0700 |
commit | d36dec9dc7019d67e0acf12c52607110cc0edc62 (patch) | |
tree | e21919661334322e998198964f72a406ba31ebda /lib | |
parent | 47f66c084291040fb11212956df9033bf263a892 (diff) |
Move sumrunwithgaps.go from btrfssum to rebuildmappings
Diffstat (limited to 'lib')
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildmappings/fuzzymatchsums.go | 2 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildmappings/logicalsums.go | 14 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildmappings/matchsums.go | 2 | ||||
-rw-r--r-- | lib/btrfsprogs/btrfsinspect/rebuildmappings/sumrunwithgaps.go (renamed from lib/btrfs/btrfssum/sumrunwithgaps.go) | 25 |
4 files changed, 22 insertions, 21 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildmappings/fuzzymatchsums.go b/lib/btrfsprogs/btrfsinspect/rebuildmappings/fuzzymatchsums.go index 9e6b864..b51526b 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildmappings/fuzzymatchsums.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildmappings/fuzzymatchsums.go @@ -41,7 +41,7 @@ func fuzzyMatchBlockGroupSums(ctx context.Context, fs *btrfs.FS, blockgroups map[btrfsvol.LogicalAddr]BlockGroup, physicalSums map[btrfsvol.DeviceID]btrfssum.SumRun[btrfsvol.PhysicalAddr], - logicalSums btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr], + logicalSums SumRunWithGaps[btrfsvol.LogicalAddr], ) error { _ctx := ctx diff --git a/lib/btrfsprogs/btrfsinspect/rebuildmappings/logicalsums.go b/lib/btrfsprogs/btrfsinspect/rebuildmappings/logicalsums.go index 537a970..69d14c7 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildmappings/logicalsums.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildmappings/logicalsums.go @@ -1,4 +1,4 @@ -// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com> +// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com> // // SPDX-License-Identifier: GPL-2.0-or-later @@ -20,7 +20,7 @@ import ( "git.lukeshu.com/btrfs-progs-ng/lib/slices" ) -func ExtractLogicalSums(ctx context.Context, scanResults btrfsinspect.ScanDevicesResult) btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr] { +func ExtractLogicalSums(ctx context.Context, scanResults btrfsinspect.ScanDevicesResult) SumRunWithGaps[btrfsvol.LogicalAddr] { var records []btrfsinspect.SysExtentCSum for _, devResults := range scanResults { records = append(records, devResults.FoundExtentCSums...) @@ -38,7 +38,7 @@ func ExtractLogicalSums(ctx context.Context, scanResults btrfsinspect.ScanDevice } }) if len(records) == 0 { - return btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr]{} + return SumRunWithGaps[btrfsvol.LogicalAddr]{} } sumSize := records[0].Sums.ChecksumSize @@ -149,7 +149,7 @@ func ExtractLogicalSums(ctx context.Context, scanResults btrfsinspect.ScanDevice } // Now flatten that RBTree in to a SumRunWithGaps. - var flattened btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr] + var flattened SumRunWithGaps[btrfsvol.LogicalAddr] var curAddr btrfsvol.LogicalAddr var curSums strings.Builder _ = addrspace.Walk(func(node *containers.RBNode[btrfsinspect.SysExtentCSum]) error { @@ -183,7 +183,7 @@ func ExtractLogicalSums(ctx context.Context, scanResults btrfsinspect.ScanDevice return flattened } -func ListUnmappedLogicalRegions(fs *btrfs.FS, logicalSums btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr]) []btrfssum.SumRun[btrfsvol.LogicalAddr] { +func ListUnmappedLogicalRegions(fs *btrfs.FS, logicalSums SumRunWithGaps[btrfsvol.LogicalAddr]) []btrfssum.SumRun[btrfsvol.LogicalAddr] { // There are a lot of ways this algorithm could be made // faster. var ret []btrfssum.SumRun[btrfsvol.LogicalAddr] @@ -226,8 +226,8 @@ func ListUnmappedLogicalRegions(fs *btrfs.FS, logicalSums btrfssum.SumRunWithGap return ret } -func SumsForLogicalRegion(sums btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr], beg btrfsvol.LogicalAddr, size btrfsvol.AddrDelta) btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr] { - runs := btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr]{ +func SumsForLogicalRegion(sums SumRunWithGaps[btrfsvol.LogicalAddr], beg btrfsvol.LogicalAddr, size btrfsvol.AddrDelta) SumRunWithGaps[btrfsvol.LogicalAddr] { + runs := SumRunWithGaps[btrfsvol.LogicalAddr]{ Addr: beg, Size: size, } diff --git a/lib/btrfsprogs/btrfsinspect/rebuildmappings/matchsums.go b/lib/btrfsprogs/btrfsinspect/rebuildmappings/matchsums.go index 02c657f..c38314a 100644 --- a/lib/btrfsprogs/btrfsinspect/rebuildmappings/matchsums.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildmappings/matchsums.go @@ -22,7 +22,7 @@ func matchBlockGroupSums(ctx context.Context, fs *btrfs.FS, blockgroups map[btrfsvol.LogicalAddr]BlockGroup, physicalSums map[btrfsvol.DeviceID]btrfssum.SumRun[btrfsvol.PhysicalAddr], - logicalSums btrfssum.SumRunWithGaps[btrfsvol.LogicalAddr], + logicalSums SumRunWithGaps[btrfsvol.LogicalAddr], ) error { regions := ListUnmappedPhysicalRegions(fs) numBlockgroups := len(blockgroups) diff --git a/lib/btrfs/btrfssum/sumrunwithgaps.go b/lib/btrfsprogs/btrfsinspect/rebuildmappings/sumrunwithgaps.go index 8362a49..8c1f3ed 100644 --- a/lib/btrfs/btrfssum/sumrunwithgaps.go +++ b/lib/btrfsprogs/btrfsinspect/rebuildmappings/sumrunwithgaps.go @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: GPL-2.0-or-later -package btrfssum +package rebuildmappings import ( "context" @@ -12,6 +12,7 @@ import ( "git.lukeshu.com/go/lowmemjson" + "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfssum" "git.lukeshu.com/btrfs-progs-ng/lib/btrfs/btrfsvol" "git.lukeshu.com/btrfs-progs-ng/lib/diskio" ) @@ -22,7 +23,7 @@ type SumRunWithGaps[Addr btrfsvol.IntAddr[Addr]] struct { Addr Addr Size btrfsvol.AddrDelta - Runs []SumRun[Addr] + Runs []btrfssum.SumRun[Addr] } var ( @@ -31,7 +32,7 @@ var ( ) func (sg SumRunWithGaps[Addr]) NumSums() int { - return int(sg.Size / BlockSize) + return int(sg.Size / btrfssum.BlockSize) } func (sg SumRunWithGaps[Addr]) PctFull() float64 { @@ -43,20 +44,20 @@ func (sg SumRunWithGaps[Addr]) PctFull() float64 { return float64(full) / float64(total) } -func (sg SumRunWithGaps[Addr]) RunForAddr(addr Addr) (SumRun[Addr], Addr, bool) { +func (sg SumRunWithGaps[Addr]) RunForAddr(addr Addr) (btrfssum.SumRun[Addr], Addr, bool) { for _, run := range sg.Runs { if run.Addr > addr { - return SumRun[Addr]{}, run.Addr, false + return btrfssum.SumRun[Addr]{}, run.Addr, false } if run.Addr.Add(run.Size()) <= addr { continue } return run, 0, true } - return SumRun[Addr]{}, math.MaxInt64, false + return btrfssum.SumRun[Addr]{}, math.MaxInt64, false } -func (sg SumRunWithGaps[Addr]) SumForAddr(addr Addr) (ShortSum, error) { +func (sg SumRunWithGaps[Addr]) SumForAddr(addr Addr) (btrfssum.ShortSum, error) { if addr < sg.Addr || addr >= sg.Addr.Add(sg.Size) { return "", io.EOF } @@ -67,13 +68,13 @@ func (sg SumRunWithGaps[Addr]) SumForAddr(addr Addr) (ShortSum, error) { if run.Addr.Add(run.Size()) <= addr { continue } - off := int((addr-run.Addr)/BlockSize) * run.ChecksumSize + off := int((addr-run.Addr)/btrfssum.BlockSize) * run.ChecksumSize return run.Sums[off : off+run.ChecksumSize], nil } return "", diskio.ErrWildcard } -func (sg SumRunWithGaps[Addr]) Walk(ctx context.Context, fn func(Addr, ShortSum) error) error { +func (sg SumRunWithGaps[Addr]) Walk(ctx context.Context, fn func(Addr, btrfssum.ShortSum) error) error { for _, run := range sg.Runs { if err := run.Walk(ctx, fn); err != nil { return err @@ -83,8 +84,8 @@ func (sg SumRunWithGaps[Addr]) Walk(ctx context.Context, fn func(Addr, ShortSum) } // Get implements diskio.Sequence[int, ShortSum] -func (sg SumRunWithGaps[Addr]) Get(sumIdx int64) (ShortSum, error) { - addr := sg.Addr.Add(btrfsvol.AddrDelta(sumIdx) * BlockSize) +func (sg SumRunWithGaps[Addr]) Get(sumIdx int64) (btrfssum.ShortSum, error) { + addr := sg.Addr.Add(btrfsvol.AddrDelta(sumIdx) * btrfssum.BlockSize) return sg.SumForAddr(addr) } @@ -144,7 +145,7 @@ func (sg *SumRunWithGaps[Addr]) DecodeJSON(r io.RuneScanner) error { return lowmemjson.NewDecoder(r).Decode(&sg.Size) case "Runs": return lowmemjson.DecodeArray(r, func(r io.RuneScanner) error { - var run SumRun[Addr] + var run btrfssum.SumRun[Addr] if err := lowmemjson.NewDecoder(r).Decode(&run); err != nil { return err } |