Skip to content

Commit

Permalink
fuse: support MountOptions.DisableSplice
Browse files Browse the repository at this point in the history
Change-Id: I929cf60fb5c04920754dd2a2e404d0afebdcd46c
  • Loading branch information
hanwen committed Nov 9, 2024
1 parent a37ff39 commit 0f594ce
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions fs/simple_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ type testOptions struct {
ro bool
directMount bool // sets MountOptions.DirectMount
directMountStrict bool // sets MountOptions.DirectMountStrict
disableSplice bool // sets MountOptions.DisableSplice
}

// newTestCase creates the directories `orig` and `mnt` inside a temporary
Expand Down Expand Up @@ -111,6 +112,7 @@ func newTestCase(t *testing.T, opts *testOptions) *testCase {
DirectMount: opts.directMount,
DirectMountStrict: opts.directMountStrict,
EnableLocks: opts.enableLocks,
DisableSplice: opts.disableSplice,
}
if !opts.suppressDebug {
mOpts.Debug = testutil.VerboseTest()
Expand Down Expand Up @@ -390,6 +392,14 @@ func TestPosix(t *testing.T) {
}
}

func TestReadDisableSplice(t *testing.T) {
tc := newTestCase(t, &testOptions{
disableSplice: true,
})

posixtest.FileBasic(t, tc.mntDir)
}

func TestOpenDirectIO(t *testing.T) {
// Apparently, tmpfs does not allow O_DIRECT, so try to create
// a test temp directory in /var/tmp.
Expand Down
3 changes: 3 additions & 0 deletions fuse/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ type MountOptions struct {
// directory queries (i.e. 'ls' without '-l') can be faster with
// ReadDir, as no per-file stat calls are needed
DisableReadDirPlus bool

// Disable splicing from files to the FUSE device.
DisableSplice bool
}

// RawFileSystem is an interface close to the FUSE wire protocol.
Expand Down
5 changes: 5 additions & 0 deletions fuse/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,6 +693,11 @@ func (ms *protocolServer) handleRequest(h *operationHandler, req *request) {
// This includes osxfuse (a.k.a. macfuse).
req.outHeader().Length = uint32(sizeOfOutHeader) + 24
}
if req.fdData != nil && ms.opts.DisableSplice {
req.outPayload, req.status = req.fdData.Bytes(req.outPayload)
req.fdData = nil
}

req.serializeHeader(req.outPayloadSize())

if ms.opts.Debug {
Expand Down
2 changes: 1 addition & 1 deletion fuse/splice_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

func (s *Server) setSplice() {
s.canSplice = splice.Resizable()
s.canSplice = splice.Resizable() && !s.opts.DisableSplice
}

// trySplice: Zero-copy read from fdData.Fd into /dev/fuse
Expand Down

0 comments on commit 0f594ce

Please sign in to comment.