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

Move CachingFileSystem out of UnionFs, and create a CachingFileSystem

in NewUnionFsFromRoots().

This allows Termite to use other forms of caching.
parent 0f93160b
...@@ -94,7 +94,7 @@ func (me *AutoUnionFs) createFs(name string, roots []string) (fuse.Status) { ...@@ -94,7 +94,7 @@ func (me *AutoUnionFs) createFs(name string, roots []string) (fuse.Status) {
return fuse.EBUSY return fuse.EBUSY
} }
ufs, err := NewUnionFsFromRoots(roots, &me.options.UnionFsOptions) ufs, err := NewUnionFsFromRoots(roots, &me.options.UnionFsOptions, true)
if err != nil { if err != nil {
log.Println("Could not create UnionFs:", err) log.Println("Could not create UnionFs:", err)
return fuse.EPERM return fuse.EPERM
......
...@@ -150,6 +150,12 @@ func (me *CachingFileSystem) DropCache() { ...@@ -150,6 +150,12 @@ func (me *CachingFileSystem) DropCache() {
} }
func (me *CachingFileSystem) GetAttr(name string) (*os.FileInfo, fuse.Status) { func (me *CachingFileSystem) GetAttr(name string) (*os.FileInfo, fuse.Status) {
if name == _DROP_CACHE {
return &os.FileInfo{
Mode: fuse.S_IFREG | 0777,
},fuse.OK
}
r := me.attributes.Get(name).(*attrResponse) r := me.attributes.Get(name).(*attrResponse)
return r.FileInfo, r.Status return r.FileInfo, r.Status
} }
...@@ -179,12 +185,9 @@ func (me *CachingFileSystem) OpenDir(name string) (stream chan fuse.DirEntry, st ...@@ -179,12 +185,9 @@ func (me *CachingFileSystem) OpenDir(name string) (stream chan fuse.DirEntry, st
return nil, r.Status return nil, r.Status
} }
// Caching file contents easily overflows available memory. func (me *CachingFileSystem) Open(name string, flags uint32) (f fuse.File, status fuse.Status) {
func (me *CachingFileSystem) DisabledOpen(name string, flags uint32) (f fuse.File, status fuse.Status) { if flags&fuse.O_ANYWRITE != 0 && name == _DROP_CACHE {
if flags&fuse.O_ANYWRITE != 0 { me.DropCache()
return nil, fuse.EPERM
} }
return me.FileSystem.Open(name, flags)
r := me.files.Get(name).(*openResponse)
return r.File, r.Status
} }
...@@ -7,9 +7,9 @@ import ( ...@@ -7,9 +7,9 @@ import (
"os" "os"
) )
func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions) (*UnionFs, os.Error) { func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions, roCaching bool) (*UnionFs, os.Error) {
fses := make([]fuse.FileSystem, 0) fses := make([]fuse.FileSystem, 0)
for _, r := range roots { for i, r := range roots {
var fs fuse.FileSystem var fs fuse.FileSystem
fi, err := os.Stat(r) fi, err := os.Stat(r)
if err != nil { if err != nil {
...@@ -23,6 +23,10 @@ func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions) (*UnionFs, os.Err ...@@ -23,6 +23,10 @@ func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions) (*UnionFs, os.Err
} }
if fs == nil { if fs == nil {
return nil, err return nil, err
}
if i > 0 && roCaching {
fs = NewCachingFileSystem(fs, 0)
} }
fses = append(fses, fs) fses = append(fses, fs)
......
...@@ -65,8 +65,6 @@ type UnionFs struct { ...@@ -65,8 +65,6 @@ type UnionFs struct {
// The same, but as interfaces. // The same, but as interfaces.
fileSystems []fuse.FileSystem fileSystems []fuse.FileSystem
cachingFileSystems []*CachingFileSystem
// A file-existence cache. // A file-existence cache.
deletionCache *DirCache deletionCache *DirCache
...@@ -90,15 +88,7 @@ func NewUnionFs(name string, fileSystems []fuse.FileSystem, options UnionFsOptio ...@@ -90,15 +88,7 @@ func NewUnionFs(name string, fileSystems []fuse.FileSystem, options UnionFsOptio
g := new(UnionFs) g := new(UnionFs)
g.name = name g.name = name
g.options = &options g.options = &options
for i, fs := range fileSystems { g.fileSystems = fileSystems
if i > 0 {
cfs := NewCachingFileSystem(fs, 0)
g.cachingFileSystems = append(g.cachingFileSystems, cfs)
fs = cfs
}
g.fileSystems = append(g.fileSystems, fs)
}
writable := g.fileSystems[0] writable := g.fileSystems[0]
code := g.createDeletionStore() code := g.createDeletionStore()
...@@ -734,8 +724,15 @@ func (me *UnionFs) DropCaches() { ...@@ -734,8 +724,15 @@ func (me *UnionFs) DropCaches() {
log.Println("Forced cache drop on", me.name) log.Println("Forced cache drop on", me.name)
me.branchCache.DropAll() me.branchCache.DropAll()
me.deletionCache.DropCache() me.deletionCache.DropCache()
for _, fs := range me.cachingFileSystems { for _, fs := range me.fileSystems {
fs.DropCache() a, code := fs.GetAttr(_DROP_CACHE)
if code.Ok() && a.IsRegular() {
f, _ := fs.Open(_DROP_CACHE, uint32(os.O_WRONLY))
if f != nil {
f.Flush()
f.Release()
}
}
} }
} }
......
...@@ -40,7 +40,8 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) { ...@@ -40,7 +40,8 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
var fses []fuse.FileSystem var fses []fuse.FileSystem
fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/rw")) fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/rw"))
fses = append(fses, fuse.NewLoopbackFileSystem(wd+"/ro")) fses = append(fses,
NewCachingFileSystem(fuse.NewLoopbackFileSystem(wd+"/ro"), 0))
ufs := NewUnionFs("testFs", fses, testOpts) ufs := NewUnionFs("testFs", fses, testOpts)
opts := &fuse.FileSystemOptions{ opts := &fuse.FileSystemOptions{
......
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