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

Reorganize dispatch() and handle().

parent b5f9b2fb
...@@ -250,48 +250,58 @@ func (me *MountState) Loop(threaded bool) { ...@@ -250,48 +250,58 @@ func (me *MountState) Loop(threaded bool) {
me.mountFile.Close() me.mountFile.Close()
} }
func (me *MountState) handle(req *request) {
defer me.discardRequest(req)
req.dispatchNs = time.Nanoseconds()
func (me *MountState) chopMessage(req *request) bool {
inHSize := unsafe.Sizeof(InHeader{}) inHSize := unsafe.Sizeof(InHeader{})
if len(req.inputBuf) < inHSize { if len(req.inputBuf) < inHSize {
me.Error(os.NewError(fmt.Sprintf("Short read for input header: %v", req.inputBuf))) me.Error(os.NewError(fmt.Sprintf("Short read for input header: %v", req.inputBuf)))
return return false
} }
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:]
me.dispatch(req)
// 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 {
serialize(req, me.Debug)
req.preWriteNs = time.Nanoseconds()
me.Write(req)
}
}
func (me *MountState) dispatch(req *request) {
argSize, ok := inputSize(req.inHeader.Opcode) argSize, ok := inputSize(req.inHeader.Opcode)
if !ok { if !ok {
log.Println("Unknown opcode %d (input)", req.inHeader.Opcode) log.Println("Unknown opcode %d (input)", req.inHeader.Opcode)
req.status = ENOSYS req.status = ENOSYS
return return true
} }
if len(req.arg) < argSize { if len(req.arg) < argSize {
log.Println("Short read for %v: %v", req.inHeader.Opcode, req.arg) log.Println("Short read for %v: %v", req.inHeader.Opcode, req.arg)
req.status = EIO req.status = EIO
return return true
} }
if argSize > 0 { if argSize > 0 {
req.inData = unsafe.Pointer(&req.arg[0]) req.inData = unsafe.Pointer(&req.arg[0])
req.arg = req.arg[argSize:] req.arg = req.arg[argSize:]
} }
return true
}
func (me *MountState) handle(req *request) {
defer me.discardRequest(req)
if !me.chopMessage(req) {
return
}
if req.status == OK {
me.dispatch(req)
}
// 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 {
serialize(req, me.Debug)
req.preWriteNs = time.Nanoseconds()
me.Write(req)
}
}
func (me *MountState) dispatch(req *request) {
req.dispatchNs = time.Nanoseconds()
f := lookupOperation(req.inHeader.Opcode) f := lookupOperation(req.inHeader.Opcode)
if f == nil { if f == nil {
......
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