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

Introduce Deletable() in node API, rather than hardcoded synthetic variable.

parent 5af9ce62
......@@ -29,8 +29,14 @@ type FsNode interface {
SetInode(node *Inode)
Lookup(name string, context *Context) (fi *os.FileInfo, node FsNode, code Status)
OnForget()
// Deletable() should return true if this inode may be
// discarded from the children list. This will be called from
// within the treeLock critical section, so you cannot look at
// other inodes.
Deletable() bool
OnForget()
// Misc.
Access(mode uint32, context *Context) (code Status)
Readlink(c *Context) ([]byte, Status)
......
......@@ -39,6 +39,10 @@ func (me *DefaultFsNode) SetInode(node *Inode) {
me.inode = node
}
func (me *DefaultFsNode) Deletable() bool {
return true
}
func (me *DefaultFsNode) Inode() *Inode {
return me.inode
}
......
......@@ -161,7 +161,7 @@ func (me *FileSystemConnector) recursiveConsiderDropInode(n *Inode) (drop bool)
ch.fsInode.OnForget()
}
if len(n.children) > 0 || n.lookupCount > 0 || n.synthetic {
if len(n.children) > 0 || n.lookupCount > 0 || !n.FsNode().Deletable() {
return false
}
if n == me.rootNode || n.mountPoint != nil {
......
......@@ -52,12 +52,10 @@ type Inode struct {
//
// The lookupCount is exclusively used for managing the
// lifetime of nodeId variable. It is ok for a node to have 0
// == lookupCount. This can happen if the inode is synthetic.
// == lookupCount. This can happen if the inode return false
// for Deletable().
lookupCount int
// This is to prevent lookupCount==0 node from being dropped.
synthetic bool
// Non-nil if this inode is a mountpoint, ie. the Root of a
// NodeFileSystem.
mountPoint *fileSystemMount
......@@ -135,13 +133,6 @@ func (me *Inode) IsDir() bool {
return me.children != nil
}
// CreateChild() creates node for synthetic use
func (me *Inode) NewSynthetic(isDir bool, fsi FsNode) *Inode {
ch := me.New(isDir, fsi)
ch.synthetic = true
return ch
}
func (me *Inode) New(isDir bool, fsi FsNode) *Inode {
ch := newInode(isDir, fsi)
ch.mount = me.mount
......
......@@ -62,7 +62,7 @@ type memNode struct {
func (me *memNode) newNode(isdir bool) *memNode {
n := me.fs.newNode()
me.Inode().NewSynthetic(isdir, n)
me.Inode().New(isdir, n)
return n
}
......
......@@ -92,6 +92,10 @@ func (me *memNode) Open(flags uint32, context *fuse.Context) (fuseFile fuse.File
return fuse.NewDataFile(me.file.Data()), fuse.OK
}
func (me *memNode) Deletable() bool {
return false
}
func (me *memNode) GetAttr(file fuse.File, context *fuse.Context) (*os.FileInfo, fuse.Status) {
if me.Inode().IsDir() {
return &os.FileInfo{
......@@ -114,7 +118,7 @@ func (me *MemTreeFs) addFile(name string, f MemFile) {
fsnode.file = f
}
child = node.NewSynthetic(fsnode.file == nil, fsnode)
child = node.New(fsnode.file == nil, fsnode)
node.AddChild(c, child)
}
node = child
......
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