fusefrontend: print dirCache stats after unmount

This commit is contained in:
Jakob Unterwurzacher 2021-04-05 18:20:17 +02:00
parent 043f81dd01
commit f73aee72f8
3 changed files with 35 additions and 13 deletions

View File

@ -151,7 +151,16 @@ func (d *dirCache) expireThread() {
for {
time.Sleep(60 * time.Second)
d.Clear()
if enableStats {
d.stats()
}
}
// stats prints hit rate statistics and resets the counters. No-op if
// enableStats == false.
func (d *dirCache) stats() {
if !enableStats {
return
}
d.Lock()
lookups := d.lookups
hits := d.hits
@ -162,8 +171,6 @@ func (d *dirCache) expireThread() {
fmt.Printf("dirCache: hits=%3d lookups=%3d, rate=%3d%%\n", hits, lookups, (hits*100)/lookups)
}
}
}
}
// dbg prints a debug message. Usually disabled.
func (d *dirCache) dbg(format string, a ...interface{}) {

View File

@ -76,6 +76,12 @@ func NewRootNode(args Args, c *contentenc.ContentEnc, n nametransform.NameTransf
return rn
}
// main.doMount() calls this after unmount
func (rn *RootNode) AfterUnmount() {
// print stats before we exit
rn.dirCache.stats()
}
// mangleOpenFlags is used by Create() and Open() to convert the open flags the user
// wants to the flags we internally use to open the backing file.
// The returned flags always contain O_NOFOLLOW.

View File

@ -37,6 +37,12 @@ import (
"github.com/rfjakob/gocryptfs/internal/tlog"
)
// AfterUnmount is called after the filesystem has been unmounted.
// This can be used for cleanup and printing statistics.
type AfterUnmounter interface {
AfterUnmount()
}
// doMount mounts an encrypted directory.
// Called from main.
func doMount(args *argContainer) {
@ -116,10 +122,13 @@ func doMount(args *argContainer) {
tlog.Debug.Printf("cli args: %#v", args)
// Initialize gocryptfs (read config file, ask for password, ...)
fs, wipeKeys := initFuseFrontend(args)
// Initialize go-fuse FUSE server
srv := initGoFuse(fs, args)
// Try to wipe secret keys from memory after unmount
defer wipeKeys()
// Initialize go-fuse FUSE server
srv := initGoFuse(fs, args)
if x, ok := fs.(AfterUnmounter); ok {
defer x.AfterUnmount()
}
tlog.Info.Println(tlog.ColorGreen + "Filesystem mounted and ready." + tlog.ColorReset)
// We have been forked into the background, as evidenced by the set