Log responses and errors.

geesefs-0-30-9
Aaron Jacobs 2015-03-24 15:59:19 +11:00
parent 2720f50225
commit 58e8a310aa
3 changed files with 43 additions and 7 deletions

View File

@ -72,7 +72,7 @@ func (c *Connection) ReadOp() (op fuseops.Op, err error) {
}
// Convert it, if possible.
if op = fuseops.Convert(bfReq); op == nil {
if op = fuseops.Convert(bfReq, c.logger); op == nil {
c.logger.Printf("Returning ENOSYS for unknown bazilfuse request: %v", bfReq)
bfReq.RespondError(ENOSYS)
continue

View File

@ -18,6 +18,8 @@
package fuseops
import (
"log"
"reflect"
"time"
"github.com/jacobsa/bazilfuse"
@ -29,7 +31,7 @@ import (
//
// This function is an implementation detail of the fuse package, and must not
// be called by anyone else.
func Convert(r bazilfuse.Request) (o Op) {
func Convert(r bazilfuse.Request, logger *log.Logger) (o Op) {
var co *commonOp
switch typed := r.(type) {
@ -184,7 +186,7 @@ func Convert(r bazilfuse.Request) (o Op) {
return
}
co.init(r)
co.init(reflect.TypeOf(o).String(), r, logger)
return
}
@ -234,13 +236,20 @@ func convertChildInodeEntry(
// A helper for embedding common behavior.
type commonOp struct {
ctx context.Context
r bazilfuse.Request
opType string
ctx context.Context
r bazilfuse.Request
logger *log.Logger
}
func (o *commonOp) init(r bazilfuse.Request) {
func (o *commonOp) init(
opType string,
r bazilfuse.Request,
logger *log.Logger) {
o.opType = opType
o.ctx = context.Background()
o.r = r
o.logger = logger
}
func (o *commonOp) Header() OpHeader {
@ -260,5 +269,10 @@ func (o *commonOp) respondErr(err error) {
panic("Expect non-nil here.")
}
o.logger.Printf(
"Responding with error to %s: %v",
o.opType,
err)
o.r.RespondError(err)
}

View File

@ -56,7 +56,10 @@ func (o *InitOp) Respond(err error) {
return
}
o.r.(*bazilfuse.InitRequest).Respond(&bazilfuse.InitResponse{})
resp := &bazilfuse.InitResponse{}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.InitRequest).Respond(resp)
}
////////////////////////////////////////////////////////////////////////
@ -94,6 +97,8 @@ func (o *LookUpInodeOp) Respond(err error) {
resp := bazilfuse.LookupResponse{}
convertChildInodeEntry(&o.Entry, &resp)
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.LookupRequest).Respond(&resp)
}
@ -125,6 +130,7 @@ func (o *GetInodeAttributesOp) Respond(err error) {
AttrValid: convertExpirationTime(o.AttributesExpiration),
}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.GetattrRequest).Respond(&resp)
}
@ -162,6 +168,7 @@ func (o *SetInodeAttributesOp) Respond(err error) {
AttrValid: convertExpirationTime(o.AttributesExpiration),
}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.SetattrRequest).Respond(&resp)
}
@ -182,6 +189,7 @@ func (o *ForgetInodeOp) Respond(err error) {
return
}
o.commonOp.logger.Printf("Responding OK to ForgetInodeOp")
o.r.(*bazilfuse.ForgetRequest).Respond()
}
@ -217,6 +225,8 @@ func (o *MkDirOp) Respond(err error) {
}
resp := bazilfuse.MkdirResponse{}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.MkdirRequest).Respond(&resp)
}
@ -273,6 +283,7 @@ func (o *CreateFileOp) Respond(err error) {
}
convertChildInodeEntry(&o.Entry, &resp.LookupResponse)
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.CreateRequest).Respond(&resp)
}
@ -302,6 +313,7 @@ func (o *RmDirOp) Respond(err error) {
return
}
o.commonOp.logger.Printf("Responding OK to RmDirOp")
o.r.(*bazilfuse.RemoveRequest).Respond()
}
@ -325,6 +337,7 @@ func (o *UnlinkOp) Respond(err error) {
return
}
o.commonOp.logger.Printf("Responding OK to UnlinkOp")
o.r.(*bazilfuse.RemoveRequest).Respond()
}
@ -368,6 +381,7 @@ func (o *OpenDirOp) Respond(err error) {
Handle: bazilfuse.HandleID(o.Handle),
}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.OpenRequest).Respond(&resp)
}
@ -471,6 +485,7 @@ func (o *ReadDirOp) Respond(err error) {
Data: o.Data,
}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.ReadRequest).Respond(&resp)
}
@ -495,6 +510,7 @@ func (o *ReleaseDirHandleOp) Respond(err error) {
return
}
o.commonOp.logger.Printf("Responding OK to ReleaseDirHandleOp")
o.r.(*bazilfuse.ReleaseRequest).Respond()
}
@ -537,6 +553,7 @@ func (o *OpenFileOp) Respond(err error) {
Handle: bazilfuse.HandleID(o.Handle),
}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.OpenRequest).Respond(&resp)
}
@ -579,6 +596,7 @@ func (o *ReadFileOp) Respond(err error) {
Data: o.Data,
}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.ReadRequest).Respond(&resp)
}
@ -659,6 +677,7 @@ func (o *WriteFileOp) Respond(err error) {
Size: len(o.Data),
}
o.commonOp.logger.Printf("Responding: %v", resp)
o.r.(*bazilfuse.WriteRequest).Respond(&resp)
}
@ -692,6 +711,7 @@ func (o *SyncFileOp) Respond(err error) {
return
}
o.commonOp.logger.Printf("Responding OK to SyncFileOp")
o.r.(*bazilfuse.FsyncRequest).Respond()
}
@ -756,6 +776,7 @@ func (o *FlushFileOp) Respond(err error) {
return
}
o.commonOp.logger.Printf("Responding OK to FlushFileOp")
o.r.(*bazilfuse.FlushRequest).Respond()
}
@ -780,5 +801,6 @@ func (o *ReleaseFileHandleOp) Respond(err error) {
return
}
o.commonOp.logger.Printf("Responding OK to ReleaseFileHandleOp")
o.r.(*bazilfuse.ReleaseRequest).Respond()
}