Allow to spawn more than 1 FUSE file descriptor reader goroutine

fuse-mt
Vitaliy Filippov 2022-01-25 12:16:02 +03:00
parent 775aacf12c
commit e8004f04a5
3 changed files with 20 additions and 5 deletions

View File

@ -20,6 +20,7 @@ import (
"net"
"os"
"os/exec"
"sync/atomic"
"syscall"
)
@ -71,6 +72,9 @@ func Mount(
if cfgCopy.OpContext == nil {
cfgCopy.OpContext = context.Background()
}
if cfgCopy.ReaderThreads < 1 {
cfgCopy.ReaderThreads = 1
}
// Create a Connection object wrapping the device.
connection, err := newConnection(
@ -83,11 +87,16 @@ func Mount(
}
// Serve the connection in the background. When done, set the join status.
go func() {
server.ServeOps(connection)
mfs.joinStatus = connection.close()
close(mfs.joinStatusAvailable)
}()
atomic.AddInt64(&mfs.joinRemaining, int64(cfgCopy.ReaderThreads))
for i := 0; i < cfgCopy.ReaderThreads; i++ {
go func() {
server.ServeOps(connection)
if atomic.AddInt64(&mfs.joinRemaining, -1) == 0 {
mfs.joinStatus = connection.close()
close(mfs.joinStatusAvailable)
}
}()
}
// Wait for the mount process to complete.
if err := <-ready; err != nil {

View File

@ -161,6 +161,11 @@ type MountConfig struct {
// the data is already in memory when they return it to FUSE.
UseVectoredRead bool
// Number of goroutines (and hopefully threads) to use for reading from
// the FUSE file descriptor. You can try to use more than 1 if memory
// copying during write operations is a bottleneck for you
ReaderThreads int
// OS X only.
//
// The name of the mounted volume, as displayed in the Finder. If empty, a

View File

@ -23,6 +23,7 @@ type MountedFileSystem struct {
// The result to return from Join. Not valid until the channel is closed.
joinStatus error
joinRemaining int64
joinStatusAvailable chan struct{}
}