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 {
OnMount(conn *FileSystemConnector)
StatFs() *StatfsOut
Root() FsNode
// Used for debug outputs
String() string
}
type FsNode interface {
......@@ -78,7 +81,7 @@ type FsNode interface {
// required methods.
type FileSystem interface {
// Used for pretty printing.
Name() string
String() string
// Attributes. This function is the main entry point, through
// which FUSE discovers which files and directories exist.
......
......@@ -95,7 +95,7 @@ func (me *DefaultFileSystem) Utimens(name string, AtimeNs uint64, CtimeNs uint64
return ENOSYS
}
func (me *DefaultFileSystem) Name() string {
func (me *DefaultFileSystem) String() string {
return "DefaultFileSystem"
}
......
......@@ -26,6 +26,10 @@ func (me *DefaultNodeFileSystem) Root() FsNode {
return new(DefaultFsNode)
}
func (me *DefaultNodeFileSystem) String() string {
return "DefaultNodeFileSystem"
}
////////////////////////////////////////////////////////////////
// FsNode default
......
......@@ -51,7 +51,9 @@ func (me *portableHandleMap) Register(obj *Handled, asInt interface{}) uint64 {
for {
h := uint64(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
}
old := me.handles[h]
......
......@@ -166,7 +166,7 @@ func (me *LoopbackFileSystem) RemoveXAttr(name string, attr string, context *Con
return Status(Removexattr(me.GetPath(name), attr))
}
func (me *LoopbackFileSystem) Name() string {
func (me *LoopbackFileSystem) String() string {
return fmt.Sprintf("LoopbackFileSystem(%s)", me.Root)
}
......
......@@ -12,13 +12,17 @@ var _ = log.Println
type MemNodeFs struct {
DefaultNodeFileSystem
backingStore string
backingStorePrefix string
root *memNode
mutex sync.Mutex
nextFree int
}
func (me *MemNodeFs) String() string {
return fmt.Sprintf("MemNodeFs(%s)", me.backingStorePrefix)
}
func (me *MemNodeFs) Root() FsNode {
return me.root
}
......@@ -34,13 +38,14 @@ func (me *MemNodeFs) newNode() *memNode {
n.info.Mtime_ns = now
n.info.Atime_ns = now
n.info.Ctime_ns = now
n.info.Mode = S_IFDIR | 0777
me.nextFree++
return n
}
func NewMemNodeFs(backingStore string) *MemNodeFs {
func NewMemNodeFs(prefix string) *MemNodeFs {
me := &MemNodeFs{}
me.backingStore = backingStore
me.backingStorePrefix = prefix
me.root = me.newNode()
return me
}
......@@ -66,7 +71,11 @@ func (me *memNode) newNode(isdir bool) *memNode {
}
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) {
......
package fuse
import (
"fmt"
"log"
"os"
"path/filepath"
......@@ -52,7 +53,7 @@ func (me *PathNodeFs) Mount(path string, nodeFs NodeFileSystem, opts *FileSystem
if dir != "" {
dir = filepath.Clean(dir)
}
parent := me.Node(dir)
parent := me.LookupNode(dir)
if parent == nil {
return ENOENT
}
......@@ -94,6 +95,10 @@ func (me *PathNodeFs) Unmount(path string) Status {
func (me *PathNodeFs) OnUnmount() {
}
func (me *PathNodeFs) String() string {
return fmt.Sprintf("PathNodeFs(%v)", me.fs)
}
func (me *PathNodeFs) OnMount(conn *FileSystemConnector) {
me.connector = conn
me.fs.OnMount(me)
......@@ -111,6 +116,11 @@ func (me *PathNodeFs) Node(name string) *Inode {
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 {
pNode := node.FsNode().(*pathInode)
return pNode.GetPath()
......
package fuse
import (
"fmt"
"os"
)
......@@ -77,6 +78,10 @@ func (me *ReadonlyFileSystem) 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) {
return me.FileSystem.Access(name, mode, context)
}
......
......@@ -113,7 +113,7 @@ func (me *SetAttrIn) String() string {
func (me *Attr) String() string {
return fmt.Sprintf(
"{0%o S=%d L=%d "+
"{M0%o S=%d L=%d "+
"%d:%d "+
"%d*%d %d:%d "+
"A %d.%09d "+
......@@ -132,6 +132,12 @@ func (me *CreateIn) String() string {
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 {
return fmt.Sprintf("{%v %v}", &me.EntryOut, &me.OpenOut)
}
......
......@@ -66,7 +66,7 @@ func NewAutoUnionFs(directory string, options AutoUnionFsOptions) *AutoUnionFs {
return a
}
func (me *AutoUnionFs) Name() string {
func (me *AutoUnionFs) String() string {
return fmt.Sprintf("AutoUnionFs(%s)", me.root)
}
......@@ -110,7 +110,7 @@ func (me *AutoUnionFs) createFs(name string, roots []string) fuse.Status {
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)
code := me.nodeFs.Mount(name, nfs, &me.options.FileSystemOptions)
if code.Ok() {
......
......@@ -140,13 +140,13 @@ func (me *CachingFileSystem) OpenDir(name string, context *fuse.Context) (stream
return nil, r.Status
}
func (me *CachingFileSystem) Name() string {
return fmt.Sprintf("CachingFileSystem(%s)", me.FileSystem.Name())
func (me *CachingFileSystem) String() string {
return fmt.Sprintf("CachingFileSystem(%v)", me.FileSystem)
}
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 {
log.Println("Dropping cache for", me.Name())
log.Println("Dropping cache for", me)
me.DropCache()
}
return me.FileSystem.Open(name, flags, context)
......
......@@ -13,7 +13,7 @@ import (
func newDirnameMap(fs fuse.FileSystem, dir string) map[string]bool {
stream, code := fs.OpenDir(dir, nil)
if !code.Ok() {
log.Printf("newDirnameMap(%s): %v %v", fs.Name(), dir, code)
log.Printf("newDirnameMap(%v): %v %v", fs, dir, code)
return nil
}
......
......@@ -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) {
if name == _DROP_CACHE {
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.DropDeletionCache()
me.DropSubFsCaches()
......@@ -949,10 +949,10 @@ func (me *UnionFs) Open(name string, flags uint32, context *fuse.Context) (fuseF
return fuseFile, status
}
func (me *UnionFs) Name() string {
func (me *UnionFs) String() string {
names := []string{}
for _, fs := range me.fileSystems {
names = append(names, fs.Name())
names = append(names, fs.String())
}
return fmt.Sprintf("%v", names)
}
......
......@@ -45,7 +45,7 @@ func NewMultiZipFs() *MultiZipFs {
return m
}
func (me *MultiZipFs) Name() string {
func (me *MultiZipFs) String() string {
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