From 497407fde2908f71607650e8fa415f22458c7fa1 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 24 Jul 2015 11:47:39 +1000 Subject: [PATCH] Better debug logging for getattr. --- connection.go | 4 ++-- fuseops/common_op.go | 5 +++++ fuseops/ops.go | 11 +++++++++++ fuseops/simple_types.go | 10 ++++++++++ 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/connection.go b/connection.go index 6029285..e1d03da 100644 --- a/connection.go +++ b/connection.go @@ -248,9 +248,9 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) { // Debug logging if c.debugLogger != nil { if opErr == nil { - op.Logf("-> %s OK", op.ShortDesc()) + op.Logf("-> OK: %s", op.DebugString()) } else { - op.Logf("-> %s error: %v", op.ShortDesc(), opErr) + op.Logf("-> error: %v", opErr) } } diff --git a/fuseops/common_op.go b/fuseops/common_op.go index fb261e9..b49c110 100644 --- a/fuseops/common_op.go +++ b/fuseops/common_op.go @@ -90,6 +90,11 @@ func (o *commonOp) ShortDesc() (desc string) { return } +func (o *commonOp) DebugString() string { + // By default, defer to ShortDesc. + return o.op.ShortDesc() +} + func (o *commonOp) init( ctx context.Context, op internalOp, diff --git a/fuseops/ops.go b/fuseops/ops.go index 13e156b..74c2074 100644 --- a/fuseops/ops.go +++ b/fuseops/ops.go @@ -32,6 +32,9 @@ type Op interface { // A short description of the op, to be used in logging. ShortDesc() string + // A long description of the op, to be used in debug logging. + DebugString() string + // A context that can be used for long-running operations. Context() context.Context @@ -122,6 +125,14 @@ func (o *GetInodeAttributesOp) kernelResponse() (msg []byte) { return } +func (o *GetInodeAttributesOp) DebugString() string { + return fmt.Sprintf( + "Inode: %d, Exp: %v, Attr: %s", + o.Inode, + o.AttributesExpiration, + o.Attributes.DebugString()) +} + // Change attributes for an inode. // // The kernel sends this for obvious cases like chmod(2), and for less obvious diff --git a/fuseops/simple_types.go b/fuseops/simple_types.go index 2ef7f54..3191b36 100644 --- a/fuseops/simple_types.go +++ b/fuseops/simple_types.go @@ -97,6 +97,16 @@ type InodeAttributes struct { Gid uint32 } +func (a *InodeAttributes) DebugString() string { + return fmt.Sprintf( + "%d %d %v %d %d", + a.Size, + a.Nlink, + a.Mode, + a.Uid, + a.Gid) +} + // A generation number for an inode. Irrelevant for file systems that won't be // exported over NFS. For those that will and that reuse inode IDs when they // become free, the generation number must change when an ID is reused.