Commit 2982f4ec authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Hide Debug public members behind SetDebug method.

parent 0abb4be6
......@@ -27,7 +27,7 @@ func setupFs(fs pathfs.FileSystem) (string, func()) {
panic(fmt.Sprintf("cannot mount %v", err)) // ugh - benchmark has no error methods.
}
state.SetRecordStatistics(true)
// state.Debug = true
// state.SetDebug(true)
go state.Loop()
return mountPoint, func() {
......
......@@ -67,9 +67,9 @@ func main() {
os.Exit(1)
}
pathfs.Debug = *debug
conn.Debug = *debug
state.Debug = *debug
pathfs.SetDebug(*debug)
conn.SetDebug(*debug)
state.SetDebug(*debug)
gofs.SetMountState(state)
gofs.SetFileSystemConnector(conn)
......
......@@ -44,7 +44,7 @@ func main() {
pathFs := pathfs.NewPathNodeFs(finalFs, nil)
conn := fuse.NewFileSystemConnector(pathFs, opts)
state := fuse.NewMountState(conn)
state.Debug = *debug
state.SetDebug(*debug)
mountPoint := flag.Arg(0)
......
......@@ -29,7 +29,7 @@ func main() {
fs := fuse.NewMemNodeFs(prefix)
conn := fuse.NewFileSystemConnector(fs, nil)
state := fuse.NewMountState(conn)
state.Debug = *debug
state.SetDebug(*debug)
fmt.Println("Mounting")
err := state.Mount(mountPoint, nil)
......
......@@ -32,6 +32,6 @@ func main() {
os.Exit(1)
}
state.Debug = *debug
state.SetDebug(*debug)
state.Loop()
}
......@@ -62,7 +62,7 @@ func main() {
}
state.SetRecordStatistics(*latencies)
state.Debug = *debug
state.SetDebug(*debug)
runtime.GC()
if profFile != nil {
pprof.StartCPUProfile(profFile)
......
......@@ -53,6 +53,6 @@ func main() {
log.Fatal("Mount fail:", err)
}
mountState.Debug = *debug
mountState.SetDebug(*debug)
mountState.Loop()
}
......@@ -64,7 +64,7 @@ func main() {
}
state.SetRecordStatistics(*latencies)
state.Debug = *debug
state.SetDebug(*debug)
runtime.GC()
if profFile != nil {
pprof.StartCPUProfile(profFile)
......
......@@ -33,6 +33,9 @@ type NodeFileSystem interface {
// Used for debug outputs
String() string
// If called, provide debug output through the log package.
SetDebug(debug bool)
}
// The FsNode implements the basic functionality of inodes; this is
......@@ -227,6 +230,9 @@ type DefaultFile struct{}
type RawFileSystem interface {
String() string
// If called, provide debug output through the log package.
SetDebug(debug bool)
Lookup(out *raw.EntryOut, context *Context, name string) (status Status)
Forget(nodeid, nlookup uint64)
......
......@@ -25,6 +25,10 @@ func (fs *DefaultNodeFileSystem) String() string {
return "DefaultNodeFileSystem"
}
func (fs *DefaultNodeFileSystem) SetDebug(dbg bool) {
}
////////////////////////////////////////////////////////////////
// FsNode default
......
......@@ -15,6 +15,9 @@ func (fs *DefaultRawFileSystem) String() string {
return os.Args[0]
}
func (fs *DefaultRawFileSystem) SetDebug(dbg bool) {
}
func (fs *DefaultRawFileSystem) StatFs(out *StatfsOut, context *Context) Status {
return ENOSYS
}
......
......@@ -37,7 +37,7 @@ type FileSystemConnector struct {
DefaultRawFileSystem
Debug bool
debug bool
// Callbacks for talking back to the kernel.
fsInit RawFsInit
......@@ -82,6 +82,10 @@ func NewFileSystemConnector(nodeFs NodeFileSystem, opts *FileSystemOptions) (c *
return c
}
func (c *FileSystemConnector) SetDebug(debug bool) {
c.debug = debug
}
func (c *FileSystemConnector) nextGeneration() uint64 {
return atomic.AddUint64(&c.generation, 1)
}
......@@ -281,7 +285,7 @@ func (c *FileSystemConnector) Mount(parent *Inode, name string, nodeFs NodeFileS
parent.addChild(name, node)
node.mountPoint.parentInode = parent
if c.Debug {
if c.debug {
log.Println("Mount: ", nodeFs, "on subdir", name,
"parent", c.inodeMap.Handle(&parent.handled))
}
......
......@@ -81,7 +81,7 @@ func (m *fileSystemMount) fillAttr(out *raw.AttrOut, nodeId uint64) {
func (m *fileSystemMount) getOpenedFile(h uint64) *openedFile {
b := (*openedFile)(unsafe.Pointer(m.openFiles.Decode(h)))
if m.connector.Debug && b.WithFlags.Description != "" {
if m.connector.debug && b.WithFlags.Description != "" {
log.Printf("File %d = %q", h, b.WithFlags.Description)
}
return b
......
......@@ -38,6 +38,11 @@ func (fs *lockingRawFileSystem) Lookup(out *raw.EntryOut, h *Context, name strin
return fs.RawFS.Lookup(out, h, name)
}
func (fs *lockingRawFileSystem) SetDebug(dbg bool) {
defer fs.locked()()
fs.RawFS.SetDebug(dbg)
}
func (fs *lockingRawFileSystem) Forget(nodeID uint64, nlookup uint64) {
defer fs.locked()()
fs.RawFS.Forget(nodeID, nlookup)
......
......@@ -29,12 +29,12 @@ func setupMemNodeTest(t *testing.T) (wd string, fs *MemNodeFs, clean func()) {
AttrTimeout: testTtl,
NegativeTimeout: 0.0,
})
connector.Debug = VerboseTest()
connector.SetDebug(VerboseTest())
state := NewMountState(connector)
state.Mount(mnt, nil)
//me.state.Debug = false
state.Debug = VerboseTest()
//me.state.SetDebug(false)
state.SetDebug(VerboseTest())
// Unthreaded, but in background.
go state.Loop()
......
......@@ -30,7 +30,7 @@ type MountState struct {
mountFd int
// Dump debug info onto stdout.
Debug bool
debug bool
latencies *LatencyMap
......@@ -67,6 +67,10 @@ func (ms *MountState) ThreadSanitizerSync() {
ms.reqMu.Unlock()
}
func (ms *MountState) SetDebug(dbg bool) {
ms.debug = dbg
}
func (ms *MountState) KernelSettings() raw.InitIn {
ms.reqMu.Lock()
s := ms.kernelSettings
......@@ -342,7 +346,7 @@ func (ms *MountState) handleRequest(req *request) {
req.status = ENOSYS
}
if req.status.Ok() && ms.Debug {
if req.status.Ok() && ms.debug {
log.Println(req.InputDebug())
}
......@@ -382,7 +386,7 @@ func (ms *MountState) write(req *request) Status {
}
header := req.serializeHeader(req.flatDataSize())
if ms.Debug {
if ms.debug {
log.Println(req.OutputDebug())
}
......@@ -412,7 +416,7 @@ func (ms *MountState) writeInodeNotify(entry *raw.NotifyInvalInodeOut) Status {
result := ms.write(&req)
ms.reqMu.Unlock()
if ms.Debug {
if ms.debug {
log.Println("Response: INODE_NOTIFY", result)
}
return result
......@@ -449,7 +453,7 @@ func (ms *MountState) writeDeleteNotify(parent uint64, child uint64, name string
result := ms.write(&req)
ms.reqMu.Unlock()
if ms.Debug {
if ms.debug {
log.Printf("Response: DELETE_NOTIFY: %v", result)
}
return result
......@@ -481,7 +485,7 @@ func (ms *MountState) writeEntryNotify(parent uint64, name string) Status {
result := ms.write(&req)
ms.reqMu.Unlock()
if ms.Debug {
if ms.debug {
log.Printf("Response: ENTRY_NOTIFY: %v", result)
}
return result
......
......@@ -29,7 +29,7 @@ type clientInodePath struct {
// linked files. The clientInode is never exported back to the kernel;
// it is only used to maintain a list of all names of an inode.
type PathNodeFs struct {
Debug bool
debug bool
fs FileSystem
root *pathInode
connector *fuse.FileSystemConnector
......@@ -44,6 +44,10 @@ type PathNodeFs struct {
options *PathNodeFsOptions
}
func (fs *PathNodeFs) SetDebug(dbg bool) {
fs.debug = dbg
}
func (fs *PathNodeFs) Mount(path string, nodeFs fuse.NodeFileSystem, opts *fuse.FileSystemOptions) fuse.Status {
dir, name := filepath.Split(path)
if dir != "" {
......@@ -264,7 +268,7 @@ func (n *pathInode) GetPath() string {
n.pathFs.pathLock.RUnlock()
path := string(pathBytes)
if n.pathFs.Debug {
if n.pathFs.debug {
// TODO: print node ID.
log.Printf("Inode = %q (%s)", path, n.fs.String())
}
......@@ -510,7 +514,7 @@ func (n *pathInode) createChild(isDir bool) *pathInode {
func (n *pathInode) Open(flags uint32, context *fuse.Context) (file fuse.File, code fuse.Status) {
file, code = n.fs.Open(n.GetPath(), flags, context)
if n.pathFs.Debug {
if n.pathFs.debug {
file = &fuse.WithFlags{
File: file,
Description: n.GetPath(),
......
......@@ -115,7 +115,7 @@ func xattrTestCase(t *testing.T, nm string) (mountPoint string, cleanup func())
if err != nil {
t.Fatalf("TempDir failed: %v", err)
}
state.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
go state.Loop()
return mountPoint, func() {
......
......@@ -47,9 +47,9 @@ func setupCacheTest(t *testing.T) (string, *pathfs.PathNodeFs, func()) {
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = fuse.VerboseTest()
conn.Debug = fuse.VerboseTest()
pfs.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
conn.SetDebug(fuse.VerboseTest())
pfs.SetDebug(fuse.VerboseTest())
go state.Loop()
return dir, pfs, func() {
......@@ -147,7 +147,7 @@ func TestNonseekable(t *testing.T) {
if err != nil {
t.Fatalf("failed: %v", err)
}
state.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
defer state.Unmount()
go state.Loop()
......@@ -181,9 +181,9 @@ func TestGetAttrRace(t *testing.T) {
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = fuse.VerboseTest()
conn.Debug = fuse.VerboseTest()
pfs.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
conn.SetDebug(fuse.VerboseTest())
pfs.SetDebug(fuse.VerboseTest())
go state.Loop()
defer state.Unmount()
......
......@@ -44,7 +44,7 @@ func defaultReadTest(t *testing.T) (root string, cleanup func()) {
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
go state.Loop()
return dir, func() {
......
......@@ -46,7 +46,7 @@ func TestDeleteNotify(t *testing.T) {
if err != nil {
t.Fatal(err)
}
state.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
go state.Loop()
defer state.Unmount()
......
......@@ -142,7 +142,7 @@ func setupFAttrTest(t *testing.T, fs pathfs.FileSystem) (dir string, clean func(
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
go state.Loop()
......
......@@ -27,7 +27,8 @@ type knownFs struct {
// A union for A/B/C will placed under directory A-B-C.
type AutoUnionFs struct {
pathfs.DefaultFileSystem
debug bool
lock sync.RWMutex
knownFileSystems map[string]knownFs
nameRootMap map[string]string
......@@ -269,13 +270,14 @@ func (fs *AutoUnionFs) Symlink(pointedTo string, linkName string, context *fuse.
func (fs *AutoUnionFs) SetDebug(b bool) {
// Officially, this should use locking, but we don't care
// about race conditions here.
fs.nodeFs.Debug = b
fs.connector.Debug = b
fs.mountState.Debug = b
fs.debug = b
fs.nodeFs.SetDebug(b)
fs.connector.SetDebug(b)
fs.mountState.SetDebug(b)
}
func (fs *AutoUnionFs) hasDebug() bool {
return fs.nodeFs.Debug
return fs.debug
}
func (fs *AutoUnionFs) Unlink(path string, context *fuse.Context) (code fuse.Status) {
......
......@@ -60,8 +60,8 @@ func setup(t *testing.T) (workdir string, cleanup func()) {
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = fuse.VerboseTest()
conn.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
conn.SetDebug(fuse.VerboseTest())
go state.Loop()
return wd, func() {
......
......@@ -97,8 +97,8 @@ func setupUfs(t *testing.T) (workdir string, cleanup func()) {
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
conn.Debug = fuse.VerboseTest()
state.Debug = fuse.VerboseTest()
conn.SetDebug(fuse.VerboseTest())
state.SetDebug(fuse.VerboseTest())
go state.Loop()
return wd, func() {
......@@ -1118,7 +1118,7 @@ func TestUnionFsDisappearing(t *testing.T) {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
defer state.Unmount()
state.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
go state.Loop()
log.Println("TestUnionFsDisappearing2")
......
......@@ -27,7 +27,7 @@ func setupMzfs(t *testing.T) (mountPoint string, cleanup func()) {
if err != nil {
t.Fatalf("MountNodeFileSystem failed: %v", err)
}
state.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
go state.Loop()
return mountPoint, func() {
......
......@@ -27,7 +27,7 @@ func setupZipfs(t *testing.T) (mountPoint string, cleanup func()) {
mountPoint, _ = ioutil.TempDir("", "")
state, _, err := fuse.MountNodeFileSystem(mountPoint, zfs, nil)
state.Debug = fuse.VerboseTest()
state.SetDebug(fuse.VerboseTest())
go state.Loop()
return mountPoint, func() {
......
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