mount, mountlib: move function tracing into mount

This commit is contained in:
Nick Craig-Wood 2017-05-09 11:39:33 +01:00
parent 50e79bc087
commit 115ac00222
10 changed files with 75 additions and 48 deletions

View file

@ -40,7 +40,8 @@ type Dir struct {
var _ fusefs.Node = (*Dir)(nil)
// Attr updates the attributes of a directory
func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) error {
func (d *Dir) Attr(ctx context.Context, a *fuse.Attr) (err error) {
defer fs.Trace(d, "")("attr=%+v, err=%v", a, &err)
a.Gid = gid
a.Uid = uid
a.Mode = os.ModeDir | dirPerms
@ -59,6 +60,7 @@ var _ fusefs.NodeSetattrer = (*Dir)(nil)
// Setattr handles attribute changes from FUSE. Currently supports ModTime only.
func (d *Dir) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) (err error) {
defer fs.Trace(d, "stat=%+v", req)("err=%v", &err)
if noModTime {
return nil
}
@ -82,6 +84,7 @@ var _ fusefs.NodeRequestLookuper = (*Dir)(nil)
//
// Lookup need not to handle the names "." and "..".
func (d *Dir) Lookup(ctx context.Context, req *fuse.LookupRequest, resp *fuse.LookupResponse) (node fusefs.Node, err error) {
defer fs.Trace(d, "name=%q", req.Name)("node=%+v, err=%v", &node, &err)
mnode, err := d.Dir.Lookup(req.Name)
if err != nil {
return nil, translateError(err)
@ -100,6 +103,8 @@ var _ fusefs.HandleReadDirAller = (*Dir)(nil)
// ReadDirAll reads the contents of the directory
func (d *Dir) ReadDirAll(ctx context.Context) (dirents []fuse.Dirent, err error) {
itemsRead := -1
defer fs.Trace(d, "")("item=%d, err=%v", &itemsRead, &err)
items, err := d.Dir.ReadDirAll()
if err != nil {
return nil, translateError(err)
@ -124,13 +129,15 @@ func (d *Dir) ReadDirAll(ctx context.Context) (dirents []fuse.Dirent, err error)
}
dirents = append(dirents, dirent)
}
itemsRead = len(dirents)
return dirents, nil
}
var _ fusefs.NodeCreater = (*Dir)(nil)
// Create makes a new file
func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (fusefs.Node, fusefs.Handle, error) {
func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.CreateResponse) (node fusefs.Node, handle fusefs.Handle, err error) {
defer fs.Trace(d, "name=%q", req.Name)("node=%v, handle=%v, err=%v", &node, &handle, &err)
file, fh, err := d.Dir.Create(req.Name)
if err != nil {
return nil, nil, translateError(err)
@ -141,7 +148,8 @@ func (d *Dir) Create(ctx context.Context, req *fuse.CreateRequest, resp *fuse.Cr
var _ fusefs.NodeMkdirer = (*Dir)(nil)
// Mkdir creates a new directory
func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (fusefs.Node, error) {
func (d *Dir) Mkdir(ctx context.Context, req *fuse.MkdirRequest) (node fusefs.Node, err error) {
defer fs.Trace(d, "name=%q", req.Name)("node=%+v, err=%v", &node, &err)
dir, err := d.Dir.Mkdir(req.Name)
if err != nil {
return nil, translateError(err)
@ -154,8 +162,9 @@ var _ fusefs.NodeRemover = (*Dir)(nil)
// Remove removes the entry with the given name from
// the receiver, which must be a directory. The entry to be removed
// may correspond to a file (unlink) or to a directory (rmdir).
func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
err := d.Dir.Remove(req.Name)
func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) (err error) {
defer fs.Trace(d, "name=%q", req.Name)("err=%v", &err)
err = d.Dir.Remove(req.Name)
if err != nil {
return translateError(err)
}
@ -166,13 +175,14 @@ func (d *Dir) Remove(ctx context.Context, req *fuse.RemoveRequest) error {
var _ fusefs.NodeRenamer = (*Dir)(nil)
// Rename the file
func (d *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fusefs.Node) error {
func (d *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fusefs.Node) (err error) {
defer fs.Trace(d, "oldName=%q, newName=%q, newDir=%+v", req.OldName, req.NewName, newDir)("err=%v", &err)
destDir, ok := newDir.(*Dir)
if !ok {
return errors.Errorf("Unknown Dir type %T", newDir)
}
err := d.Dir.Rename(req.OldName, req.NewName, destDir.Dir)
err = d.Dir.Rename(req.OldName, req.NewName, destDir.Dir)
if err != nil {
return translateError(err)
}
@ -184,8 +194,9 @@ func (d *Dir) Rename(ctx context.Context, req *fuse.RenameRequest, newDir fusefs
var _ fusefs.NodeFsyncer = (*Dir)(nil)
// Fsync the directory
func (d *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
err := d.Dir.Fsync()
func (d *Dir) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) {
defer fs.Trace(d, "")("err=%v", &err)
err = d.Dir.Fsync()
if err != nil {
return translateError(err)
}

View file

@ -8,6 +8,7 @@ import (
"bazil.org/fuse"
fusefs "bazil.org/fuse/fs"
"github.com/ncw/rclone/cmd/mountlib"
"github.com/ncw/rclone/fs"
"github.com/pkg/errors"
"golang.org/x/net/context"
)
@ -27,7 +28,8 @@ type File struct {
var _ fusefs.Node = (*File)(nil)
// Attr fills out the attributes for the file
func (f *File) Attr(ctx context.Context, a *fuse.Attr) error {
func (f *File) Attr(ctx context.Context, a *fuse.Attr) (err error) {
defer fs.Trace(f, "")("a=%+v, err=%v", a, &err)
modTime, Size, Blocks, err := f.File.Attr(noModTime)
if err != nil {
return translateError(err)
@ -48,11 +50,11 @@ func (f *File) Attr(ctx context.Context, a *fuse.Attr) error {
var _ fusefs.NodeSetattrer = (*File)(nil)
// Setattr handles attribute changes from FUSE. Currently supports ModTime only.
func (f *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) error {
func (f *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *fuse.SetattrResponse) (err error) {
defer fs.Trace(f, "a=%+v", req)("err=%v", &err)
if noModTime {
return nil
}
var err error
if req.Valid.MtimeNow() {
err = f.File.SetModTime(time.Now())
} else if req.Valid.Mtime() {
@ -66,6 +68,7 @@ var _ fusefs.NodeOpener = (*File)(nil)
// Open the file for read or write
func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenResponse) (fh fusefs.Handle, err error) {
defer fs.Trace(f, "flags=%v", req.Flags)("fh=%v, err=%v", &fh, &err)
switch {
case req.Flags.IsReadOnly():
if noSeek {
@ -109,6 +112,7 @@ var _ fusefs.NodeFsyncer = (*File)(nil)
// Fsync the file
//
// Note that we don't do anything except return OK
func (f *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) error {
func (f *File) Fsync(ctx context.Context, req *fuse.FsyncRequest) (err error) {
defer fs.Trace(f, "")("err=%v", &err)
return nil
}

View file

@ -38,7 +38,8 @@ func NewFS(f fs.Fs) *FS {
}
// Root returns the root node
func (f *FS) Root() (fusefs.Node, error) {
func (f *FS) Root() (node fusefs.Node, err error) {
defer fs.Trace("", "")("node=%+v, err=%v", &node, &err)
root, err := f.FS.Root()
if err != nil {
return nil, translateError(err)
@ -51,7 +52,8 @@ var _ fusefs.FSStatfser = (*FS)(nil)
// Statfs is called to obtain file system metadata.
// It should write that data to resp.
func (f *FS) Statfs(ctx context.Context, req *fuse.StatfsRequest, resp *fuse.StatfsResponse) error {
func (f *FS) Statfs(ctx context.Context, req *fuse.StatfsRequest, resp *fuse.StatfsResponse) (err error) {
defer fs.Trace("", "")("stat=%+v, err=%v", resp, &err)
const blockSize = 4096
const fsBlocks = (1 << 50) / blockSize
resp.Blocks = fsBlocks // Total data blocks in file system.

View file

@ -6,6 +6,7 @@ import (
"bazil.org/fuse"
fusefs "bazil.org/fuse/fs"
"github.com/ncw/rclone/cmd/mountlib"
"github.com/ncw/rclone/fs"
"golang.org/x/net/context"
)
@ -28,11 +29,14 @@ var _ fusefs.HandleReader = (*ReadFileHandle)(nil)
// Read from the file handle
func (fh *ReadFileHandle) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) (err error) {
dataRead := -1
defer fs.Trace(fh, "len=%d, offset=%d", req.Size, req.Offset)("read=%d, err=%v", &dataRead, &err)
data, err := fh.ReadFileHandle.Read(int64(req.Size), req.Offset)
if err != nil {
return translateError(err)
}
resp.Data = data
dataRead = len(data)
return nil
}
@ -42,7 +46,8 @@ var _ fusefs.HandleFlusher = (*ReadFileHandle)(nil)
// Flush is called each time the file or directory is closed.
// Because there can be multiple file descriptors referring to a
// single opened file, Flush can be called multiple times.
func (fh *ReadFileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error {
func (fh *ReadFileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) (err error) {
defer fs.Trace(fh, "")("err=%v", &err)
return translateError(fh.ReadFileHandle.Flush())
}
@ -52,6 +57,7 @@ var _ fusefs.HandleReleaser = (*ReadFileHandle)(nil)
//
// It isn't called directly from userspace so the error is ignored by
// the kernel
func (fh *ReadFileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) error {
func (fh *ReadFileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) (err error) {
defer fs.Trace(fh, "")("err=%v", &err)
return translateError(fh.ReadFileHandle.Release())
}

View file

@ -8,6 +8,7 @@ import (
"bazil.org/fuse"
fusefs "bazil.org/fuse/fs"
"github.com/ncw/rclone/cmd/mountlib"
"github.com/ncw/rclone/fs"
"golang.org/x/net/context"
)
@ -25,7 +26,8 @@ var _ fusefs.Handle = (*WriteFileHandle)(nil)
var _ fusefs.HandleWriter = (*WriteFileHandle)(nil)
// Write data to the file handle
func (fh *WriteFileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) error {
func (fh *WriteFileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *fuse.WriteResponse) (err error) {
defer fs.Trace(fh, "len=%d, offset=%d", len(req.Data), req.Offset)("written=%d, err=%v", &resp.Size, &err)
n, err := fh.WriteFileHandle.Write(req.Data, req.Offset)
if err != nil {
return translateError(err)
@ -49,7 +51,8 @@ func (fh *WriteFileHandle) Write(ctx context.Context, req *fuse.WriteRequest, re
//
// Filesystems shouldn't assume that flush will always be called after
// some writes, or that if will be called at all.
func (fh *WriteFileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error {
func (fh *WriteFileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) (err error) {
defer fs.Trace(fh, "")("err=%v", &err)
return translateError(fh.WriteFileHandle.Flush())
}
@ -59,6 +62,7 @@ var _ fusefs.HandleReleaser = (*WriteFileHandle)(nil)
//
// It isn't called directly from userspace so the error is ignored by
// the kernel
func (fh *WriteFileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) error {
func (fh *WriteFileHandle) Release(ctx context.Context, req *fuse.ReleaseRequest) (err error) {
defer fs.Trace(fh, "")("err=%v", &err)
return translateError(fh.WriteFileHandle.Release())
}

View file

@ -149,7 +149,7 @@ func (d *Dir) readDir() error {
defer d.mu.Unlock()
when := time.Now()
if d.read.IsZero() {
fs.Debugf(d.path, "Reading directory")
// fs.Debugf(d.path, "Reading directory")
} else {
age := when.Sub(d.read)
if age < dirCacheTime {
@ -236,7 +236,7 @@ func (d *Dir) isEmpty() (bool, error) {
// ModTime returns the modification time of the directory
func (d *Dir) ModTime() time.Time {
fs.Debugf(d.path, "Dir.ModTime %v", d.modTime)
// fs.Debugf(d.path, "Dir.ModTime %v", d.modTime)
return d.modTime
}
@ -281,7 +281,7 @@ func (d *Dir) lookupNode(leaf string) (item *DirEntry, err error) {
// Lookup need not to handle the names "." and "..".
func (d *Dir) Lookup(name string) (node Node, err error) {
path := path.Join(d.path, name)
fs.Debugf(path, "Dir.Lookup")
// fs.Debugf(path, "Dir.Lookup")
item, err := d.lookupNode(name)
if err != nil {
if err != ENOENT {
@ -289,13 +289,13 @@ func (d *Dir) Lookup(name string) (node Node, err error) {
}
return nil, err
}
fs.Debugf(path, "Dir.Lookup OK")
// fs.Debugf(path, "Dir.Lookup OK")
return item.Node, nil
}
// ReadDirAll reads the contents of the directory
func (d *Dir) ReadDirAll() (items []*DirEntry, err error) {
fs.Debugf(d.path, "Dir.ReadDirAll")
// fs.Debugf(d.path, "Dir.ReadDirAll")
err = d.readDir()
if err != nil {
fs.Debugf(d.path, "Dir.ReadDirAll error: %v", err)
@ -306,14 +306,14 @@ func (d *Dir) ReadDirAll() (items []*DirEntry, err error) {
for _, item := range d.items {
items = append(items, item)
}
fs.Debugf(d.path, "Dir.ReadDirAll OK with %d entries", len(items))
// fs.Debugf(d.path, "Dir.ReadDirAll OK with %d entries", len(items))
return items, nil
}
// Create makes a new file
func (d *Dir) Create(name string) (*File, *WriteFileHandle, error) {
path := path.Join(d.path, name)
fs.Debugf(path, "Dir.Create")
// fs.Debugf(path, "Dir.Create")
src := newCreateInfo(d.f, path)
// This gets added to the directory when the file is written
file := newFile(d, nil, name)
@ -322,14 +322,14 @@ func (d *Dir) Create(name string) (*File, *WriteFileHandle, error) {
fs.Errorf(path, "Dir.Create error: %v", err)
return nil, nil, err
}
fs.Debugf(path, "Dir.Create OK")
// fs.Debugf(path, "Dir.Create OK")
return file, fh, nil
}
// Mkdir creates a new directory
func (d *Dir) Mkdir(name string) (*Dir, error) {
path := path.Join(d.path, name)
fs.Debugf(path, "Dir.Mkdir")
// fs.Debugf(path, "Dir.Mkdir")
err := d.f.Mkdir(path)
if err != nil {
fs.Errorf(path, "Dir.Mkdir failed to create directory: %v", err)
@ -341,7 +341,7 @@ func (d *Dir) Mkdir(name string) (*Dir, error) {
}
dir := newDir(d.fsys, d.f, fsDir)
d.addObject(fsDir, dir)
fs.Debugf(path, "Dir.Mkdir OK")
// fs.Debugf(path, "Dir.Mkdir OK")
return dir, nil
}
@ -350,7 +350,7 @@ func (d *Dir) Mkdir(name string) (*Dir, error) {
// may correspond to a file (unlink) or to a directory (rmdir).
func (d *Dir) Remove(name string) error {
path := path.Join(d.path, name)
fs.Debugf(path, "Dir.Remove")
// fs.Debugf(path, "Dir.Remove")
item, err := d.lookupNode(name)
if err != nil {
fs.Errorf(path, "Dir.Remove error: %v", err)
@ -387,7 +387,7 @@ func (d *Dir) Remove(name string) error {
}
// Remove the item from the directory listing
d.delObject(name)
fs.Debugf(path, "Dir.Remove OK")
// fs.Debugf(path, "Dir.Remove OK")
return nil
}
@ -395,7 +395,7 @@ func (d *Dir) Remove(name string) error {
func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
oldPath := path.Join(d.path, oldName)
newPath := path.Join(destDir.path, newName)
fs.Debugf(oldPath, "Dir.Rename to %q", newPath)
// fs.Debugf(oldPath, "Dir.Rename to %q", newPath)
oldItem, err := d.lookupNode(oldName)
if err != nil {
fs.Errorf(oldPath, "Dir.Rename error: %v", err)
@ -462,7 +462,7 @@ func (d *Dir) Rename(oldName, newName string, destDir *Dir) error {
d.delObject(oldName)
destDir.addObject(newObj, oldNode)
fs.Debugf(newPath, "Dir.Rename renamed from %q", oldPath)
// fs.Debugf(newPath, "Dir.Rename renamed from %q", oldPath)
return nil
}

View file

@ -87,7 +87,7 @@ func (f *File) Attr(noModTime bool) (modTime time.Time, Size, Blocks uint64, err
}
}
Blocks = (Size + 511) / 512
fs.Debugf(f.o, "File.Attr modTime=%v, Size=%d, Blocks=%v", modTime, Size, Blocks)
// fs.Debugf(f.o, "File.Attr modTime=%v, Size=%d, Blocks=%v", modTime, Size, Blocks)
return
}
@ -174,7 +174,7 @@ func (f *File) OpenRead() (fh *ReadFileHandle, err error) {
if err != nil {
return nil, err
}
fs.Debugf(o, "File.OpenRead")
// fs.Debugf(o, "File.OpenRead")
fh, err = newReadFileHandle(f, o)
err = errors.Wrap(err, "open for read")
@ -193,7 +193,7 @@ func (f *File) OpenWrite() (fh *WriteFileHandle, err error) {
if err != nil {
return nil, err
}
fs.Debugf(o, "File.OpenWrite")
// fs.Debugf(o, "File.OpenWrite")
src := newCreateInfo(f.d.f, o.Remote())
fh, err = newWriteFileHandle(f.d, f, src)

View file

@ -68,7 +68,7 @@ func (fsys *FS) NoChecksum() *FS {
// Root returns the root node
func (fsys *FS) Root() (*Dir, error) {
fs.Debugf(fsys.f, "Root()")
// fs.Debugf(fsys.f, "Root()")
return fsys.root, nil
}

View file

@ -106,7 +106,7 @@ func (fh *ReadFileHandle) seek(offset int64, reopen bool) (err error) {
func (fh *ReadFileHandle) Read(reqSize, reqOffset int64) (respData []byte, err error) {
fh.mu.Lock()
defer fh.mu.Unlock()
fs.Debugf(fh.o, "ReadFileHandle.Read size %d offset %d", reqSize, reqOffset)
// fs.Debugf(fh.o, "ReadFileHandle.Read size %d offset %d", reqSize, reqOffset)
if fh.closed {
fs.Errorf(fh.o, "ReadFileHandle.Read error: %v", EBADF)
return nil, EBADF
@ -165,7 +165,7 @@ func (fh *ReadFileHandle) Read(reqSize, reqOffset int64) (respData []byte, err e
} else {
respData = buf[:n]
fh.offset = newOffset
fs.Debugf(fh.o, "ReadFileHandle.Read OK")
// fs.Debugf(fh.o, "ReadFileHandle.Read OK")
if fh.hash != nil {
_, err = fh.hash.Write(respData)
@ -220,14 +220,14 @@ func (fh *ReadFileHandle) close() error {
func (fh *ReadFileHandle) Flush() error {
fh.mu.Lock()
defer fh.mu.Unlock()
fs.Debugf(fh.o, "ReadFileHandle.Flush")
// fs.Debugf(fh.o, "ReadFileHandle.Flush")
if err := fh.checkHash(); err != nil {
fs.Errorf(fh.o, "ReadFileHandle.Flush error: %v", err)
return err
}
fs.Debugf(fh.o, "ReadFileHandle.Flush OK")
// fs.Debugf(fh.o, "ReadFileHandle.Flush OK")
return nil
}
@ -247,7 +247,7 @@ func (fh *ReadFileHandle) Release() error {
if err != nil {
fs.Errorf(fh.o, "ReadFileHandle.Release error: %v", err)
} else {
fs.Debugf(fh.o, "ReadFileHandle.Release OK")
// fs.Debugf(fh.o, "ReadFileHandle.Release OK")
}
return err
}

View file

@ -70,7 +70,7 @@ func (fh *WriteFileHandle) Node() Node {
// Write data to the file handle
func (fh *WriteFileHandle) Write(data []byte, offset int64) (written int64, err error) {
fs.Debugf(fh.remote, "WriteFileHandle.Write len=%d", len(data))
// fs.Debugf(fh.remote, "WriteFileHandle.Write len=%d", len(data))
fh.mu.Lock()
defer fh.mu.Unlock()
if fh.offset != offset {
@ -91,7 +91,7 @@ func (fh *WriteFileHandle) Write(data []byte, offset int64) (written int64, err
fs.Errorf(fh.remote, "WriteFileHandle.Write error: %v", err)
return 0, err
}
fs.Debugf(fh.remote, "WriteFileHandle.Write OK (%d bytes written)", n)
// fs.Debugf(fh.remote, "WriteFileHandle.Write OK (%d bytes written)", n)
if fh.hash != nil {
_, err = fh.hash.Write(data[:n])
if err != nil {
@ -160,7 +160,7 @@ func (fh *WriteFileHandle) close() error {
func (fh *WriteFileHandle) Flush() error {
fh.mu.Lock()
defer fh.mu.Unlock()
fs.Debugf(fh.remote, "WriteFileHandle.Flush")
// fs.Debugf(fh.remote, "WriteFileHandle.Flush")
// If Write hasn't been called then ignore the Flush - Release
// will pick it up
if !fh.writeCalled {
@ -172,7 +172,7 @@ func (fh *WriteFileHandle) Flush() error {
if err != nil {
fs.Errorf(fh.remote, "WriteFileHandle.Flush error: %v", err)
} else {
fs.Debugf(fh.remote, "WriteFileHandle.Flush OK")
// fs.Debugf(fh.remote, "WriteFileHandle.Flush OK")
}
return err
}
@ -193,7 +193,7 @@ func (fh *WriteFileHandle) Release() error {
if err != nil {
fs.Errorf(fh.remote, "WriteFileHandle.Release error: %v", err)
} else {
fs.Debugf(fh.remote, "WriteFileHandle.Release OK")
// fs.Debugf(fh.remote, "WriteFileHandle.Release OK")
}
return err
}