diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-01 00:19:38 -0600 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2022-07-01 00:19:38 -0600 |
commit | 7d2d4ae383e02a03dec6aa60207e3a1dfa8e79a9 (patch) | |
tree | 5cbe78f32ae384eaae01352a6626bc83461677ff /cmd/btrfs-fsck/pass1.go | |
parent | aee0fa4cf09ef5af90e28441d673ce440e4c2c16 (diff) |
move dumb map and sort operations to util/generic.go
Also, the optimization of reversing the node list in pass1 isn't relevant
anymore now that I'm using rbtrees
Diffstat (limited to 'cmd/btrfs-fsck/pass1.go')
-rw-r--r-- | cmd/btrfs-fsck/pass1.go | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/cmd/btrfs-fsck/pass1.go b/cmd/btrfs-fsck/pass1.go index 2cb58bf..6812c73 100644 --- a/cmd/btrfs-fsck/pass1.go +++ b/cmd/btrfs-fsck/pass1.go @@ -125,16 +125,7 @@ func (found pass1ScanOneDevResult) AddToLV(fs *btrfs.FS, dev *btrfs.Device) { // nodes will be subsumed by other things.) // // Sort them so that progress numbers are predictable. - laddrs := make([]btrfsvol.LogicalAddr, 0, len(found.FoundNodes)) - for laddr := range found.FoundNodes { - laddrs = append(laddrs, laddr) - } - sort.Slice(laddrs, func(i, j int) bool { - // And sort them in reverse order to keep insertions - // fast. - return laddrs[i] > laddrs[j] - }) - for _, laddr := range laddrs { + for _, laddr := range util.SortedMapKeys(found.FoundNodes) { for _, paddr := range found.FoundNodes[laddr] { if err := fs.LV.AddMapping(btrfsvol.Mapping{ LAddr: laddr, @@ -164,15 +155,19 @@ func (found pass1ScanOneDevResult) AddToLV(fs *btrfs.FS, dev *btrfs.Device) { Size btrfsvol.AddrDelta Flags btrfsvol.BlockGroupFlags } - blockgroups := make(map[blockgroup]struct{}) + bgsSet := make(map[blockgroup]struct{}) for _, bg := range found.FoundBlockGroups { - blockgroups[blockgroup{ + bgsSet[blockgroup{ LAddr: btrfsvol.LogicalAddr(bg.Key.ObjectID), Size: btrfsvol.AddrDelta(bg.Key.Offset), Flags: bg.BG.Flags, }] = struct{}{} } - for bg := range blockgroups { + bgsOrdered := util.MapKeys(bgsSet) + sort.Slice(bgsOrdered, func(i, j int) bool { + return bgsOrdered[i].LAddr < bgsOrdered[j].LAddr + }) + for _, bg := range bgsOrdered { otherLAddr, otherPAddr := fs.LV.ResolveAny(bg.LAddr, bg.Size) if otherLAddr < 0 || otherPAddr.Addr < 0 { fmt.Printf("Pass 1: ... error: could not pair blockgroup laddr=%v (size=%v flags=%v) with a mapping\n", |