From 85cd1cb2999b9c64a9502296e3553a65a93fd15e Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Fri, 24 Jul 2015 11:38:23 +1000 Subject: [PATCH] Fixed error and debug logging. --- connection.go | 15 +++++++++++++++ fuseops/common_op.go | 25 ++++--------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/connection.go b/connection.go index 6295dab..6029285 100644 --- a/connection.go +++ b/connection.go @@ -234,6 +234,7 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) { } sendReply := func( + op fuseops.Op, fuseID uint64, replyMsg []byte, opErr error) (err error) { @@ -244,6 +245,20 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) { // Clean up state for this op. c.finishOp(m.Hdr.Opcode, m.Hdr.Unique) + // Debug logging + if c.debugLogger != nil { + if opErr == nil { + op.Logf("-> %s OK", op.ShortDesc()) + } else { + op.Logf("-> %s error: %v", op.ShortDesc(), opErr) + } + } + + // Error logging + if opErr != nil && c.errorLogger != nil { + c.errorLogger.Printf("(%s) error: %v", op.ShortDesc(), opErr) + } + // Send the reply to the kernel. err = c.wrapped.WriteToKernel(replyMsg) if err != nil { diff --git a/fuseops/common_op.go b/fuseops/common_op.go index c083b1c..fb261e9 100644 --- a/fuseops/common_op.go +++ b/fuseops/common_op.go @@ -40,7 +40,7 @@ type internalOp interface { // A function that sends a reply message back to the kernel for the request // with the given fuse unique ID. The error argument is for informational // purposes only; the error to hand to the kernel is encoded in the message. -type replyFunc func(uint64, []byte, error) error +type replyFunc func(Op, uint64, []byte, error) error // A helper for embedding common behavior. type commonOp struct { @@ -111,9 +111,9 @@ func (o *commonOp) init( // When the op is finished, report to both reqtrace and the connection. prevSendReply := o.sendReply - o.sendReply = func(fuseID uint64, msg []byte, opErr error) (err error) { + o.sendReply = func(op Op, fuseID uint64, msg []byte, opErr error) (err error) { reportForTrace(opErr) - err = prevSendReply(fuseID, msg, opErr) + err = prevSendReply(op, fuseID, msg, opErr) return } } @@ -155,25 +155,8 @@ func (o *commonOp) Respond(err error) { h.Error = -int32(errno) } - // Log the error, if any. - if err != nil { - if o.debugLog != nil { - o.Logf( - "-> (%s) error: %v", - o.op.ShortDesc(), - err) - } - - if o.errorLogger != nil { - o.errorLogger.Printf( - "(%s) error: %v", - o.op.ShortDesc(), - err) - } - } - // Reply. - replyErr := o.sendReply(o.fuseID, msg, err) + replyErr := o.sendReply(o.op, o.fuseID, msg, err) if replyErr != nil && o.errorLogger != nil { o.errorLogger.Printf("Error from sendReply: %v", replyErr) }