Commit f72abcb4 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Make lookupUpdate take the treeLock too.

Simplifies the API, and fixes a race condition.
parent e9d284fc
...@@ -60,12 +60,12 @@ func NewFileSystemConnector(nodeFs NodeFileSystem, opts *FileSystemOptions) (me ...@@ -60,12 +60,12 @@ func NewFileSystemConnector(nodeFs NodeFileSystem, opts *FileSystemOptions) (me
me.inodeMap = NewHandleMap(opts.PortableInodes) me.inodeMap = NewHandleMap(opts.PortableInodes)
me.rootNode = newInode(true, nodeFs.Root()) me.rootNode = newInode(true, nodeFs.Root())
me.verify()
me.MountRoot(nodeFs, opts)
// FUSE does not issue a LOOKUP for 1 (obviously), but it does // FUSE does not issue a LOOKUP for 1 (obviously), but it does
// issue a forget. This lookupUpdate is to make the counts match. // issue a forget. This lookupUpdate is to make the counts match.
me.lookupUpdate(me.rootNode) me.lookupUpdate(me.rootNode)
me.verify()
me.MountRoot(nodeFs, opts)
return me return me
} }
...@@ -104,8 +104,12 @@ func (me *FileSystemConnector) toInode(nodeid uint64) *Inode { ...@@ -104,8 +104,12 @@ func (me *FileSystemConnector) toInode(nodeid uint64) *Inode {
return i return i
} }
// Must run in treeLock. Returns the nodeId. // Must run outside treeLock. Returns the nodeId.
//
// TODO - write a stress test to exercise this.
func (me *FileSystemConnector) lookupUpdate(node *Inode) uint64 { func (me *FileSystemConnector) lookupUpdate(node *Inode) uint64 {
node.treeLock.Lock()
defer node.treeLock.Unlock()
if node.lookupCount == 0 { if node.lookupCount == 0 {
node.nodeId = me.inodeMap.Register(&node.handled, node) node.nodeId = me.inodeMap.Register(&node.handled, node)
} }
...@@ -114,8 +118,6 @@ func (me *FileSystemConnector) lookupUpdate(node *Inode) uint64 { ...@@ -114,8 +118,6 @@ func (me *FileSystemConnector) lookupUpdate(node *Inode) uint64 {
} }
// Must run outside treeLock. // Must run outside treeLock.
//
// TODO - reconcile api for lookupUpdate() and forgetUpdate().
func (me *FileSystemConnector) forgetUpdate(node *Inode, forgetCount int) { func (me *FileSystemConnector) forgetUpdate(node *Inode, forgetCount int) {
defer me.verify() defer me.verify()
......
...@@ -23,8 +23,6 @@ func (me *FileSystemConnector) lookupMountUpdate(mount *fileSystemMount) (out *E ...@@ -23,8 +23,6 @@ func (me *FileSystemConnector) lookupMountUpdate(mount *fileSystemMount) (out *E
if !err.Ok() { if !err.Ok() {
return nil, err return nil, err
} }
mount.treeLock.Lock()
defer mount.treeLock.Unlock()
out = mount.fileInfoToEntry(fi) out = mount.fileInfoToEntry(fi)
out.NodeId = me.lookupUpdate(mount.mountInode) out.NodeId = me.lookupUpdate(mount.mountInode)
......
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