summaryrefslogtreecommitdiff
path: root/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-12-20 20:06:15 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2022-12-20 20:06:15 -0700
commit8ff81c1ed6a50179166ffc4cfb60bef85394265e (patch)
treef2395593d4d4cfd12b26ba2030bb94930fe4ba56 /lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
parent7315c38414b3a6840d71f254b7c8192640b41d7c (diff)
parent94a86a763157327ac969c98e19d7770db477a6a3 (diff)
Merge branch 'lukeshu/rebuild-nodes-take2'
Diffstat (limited to 'lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go')
-rw-r--r--lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go42
1 files changed, 9 insertions, 33 deletions
diff --git a/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go b/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
index 7e0eab1..8c43dad 100644
--- a/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
+++ b/lib/btrfsprogs/btrfsinspect/rebuildnodes/util.go
@@ -5,43 +5,11 @@
package rebuildnodes
import (
- "fmt"
+ "golang.org/x/exp/constraints"
"git.lukeshu.com/btrfs-progs-ng/lib/btrfsprogs/btrfsinspect"
)
-func ptrTo[T any](x T) *T {
- return &x
-}
-
-func maybeSet[K, V comparable](name string, m map[K]V, k K, v V) error {
- if other, conflict := m[k]; conflict && other != v {
- return fmt.Errorf("conflict: %s %v can't have both %v and %v", name, k, other, v)
- }
- m[k] = v
- return nil
-}
-
-/*
-var maxKey = btrfsprim.Key{
- ObjectID: math.MaxUint64,
- ItemType: math.MaxUint8,
- Offset: math.MaxUint64,
-}
-
-func keyMm(key btrfsprim.Key) btrfsprim.Key {
- switch {
- case key.Offset > 0:
- key.Offset--
- case key.ItemType > 0:
- key.ItemType--
- case key.ObjectID > 0:
- key.ObjectID--
- }
- return key
-}
-*/
-
func countNodes(nodeScanResults btrfsinspect.ScanDevicesResult) int {
var cnt int
for _, devResults := range nodeScanResults {
@@ -49,3 +17,11 @@ func countNodes(nodeScanResults btrfsinspect.ScanDevicesResult) int {
}
return cnt
}
+
+func roundDown[T constraints.Integer](n, d T) T {
+ return (n / d) * d
+}
+
+func roundUp[T constraints.Integer](n, d T) T {
+ return ((n + d - 1) / d) * d
+}