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

fuse: hide ReadResultData and ReadResultFd types.

parent fb412460
...@@ -112,7 +112,7 @@ func (fs *defaultRawFileSystem) OpenDir(out *raw.OpenOut, context *Context, inpu ...@@ -112,7 +112,7 @@ func (fs *defaultRawFileSystem) OpenDir(out *raw.OpenOut, context *Context, inpu
} }
func (fs *defaultRawFileSystem) Read(context *Context, input *raw.ReadIn, buf []byte) (ReadResult, Status) { func (fs *defaultRawFileSystem) Read(context *Context, input *raw.ReadIn, buf []byte) (ReadResult, Status) {
return &ReadResultData{}, ENOSYS return nil, ENOSYS
} }
func (fs *defaultRawFileSystem) Release(context *Context, input *raw.ReleaseIn) { func (fs *defaultRawFileSystem) Release(context *Context, input *raw.ReleaseIn) {
......
...@@ -49,11 +49,9 @@ func (f *dataFile) Read(buf []byte, off int64) (res fuse.ReadResult, code fuse.S ...@@ -49,11 +49,9 @@ func (f *dataFile) Read(buf []byte, off int64) (res fuse.ReadResult, code fuse.S
end = len(f.data) end = len(f.data)
} }
return &fuse.ReadResultData{f.data[off:end]}, fuse.OK return fuse.ReadResultData(f.data[off:end]), fuse.OK
} }
////////////////
type devNullFile struct { type devNullFile struct {
File File
} }
...@@ -75,7 +73,7 @@ func (f *devNullFile) String() string { ...@@ -75,7 +73,7 @@ func (f *devNullFile) String() string {
} }
func (f *devNullFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) { func (f *devNullFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Status) {
return &fuse.ReadResultData{}, fuse.OK return fuse.ReadResultData(nil), fuse.OK
} }
func (f *devNullFile) Write(content []byte, off int64) (uint32, fuse.Status) { func (f *devNullFile) Write(content []byte, off int64) (uint32, fuse.Status) {
...@@ -126,12 +124,9 @@ func (f *loopbackFile) String() string { ...@@ -126,12 +124,9 @@ func (f *loopbackFile) String() string {
} }
func (f *loopbackFile) Read(buf []byte, off int64) (res fuse.ReadResult, code fuse.Status) { func (f *loopbackFile) Read(buf []byte, off int64) (res fuse.ReadResult, code fuse.Status) {
// TODO - this is racy. The lock should be taken when the Fd is spliced.
f.lock.Lock() f.lock.Lock()
r := &fuse.ReadResultFd{ r := fuse.ReadResultFd(f.File.Fd(), off, len(buf))
Fd: f.File.Fd(),
Off: off,
Sz: len(buf),
}
f.lock.Unlock() f.lock.Unlock()
return r, fuse.OK return r, fuse.OK
} }
......
...@@ -288,7 +288,7 @@ func doRead(state *Server, req *request) { ...@@ -288,7 +288,7 @@ func doRead(state *Server, req *request) {
buf := state.allocOut(req, in.Size) buf := state.allocOut(req, in.Size)
req.readResult, req.status = state.fileSystem.Read(&req.context, in, buf) req.readResult, req.status = state.fileSystem.Read(&req.context, in, buf)
if fd, ok := req.readResult.(*ReadResultFd); ok { if fd, ok := req.readResult.(*readResultFd); ok {
req.fdData = fd req.fdData = fd
req.flatData = nil req.flatData = nil
} else if req.readResult != nil && req.status.Ok() { } else if req.readResult != nil && req.status.Ok() {
......
...@@ -6,24 +6,32 @@ import ( ...@@ -6,24 +6,32 @@ import (
) )
// ReadResultData is the read return for returning bytes directly. // ReadResultData is the read return for returning bytes directly.
type ReadResultData struct { type readResultData struct {
// Raw bytes for the read. // Raw bytes for the read.
Data []byte Data []byte
} }
func (r *ReadResultData) Size() int { func (r *readResultData) Size() int {
return len(r.Data) return len(r.Data)
} }
func (r *ReadResultData) Done() { 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
} }
func ReadResultData(b []byte) ReadResult {
return &readResultData{b}
}
func ReadResultFd(fd uintptr, off int64, sz int) ReadResult {
return &readResultFd{fd, off, sz}
}
// ReadResultFd is the read return for zero-copy file data. // ReadResultFd is the read return for zero-copy file data.
type ReadResultFd struct { type readResultFd struct {
// Splice from the following file. // Splice from the following file.
Fd uintptr Fd uintptr
...@@ -37,7 +45,7 @@ type ReadResultFd struct { ...@@ -37,7 +45,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, Status) { 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)
...@@ -55,9 +63,9 @@ func (r *ReadResultFd) Bytes(buf []byte) ([]byte, Status) { ...@@ -55,9 +63,9 @@ func (r *ReadResultFd) Bytes(buf []byte) ([]byte, Status) {
return buf[:n], ToStatus(err) return buf[:n], ToStatus(err)
} }
func (r *ReadResultFd) Size() int { func (r *readResultFd) Size() int {
return r.Sz return r.Sz
} }
func (r *ReadResultFd) Done() { func (r *readResultFd) Done() {
} }
...@@ -28,7 +28,7 @@ type request struct { ...@@ -28,7 +28,7 @@ type request struct {
outData unsafe.Pointer outData unsafe.Pointer
status Status status Status
flatData []byte flatData []byte
fdData *ReadResultFd fdData *readResultFd
// In case of read, keep read result here so we can call // In case of read, keep read result here so we can call
// Done() on it. // Done() on it.
......
...@@ -11,7 +11,7 @@ func (s *Server) setSplice() { ...@@ -11,7 +11,7 @@ func (s *Server) setSplice() {
s.canSplice = splice.Resizable() s.canSplice = splice.Resizable()
} }
func (ms *Server) trySplice(header []byte, req *request, fdData *ReadResultFd) error { func (ms *Server) trySplice(header []byte, req *request, fdData *readResultFd) error {
pair, err := splice.Get() pair, err := splice.Get()
if err != nil { if err != nil {
return err return err
...@@ -43,7 +43,7 @@ func (ms *Server) trySplice(header []byte, req *request, fdData *ReadResultFd) e ...@@ -43,7 +43,7 @@ func (ms *Server) trySplice(header []byte, req *request, fdData *ReadResultFd) e
header = req.serializeHeader(n) header = req.serializeHeader(n)
newFd := ReadResultFd{ newFd := readResultFd{
Fd: pair.ReadFd(), Fd: pair.ReadFd(),
Off: -1, Off: -1,
Sz: n, Sz: n,
......
...@@ -31,7 +31,7 @@ func (f *MutableDataFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Sta ...@@ -31,7 +31,7 @@ func (f *MutableDataFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Sta
end = len(f.data) end = len(f.data)
} }
return &fuse.ReadResultData{Data: f.data[off:end]}, fuse.OK return fuse.ReadResultData(f.data[off:end]), fuse.OK
} }
func (f *MutableDataFile) Write(d []byte, off int64) (uint32, fuse.Status) { func (f *MutableDataFile) Write(d []byte, off int64) (uint32, fuse.Status) {
......
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