Commit 0dab71c8 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Add Done() method to ReadResult, so splicing code manage resources.

parent a626ad83
......@@ -195,6 +195,9 @@ type ReadResult interface {
// Size returns how many bytes this return value takes at most.
Size() int
// Done() is called after sending the data to the kernel.
Done()
}
// Wrap a File return in this to set FUSE flags. Also used internally
......
......@@ -382,6 +382,7 @@ func (ms *MountState) write(req *request) Status {
if req.fdData != nil {
if err := ms.trySplice(header, req, req.fdData); err == nil {
req.readResult.Done()
return OK
} else {
log.Println("trySplice:", err)
......@@ -393,6 +394,9 @@ func (ms *MountState) write(req *request) Status {
}
_, err := Writev(int(ms.mountFile.Fd()), [][]byte{header, req.flatData})
if req.readResult != nil {
req.readResult.Done()
}
return ToStatus(err)
}
......
......@@ -279,13 +279,12 @@ func doRead(state *MountState, req *request) {
in := (*raw.ReadIn)(req.inData)
buf := state.AllocOut(req, in.Size)
var r ReadResult
r, req.status = state.fileSystem.Read(&req.context, in, buf)
if fd, ok := r.(*ReadResultFd); ok {
req.readResult, req.status = state.fileSystem.Read(&req.context, in, buf)
if fd, ok := req.readResult.(*ReadResultFd); ok {
req.fdData = fd
req.flatData = nil
} else if r != nil {
req.flatData, req.status = r.Bytes(buf)
} else if req.readResult != nil {
req.flatData, req.status = req.readResult.Bytes(buf)
}
}
......
......@@ -15,6 +15,9 @@ func (r *ReadResultData) Size() int {
return len(r.Data)
}
func (r *ReadResultData) Done() {
}
func (r *ReadResultData) Bytes(buf []byte) ([]byte, Status) {
return r.Data, OK
}
......@@ -55,3 +58,6 @@ func (r *ReadResultFd) Bytes(buf []byte) ([]byte, Status) {
func (r *ReadResultFd) Size() int {
return r.Sz
}
func (r *ReadResultFd) Done() {
}
......@@ -29,6 +29,10 @@ type request struct {
flatData []byte
fdData *ReadResultFd
// In case of read, keep read result here so we can call
// Done() on it.
readResult ReadResult
// Start timestamp for timing info.
startNs int64
preWriteNs int64
......@@ -66,6 +70,7 @@ func (r *request) clear() {
r.preWriteNs = 0
r.startNs = 0
r.handler = nil
r.readResult = nil
}
func (r *request) InputDebug() string {
......
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