summaryrefslogtreecommitdiff
path: root/lib/btrfs
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-05 10:03:08 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-05 21:01:58 -0700
commit0ff1d420f21101a92d8da888d491860cf0cf16cc (patch)
tree3e5715b4e4fd6619f2edddf5bab315cb9a125598 /lib/btrfs
parent53d7fbb73869eb5defa1ca5c52b26abd346b13b9 (diff)
containers: s/Cmp/Compare/ to match the standard library
Go 1.18 added net/netip.Addr.Compare, and Go 1.20 added time.Time.Compare.
Diffstat (limited to 'lib/btrfs')
-rw-r--r--lib/btrfs/btrfsprim/misc.go8
-rw-r--r--lib/btrfs/btrfsprim/uuid.go2
-rw-r--r--lib/btrfs/btrfstree/ops.go2
-rw-r--r--lib/btrfs/btrfstree/root.go2
-rw-r--r--lib/btrfs/btrfstree/types_node.go4
-rw-r--r--lib/btrfs/btrfsvol/addr.go4
-rw-r--r--lib/btrfs/btrfsvol/chunk.go8
-rw-r--r--lib/btrfs/btrfsvol/devext.go6
-rw-r--r--lib/btrfs/btrfsvol/lvm.go10
-rw-r--r--lib/btrfs/io4_fs.go2
10 files changed, 24 insertions, 24 deletions
diff --git a/lib/btrfs/btrfsprim/misc.go b/lib/btrfs/btrfsprim/misc.go
index 22939bf..da661f6 100644
--- a/lib/btrfs/btrfsprim/misc.go
+++ b/lib/btrfs/btrfsprim/misc.go
@@ -44,14 +44,14 @@ func (key Key) Mm() Key {
return key
}
-func (a Key) Cmp(b Key) int {
- if d := containers.NativeCmp(a.ObjectID, b.ObjectID); d != 0 {
+func (a Key) Compare(b Key) int {
+ if d := containers.NativeCompare(a.ObjectID, b.ObjectID); d != 0 {
return d
}
- if d := containers.NativeCmp(a.ItemType, b.ItemType); d != 0 {
+ if d := containers.NativeCompare(a.ItemType, b.ItemType); d != 0 {
return d
}
- return containers.NativeCmp(a.Offset, b.Offset)
+ return containers.NativeCompare(a.Offset, b.Offset)
}
var _ containers.Ordered[Key] = Key{}
diff --git a/lib/btrfs/btrfsprim/uuid.go b/lib/btrfs/btrfsprim/uuid.go
index 0103ee4..232ab58 100644
--- a/lib/btrfs/btrfsprim/uuid.go
+++ b/lib/btrfs/btrfsprim/uuid.go
@@ -47,7 +47,7 @@ func (uuid UUID) Format(f fmt.State, verb rune) {
fmtutil.FormatByteArrayStringer(uuid, uuid[:], f, verb)
}
-func (a UUID) Cmp(b UUID) int {
+func (a UUID) Compare(b UUID) int {
for i := range a {
if d := int(a[i]) - int(b[i]); d != 0 {
return d
diff --git a/lib/btrfs/btrfstree/ops.go b/lib/btrfs/btrfstree/ops.go
index 537773a..cdacef9 100644
--- a/lib/btrfs/btrfstree/ops.go
+++ b/lib/btrfs/btrfstree/ops.go
@@ -481,7 +481,7 @@ func KeySearch(fn func(btrfsprim.Key) int) func(btrfsprim.Key, uint32) int {
// TreeLookup implements the 'Trees' interface.
func (fs TreeOperatorImpl) TreeLookup(treeID btrfsprim.ObjID, key btrfsprim.Key) (Item, error) {
- item, err := fs.TreeSearch(treeID, KeySearch(key.Cmp))
+ item, err := fs.TreeSearch(treeID, KeySearch(key.Compare))
if err != nil {
err = fmt.Errorf("item with key=%v: %w", key, err)
}
diff --git a/lib/btrfs/btrfstree/root.go b/lib/btrfs/btrfstree/root.go
index 6ec45b5..319904b 100644
--- a/lib/btrfs/btrfstree/root.go
+++ b/lib/btrfs/btrfstree/root.go
@@ -30,7 +30,7 @@ func RootItemSearchFn(treeID btrfsprim.ObjID) func(btrfsprim.Key, uint32) int {
ObjectID: treeID,
ItemType: btrfsitem.ROOT_ITEM_KEY,
Offset: 0,
- }.Cmp(key)
+ }.Compare(key)
}
}
diff --git a/lib/btrfs/btrfstree/types_node.go b/lib/btrfs/btrfstree/types_node.go
index a26215b..d9d7118 100644
--- a/lib/btrfs/btrfstree/types_node.go
+++ b/lib/btrfs/btrfstree/types_node.go
@@ -507,11 +507,11 @@ func ReadNode[Addr ~int64](fs diskio.File[Addr], sb Superblock, addr Addr, exp N
if nodeRef.Data.Head.NumItems == 0 {
errs = append(errs, fmt.Errorf("has no items"))
} else {
- if minItem, _ := nodeRef.Data.MinItem(); exp.MinItem.OK && exp.MinItem.Val.Cmp(minItem) > 0 {
+ if minItem, _ := nodeRef.Data.MinItem(); exp.MinItem.OK && exp.MinItem.Val.Compare(minItem) > 0 {
errs = append(errs, fmt.Errorf("expected minItem>=%v but node has minItem=%v",
exp.MinItem, minItem))
}
- if maxItem, _ := nodeRef.Data.MaxItem(); exp.MaxItem.OK && exp.MaxItem.Val.Cmp(maxItem) < 0 {
+ if maxItem, _ := nodeRef.Data.MaxItem(); exp.MaxItem.OK && exp.MaxItem.Val.Compare(maxItem) < 0 {
errs = append(errs, fmt.Errorf("expected maxItem<=%v but node has maxItem=%v",
exp.MaxItem, maxItem))
}
diff --git a/lib/btrfs/btrfsvol/addr.go b/lib/btrfs/btrfsvol/addr.go
index 94320ef..655f4e9 100644
--- a/lib/btrfs/btrfsvol/addr.go
+++ b/lib/btrfs/btrfsvol/addr.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
@@ -50,7 +50,7 @@ func (a QualifiedPhysicalAddr) Add(b AddrDelta) QualifiedPhysicalAddr {
}
}
-func (a QualifiedPhysicalAddr) Cmp(b QualifiedPhysicalAddr) int {
+func (a QualifiedPhysicalAddr) Compare(b QualifiedPhysicalAddr) int {
if d := int(a.Dev - b.Dev); d != 0 {
return d
}
diff --git a/lib/btrfs/btrfsvol/chunk.go b/lib/btrfs/btrfsvol/chunk.go
index 5f1baa8..08a0b2b 100644
--- a/lib/btrfs/btrfsvol/chunk.go
+++ b/lib/btrfs/btrfsvol/chunk.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
@@ -27,7 +27,7 @@ type ChunkMapping = chunkMapping
// return -1 if 'a' is wholly to the left of 'b'
// return 0 if there is some overlap between 'a' and 'b'
// return 1 if 'a is wholly to the right of 'b'
-func (a chunkMapping) cmpRange(b chunkMapping) int {
+func (a chunkMapping) compareRange(b chunkMapping) int {
switch {
case a.LAddr.Add(a.Size) <= b.LAddr:
// 'a' is wholly to the left of 'b'.
@@ -44,7 +44,7 @@ func (a chunkMapping) cmpRange(b chunkMapping) int {
func (a chunkMapping) union(rest ...chunkMapping) (chunkMapping, error) {
// sanity check
for _, chunk := range rest {
- if a.cmpRange(chunk) != 0 {
+ if a.compareRange(chunk) != 0 {
return chunkMapping{}, fmt.Errorf("chunks don't overlap")
}
}
@@ -79,7 +79,7 @@ func (a chunkMapping) union(rest ...chunkMapping) (chunkMapping, error) {
}
ret.PAddrs = maps.Keys(paddrs)
sort.Slice(ret.PAddrs, func(i, j int) bool {
- return ret.PAddrs[i].Cmp(ret.PAddrs[j]) < 0
+ return ret.PAddrs[i].Compare(ret.PAddrs[j]) < 0
})
// figure out the flags (.Flags)
for _, chunk := range chunks {
diff --git a/lib/btrfs/btrfsvol/devext.go b/lib/btrfs/btrfsvol/devext.go
index e8e5446..037021c 100644
--- a/lib/btrfs/btrfsvol/devext.go
+++ b/lib/btrfs/btrfsvol/devext.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
@@ -23,7 +23,7 @@ type devextMapping struct {
// return -1 if 'a' is wholly to the left of 'b'
// return 0 if there is some overlap between 'a' and 'b'
// return 1 if 'a is wholly to the right of 'b'
-func (a devextMapping) cmpRange(b devextMapping) int {
+func (a devextMapping) compareRange(b devextMapping) int {
switch {
case a.PAddr.Add(a.Size) <= b.PAddr:
// 'a' is wholly to the left of 'b'.
@@ -40,7 +40,7 @@ func (a devextMapping) cmpRange(b devextMapping) int {
func (a devextMapping) union(rest ...devextMapping) (devextMapping, error) {
// sanity check
for _, ext := range rest {
- if a.cmpRange(ext) != 0 {
+ if a.compareRange(ext) != 0 {
return devextMapping{}, fmt.Errorf("devexts don't overlap")
}
}
diff --git a/lib/btrfs/btrfsvol/lvm.go b/lib/btrfs/btrfsvol/lvm.go
index 1cb1ded..b83e9cd 100644
--- a/lib/btrfs/btrfsvol/lvm.go
+++ b/lib/btrfs/btrfsvol/lvm.go
@@ -143,7 +143,7 @@ func (lv *LogicalVolume[PhysicalVolume]) addMapping(m Mapping, dryRun bool) erro
SizeLocked: m.SizeLocked,
Flags: m.Flags,
}
- logicalOverlaps := lv.logical2physical.SearchRange(newChunk.cmpRange)
+ logicalOverlaps := lv.logical2physical.SearchRange(newChunk.compareRange)
var err error
newChunk, err = newChunk.union(logicalOverlaps...)
if err != nil {
@@ -158,7 +158,7 @@ func (lv *LogicalVolume[PhysicalVolume]) addMapping(m Mapping, dryRun bool) erro
SizeLocked: m.SizeLocked,
Flags: m.Flags,
}
- physicalOverlaps := lv.physical2logical[m.PAddr.Dev].SearchRange(newExt.cmpRange)
+ physicalOverlaps := lv.physical2logical[m.PAddr.Dev].SearchRange(newExt.compareRange)
newExt, err = newExt.union(physicalOverlaps...)
if err != nil {
return fmt.Errorf("(%p).AddMapping: %w", lv, err)
@@ -261,7 +261,7 @@ func (lv *LogicalVolume[PhysicalVolume]) Mappings() []Mapping {
func (lv *LogicalVolume[PhysicalVolume]) Resolve(laddr LogicalAddr) (paddrs containers.Set[QualifiedPhysicalAddr], maxlen AddrDelta) {
node := lv.logical2physical.Search(func(chunk chunkMapping) int {
- return chunkMapping{LAddr: laddr, Size: 1}.cmpRange(chunk)
+ return chunkMapping{LAddr: laddr, Size: 1}.compareRange(chunk)
})
if node == nil {
return nil, 0
@@ -281,7 +281,7 @@ func (lv *LogicalVolume[PhysicalVolume]) Resolve(laddr LogicalAddr) (paddrs cont
func (lv *LogicalVolume[PhysicalVolume]) ResolveAny(laddr LogicalAddr, size AddrDelta) (LogicalAddr, QualifiedPhysicalAddr) {
node := lv.logical2physical.Search(func(chunk chunkMapping) int {
- return chunkMapping{LAddr: laddr, Size: size}.cmpRange(chunk)
+ return chunkMapping{LAddr: laddr, Size: size}.compareRange(chunk)
})
if node == nil {
return -1, QualifiedPhysicalAddr{0, -1}
@@ -291,7 +291,7 @@ func (lv *LogicalVolume[PhysicalVolume]) ResolveAny(laddr LogicalAddr, size Addr
func (lv *LogicalVolume[PhysicalVolume]) UnResolve(paddr QualifiedPhysicalAddr) LogicalAddr {
node := lv.physical2logical[paddr.Dev].Search(func(ext devextMapping) int {
- return devextMapping{PAddr: paddr.Addr, Size: 1}.cmpRange(ext)
+ return devextMapping{PAddr: paddr.Addr, Size: 1}.compareRange(ext)
})
if node == nil {
return -1
diff --git a/lib/btrfs/io4_fs.go b/lib/btrfs/io4_fs.go
index 799c865..fce9c76 100644
--- a/lib/btrfs/io4_fs.go
+++ b/lib/btrfs/io4_fs.go
@@ -152,7 +152,7 @@ func (sv *Subvolume) LoadFullInode(inode btrfsprim.ObjID) (*FullInode, error) {
XAttrs: make(map[string]string),
}
items, err := sv.FS.TreeSearchAll(sv.TreeID, func(key btrfsprim.Key, _ uint32) int {
- return containers.NativeCmp(inode, key.ObjectID)
+ return containers.NativeCompare(inode, key.ObjectID)
})
if err != nil {
val.Errs = append(val.Errs, err)