inomap: fix spillBit not set on 2nd hit
Also add a test for this. Thanks @slackner for the comment.
This commit is contained in:
parent
91f5c242a8
commit
8c9c68fb72
@ -27,6 +27,8 @@ const (
|
|||||||
maxPassthruIno = 1<<48 - 1
|
maxPassthruIno = 1<<48 - 1
|
||||||
// max value of 63 bit spill inode number
|
// max value of 63 bit spill inode number
|
||||||
maxSpillIno = 1<<63 - 1
|
maxSpillIno = 1<<63 - 1
|
||||||
|
// bit 63 is used as the spill bit
|
||||||
|
spillBit = 1 << 63
|
||||||
)
|
)
|
||||||
|
|
||||||
// InoMap stores the maps using for inode number translation.
|
// InoMap stores the maps using for inode number translation.
|
||||||
@ -57,7 +59,7 @@ func New() *InoMap {
|
|||||||
func (m *InoMap) spill(in QIno) (out uint64) {
|
func (m *InoMap) spill(in QIno) (out uint64) {
|
||||||
out, found := m.spillMap[in]
|
out, found := m.spillMap[in]
|
||||||
if found {
|
if found {
|
||||||
return out
|
return out | spillBit
|
||||||
}
|
}
|
||||||
if m.spillNext >= maxSpillIno {
|
if m.spillNext >= maxSpillIno {
|
||||||
log.Panicf("spillMap overflow: spillNext = 0x%x", m.spillNext)
|
log.Panicf("spillMap overflow: spillNext = 0x%x", m.spillNext)
|
||||||
@ -65,7 +67,7 @@ func (m *InoMap) spill(in QIno) (out uint64) {
|
|||||||
out = m.spillNext
|
out = m.spillNext
|
||||||
m.spillNext++
|
m.spillNext++
|
||||||
m.spillMap[in] = out
|
m.spillMap[in] = out
|
||||||
return 1<<63 | out
|
return out | spillBit
|
||||||
}
|
}
|
||||||
|
|
||||||
// Translate maps the passed-in (device, inode) pair to a unique inode number.
|
// Translate maps the passed-in (device, inode) pair to a unique inode number.
|
||||||
|
@ -99,6 +99,23 @@ func TestTranslateStress(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSpill(t *testing.T) {
|
||||||
|
m := New()
|
||||||
|
var q QIno
|
||||||
|
q.Ino = maxPassthruIno + 1
|
||||||
|
out1 := m.Translate(q)
|
||||||
|
if out1|spillBit == 0 {
|
||||||
|
t.Error("spill bit not set")
|
||||||
|
}
|
||||||
|
out2 := m.Translate(q)
|
||||||
|
if out2|spillBit == 0 {
|
||||||
|
t.Error("spill bit not set")
|
||||||
|
}
|
||||||
|
if out1 != out2 {
|
||||||
|
t.Errorf("unstable mapping: %d vs %d", out1, out2)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TestUniqueness checks that unique (Dev, Flags, Ino) tuples get unique inode
|
// TestUniqueness checks that unique (Dev, Flags, Ino) tuples get unique inode
|
||||||
// numbers
|
// numbers
|
||||||
func TestUniqueness(t *testing.T) {
|
func TestUniqueness(t *testing.T) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user