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
}
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) {
......
......@@ -49,11 +49,9 @@ func (f *dataFile) Read(buf []byte, off int64) (res fuse.ReadResult, code fuse.S
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 {
File
}
......@@ -75,7 +73,7 @@ func (f *devNullFile) String() string {
}
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) {
......@@ -126,12 +124,9 @@ func (f *loopbackFile) String() string {
}
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()
r := &fuse.ReadResultFd{
Fd: f.File.Fd(),
Off: off,
Sz: len(buf),
}
r := fuse.ReadResultFd(f.File.Fd(), off, len(buf))
f.lock.Unlock()
return r, fuse.OK
}
......
......@@ -288,7 +288,7 @@ func doRead(state *Server, req *request) {
buf := state.allocOut(req, in.Size)
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.flatData = nil
} else if req.readResult != nil && req.status.Ok() {
......
......@@ -6,24 +6,32 @@ import (
)
// ReadResultData is the read return for returning bytes directly.
type ReadResultData struct {
type readResultData struct {
// Raw bytes for the read.
Data []byte
}
func (r *ReadResultData) Size() int {
func (r *readResultData) Size() int {
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
}
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.
type ReadResultFd struct {
type readResultFd struct {
// Splice from the following file.
Fd uintptr
......@@ -37,7 +45,7 @@ type ReadResultFd struct {
// Reads raw bytes from file descriptor if necessary, using the passed
// buffer as storage.
func (r *ReadResultFd) Bytes(buf []byte) ([]byte, Status) {
func (r *readResultFd) Bytes(buf []byte) ([]byte, Status) {
sz := r.Sz
if len(buf) < sz {
sz = len(buf)
......@@ -55,9 +63,9 @@ func (r *ReadResultFd) Bytes(buf []byte) ([]byte, Status) {
return buf[:n], ToStatus(err)
}
func (r *ReadResultFd) Size() int {
func (r *readResultFd) Size() int {
return r.Sz
}
func (r *ReadResultFd) Done() {
func (r *readResultFd) Done() {
}
......@@ -28,7 +28,7 @@ type request struct {
outData unsafe.Pointer
status Status
flatData []byte
fdData *ReadResultFd
fdData *readResultFd
// In case of read, keep read result here so we can call
// Done() on it.
......
......@@ -11,7 +11,7 @@ func (s *Server) setSplice() {
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()
if err != nil {
return err
......@@ -43,7 +43,7 @@ func (ms *Server) trySplice(header []byte, req *request, fdData *ReadResultFd) e
header = req.serializeHeader(n)
newFd := ReadResultFd{
newFd := readResultFd{
Fd: pair.ReadFd(),
Off: -1,
Sz: n,
......
......@@ -31,7 +31,7 @@ func (f *MutableDataFile) Read(buf []byte, off int64) (fuse.ReadResult, fuse.Sta
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) {
......
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