Commit ee9c8261 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fs: add Options.Logger, and use throughout

Change-Id: I4fabf222a306e5d3abdfda28422b046cd75c9a8c
parent 46bf7a5b
......@@ -168,6 +168,7 @@ package fs
import (
"context"
"log"
"syscall"
"time"
......@@ -603,4 +604,10 @@ type Options struct {
// ServerCallbacks can be provided to stub out notification
// functions for testing a filesystem without mounting it.
ServerCallbacks ServerCallbacks
// Logger is a sink for diagnostic messages. Diagnostic
// messages are printed under conditions where we cannot
// return error, but want to signal something seems off
// anyway. If unset, no messages are printed.
Logger *log.Logger
}
......@@ -119,7 +119,7 @@ func (b *rawBridge) newInodeUnlocked(ops InodeEmbedder, id StableAttr, persisten
t = expSleep(t)
if i%5000 == 0 {
log.Printf("blocked for %.0f seconds waiting for FORGET on i%d", time.Since(t0).Seconds(), id.Ino)
b.logf("blocked for %.0f seconds waiting for FORGET on i%d", time.Since(t0).Seconds(), id.Ino)
}
b.mu.Lock()
}
......@@ -129,6 +129,12 @@ func (b *rawBridge) newInodeUnlocked(ops InodeEmbedder, id StableAttr, persisten
return ops.embed()
}
func (b *rawBridge) logf(format string, args ...interface{}) {
if b.options.Logger != nil {
b.options.Logger.Printf(format, args...)
}
}
// expSleep sleeps for time `t` and returns an exponentially increasing value
// for the next sleep time, capped at 1 ms.
func expSleep(t time.Duration) time.Duration {
......
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