Skip to content

Commit

Permalink
inomap: incorporate spillBit into the spillNext start value
Browse files Browse the repository at this point in the history
This avoids the manual "| spillBit" logic.
  • Loading branch information
rfjakob committed May 5, 2024
1 parent ed0a12b commit c85c092
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
21 changes: 10 additions & 11 deletions internal/inomap/inomap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -16,6 +16,7 @@ package inomap

import (
"log"
"math"
"sync"
"syscall"

Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions internal/inomap/inomap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit c85c092

Please sign in to comment.