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" "net"
"os" "os"
"os/exec" "os/exec"
"sync/atomic"
"syscall" "syscall"
) )
@ -71,6 +72,9 @@ func Mount(
if cfgCopy.OpContext == nil { if cfgCopy.OpContext == nil {
cfgCopy.OpContext = context.Background() cfgCopy.OpContext = context.Background()
} }
if cfgCopy.ReaderThreads < 1 {
cfgCopy.ReaderThreads = 1
}
// Create a Connection object wrapping the device. // Create a Connection object wrapping the device.
connection, err := newConnection( connection, err := newConnection(
@ -83,11 +87,16 @@ func Mount(
} }
// Serve the connection in the background. When done, set the join status. // Serve the connection in the background. When done, set the join status.
go func() { atomic.AddInt64(&mfs.joinRemaining, int64(cfgCopy.ReaderThreads))
server.ServeOps(connection) for i := 0; i < cfgCopy.ReaderThreads; i++ {
mfs.joinStatus = connection.close() go func() {
close(mfs.joinStatusAvailable) server.ServeOps(connection)
}() if atomic.AddInt64(&mfs.joinRemaining, -1) == 0 {
mfs.joinStatus = connection.close()
close(mfs.joinStatusAvailable)
}
}()
}
// Wait for the mount process to complete. // Wait for the mount process to complete.
if err := <-ready; err != nil { 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. // the data is already in memory when they return it to FUSE.
UseVectoredRead bool 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. // OS X only.
// //
// The name of the mounted volume, as displayed in the Finder. If empty, a // 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. // The result to return from Join. Not valid until the channel is closed.
joinStatus error joinStatus error
joinRemaining int64
joinStatusAvailable chan struct{} joinStatusAvailable chan struct{}
} }