Commit d397cca6 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Move debug into request methods.

parent 01d86c93
......@@ -57,6 +57,50 @@ func (me *request) filenames(count int) []string {
return nameStrings
}
func (me *request) InputDebug(h *operationHandler) string {
var val interface{}
if h.DecodeIn != nil {
val = h.DecodeIn(me.inData)
} else {
val = ""
}
var names interface{}
if h.FileNames > 0 {
names = me.filenames(h.FileNames)
} else {
names = ""
}
return fmt.Sprintf("Dispatch: %v, NodeId: %v. Data: %v Names: %v",
me.inHeader.opcode, me.inHeader.NodeId, val, names)
}
func (me *request) OutputDebug(h *operationHandler) string {
var val interface{}
if h.DecodeOut != nil {
val = h.DecodeOut(me.outData)
}
dataStr := ""
if val != nil {
dataStr = fmt.Sprintf("%v", val)
}
max := 1024
if len(dataStr) > max {
dataStr = dataStr[:max] + fmt.Sprintf(" ...trimmed (response size %d)", len(me.outHeaderBytes))
}
flatStr := ""
if len(me.flatData) > 0 {
flatStr = fmt.Sprintf(" %d bytes data\n", len(me.flatData))
}
return fmt.Sprintf("Serialize: %v code: %v value: %v%v",
me.inHeader.opcode, me.status, dataStr, flatStr)
}
////////////////////////////////////////////////////////////////
// State related to this mount point.
type MountState struct {
......@@ -300,15 +344,7 @@ func (me *MountState) handle(req *request) {
func (me *MountState) dispatch(req *request, handler *operationHandler) {
if me.Debug {
handler := getHandler(req.inHeader.opcode)
var names interface{}
if handler.FileNames > 0 {
names = req.filenames(handler.FileNames)
} else {
names = ""
}
log.Printf("Dispatch: %v, NodeId: %v %v\n",
operationName(req.inHeader.opcode), req.inHeader.NodeId, names)
log.Println(req.InputDebug(handler))
}
handler.Func(me, req)
}
......@@ -335,17 +371,6 @@ func serialize(req *request, handler *operationHandler, debug bool) {
copy(req.outHeaderBytes[sizeOfOutHeader:], asSlice(req.outData, dataLength))
if debug {
val := fmt.Sprintf("%v", replyString(req.inHeader.opcode, req.outData))
max := 1024
if len(val) > max {
val = val[:max] + fmt.Sprintf(" ...trimmed (response size %d)", outHeader.Length)
}
msg := ""
if len(req.flatData) > 0 {
msg = fmt.Sprintf(" flat: %d\n", len(req.flatData))
}
log.Printf("Serialize: %v code: %v value: %v%v",
operationName(req.inHeader.opcode), req.status, val, msg)
log.Println(req.OutputDebug(handler))
}
}
......@@ -8,6 +8,7 @@ import (
)
var _ = log.Printf
var _ = fmt.Printf
type opcode int
......@@ -54,17 +55,6 @@ const (
OPCODE_COUNT = opcode(41)
)
func replyString(op opcode, ptr unsafe.Pointer) string {
h := getHandler(op)
var val interface{}
if h.DecodeOut != nil {
val = h.DecodeOut(ptr)
}
if val != nil {
return fmt.Sprintf("%v", val)
}
return ""
}
////////////////////////////////////////////////////////////////
......@@ -474,7 +464,12 @@ func init() {
} {
operationHandlers[op].DecodeOut = f
}
for op, f := range map[opcode]castPointerFunc{
_OP_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*GetAttrIn)(ptr) },
_OP_SETATTR: func(ptr unsafe.Pointer) interface{} { return (*SetAttrIn)(ptr) },
} {
operationHandlers[op].DecodeIn = f
}
for op, count := range map[opcode]int{
_OP_LOOKUP: 1,
_OP_RENAME: 2,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment