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) {
}
if err != nil {
log.Printf("writer: Write/Writev %v failed, err: %v. Opcode: %v",
req.outHeaderBytes, err, operationName(req.inHeader.Opcode))
log.Printf("writer: Write/Writev %v failed, err: %v. opcode: %v",
req.outHeaderBytes, err, operationName(req.inHeader.opcode))
}
}
......@@ -179,7 +179,7 @@ func (me *MountState) discardRequest(req *request) {
endNs := time.Nanoseconds()
dt := endNs - req.startNs
opname := operationName(req.inHeader.Opcode)
opname := operationName(req.inHeader.opcode)
me.LatencyMap.AddMany(
[]LatencyArg{
{opname, "", dt},
......@@ -249,19 +249,19 @@ func (me *MountState) chopMessage(req *request) *operationHandler {
req.inHeader = (*InHeader)(unsafe.Pointer(&req.inputBuf[0]))
req.arg = req.inputBuf[inHSize:]
handler := getHandler(req.inHeader.Opcode)
handler := getHandler(req.inHeader.opcode)
if handler == nil || handler.Func == nil {
msg := "Unimplemented"
if handler == nil {
msg = "Unknown"
}
log.Printf("%s opcode %v", msg, req.inHeader.Opcode)
log.Printf("%s opcode %v", msg, req.inHeader.opcode)
req.status = ENOSYS
return handler
}
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
return handler
}
......@@ -288,7 +288,7 @@ func (me *MountState) handle(req *request) {
// 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]]
// 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)
me.Write(req)
}
......@@ -296,7 +296,7 @@ func (me *MountState) handle(req *request) {
func (me *MountState) dispatch(req *request, handler *operationHandler) {
if me.Debug {
handler := getHandler(req.inHeader.Opcode)
handler := getHandler(req.inHeader.opcode)
var names interface{}
if handler.FileNames > 0 {
names = req.filenames(handler.FileNames)
......@@ -304,7 +304,7 @@ func (me *MountState) dispatch(req *request, handler *operationHandler) {
names = ""
}
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)
}
......@@ -331,7 +331,7 @@ 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))
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)
......@@ -342,6 +342,6 @@ func serialize(req *request, handler *operationHandler, debug bool) {
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)
operationName(req.inHeader.opcode), req.status, val, msg)
}
}
......@@ -9,8 +9,8 @@ import (
var _ = log.Printf
func replyString(opcode Opcode, ptr unsafe.Pointer) string {
h := getHandler(opcode)
func replyString(op opcode, ptr unsafe.Pointer) string {
h := getHandler(op)
var val interface{}
if h.DecodeOut != nil {
val = h.DecodeOut(ptr)
......@@ -120,7 +120,7 @@ func doWrite(state *MountState, req *request) {
func doGetXAttr(state *MountState, req *request) {
input := (*GetXAttrIn)(req.inData)
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())
} else {
data, req.status = state.fileSystem.ListXAttr(req.inHeader)
......@@ -265,19 +265,19 @@ type operationHandler struct {
var operationHandlers []*operationHandler
func operationName(opcode Opcode) string {
h := getHandler(opcode)
func operationName(op opcode) string {
h := getHandler(op)
if h == nil {
return "unknown"
}
return h.Name
}
func (op Opcode) String() string {
func (op opcode) String() string {
return operationName(op)
}
func getHandler(o Opcode) *operationHandler {
func getHandler(o opcode) *operationHandler {
if o >= OPCODE_COUNT {
return nil
}
......@@ -387,7 +387,7 @@ func init() {
operationHandlers[op].Name = v
}
for op, v := range map[Opcode]operationFunc{
for op, v := range map[opcode]operationFunc{
FUSE_OPEN: doOpen,
FUSE_READDIR: doReadDir,
FUSE_WRITE: doWrite,
......@@ -422,7 +422,7 @@ func init() {
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_OPEN: func(ptr unsafe.Pointer) interface{} { return (*EntryOut)(ptr) },
FUSE_GETATTR: func(ptr unsafe.Pointer) interface{} { return (*AttrOut)(ptr) },
......@@ -430,7 +430,7 @@ func init() {
operationHandlers[op].DecodeOut = f
}
for op, count := range map[Opcode]int {
for op, count := range map[opcode]int {
FUSE_LOOKUP: 1,
FUSE_RENAME: 2,
FUSE_SYMLINK: 2,
......
......@@ -98,7 +98,7 @@ const (
EXDEV = Status(syscall.EXDEV)
)
type Opcode int
type opcode int
const (
FUSE_LOOKUP = 1
......@@ -455,7 +455,7 @@ type NotifyPollWakeupOut struct {
type InHeader struct {
Length uint32
Opcode
opcode
Unique uint64
NodeId uint64
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