From d12e71f7734f449714c706cc4109a1e585b81b7b Mon Sep 17 00:00:00 2001 From: Aaron Jacobs Date: Wed, 29 Apr 2015 11:32:21 +1000 Subject: [PATCH] Added a Connection.log method, with a TODO. --- connection.go | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/connection.go b/connection.go index 832f641..75bc712 100644 --- a/connection.go +++ b/connection.go @@ -27,6 +27,7 @@ type Connection struct { logger *log.Logger wrapped *bazilfuse.Conn opsInFlight sync.WaitGroup + nextOpID uint64 } // Responsibility for closing the wrapped connection is transferred to the @@ -42,6 +43,15 @@ func newConnection( return } +// Log information for an operation with the given unique ID. +func (c *Connection) log( + opID uint64, + format string, + v ...interface{}) { + // TODO(jacobsa): Add op ID and fixed-width file:line to output. + c.logger.Printf(format, v...) +} + // Read the next op from the kernel process. Return io.EOF if the kernel has // closed the connection. // @@ -58,20 +68,25 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) { return } - c.logger.Printf("Received: %v", bfReq) + // Choose an ID for this operation. + opID := c.nextOpID + c.nextOpID++ + + // Log the receipt of the operation. + c.log(opID, "Received: %v", bfReq) // Special case: responding to this is required to make mounting work on OS // X. We don't currently expose the capability for the file system to // intercept this. if statfsReq, ok := bfReq.(*bazilfuse.StatfsRequest); ok { - c.logger.Println("Responding OK to Statfs.") + c.log(opID, "Responding OK to Statfs.") statfsReq.Respond(&bazilfuse.StatfsResponse{}) continue } // Convert it, if possible. if op = fuseops.Convert(bfReq, c.logger, &c.opsInFlight); op == nil { - c.logger.Printf("Returning ENOSYS for unknown bazilfuse request: %v", bfReq) + c.log(opID, "Returning ENOSYS for unknown bazilfuse request: %v", bfReq) bfReq.RespondError(ENOSYS) continue }