From 54bd1dd91003df60dc2aa172fdd8035b1ac5fabc Mon Sep 17 00:00:00 2001 From: Sandy Xu Date: Wed, 6 Nov 2024 16:18:43 +0800 Subject: [PATCH 1/2] use interface for ReadResultFd --- fuse/api.go | 5 +++++ fuse/opcode.go | 2 +- fuse/read.go | 4 ---- fuse/request.go | 2 +- fuse/splice_darwin.go | 2 +- fuse/splice_linux.go | 14 +++++++------- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/fuse/api.go b/fuse/api.go index 6486538dd..085d9df53 100644 --- a/fuse/api.go +++ b/fuse/api.go @@ -112,6 +112,11 @@ type ReadResult interface { Done() } +type ReadResultFd interface { + ReadResult + ReadFd() uintptr +} + type MountOptions struct { AllowOther bool diff --git a/fuse/opcode.go b/fuse/opcode.go index 392bd30ae..44f408451 100644 --- a/fuse/opcode.go +++ b/fuse/opcode.go @@ -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() { diff --git a/fuse/read.go b/fuse/read.go index ee0508155..22075040b 100644 --- a/fuse/read.go +++ b/fuse/read.go @@ -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. diff --git a/fuse/request.go b/fuse/request.go index 7628159e0..22d0a3e25 100644 --- a/fuse/request.go +++ b/fuse/request.go @@ -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 diff --git a/fuse/splice_darwin.go b/fuse/splice_darwin.go index dc4774af3..354d6053b 100644 --- a/fuse/splice_darwin.go +++ b/fuse/splice_darwin.go @@ -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") } diff --git a/fuse/splice_linux.go b/fuse/splice_linux.go index bf331301e..9fcfe0b7f 100644 --- a/fuse/splice_linux.go +++ b/fuse/splice_linux.go @@ -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 { @@ -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 } From 032b51d23ef82fdadb10bc49ad19e2cddf31c60f Mon Sep 17 00:00:00 2001 From: Sandy Xu Date: Wed, 6 Nov 2024 17:29:47 +0800 Subject: [PATCH 2/2] adjust name --- fuse/api.go | 2 +- fuse/opcode.go | 2 +- fuse/read.go | 4 ++++ fuse/request.go | 2 +- fuse/splice_darwin.go | 2 +- fuse/splice_linux.go | 2 +- 6 files changed, 9 insertions(+), 5 deletions(-) diff --git a/fuse/api.go b/fuse/api.go index 085d9df53..215d59fd0 100644 --- a/fuse/api.go +++ b/fuse/api.go @@ -112,7 +112,7 @@ type ReadResult interface { Done() } -type ReadResultFd interface { +type ReadResultWithFd interface { ReadResult ReadFd() uintptr } diff --git a/fuse/opcode.go b/fuse/opcode.go index 44f408451..f16b66695 100644 --- a/fuse/opcode.go +++ b/fuse/opcode.go @@ -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() { diff --git a/fuse/read.go b/fuse/read.go index 22075040b..ee0508155 100644 --- a/fuse/read.go +++ b/fuse/read.go @@ -30,6 +30,10 @@ 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. diff --git a/fuse/request.go b/fuse/request.go index 22d0a3e25..8eab1aee9 100644 --- a/fuse/request.go +++ b/fuse/request.go @@ -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 diff --git a/fuse/splice_darwin.go b/fuse/splice_darwin.go index 354d6053b..b2ef73eb4 100644 --- a/fuse/splice_darwin.go +++ b/fuse/splice_darwin.go @@ -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") } diff --git a/fuse/splice_linux.go b/fuse/splice_linux.go index 9fcfe0b7f..5754bc1db 100644 --- a/fuse/splice_linux.go +++ b/fuse/splice_linux.go @@ -28,7 +28,7 @@ func (s *Server) setSplice() { // // 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 {