From 41ea2b7530d1eff75e62977d0ba3184a56ec1ea1 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 6 Aug 2015 15:37:32 +1000 Subject: [PATCH 1/3] Don't repeat the op when logging the response. Doing so adds lots of visual clutter. --- connection.go | 4 ++-- debug.go | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/connection.go b/connection.go index 021f4a2..7dfd29f 100644 --- a/connection.go +++ b/connection.go @@ -476,9 +476,9 @@ func (c *Connection) Reply(ctx context.Context, opErr error) { // Debug logging if c.debugLogger != nil { if opErr == nil { - c.debugLog(fuseID, 1, "-> OK: %s", describeResponse(op)) + c.debugLog(fuseID, 1, "-> OK") } else { - c.debugLog(fuseID, 1, "-> error: %v", opErr) + c.debugLog(fuseID, 1, "-> Error: %q", opErr.Error()) } } diff --git a/debug.go b/debug.go index 8d5ec9e..91cc746 100644 --- a/debug.go +++ b/debug.go @@ -41,7 +41,3 @@ func describeRequest(op interface{}) (s string) { return } - -func describeResponse(op interface{}) (s string) { - return describeRequest(op) -} From 5c05a7c040921ab8782e56ac9e6c6f6d5a9044f3 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 6 Aug 2015 15:44:08 +1000 Subject: [PATCH 2/3] Refactored describeRequest. --- debug.go | 44 ++++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/debug.go b/debug.go index 91cc746..c51a399 100644 --- a/debug.go +++ b/debug.go @@ -17,27 +17,43 @@ package fuse import ( "fmt" "reflect" + "strings" ) +// Decide on the name of the given op. +func opName(op interface{}) string { + // We expect all ops to be pointers. + t := reflect.TypeOf(op).Elem() + + // Strip the "Op" from "FooOp". + return strings.TrimSuffix(t.Name(), "Op") +} + func describeRequest(op interface{}) (s string) { - // Handle special cases with custom formatting. + v := reflect.ValueOf(op).Elem() + + // We will set up a comma-separated list of components. + var components []string + addComponent := func(format string, v ...interface{}) { + components = append(components, fmt.Sprintf(format, v...)) + } + + // Include an inode number, if available. + if f := v.FieldByName("Inode"); f.IsValid() { + addComponent("inode %v", f.Interface()) + } + + // Handle special cases. switch typed := op.(type) { case *interruptOp: - s = fmt.Sprintf("interruptOp(fuseid=0x%08x)", typed.FuseID) - return + addComponent("fuseid 0x%08x", typed.FuseID) } - v := reflect.ValueOf(op).Elem() - t := v.Type() - - // Find the inode number involved, if possible. - var inodeDesc string - if f := v.FieldByName("Inode"); f.IsValid() { - inodeDesc = fmt.Sprintf("(inode=%v)", f.Interface()) + // Use just the name if there is no extra info. + if len(components) == 0 { + return opName(op) } - // Use the type name. - s = fmt.Sprintf("%s%s", t.Name(), inodeDesc) - - return + // Otherwise, include the extra info. + return fmt.Sprintf("%s (%s)", opName(op), strings.Join(components, ", ")) } From 6450a1cbbf652709b5a6b38a8a8b9a00829f6072 Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Thu, 6 Aug 2015 15:45:40 +1000 Subject: [PATCH 3/3] Added special cases for ReadFile and WriteFile. --- debug.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/debug.go b/debug.go index c51a399..2003fc0 100644 --- a/debug.go +++ b/debug.go @@ -18,6 +18,8 @@ import ( "fmt" "reflect" "strings" + + "github.com/jacobsa/fuse/fuseops" ) // Decide on the name of the given op. @@ -47,6 +49,16 @@ func describeRequest(op interface{}) (s string) { switch typed := op.(type) { case *interruptOp: addComponent("fuseid 0x%08x", typed.FuseID) + + case *fuseops.ReadFileOp: + addComponent("handle %d", typed.Handle) + addComponent("offset %d", typed.Offset) + addComponent("%d bytes", len(typed.Dst)) + + case *fuseops.WriteFileOp: + addComponent("handle %d", typed.Handle) + addComponent("offset %d", typed.Offset) + addComponent("%d bytes", len(typed.Data)) } // Use just the name if there is no extra info.