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