Skip to content

Commit

Permalink
use interface for ReadResultFd
Browse files Browse the repository at this point in the history
  • Loading branch information
SandyXSD committed Nov 6, 2024
1 parent 3abc6b3 commit 54bd1dd
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
5 changes: 5 additions & 0 deletions fuse/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ type ReadResult interface {
Done()
}

type ReadResultFd interface {
ReadResult
ReadFd() uintptr
}

type MountOptions struct {
AllowOther bool

Expand Down
2 changes: 1 addition & 1 deletion fuse/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func doRead(server *Server, req *request) {
}

req.readResult, req.status = server.fileSystem.Read(req.cancel, 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() {
Expand Down
4 changes: 0 additions & 4 deletions fuse/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ 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 {
// Splice from the following file.
Expand Down
2 changes: 1 addition & 1 deletion fuse/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type request struct {
// Output data.
status Status
flatData []byte
fdData *readResultFd
fdData ReadResultFd
slices [][]byte

// In case of read, keep read result here so we can call
Expand Down
2 changes: 1 addition & 1 deletion fuse/splice_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ func (s *Server) setSplice() {
s.canSplice = false
}

func (ms *Server) trySplice(header []byte, req *request, fdData *readResultFd) error {
func (ms *Server) trySplice(header []byte, req *request, fdData ReadResultFd) error {
return fmt.Errorf("unimplemented")
}
14 changes: 7 additions & 7 deletions fuse/splice_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ func (s *Server) setSplice() {
//
// This is a four-step process:
//
// 1) Splice data form fdData.Fd into the "pair1" pipe buffer --> pair1: [payload]
// Now we know the actual payload length and can
// 1. Splice data form fdData.Fd into the "pair1" pipe buffer --> pair1: [payload]
// Now we know the actual payload length and can
// construct the reply header
// 2) Write header into the "pair2" pipe buffer --> pair2: [header]
// 4) Splice data from "pair1" into "pair2" --> pair2: [header][payload]
// 3) Splice the data from "pair2" into /dev/fuse
// 2. Write header into the "pair2" pipe buffer --> pair2: [header]
// 4. Splice data from "pair1" into "pair2" --> pair2: [header][payload]
// 3. Splice the data from "pair2" into /dev/fuse
//
// This dance is neccessary because header and payload cannot be split across
// two splices and we cannot seek in a pipe buffer.
func (ms *Server) trySplice(header []byte, req *request, fdData *readResultFd) error {
func (ms *Server) trySplice(header []byte, req *request, fdData ReadResultFd) error {
// Get a pair of connected pipes
pair, err := splice.Get()
if err != nil {
Expand Down Expand Up @@ -56,7 +56,7 @@ func (ms *Server) trySplice(header []byte, req *request, fdData *readResultFd) e
}

// Write data into pair2
n, err = pair.LoadFrom(fdData.Fd, payloadLen)
n, err = pair.LoadFrom(fdData.ReadFd(), payloadLen)
if err != nil {
return err
}
Expand Down

0 comments on commit 54bd1dd

Please sign in to comment.