-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
If a returned file implements the FilePassthroughFder interface, we try to register the file in the kernel. Implement this for loopbackFile, and test the behavior. For benchmarking, use a single reader. With multiple readers, contents are served out of kernel cache, and do not reflect FUSE performance. Benchmark (CPU i5-8350U pinned at 2Ghz): $ go build -v && go test -run "abc" -bench '(Libfuse|FD)' --passthrough_hp ~/vc/libfuse/build/example/passthrough_hp -test.cpu=1 BenchmarkGoFuseFDRead 27444 45997 ns/op 1424.80 MB/s 87 B/op 1 allocs/op BenchmarkLibfuseHP 35377 32198 ns/op 2035.43 MB/s 0 B/op 0 allocs/op $ go build -v && sudo go test -run "abc" -bench '(Libfuse|FD)' --passthrough_hp ~/vc/libfuse/build/example/passthrough_hp -test.cpu=1 BenchmarkGoFuseFDRead 91788 11902 ns/op 5506.23 MB/s 3 B/op 0 allocs/op BenchmarkLibfuseHP 100556 11831 ns/op 5539.38 MB/s 0 B/op 0 allocs/op Change-Id: If8bde502a3450028f4d87ba61fa9c76ea3ea6c63
- Loading branch information
Showing
7 changed files
with
222 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
// Copyright 2024 the Go-FUSE Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package fs | ||
|
||
import ( | ||
"context" | ||
"io" | ||
"os" | ||
"sync" | ||
"syscall" | ||
"testing" | ||
|
||
"github.com/hanwen/go-fuse/v2/fuse" | ||
"github.com/hanwen/go-fuse/v2/internal/testutil" | ||
) | ||
|
||
type rwRegisteringNode struct { | ||
LoopbackNode | ||
|
||
mu sync.Mutex | ||
reads int | ||
writes int | ||
} | ||
|
||
func (n *rwRegisteringNode) Read(ctx context.Context, f FileHandle, dest []byte, off int64) (fuse.ReadResult, syscall.Errno) { | ||
n.mu.Lock() | ||
defer n.mu.Unlock() | ||
n.reads++ | ||
return f.(FileReader).Read(ctx, dest, off) | ||
} | ||
|
||
func (n *rwRegisteringNode) Write(ctx context.Context, f FileHandle, data []byte, off int64) (written uint32, errno syscall.Errno) { | ||
n.mu.Lock() | ||
defer n.mu.Unlock() | ||
n.writes++ | ||
return f.(FileWriter).Write(ctx, data, off) | ||
} | ||
|
||
func TestPassthrough(t *testing.T) { | ||
if os.Geteuid() != 0 { | ||
t.Skip("passthrough requires CAP_SYS_ADMIN") | ||
} | ||
|
||
mnt := t.TempDir() | ||
n := &rwRegisteringNode{} | ||
|
||
rootData := &LoopbackRoot{ | ||
Path: t.TempDir(), | ||
NewNode: func(rootData *LoopbackRoot, parent *Inode, name string, st *syscall.Stat_t) InodeEmbedder { | ||
return n | ||
}, | ||
} | ||
n.RootData = rootData | ||
root := &LoopbackNode{ | ||
RootData: rootData, | ||
} | ||
opts := &Options{} | ||
opts.Debug = testutil.VerboseTest() | ||
server, err := Mount(mnt, root, opts) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer server.Unmount() | ||
|
||
fn := mnt + "/file" | ||
want := "hello there" | ||
if err := os.WriteFile(fn, []byte(want), 0666); err != nil { | ||
t.Fatalf("WriteFile: %v", err) | ||
} | ||
|
||
f, err := os.Open(fn) | ||
if err != nil { | ||
t.Fatalf("Open: %v", err) | ||
} | ||
defer f.Close() | ||
|
||
got, err := io.ReadAll(f) | ||
if err != nil { | ||
t.Fatalf("Open: %v", err) | ||
} | ||
if want != string(got) { | ||
t.Errorf("got %q want %q", got, want) | ||
} | ||
|
||
want2 := "xxxx" | ||
if err := os.WriteFile(fn, []byte(want2), 0666); err != nil { | ||
t.Fatalf("WriteFile: %v", err) | ||
} | ||
|
||
got2, err := os.ReadFile(fn) | ||
if err != nil { | ||
t.Fatalf("ReadFile: %v", err) | ||
} | ||
if string(got2) != want2 { | ||
t.Errorf("got %q want %q", got2, want2) | ||
} | ||
|
||
f.Close() | ||
server.Unmount() | ||
|
||
if n.reads > 0 { | ||
t.Errorf("got readcount %d want 0", n.reads) | ||
} | ||
if n.writes > 0 { | ||
t.Errorf("got writecount %d want 0", n.writes) | ||
} | ||
} |