Commit 561c7984 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Introduce FileSystem.Release()

This method gets called when a writable file gets closed in the
filesystem.  This allows filesystems to react to changed file sizes
due to writes.
parent 1a0bc1d4
......@@ -43,6 +43,9 @@ type FileSystem interface {
// File handling
Open(name string, flags uint32) (file File, code Status)
Create(name string, flags uint32, mode uint32) (file File, code Status)
// Release() gets called after File.Release() on a file opened
// as writable.
Release(name string)
// Directory handling
OpenDir(name string) (stream chan DirEntry, code Status)
......@@ -128,6 +131,7 @@ type RawFileSystem interface {
Create(header *InHeader, input *CreateIn, name string) (flags uint32, handle uint64, out *EntryOut, code Status)
Open(header *InHeader, input *OpenIn) (flags uint32, handle uint64, status Status)
Read(*ReadIn, *BufferPool) ([]byte, Status)
Release(header *InHeader, input *ReleaseIn)
Write(*WriteIn, []byte) (written uint32, code Status)
Flush(*FlushIn) Status
......
......@@ -247,6 +247,9 @@ func (me *DefaultFileSystem) Open(name string, flags uint32) (file File, code St
return nil, ENOSYS
}
func (me *DefaultFileSystem) Release(name string) {
}
func (me *DefaultFileSystem) OpenDir(name string) (stream chan DirEntry, status Status) {
return nil, ENOSYS
}
......
......@@ -213,7 +213,7 @@ func (me *FileSystemConnector) Statistics() string {
len(me.openFiles), len(me.inodeMap))
}
func (me *FileSystemConnector) unregisterFile(node *inode, handle uint64) interface{} {
func (me *FileSystemConnector) unregisterFile(node *inode, handle uint64) (interface{}) {
me.fileLock.Lock()
defer me.fileLock.Unlock()
b, ok := me.openFiles[handle]
......
......@@ -376,6 +376,22 @@ func (me *FileSystemConnector) Release(header *InHeader, input *ReleaseIn) {
node := me.getInodeData(header.NodeId)
f := me.unregisterFile(node, input.Fh).(File)
f.Release()
if input.Flags & O_ANYWRITE != 0 {
// We only signal releases to the FS if the
// open could have changed things.
var path string
var mount *mountData
me.treeLock.RLock()
if node.Parent != nil {
path, mount = node.GetPath()
}
me.treeLock.RUnlock()
if mount != nil {
mount.fs.Release(path)
}
}
me.considerDropInode(node)
}
......
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