Commit c4a6d9fd authored by Frederick Akalin's avatar Frederick Akalin

Make handleMap return generation on Register

parent 6944ad89
......@@ -100,8 +100,8 @@ func (c *FileSystemConnector) verify() {
func (c *rawBridge) childLookup(out *fuse.EntryOut, n *Inode, context *fuse.Context) {
n.Node().GetAttr((*fuse.Attr)(&out.Attr), nil, context)
n.mount.fillEntry(out)
out.Ino = c.fsConn().lookupUpdate(n)
out.NodeId = out.Ino
out.NodeId, out.Generation = c.fsConn().lookupUpdate(n)
out.Ino = out.NodeId
if out.Nlink == 0 {
// With Nlink == 0, newer kernels will refuse link
// operations.
......@@ -117,11 +117,11 @@ func (c *rawBridge) toInode(nodeid uint64) *Inode {
return i
}
// Must run outside treeLock. Returns the nodeId.
func (c *FileSystemConnector) lookupUpdate(node *Inode) (id uint64) {
id = c.inodeMap.Register(&node.handled)
// Must run outside treeLock. Returns the nodeId and generation.
func (c *FileSystemConnector) lookupUpdate(node *Inode) (id, generation uint64) {
id, generation = c.inodeMap.Register(&node.handled)
c.verify()
return id
return
}
// Must run outside treeLock.
......
......@@ -135,7 +135,7 @@ func (m *fileSystemMount) registerFileHandle(node *Inode, dir *connectorDir, f F
b.WithFlags.File.SetInode(node)
}
node.openFiles = append(node.openFiles, b)
handle := m.openFiles.Register(&b.handled)
handle, _ := m.openFiles.Register(&b.handled)
node.openFilesMutex.Unlock()
return handle, b
}
......
......@@ -98,8 +98,7 @@ func (c *rawBridge) Lookup(header *fuse.InHeader, name string, out *fuse.EntryOu
}
child.mount.fillEntry(out)
out.NodeId = c.fsConn().lookupUpdate(child)
out.Generation = child.generation
out.NodeId, out.Generation = c.fsConn().lookupUpdate(child)
out.Ino = out.NodeId
return fuse.OK
......
......@@ -15,7 +15,7 @@ import (
//
// This structure is thread-safe.
type handleMap interface {
Register(obj *handled) uint64
Register(obj *handled) (handle, generation uint64)
Count() int
Decode(uint64) *handled
Forget(handle uint64, count int) (bool, *handled)
......@@ -57,7 +57,7 @@ func newPortableHandleMap() *portableHandleMap {
}
}
func (m *portableHandleMap) Register(obj *handled) (handle uint64) {
func (m *portableHandleMap) Register(obj *handled) (handle, generation uint64) {
m.Lock()
if obj.count == 0 {
if obj.check != 0 {
......@@ -79,7 +79,7 @@ func (m *portableHandleMap) Register(obj *handled) (handle uint64) {
}
obj.count++
m.Unlock()
return handle
return
}
func (m *portableHandleMap) Handle(obj *handled) (h uint64) {
......
......@@ -21,8 +21,8 @@ func TestHandleMapLookupCount(t *testing.T) {
t.Log("portable:", portable)
v := new(handled)
hm := newPortableHandleMap()
h1 := hm.Register(v)
h2 := hm.Register(v)
h1, _ := hm.Register(v)
h2, _ := hm.Register(v)
if h1 != h2 {
t.Fatalf("double register should reuse handle: got %d want %d.", h2, h1)
......@@ -61,7 +61,7 @@ func TestHandleMapLookupCount(t *testing.T) {
func TestHandleMapBasic(t *testing.T) {
v := new(handled)
hm := newPortableHandleMap()
h := hm.Register(v)
h, _ := hm.Register(v)
t.Logf("Got handle 0x%x", h)
if !hm.Has(h) {
t.Fatal("Does not have handle")
......@@ -91,7 +91,7 @@ func TestHandleMapMultiple(t *testing.T) {
hm := newPortableHandleMap()
for i := 0; i < 10; i++ {
v := &handled{}
h := hm.Register(v)
h, _ := hm.Register(v)
if hm.Decode(h) != v {
t.Fatal("address mismatch")
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment