Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use interface for ReadResultFd #33

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 ReadResultWithFd 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.(ReadResultWithFd); ok {
req.fdData = fd
req.flatData = nil
} else if req.readResult != nil && req.status.Ok() {
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 ReadResultWithFd
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 ReadResultWithFd) 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 ReadResultWithFd) 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
Loading