Commit 04a0abbf authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use String() throughout for debug prints.

parent 1229efb2
...@@ -21,6 +21,9 @@ type NodeFileSystem interface { ...@@ -21,6 +21,9 @@ type NodeFileSystem interface {
OnMount(conn *FileSystemConnector) OnMount(conn *FileSystemConnector)
StatFs() *StatfsOut StatFs() *StatfsOut
Root() FsNode Root() FsNode
// Used for debug outputs
String() string
} }
type FsNode interface { type FsNode interface {
...@@ -78,7 +81,7 @@ type FsNode interface { ...@@ -78,7 +81,7 @@ type FsNode interface {
// required methods. // required methods.
type FileSystem interface { type FileSystem interface {
// Used for pretty printing. // Used for pretty printing.
Name() string String() string
// Attributes. This function is the main entry point, through // Attributes. This function is the main entry point, through
// which FUSE discovers which files and directories exist. // which FUSE discovers which files and directories exist.
......
...@@ -95,7 +95,7 @@ func (me *DefaultFileSystem) Utimens(name string, AtimeNs uint64, CtimeNs uint64 ...@@ -95,7 +95,7 @@ func (me *DefaultFileSystem) Utimens(name string, AtimeNs uint64, CtimeNs uint64
return ENOSYS return ENOSYS
} }
func (me *DefaultFileSystem) Name() string { func (me *DefaultFileSystem) String() string {
return "DefaultFileSystem" return "DefaultFileSystem"
} }
......
...@@ -26,6 +26,10 @@ func (me *DefaultNodeFileSystem) Root() FsNode { ...@@ -26,6 +26,10 @@ func (me *DefaultNodeFileSystem) Root() FsNode {
return new(DefaultFsNode) return new(DefaultFsNode)
} }
func (me *DefaultNodeFileSystem) String() string {
return "DefaultNodeFileSystem"
}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// FsNode default // FsNode default
......
...@@ -51,7 +51,9 @@ func (me *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 { ...@@ -51,7 +51,9 @@ func (me *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 {
for { for {
h := uint64(me.nextFree) h := uint64(me.nextFree)
me.nextFree++ me.nextFree++
if h < 2 { // HACK - we make sure we start with 1, so we always
// assign root to 1.
if h < 1 {
continue continue
} }
old := me.handles[h] old := me.handles[h]
......
...@@ -166,7 +166,7 @@ func (me *LoopbackFileSystem) RemoveXAttr(name string, attr string, context *Con ...@@ -166,7 +166,7 @@ func (me *LoopbackFileSystem) RemoveXAttr(name string, attr string, context *Con
return Status(Removexattr(me.GetPath(name), attr)) return Status(Removexattr(me.GetPath(name), attr))
} }
func (me *LoopbackFileSystem) Name() string { func (me *LoopbackFileSystem) String() string {
return fmt.Sprintf("LoopbackFileSystem(%s)", me.Root) return fmt.Sprintf("LoopbackFileSystem(%s)", me.Root)
} }
......
...@@ -12,13 +12,17 @@ var _ = log.Println ...@@ -12,13 +12,17 @@ var _ = log.Println
type MemNodeFs struct { type MemNodeFs struct {
DefaultNodeFileSystem DefaultNodeFileSystem
backingStore string backingStorePrefix string
root *memNode root *memNode
mutex sync.Mutex mutex sync.Mutex
nextFree int nextFree int
} }
func (me *MemNodeFs) String() string {
return fmt.Sprintf("MemNodeFs(%s)", me.backingStorePrefix)
}
func (me *MemNodeFs) Root() FsNode { func (me *MemNodeFs) Root() FsNode {
return me.root return me.root
} }
...@@ -34,13 +38,14 @@ func (me *MemNodeFs) newNode() *memNode { ...@@ -34,13 +38,14 @@ func (me *MemNodeFs) newNode() *memNode {
n.info.Mtime_ns = now n.info.Mtime_ns = now
n.info.Atime_ns = now n.info.Atime_ns = now
n.info.Ctime_ns = now n.info.Ctime_ns = now
n.info.Mode = S_IFDIR | 0777
me.nextFree++ me.nextFree++
return n return n
} }
func NewMemNodeFs(backingStore string) *MemNodeFs { func NewMemNodeFs(prefix string) *MemNodeFs {
me := &MemNodeFs{} me := &MemNodeFs{}
me.backingStore = backingStore me.backingStorePrefix = prefix
me.root = me.newNode() me.root = me.newNode()
return me return me
} }
...@@ -66,7 +71,11 @@ func (me *memNode) newNode(isdir bool) *memNode { ...@@ -66,7 +71,11 @@ func (me *memNode) newNode(isdir bool) *memNode {
} }
func (me *memNode) filename() string { func (me *memNode) filename() string {
return fmt.Sprintf("%s/%d", me.fs.backingStore, me.id) return fmt.Sprintf("%s%d", me.fs.backingStorePrefix, me.id)
}
func (me *memNode) Deletable() bool {
return false
} }
func (me *memNode) Readlink(c *Context) ([]byte, Status) { func (me *memNode) Readlink(c *Context) ([]byte, Status) {
......
package fuse package fuse
import ( import (
"fmt"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
...@@ -52,7 +53,7 @@ func (me *PathNodeFs) Mount(path string, nodeFs NodeFileSystem, opts *FileSystem ...@@ -52,7 +53,7 @@ func (me *PathNodeFs) Mount(path string, nodeFs NodeFileSystem, opts *FileSystem
if dir != "" { if dir != "" {
dir = filepath.Clean(dir) dir = filepath.Clean(dir)
} }
parent := me.Node(dir) parent := me.LookupNode(dir)
if parent == nil { if parent == nil {
return ENOENT return ENOENT
} }
...@@ -94,6 +95,10 @@ func (me *PathNodeFs) Unmount(path string) Status { ...@@ -94,6 +95,10 @@ func (me *PathNodeFs) Unmount(path string) Status {
func (me *PathNodeFs) OnUnmount() { func (me *PathNodeFs) OnUnmount() {
} }
func (me *PathNodeFs) String() string {
return fmt.Sprintf("PathNodeFs(%v)", me.fs)
}
func (me *PathNodeFs) OnMount(conn *FileSystemConnector) { func (me *PathNodeFs) OnMount(conn *FileSystemConnector) {
me.connector = conn me.connector = conn
me.fs.OnMount(me) me.fs.OnMount(me)
...@@ -111,6 +116,11 @@ func (me *PathNodeFs) Node(name string) *Inode { ...@@ -111,6 +116,11 @@ func (me *PathNodeFs) Node(name string) *Inode {
return n return n
} }
// Like node, but use Lookup to discover inodes we may not have yet.
func (me *PathNodeFs) LookupNode(name string) *Inode {
return me.connector.LookupNode(me.Root().Inode(), name)
}
func (me *PathNodeFs) Path(node *Inode) string { func (me *PathNodeFs) Path(node *Inode) string {
pNode := node.FsNode().(*pathInode) pNode := node.FsNode().(*pathInode)
return pNode.GetPath() return pNode.GetPath()
......
package fuse package fuse
import ( import (
"fmt"
"os" "os"
) )
...@@ -77,6 +78,10 @@ func (me *ReadonlyFileSystem) OnUnmount() { ...@@ -77,6 +78,10 @@ func (me *ReadonlyFileSystem) OnUnmount() {
me.FileSystem.OnUnmount() me.FileSystem.OnUnmount()
} }
func (me *ReadonlyFileSystem) String() string {
return fmt.Sprintf("ReadonlyFileSystem(%v)", me.FileSystem)
}
func (me *ReadonlyFileSystem) Access(name string, mode uint32, context *Context) (code Status) { func (me *ReadonlyFileSystem) Access(name string, mode uint32, context *Context) (code Status) {
return me.FileSystem.Access(name, mode, context) return me.FileSystem.Access(name, mode, context)
} }
......
...@@ -113,7 +113,7 @@ func (me *SetAttrIn) String() string { ...@@ -113,7 +113,7 @@ func (me *SetAttrIn) String() string {
func (me *Attr) String() string { func (me *Attr) String() string {
return fmt.Sprintf( return fmt.Sprintf(
"{0%o S=%d L=%d "+ "{M0%o S=%d L=%d "+
"%d:%d "+ "%d:%d "+
"%d*%d %d:%d "+ "%d*%d %d:%d "+
"A %d.%09d "+ "A %d.%09d "+
...@@ -132,6 +132,12 @@ func (me *CreateIn) String() string { ...@@ -132,6 +132,12 @@ func (me *CreateIn) String() string {
flagString(openFlagNames, int(me.Flags), "O_RDONLY"), me.Umask) flagString(openFlagNames, int(me.Flags), "O_RDONLY"), me.Umask)
} }
func (me *EntryOut) String() string {
return fmt.Sprintf("{%d E%d.%09d A%d.%09d %v}",
me.NodeId, me.EntryValid, me.EntryValidNsec,
me.AttrValid, me.AttrValidNsec, &me.Attr)
}
func (me *CreateOut) String() string { func (me *CreateOut) String() string {
return fmt.Sprintf("{%v %v}", &me.EntryOut, &me.OpenOut) return fmt.Sprintf("{%v %v}", &me.EntryOut, &me.OpenOut)
} }
......
...@@ -66,7 +66,7 @@ func NewAutoUnionFs(directory string, options AutoUnionFsOptions) *AutoUnionFs { ...@@ -66,7 +66,7 @@ func NewAutoUnionFs(directory string, options AutoUnionFsOptions) *AutoUnionFs {
return a return a
} }
func (me *AutoUnionFs) Name() string { func (me *AutoUnionFs) String() string {
return fmt.Sprintf("AutoUnionFs(%s)", me.root) return fmt.Sprintf("AutoUnionFs(%s)", me.root)
} }
...@@ -110,7 +110,7 @@ func (me *AutoUnionFs) createFs(name string, roots []string) fuse.Status { ...@@ -110,7 +110,7 @@ func (me *AutoUnionFs) createFs(name string, roots []string) fuse.Status {
return fuse.EPERM return fuse.EPERM
} }
log.Printf("Adding workspace %v for roots %v", name, ufs.Name()) log.Printf("Adding workspace %v for roots %v", name, ufs.String())
nfs := fuse.NewPathNodeFs(ufs, &me.options.PathNodeFsOptions) nfs := fuse.NewPathNodeFs(ufs, &me.options.PathNodeFsOptions)
code := me.nodeFs.Mount(name, nfs, &me.options.FileSystemOptions) code := me.nodeFs.Mount(name, nfs, &me.options.FileSystemOptions)
if code.Ok() { if code.Ok() {
......
...@@ -140,13 +140,13 @@ func (me *CachingFileSystem) OpenDir(name string, context *fuse.Context) (stream ...@@ -140,13 +140,13 @@ func (me *CachingFileSystem) OpenDir(name string, context *fuse.Context) (stream
return nil, r.Status return nil, r.Status
} }
func (me *CachingFileSystem) Name() string { func (me *CachingFileSystem) String() string {
return fmt.Sprintf("CachingFileSystem(%s)", me.FileSystem.Name()) return fmt.Sprintf("CachingFileSystem(%v)", me.FileSystem)
} }
func (me *CachingFileSystem) Open(name string, flags uint32, context *fuse.Context) (f fuse.File, status fuse.Status) { func (me *CachingFileSystem) Open(name string, flags uint32, context *fuse.Context) (f fuse.File, status fuse.Status) {
if flags&fuse.O_ANYWRITE != 0 && name == _DROP_CACHE { if flags&fuse.O_ANYWRITE != 0 && name == _DROP_CACHE {
log.Println("Dropping cache for", me.Name()) log.Println("Dropping cache for", me)
me.DropCache() me.DropCache()
} }
return me.FileSystem.Open(name, flags, context) return me.FileSystem.Open(name, flags, context)
......
...@@ -13,7 +13,7 @@ import ( ...@@ -13,7 +13,7 @@ import (
func newDirnameMap(fs fuse.FileSystem, dir string) map[string]bool { func newDirnameMap(fs fuse.FileSystem, dir string) map[string]bool {
stream, code := fs.OpenDir(dir, nil) stream, code := fs.OpenDir(dir, nil)
if !code.Ok() { if !code.Ok() {
log.Printf("newDirnameMap(%s): %v %v", fs.Name(), dir, code) log.Printf("newDirnameMap(%v): %v %v", fs, dir, code)
return nil return nil
} }
......
...@@ -918,7 +918,7 @@ func (me *UnionFs) DropSubFsCaches() { ...@@ -918,7 +918,7 @@ func (me *UnionFs) DropSubFsCaches() {
func (me *UnionFs) Open(name string, flags uint32, context *fuse.Context) (fuseFile fuse.File, status fuse.Status) { func (me *UnionFs) Open(name string, flags uint32, context *fuse.Context) (fuseFile fuse.File, status fuse.Status) {
if name == _DROP_CACHE { if name == _DROP_CACHE {
if flags&fuse.O_ANYWRITE != 0 { if flags&fuse.O_ANYWRITE != 0 {
log.Println("Forced cache drop on", me.Name()) log.Println("Forced cache drop on", me)
me.DropBranchCache(nil) me.DropBranchCache(nil)
me.DropDeletionCache() me.DropDeletionCache()
me.DropSubFsCaches() me.DropSubFsCaches()
...@@ -949,10 +949,10 @@ func (me *UnionFs) Open(name string, flags uint32, context *fuse.Context) (fuseF ...@@ -949,10 +949,10 @@ func (me *UnionFs) Open(name string, flags uint32, context *fuse.Context) (fuseF
return fuseFile, status return fuseFile, status
} }
func (me *UnionFs) Name() string { func (me *UnionFs) String() string {
names := []string{} names := []string{}
for _, fs := range me.fileSystems { for _, fs := range me.fileSystems {
names = append(names, fs.Name()) names = append(names, fs.String())
} }
return fmt.Sprintf("%v", names) return fmt.Sprintf("%v", names)
} }
......
...@@ -45,7 +45,7 @@ func NewMultiZipFs() *MultiZipFs { ...@@ -45,7 +45,7 @@ func NewMultiZipFs() *MultiZipFs {
return m return m
} }
func (me *MultiZipFs) Name() string { func (me *MultiZipFs) String() string {
return "MultiZipFs" return "MultiZipFs"
} }
......
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