Added a Connection.log method, with a TODO.

geesefs-0-30-9
Aaron Jacobs 2015-04-29 11:32:21 +10:00
parent 380eba1dd5
commit d12e71f773
1 changed files with 18 additions and 3 deletions

View File

@ -27,6 +27,7 @@ type Connection struct {
logger *log.Logger logger *log.Logger
wrapped *bazilfuse.Conn wrapped *bazilfuse.Conn
opsInFlight sync.WaitGroup opsInFlight sync.WaitGroup
nextOpID uint64
} }
// Responsibility for closing the wrapped connection is transferred to the // Responsibility for closing the wrapped connection is transferred to the
@ -42,6 +43,15 @@ func newConnection(
return 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 // Read the next op from the kernel process. Return io.EOF if the kernel has
// closed the connection. // closed the connection.
// //
@ -58,20 +68,25 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) {
return 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 // 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 // X. We don't currently expose the capability for the file system to
// intercept this. // intercept this.
if statfsReq, ok := bfReq.(*bazilfuse.StatfsRequest); ok { 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{}) statfsReq.Respond(&bazilfuse.StatfsResponse{})
continue continue
} }
// Convert it, if possible. // Convert it, if possible.
if op = fuseops.Convert(bfReq, c.logger, &c.opsInFlight); op == nil { 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) bfReq.RespondError(ENOSYS)
continue continue
} }