aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2024-05-05 22:05:08 +0200
committerJakob Unterwurzacher2024-05-05 22:05:08 +0200
commitc85c092189df44e9a88ad30c1f91cfc7fbeb4ccb (patch)
tree992b2b0f9ab705e14340038d580977eca745d175
parented0a12b7337c2d88c027329f64e73070da17d5b3 (diff)
inomap: incorporate spillBit into the spillNext start value
This avoids the manual "| spillBit" logic.
-rw-r--r--internal/inomap/inomap.go21
-rw-r--r--internal/inomap/inomap_test.go5
2 files changed, 15 insertions, 11 deletions
diff --git a/internal/inomap/inomap.go b/internal/inomap/inomap.go
index 0f7ade3..1c012d9 100644
--- a/internal/inomap/inomap.go
+++ b/internal/inomap/inomap.go
@@ -3,8 +3,8 @@
//
// Format of the returned inode numbers:
//
-// [spill bit = 0][15 bit namespace id][48 bit passthru inode number]
-// [spill bit = 1][63 bit spill inode number ]
+// [spill bit = 0][15 bit namespace id][48 bit passthru inode number] = 64 bit translated inode number
+// [spill bit = 1][63 bit counter ] = 64 bit spill inode number
//
// Each (Dev, Tag) tuple gets a namespace id assigned. The original inode
// number is then passed through in the lower 48 bits.
@@ -16,6 +16,7 @@ package inomap
import (
"log"
+ "math"
"sync"
"syscall"
@@ -27,10 +28,8 @@ const (
maxNamespaceId = 1<<15 - 1
// max value of 48 bit passthru inode number
maxPassthruIno = 1<<48 - 1
- // max value of 63 bit spill inode number
- maxSpillIno = 1<<63 - 1
- // bit 63 is used as the spill bit
- spillBit = 1 << 63
+ // the spill inode number space starts at 0b10000...0.
+ spillSpaceStart = 1 << 63
)
// InoMap stores the maps using for inode number translation.
@@ -57,7 +56,7 @@ func New(rootDev uint64) *InoMap {
namespaceMap: make(map[namespaceData]uint16),
namespaceNext: 0,
spillMap: make(map[QIno]uint64),
- spillNext: 0,
+ spillNext: spillSpaceStart,
}
if rootDev > 0 {
// Reserve namespace 0 for rootDev
@@ -74,18 +73,18 @@ func (m *InoMap) spill(in QIno) (out uint64) {
out, found := m.spillMap[in]
if found {
- return out | spillBit
+ return out
}
- if m.spillNext >= maxSpillIno {
+ if m.spillNext == math.MaxUint64 {
log.Panicf("spillMap overflow: spillNext = 0x%x", m.spillNext)
}
out = m.spillNext
m.spillNext++
m.spillMap[in] = out
- return out | spillBit
+ return out
}
-// Translate maps the passed-in (device, inode) pair to a unique inode number.
+// Translate maps the passed-in (device, tag, inode) tuple to a unique inode number.
func (m *InoMap) Translate(in QIno) (out uint64) {
m.Lock()
defer m.Unlock()
diff --git a/internal/inomap/inomap_test.go b/internal/inomap/inomap_test.go
index 9ec2932..430ec94 100644
--- a/internal/inomap/inomap_test.go
+++ b/internal/inomap/inomap_test.go
@@ -5,6 +5,11 @@ import (
"testing"
)
+const (
+ // bit 63 is used as the spill bit
+ spillBit = 1 << 63
+)
+
func TestTranslate(t *testing.T) {
m := New(0)
q := QIno{Ino: 1}