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 { for {
time.Sleep(60 * time.Second) time.Sleep(60 * time.Second)
d.Clear() 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() d.Lock()
lookups := d.lookups lookups := d.lookups
hits := d.hits 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) fmt.Printf("dirCache: hits=%3d lookups=%3d, rate=%3d%%\n", hits, lookups, (hits*100)/lookups)
} }
} }
}
}
// dbg prints a debug message. Usually disabled. // dbg prints a debug message. Usually disabled.
func (d *dirCache) dbg(format string, a ...interface{}) { 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 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 // 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. // wants to the flags we internally use to open the backing file.
// The returned flags always contain O_NOFOLLOW. // The returned flags always contain O_NOFOLLOW.

View File

@ -37,6 +37,12 @@ import (
"github.com/rfjakob/gocryptfs/internal/tlog" "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. // doMount mounts an encrypted directory.
// Called from main. // Called from main.
func doMount(args *argContainer) { func doMount(args *argContainer) {
@ -116,10 +122,13 @@ func doMount(args *argContainer) {
tlog.Debug.Printf("cli args: %#v", args) tlog.Debug.Printf("cli args: %#v", args)
// Initialize gocryptfs (read config file, ask for password, ...) // Initialize gocryptfs (read config file, ask for password, ...)
fs, wipeKeys := initFuseFrontend(args) fs, wipeKeys := initFuseFrontend(args)
// Initialize go-fuse FUSE server
srv := initGoFuse(fs, args)
// Try to wipe secret keys from memory after unmount // Try to wipe secret keys from memory after unmount
defer wipeKeys() 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) tlog.Info.Println(tlog.ColorGreen + "Filesystem mounted and ready." + tlog.ColorReset)
// We have been forked into the background, as evidenced by the set // We have been forked into the background, as evidenced by the set