Commit 77de056f authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Hide the opcode type.

parent 38077f24
...@@ -118,8 +118,8 @@ func (me *MountState) Write(req *request) { ...@@ -118,8 +118,8 @@ func (me *MountState) Write(req *request) {
} }
if err != nil { if err != nil {
log.Printf("writer: Write/Writev %v failed, err: %v. Opcode: %v", log.Printf("writer: Write/Writev %v failed, err: %v. opcode: %v",
req.outHeaderBytes, err, operationName(req.inHeader.Opcode)) req.outHeaderBytes, err, operationName(req.inHeader.opcode))
} }
} }
...@@ -179,7 +179,7 @@ func (me *MountState) discardRequest(req *request) { ...@@ -179,7 +179,7 @@ func (me *MountState) discardRequest(req *request) {
endNs := time.Nanoseconds() endNs := time.Nanoseconds()
dt := endNs - req.startNs dt := endNs - req.startNs
opname := operationName(req.inHeader.Opcode) opname := operationName(req.inHeader.opcode)
me.LatencyMap.AddMany( me.LatencyMap.AddMany(
[]LatencyArg{ []LatencyArg{
{opname, "", dt}, {opname, "", dt},
...@@ -249,19 +249,19 @@ func (me *MountState) chopMessage(req *request) *operationHandler { ...@@ -249,19 +249,19 @@ func (me *MountState) chopMessage(req *request) *operationHandler {
req.inHeader = (*InHeader)(unsafe.Pointer(&req.inputBuf[0])) req.inHeader = (*InHeader)(unsafe.Pointer(&req.inputBuf[0]))
req.arg = req.inputBuf[inHSize:] req.arg = req.inputBuf[inHSize:]
handler := getHandler(req.inHeader.Opcode) handler := getHandler(req.inHeader.opcode)
if handler == nil || handler.Func == nil { if handler == nil || handler.Func == nil {
msg := "Unimplemented" msg := "Unimplemented"
if handler == nil { if handler == nil {
msg = "Unknown" msg = "Unknown"
} }
log.Printf("%s opcode %v", msg, req.inHeader.Opcode) log.Printf("%s opcode %v", msg, req.inHeader.opcode)
req.status = ENOSYS req.status = ENOSYS
return handler return handler
} }
if len(req.arg) < handler.InputSize { if len(req.arg) < handler.InputSize {
log.Printf("Short read for %v: %v", req.inHeader.Opcode, req.arg) log.Printf("Short read for %v: %v", req.inHeader.opcode, req.arg)
req.status = EIO req.status = EIO
return handler return handler
} }
...@@ -288,7 +288,7 @@ func (me *MountState) handle(req *request) { ...@@ -288,7 +288,7 @@ func (me *MountState) handle(req *request) {
// If we try to write OK, nil, we will get // If we try to write OK, nil, we will get
// error: writer: Writev [[16 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0]] // error: writer: Writev [[16 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0]]
// failed, err: writev: no such file or directory // failed, err: writev: no such file or directory
if req.inHeader.Opcode != FUSE_FORGET { if req.inHeader.opcode != FUSE_FORGET {
serialize(req, handler, me.Debug) serialize(req, handler, me.Debug)
me.Write(req) me.Write(req)
} }
...@@ -296,7 +296,7 @@ func (me *MountState) handle(req *request) { ...@@ -296,7 +296,7 @@ func (me *MountState) handle(req *request) {
func (me *MountState) dispatch(req *request, handler *operationHandler) { func (me *MountState) dispatch(req *request, handler *operationHandler) {
if me.Debug { if me.Debug {
handler := getHandler(req.inHeader.Opcode) handler := getHandler(req.inHeader.opcode)
var names interface{} var names interface{}
if handler.FileNames > 0 { if handler.FileNames > 0 {
names = req.filenames(handler.FileNames) names = req.filenames(handler.FileNames)
...@@ -304,7 +304,7 @@ func (me *MountState) dispatch(req *request, handler *operationHandler) { ...@@ -304,7 +304,7 @@ func (me *MountState) dispatch(req *request, handler *operationHandler) {
names = "" names = ""
} }
log.Printf("Dispatch: %v, NodeId: %v %v\n", log.Printf("Dispatch: %v, NodeId: %v %v\n",
operationName(req.inHeader.Opcode), req.inHeader.NodeId, names) operationName(req.inHeader.opcode), req.inHeader.NodeId, names)
} }
handler.Func(me, req) handler.Func(me, req)
} }
...@@ -331,7 +331,7 @@ func serialize(req *request, handler *operationHandler, debug bool) { ...@@ -331,7 +331,7 @@ func serialize(req *request, handler *operationHandler, debug bool) {
copy(req.outHeaderBytes[sizeOfOutHeader:], asSlice(req.outData, dataLength)) copy(req.outHeaderBytes[sizeOfOutHeader:], asSlice(req.outData, dataLength))
if debug { if debug {
val := fmt.Sprintf("%v", replyString(req.inHeader.Opcode, req.outData)) val := fmt.Sprintf("%v", replyString(req.inHeader.opcode, req.outData))
max := 1024 max := 1024
if len(val) > max { if len(val) > max {
val = val[:max] + fmt.Sprintf(" ...trimmed (response size %d)", outHeader.Length) val = val[:max] + fmt.Sprintf(" ...trimmed (response size %d)", outHeader.Length)
...@@ -342,6 +342,6 @@ func serialize(req *request, handler *operationHandler, debug bool) { ...@@ -342,6 +342,6 @@ func serialize(req *request, handler *operationHandler, debug bool) {
msg = fmt.Sprintf(" flat: %d\n", len(req.flatData)) msg = fmt.Sprintf(" flat: %d\n", len(req.flatData))
} }
log.Printf("Serialize: %v code: %v value: %v%v", log.Printf("Serialize: %v code: %v value: %v%v",
operationName(req.inHeader.Opcode), req.status, val, msg) operationName(req.inHeader.opcode), req.status, val, msg)
} }
} }
...@@ -9,8 +9,8 @@ import ( ...@@ -9,8 +9,8 @@ import (
var _ = log.Printf var _ = log.Printf
func replyString(opcode Opcode, ptr unsafe.Pointer) string { func replyString(op opcode, ptr unsafe.Pointer) string {
h := getHandler(opcode) h := getHandler(op)
var val interface{} var val interface{}
if h.DecodeOut != nil { if h.DecodeOut != nil {
val = h.DecodeOut(ptr) val = h.DecodeOut(ptr)
...@@ -120,7 +120,7 @@ func doWrite(state *MountState, req *request) { ...@@ -120,7 +120,7 @@ func doWrite(state *MountState, req *request) {
func doGetXAttr(state *MountState, req *request) { func doGetXAttr(state *MountState, req *request) {
input := (*GetXAttrIn)(req.inData) input := (*GetXAttrIn)(req.inData)
var data []byte var data []byte
if req.inHeader.Opcode == FUSE_GETXATTR { if req.inHeader.opcode == FUSE_GETXATTR {
data, req.status = state.fileSystem.GetXAttr(req.inHeader, req.filename()) data, req.status = state.fileSystem.GetXAttr(req.inHeader, req.filename())
} else { } else {
data, req.status = state.fileSystem.ListXAttr(req.inHeader) data, req.status = state.fileSystem.ListXAttr(req.inHeader)
...@@ -265,19 +265,19 @@ type operationHandler struct { ...@@ -265,19 +265,19 @@ type operationHandler struct {
var operationHandlers []*operationHandler var operationHandlers []*operationHandler
func operationName(opcode Opcode) string { func operationName(op opcode) string {
h := getHandler(opcode) h := getHandler(op)
if h == nil { if h == nil {
return "unknown" return "unknown"
} }
return h.Name return h.Name
} }
func (op Opcode) String() string { func (op opcode) String() string {
return operationName(op) return operationName(op)
} }
func getHandler(o Opcode) *operationHandler { func getHandler(o opcode) *operationHandler {
if o >= OPCODE_COUNT { if o >= OPCODE_COUNT {
return nil return nil
} }
...@@ -387,7 +387,7 @@ func init() { ...@@ -387,7 +387,7 @@ func init() {
operationHandlers[op].Name = v operationHandlers[op].Name = v
} }
for op, v := range map[Opcode]operationFunc{ for op, v := range map[opcode]operationFunc{
FUSE_OPEN: doOpen, FUSE_OPEN: doOpen,
FUSE_READDIR: doReadDir, FUSE_READDIR: doReadDir,
FUSE_WRITE: doWrite, FUSE_WRITE: doWrite,
...@@ -422,7 +422,7 @@ func init() { ...@@ -422,7 +422,7 @@ func init() {
operationHandlers[op].Func = v operationHandlers[op].Func = v
} }
for op, f := range map[Opcode]castPointerFunc{ for op, f := range map[opcode]castPointerFunc{
FUSE_LOOKUP: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) }, FUSE_LOOKUP: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) },
FUSE_OPEN: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) }, FUSE_OPEN: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) },
FUSE_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*AttrOut)(ptr) }, FUSE_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*AttrOut)(ptr) },
...@@ -430,7 +430,7 @@ func init() { ...@@ -430,7 +430,7 @@ func init() {
operationHandlers[op].DecodeOut = f operationHandlers[op].DecodeOut = f
} }
for op, count := range map[Opcode]int { for op, count := range map[opcode]int {
FUSE_LOOKUP: 1, FUSE_LOOKUP: 1,
FUSE_RENAME: 2, FUSE_RENAME: 2,
FUSE_SYMLINK: 2, FUSE_SYMLINK: 2,
......
...@@ -98,7 +98,7 @@ const ( ...@@ -98,7 +98,7 @@ const (
EXDEV = Status(syscall.EXDEV) EXDEV = Status(syscall.EXDEV)
) )
type Opcode int type opcode int
const ( const (
FUSE_LOOKUP = 1 FUSE_LOOKUP = 1
...@@ -455,7 +455,7 @@ type NotifyPollWakeupOut struct { ...@@ -455,7 +455,7 @@ type NotifyPollWakeupOut struct {
type InHeader struct { type InHeader struct {
Length uint32 Length uint32
Opcode opcode
Unique uint64 Unique uint64
NodeId uint64 NodeId uint64
Identity Identity
......
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