Commit 54b42724 authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Handle error conditions in ReadResultFd.

parent f165c912
...@@ -191,7 +191,7 @@ type ReadResult interface { ...@@ -191,7 +191,7 @@ type ReadResult interface {
// Returns the raw bytes for the read, possibly using the // Returns the raw bytes for the read, possibly using the
// passed buffer. The buffer should be larger than the return // passed buffer. The buffer should be larger than the return
// value from Size. // value from Size.
Bytes(buf []byte) []byte Bytes(buf []byte) ([]byte, Status)
// 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
......
...@@ -31,7 +31,10 @@ func CopyFile(srcFs, destFs FileSystem, srcFile, destFile string, context *Conte ...@@ -31,7 +31,10 @@ func CopyFile(srcFs, destFs FileSystem, srcFile, destFile string, context *Conte
if !code.Ok() { if !code.Ok() {
return code return code
} }
data := res.Bytes(buf) data, code := res.Bytes(buf)
if !code.Ok() {
return code
}
if len(data) == 0 { if len(data) == 0 {
break break
......
...@@ -363,7 +363,7 @@ func (ms *MountState) write(req *request) Status { ...@@ -363,7 +363,7 @@ func (ms *MountState) write(req *request) Status {
log.Println("TrySplice:", err) log.Println("TrySplice:", err)
sz := req.flatDataSize() sz := req.flatDataSize()
buf := ms.AllocOut(req, uint32(sz)) buf := ms.AllocOut(req, uint32(sz))
req.flatData = req.fdData.Bytes(buf) req.flatData, req.status = req.fdData.Bytes(buf)
header = req.serializeHeader(len(req.flatData)) header = req.serializeHeader(len(req.flatData))
} }
} }
...@@ -449,7 +449,7 @@ func (ms *MountState) writeDeleteNotify(parent uint64, child uint64, name string ...@@ -449,7 +449,7 @@ func (ms *MountState) writeDeleteNotify(parent uint64, child uint64, name string
if ms.kernelSettings.Minor < 18 { if ms.kernelSettings.Minor < 18 {
return ms.writeEntryNotify(parent, name) return ms.writeEntryNotify(parent, name)
} }
req := request{ req := request{
inHeader: &raw.InHeader{ inHeader: &raw.InHeader{
Opcode: _OP_NOTIFY_DELETE, Opcode: _OP_NOTIFY_DELETE,
...@@ -459,7 +459,7 @@ func (ms *MountState) writeDeleteNotify(parent uint64, child uint64, name string ...@@ -459,7 +459,7 @@ func (ms *MountState) writeDeleteNotify(parent uint64, child uint64, name string
} }
entry := &raw.NotifyInvalDeleteOut{ entry := &raw.NotifyInvalDeleteOut{
Parent: parent, Parent: parent,
Child: child, Child: child,
NameLen: uint32(len(name)), NameLen: uint32(len(name)),
} }
......
...@@ -279,7 +279,7 @@ func doRead(state *MountState, req *request) { ...@@ -279,7 +279,7 @@ func doRead(state *MountState, req *request) {
req.fdData = fd req.fdData = fd
req.flatData = nil req.flatData = nil
} else if r != nil { } else if r != nil {
req.flatData = r.Bytes(buf) req.flatData, req.status = r.Bytes(buf)
} }
} }
......
...@@ -15,8 +15,8 @@ func (r *ReadResultData) Size() int { ...@@ -15,8 +15,8 @@ func (r *ReadResultData) Size() int {
return len(r.Data) return len(r.Data)
} }
func (r *ReadResultData) Bytes(buf []byte) []byte { func (r *ReadResultData) Bytes(buf []byte) ([]byte, Status) {
return r.Data return r.Data, OK
} }
// ReadResultFd is the read return for zero-copy file data. // ReadResultFd is the read return for zero-copy file data.
...@@ -34,7 +34,7 @@ type ReadResultFd struct { ...@@ -34,7 +34,7 @@ type ReadResultFd struct {
// Reads raw bytes from file descriptor if necessary, using the passed // Reads raw bytes from file descriptor if necessary, using the passed
// buffer as storage. // buffer as storage.
func (r *ReadResultFd) Bytes(buf []byte) []byte { func (r *ReadResultFd) Bytes(buf []byte) ([]byte, Status) {
sz := r.Sz sz := r.Sz
if len(buf) < sz { if len(buf) < sz {
sz = len(buf) sz = len(buf)
...@@ -44,8 +44,12 @@ func (r *ReadResultFd) Bytes(buf []byte) []byte { ...@@ -44,8 +44,12 @@ func (r *ReadResultFd) Bytes(buf []byte) []byte {
if err == io.EOF { if err == io.EOF {
err = nil err = nil
} }
// TODO - error handling?
return buf[:n] if n < 0 {
n = 0
}
return buf[:n], ToStatus(err)
} }
func (r *ReadResultFd) Size() int { func (r *ReadResultFd) Size() int {
......
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