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