Commit 0cc52fac authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Derive iosize on Darwin from the MaxWrite setting we send to the

kernel.

Change-Id: Ic481d3aadac3979722f9d7c1e2f8d305dcbd7e10
parent b2ac4af8
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"strings"
"syscall" "syscall"
) )
...@@ -31,13 +32,13 @@ func openFUSEDevice() (*os.File, error) { ...@@ -31,13 +32,13 @@ func openFUSEDevice() (*os.File, error) {
const bin = "/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs" const bin = "/Library/Filesystems/osxfusefs.fs/Support/mount_osxfusefs"
func mount(mountPoint, options string, ready chan<- error) (fd int, err error) { func mount(mountPoint string, opts *MountOptions, ready chan<- error) (fd int, err error) {
f, err := openFUSEDevice() f, err := openFUSEDevice()
if err != nil { if err != nil {
return 0, err return 0, err
} }
cmd := exec.Command(bin, "-o", options, "-o", fmt.Sprintf("iosize=%d", MAX_KERNEL_WRITE), "3", mountPoint) cmd := exec.Command(bin, "-o", strings.Join(opts.optionsStrings(), ","), "-o", fmt.Sprintf("iosize=%d", opts.MaxWrite), "3", mountPoint)
cmd.ExtraFiles = []*os.File{f} cmd.ExtraFiles = []*os.File{f}
cmd.Env = append(os.Environ(), "MOUNT_FUSEFS_CALL_BY_LIB=", "MOUNT_OSXFUSE_CALL_BY_LIB=", cmd.Env = append(os.Environ(), "MOUNT_FUSEFS_CALL_BY_LIB=", "MOUNT_OSXFUSE_CALL_BY_LIB=",
"MOUNT_OSXFUSE_DAEMON_PATH="+os.Args[0], "MOUNT_OSXFUSE_DAEMON_PATH="+os.Args[0],
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"os/exec" "os/exec"
"path" "path"
"path/filepath" "path/filepath"
"strings"
"syscall" "syscall"
"unsafe" "unsafe"
) )
...@@ -24,7 +25,7 @@ func unixgramSocketpair() (l, r *os.File, err error) { ...@@ -24,7 +25,7 @@ func unixgramSocketpair() (l, r *os.File, err error) {
// Create a FUSE FS on the specified mount point. The returned // Create a FUSE FS on the specified mount point. The returned
// mount point is always absolute. // mount point is always absolute.
func mount(mountPoint string, options string, ready chan<- error) (fd int, err error) { func mount(mountPoint string, opts *MountOptions, ready chan<- error) (fd int, err error) {
local, remote, err := unixgramSocketpair() local, remote, err := unixgramSocketpair()
if err != nil { if err != nil {
return return
...@@ -39,9 +40,8 @@ func mount(mountPoint string, options string, ready chan<- error) (fd int, err e ...@@ -39,9 +40,8 @@ func mount(mountPoint string, options string, ready chan<- error) (fd int, err e
} }
cmd := []string{bin, mountPoint} cmd := []string{bin, mountPoint}
if options != "" { if s := opts.optionsStrings(); len(s) > 0 {
cmd = append(cmd, "-o") cmd = append(cmd, "-o", strings.Join(s, ","))
cmd = append(cmd, options)
} }
proc, err := os.StartProcess(bin, proc, err := os.StartProcess(bin,
cmd, cmd,
......
...@@ -135,7 +135,21 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server ...@@ -135,7 +135,21 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
if o.MaxWrite > MAX_KERNEL_WRITE { if o.MaxWrite > MAX_KERNEL_WRITE {
o.MaxWrite = MAX_KERNEL_WRITE o.MaxWrite = MAX_KERNEL_WRITE
} }
opts = &o if o.Name == "" {
name := fs.String()
l := len(name)
if l > _MAX_NAME_LEN {
l = _MAX_NAME_LEN
}
o.Name = strings.Replace(name[:l], ",", ";", -1)
}
for _, s := range o.optionsStrings() {
if strings.Contains(s, ",") {
return nil, fmt.Errorf("found ',' in option string %q", s)
}
}
ms := &Server{ ms := &Server{
fileSystem: fs, fileSystem: fs,
opts: &o, opts: &o,
...@@ -146,26 +160,6 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server ...@@ -146,26 +160,6 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
} }
ms.reqPool.New = func() interface{} { return new(request) } ms.reqPool.New = func() interface{} { return new(request) }
ms.readPool.New = func() interface{} { return make([]byte, o.MaxWrite+PAGESIZE) } ms.readPool.New = func() interface{} { return make([]byte, o.MaxWrite+PAGESIZE) }
optStrs := opts.Options
if opts.AllowOther {
optStrs = append(optStrs, "allow_other")
}
name := opts.Name
if name == "" {
name = ms.fileSystem.String()
l := len(name)
if l > _MAX_NAME_LEN {
l = _MAX_NAME_LEN
}
name = strings.Replace(name[:l], ",", ";", -1)
}
optStrs = append(optStrs, "subtype="+name)
fsname := opts.FsName
if len(fsname) > 0 {
optStrs = append(optStrs, "fsname="+fsname)
}
mountPoint = filepath.Clean(mountPoint) mountPoint = filepath.Clean(mountPoint)
if !filepath.IsAbs(mountPoint) { if !filepath.IsAbs(mountPoint) {
...@@ -176,7 +170,7 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server ...@@ -176,7 +170,7 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
mountPoint = filepath.Clean(filepath.Join(cwd, mountPoint)) mountPoint = filepath.Clean(filepath.Join(cwd, mountPoint))
} }
ms.ready = make(chan error, 1) ms.ready = make(chan error, 1)
fd, err := mount(mountPoint, strings.Join(optStrs, ","), ms.ready) fd, err := mount(mountPoint, &o, ms.ready)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -192,6 +186,24 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server ...@@ -192,6 +186,24 @@ func NewServer(fs RawFileSystem, mountPoint string, opts *MountOptions) (*Server
return ms, nil return ms, nil
} }
func (o *MountOptions) optionsStrings() []string {
var r []string
r = append(r, o.Options...)
if o.AllowOther {
r = append(r, "allow_other")
}
if o.FsName != "" {
r = append(r, "fsname="+o.FsName)
}
if o.Name != "" {
r = append(r, "subtype="+o.Name)
}
return r
}
// DebugData returns internal status information for debugging // DebugData returns internal status information for debugging
// purposes. // purposes.
func (ms *Server) DebugData() string { func (ms *Server) DebugData() string {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment