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

Add magic .drop_cache file.

parent f1e3a827
...@@ -57,11 +57,13 @@ func (me *DirCache) setMap(newMap map[string]bool) { ...@@ -57,11 +57,13 @@ func (me *DirCache) setMap(newMap map[string]bool) {
me.names = newMap me.names = newMap
me.updateRunning = false me.updateRunning = false
_ = time.AfterFunc(me.ttlNs, _ = time.AfterFunc(me.ttlNs,
func() { func() { me.DropCache() })
}
func (me *DirCache) DropCache() {
me.lock.Lock() me.lock.Lock()
me.names = nil me.names = nil
me.lock.Unlock() me.lock.Unlock()
})
} }
// Try to refresh: if another update is already running, do nothing, // Try to refresh: if another update is already running, do nothing,
......
...@@ -82,3 +82,9 @@ func (me *TimedCache) Purge() { ...@@ -82,3 +82,9 @@ func (me *TimedCache) Purge() {
me.cacheMap[k] = nil, false me.cacheMap[k] = nil, false
} }
} }
func (me *TimedCache) RecurringPurge() {
me.Purge()
time.AfterFunc(5*me.ttlNs,
func() { me.RecurringPurge() })
}
...@@ -26,6 +26,7 @@ func filePathHash(path string) string { ...@@ -26,6 +26,7 @@ func filePathHash(path string) string {
return fmt.Sprintf("%x-%s", h.Sum()[:8], base) return fmt.Sprintf("%x-%s", h.Sum()[:8], base)
} }
/* /*
UnionFs implements a user-space union file system, which is UnionFs implements a user-space union file system, which is
...@@ -103,6 +104,7 @@ func NewUnionFs(roots []string, options UnionFsOptions) *UnionFs { ...@@ -103,6 +104,7 @@ func NewUnionFs(roots []string, options UnionFsOptions) *UnionFs {
g.branchCache = NewTimedCache( g.branchCache = NewTimedCache(
func(n string) interface{} { return g.getBranchAttrNoCache(n) }, func(n string) interface{} { return g.getBranchAttrNoCache(n) },
int64(options.BranchCacheTTLSecs*1e9)) int64(options.BranchCacheTTLSecs*1e9))
g.branchCache.RecurringPurge()
return g return g
} }
...@@ -300,7 +302,12 @@ func (me *UnionFs) Create(name string, flags uint32, mode uint32) (fuseFile fuse ...@@ -300,7 +302,12 @@ func (me *UnionFs) Create(name string, flags uint32, mode uint32) (fuseFile fuse
} }
func (me *UnionFs) GetAttr(name string) (a *fuse.Attr, s fuse.Status) { func (me *UnionFs) GetAttr(name string) (a *fuse.Attr, s fuse.Status) {
if name == "READONLY" { if name == _READONLY {
return nil, fuse.ENOENT
}
if name == ".drop_cache" {
me.branchCache.Purge()
me.deletionCache.DropCache()
return nil, fuse.ENOENT return nil, fuse.ENOENT
} }
if name == me.options.DeletionDirName { if name == me.options.DeletionDirName {
......
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