aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-04-05 18:20:17 +0200
committerJakob Unterwurzacher2021-04-05 18:20:17 +0200
commitf73aee72f87ba6cd3e46184ae75824fd38250f04 (patch)
tree270b10742ea9f4fb70795becb9e44d862480048e
parent043f81dd0129b78ec7d4553843f90203535fa406 (diff)
fusefrontend: print dirCache stats after unmount
-rw-r--r--internal/fusefrontend/dircache.go29
-rw-r--r--internal/fusefrontend/root_node.go6
-rw-r--r--mount.go13
3 files changed, 35 insertions, 13 deletions
diff --git a/internal/fusefrontend/dircache.go b/internal/fusefrontend/dircache.go
index ea0d1c8..6732de1 100644
--- a/internal/fusefrontend/dircache.go
+++ b/internal/fusefrontend/dircache.go
@@ -151,17 +151,24 @@ func (d *dirCache) expireThread() {
for {
time.Sleep(60 * time.Second)
d.Clear()
- if enableStats {
- d.Lock()
- lookups := d.lookups
- hits := d.hits
- d.lookups = 0
- d.hits = 0
- d.Unlock()
- if lookups > 0 {
- fmt.Printf("dirCache: hits=%3d lookups=%3d, rate=%3d%%\n", hits, lookups, (hits*100)/lookups)
- }
- }
+ 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
+ d.lookups = 0
+ d.hits = 0
+ d.Unlock()
+ if lookups > 0 {
+ fmt.Printf("dirCache: hits=%3d lookups=%3d, rate=%3d%%\n", hits, lookups, (hits*100)/lookups)
}
}
diff --git a/internal/fusefrontend/root_node.go b/internal/fusefrontend/root_node.go
index 2b4ad24..3a2ecf3 100644
--- a/internal/fusefrontend/root_node.go
+++ b/internal/fusefrontend/root_node.go
@@ -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.
diff --git a/mount.go b/mount.go
index 571b51b..1194104 100644
--- a/mount.go
+++ b/mount.go
@@ -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