Commit 0cc2370b authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Set timeouts on Lookups in pathfilesystem.go.

parent 65a00e12
...@@ -198,3 +198,7 @@ func (self *DummyPathFuse) Create(name string, flags uint32, mode uint32) (file ...@@ -198,3 +198,7 @@ func (self *DummyPathFuse) Create(name string, flags uint32, mode uint32) (file
func (self *DummyPathFuse) Utimens(name string, AtimeNs uint64, CtimeNs uint64) (code fuse.Status) { func (self *DummyPathFuse) Utimens(name string, AtimeNs uint64, CtimeNs uint64) (code fuse.Status) {
return fuse.ENOSYS return fuse.ENOSYS
} }
func (self *DummyPathFuse) SetOptions(*fuse.PathFileSystemConnectorOptions) {
}
...@@ -150,6 +150,12 @@ func (self *PassThroughFuse) Create(path string, flags uint32, mode uint32) (fus ...@@ -150,6 +150,12 @@ func (self *PassThroughFuse) Create(path string, flags uint32, mode uint32) (fus
return &PassThroughFile{file: f}, fuse.OsErrorToFuseError(err) return &PassThroughFile{file: f}, fuse.OsErrorToFuseError(err)
} }
func (self *PassThroughFuse) SetOptions(options *fuse.PathFileSystemConnectorOptions) {
options.NegativeTimeout = 100.0
options.AttrTimeout = 100.0
options.EntryTimeout = 100.0
}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
type PassThroughFile struct { type PassThroughFile struct {
...@@ -251,3 +257,4 @@ func (self *PassThroughDir) ReleaseDir() { ...@@ -251,3 +257,4 @@ func (self *PassThroughDir) ReleaseDir() {
func (self *PassThroughDir) FsyncDir(input *fuse.FsyncIn) (code fuse.Status) { func (self *PassThroughDir) FsyncDir(input *fuse.FsyncIn) (code fuse.Status) {
return fuse.ENOSYS return fuse.ENOSYS
} }
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"time" "time"
"fmt" "fmt"
"path" "path"
"math"
) )
// Make a temporary directory securely. // Make a temporary directory securely.
...@@ -206,3 +207,8 @@ func parseLittleEndian(b *bytes.Buffer, data interface{}) bool { ...@@ -206,3 +207,8 @@ func parseLittleEndian(b *bytes.Buffer, data interface{}) bool {
} }
panic(fmt.Sprintf("Cannot parse %v", data)) panic(fmt.Sprintf("Cannot parse %v", data))
} }
func SplitNs(time float64, secs *uint64, nsecs *uint32) {
*nsecs = uint32(1e9 * (time - math.Trunc(time)))
*secs = uint64(math.Trunc(time))
}
...@@ -47,6 +47,11 @@ func (self *inodeData) GetPath() string { ...@@ -47,6 +47,11 @@ func (self *inodeData) GetPath() string {
return fullPath return fullPath
} }
type PathFileSystemConnectorOptions struct {
EntryTimeout float64
AttrTimeout float64
NegativeTimeout float64
}
type PathFileSystemConnector struct { type PathFileSystemConnector struct {
fileSystem PathFilesystem fileSystem PathFilesystem
...@@ -67,6 +72,8 @@ type PathFileSystemConnector struct { ...@@ -67,6 +72,8 @@ type PathFileSystemConnector struct {
inodePathMap map[string]*inodeData inodePathMap map[string]*inodeData
inodePathMapByInode map[uint64]*inodeData inodePathMapByInode map[uint64]*inodeData
nextFreeInode uint64 nextFreeInode uint64
options PathFileSystemConnectorOptions
} }
// Must be called with lock held. // Must be called with lock held.
...@@ -204,7 +211,6 @@ func NewPathFileSystemConnector(fs PathFilesystem) (out *PathFileSystemConnector ...@@ -204,7 +211,6 @@ func NewPathFileSystemConnector(fs PathFilesystem) (out *PathFileSystemConnector
out = new(PathFileSystemConnector) out = new(PathFileSystemConnector)
out.inodePathMap = make(map[string]*inodeData) out.inodePathMap = make(map[string]*inodeData)
out.inodePathMapByInode = make(map[uint64]*inodeData) out.inodePathMapByInode = make(map[uint64]*inodeData)
out.fileSystem = fs out.fileSystem = fs
rootData := new(inodeData) rootData := new(inodeData)
...@@ -214,6 +220,12 @@ func NewPathFileSystemConnector(fs PathFilesystem) (out *PathFileSystemConnector ...@@ -214,6 +220,12 @@ func NewPathFileSystemConnector(fs PathFilesystem) (out *PathFileSystemConnector
out.inodePathMapByInode[FUSE_ROOT_ID] = rootData out.inodePathMapByInode[FUSE_ROOT_ID] = rootData
out.nextFreeInode = FUSE_ROOT_ID + 1 out.nextFreeInode = FUSE_ROOT_ID + 1
out.options.NegativeTimeout = 0.0
out.options.AttrTimeout = 1.0
out.options.EntryTimeout = 1.0
fs.SetOptions(&out.options)
return out return out
} }
...@@ -240,8 +252,14 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out ...@@ -240,8 +252,14 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out
fullPath := path.Join(parent.GetPath(), name) fullPath := path.Join(parent.GetPath(), name)
attr, err := self.fileSystem.GetAttr(fullPath) attr, err := self.fileSystem.GetAttr(fullPath)
if err == ENOENT && self.options.NegativeTimeout > 0.0 {
out = new(EntryOut)
out.NodeId = 0
SplitNs(self.options.NegativeTimeout, &out.EntryValid, &out.EntryValidNsec)
return out, OK
}
if err != OK { if err != OK {
// TODO - set a EntryValid timeout on ENOENT.
return nil, err return nil, err
} }
...@@ -250,11 +268,9 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out ...@@ -250,11 +268,9 @@ func (self *PathFileSystemConnector) Lookup(header *InHeader, name string) (out
out = new(EntryOut) out = new(EntryOut)
out.NodeId = data.NodeId out.NodeId = data.NodeId
out.Generation = 1 // where to get the generation? out.Generation = 1 // where to get the generation?
out.EntryValid = 0
out.AttrValid = 0
out.EntryValidNsec = 0 SplitNs(self.options.EntryTimeout, &out.EntryValid, &out.EntryValidNsec)
out.AttrValidNsec = 0 SplitNs(self.options.AttrTimeout, &out.AttrValid, &out.AttrValidNsec)
out.Attr = *attr out.Attr = *attr
return out, OK return out, OK
......
...@@ -580,5 +580,7 @@ type PathFilesystem interface { ...@@ -580,5 +580,7 @@ type PathFilesystem interface {
Create(name string, flags uint32, mode uint32) (file RawFuseFile, code Status) Create(name string, flags uint32, mode uint32) (file RawFuseFile, code Status)
Utimens(name string, AtimeNs uint64, CtimeNs uint64) (code Status) Utimens(name string, AtimeNs uint64, CtimeNs uint64) (code Status)
// unimplemented: poll, ioctl, bmap. // unimplemented: poll, ioctl, bmap.
SetOptions(*PathFileSystemConnectorOptions)
} }
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