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) {
return fuse.EBUSY
}
ufs, err := NewUnionFsFromRoots(roots, &me.options.UnionFsOptions)
ufs, err := NewUnionFsFromRoots(roots, &me.options.UnionFsOptions, true)
if err != nil {
log.Println("Could not create UnionFs:", err)
return fuse.EPERM
......
......@@ -150,6 +150,12 @@ func (me *CachingFileSystem) DropCache() {
}
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)
return r.FileInfo, r.Status
}
......@@ -179,12 +185,9 @@ func (me *CachingFileSystem) OpenDir(name string) (stream chan fuse.DirEntry, st
return nil, r.Status
}
// Caching file contents easily overflows available memory.
func (me *CachingFileSystem) DisabledOpen(name string, flags uint32) (f fuse.File, status fuse.Status) {
if flags&fuse.O_ANYWRITE != 0 {
return nil, fuse.EPERM
func (me *CachingFileSystem) Open(name string, flags uint32) (f fuse.File, status fuse.Status) {
if flags&fuse.O_ANYWRITE != 0 && name == _DROP_CACHE {
me.DropCache()
}
r := me.files.Get(name).(*openResponse)
return r.File, r.Status
return me.FileSystem.Open(name, flags)
}
......@@ -7,9 +7,9 @@ import (
"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)
for _, r := range roots {
for i, r := range roots {
var fs fuse.FileSystem
fi, err := os.Stat(r)
if err != nil {
......@@ -23,6 +23,10 @@ func NewUnionFsFromRoots(roots []string, opts *UnionFsOptions) (*UnionFs, os.Err
}
if fs == nil {
return nil, err
}
if i > 0 && roCaching {
fs = NewCachingFileSystem(fs, 0)
}
fses = append(fses, fs)
......
......@@ -65,8 +65,6 @@ type UnionFs struct {
// The same, but as interfaces.
fileSystems []fuse.FileSystem
cachingFileSystems []*CachingFileSystem
// A file-existence cache.
deletionCache *DirCache
......@@ -90,15 +88,7 @@ func NewUnionFs(name string, fileSystems []fuse.FileSystem, options UnionFsOptio
g := new(UnionFs)
g.name = name
g.options = &options
for i, fs := range fileSystems {
if i > 0 {
cfs := NewCachingFileSystem(fs, 0)
g.cachingFileSystems = append(g.cachingFileSystems, cfs)
fs = cfs
}
g.fileSystems = append(g.fileSystems, fs)
}
g.fileSystems = fileSystems
writable := g.fileSystems[0]
code := g.createDeletionStore()
......@@ -734,8 +724,15 @@ func (me *UnionFs) DropCaches() {
log.Println("Forced cache drop on", me.name)
me.branchCache.DropAll()
me.deletionCache.DropCache()
for _, fs := range me.cachingFileSystems {
fs.DropCache()
for _, fs := range me.fileSystems {
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()) {
var fses []fuse.FileSystem
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)
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