Commit dd926abd authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Use file descriptor in mounstate.

parent 675a48a2
...@@ -114,7 +114,7 @@ import ( ...@@ -114,7 +114,7 @@ import (
"unsafe" "unsafe"
) )
func mount(dir string, options string) (connection *os.File, err error) { func mount(dir string, options string) (int, error) {
errp := (**C.char)(C.malloc(16)) errp := (**C.char)(C.malloc(16))
*errp = nil *errp = nil
defer C.free(unsafe.Pointer(errp)) defer C.free(unsafe.Pointer(errp))
...@@ -124,7 +124,7 @@ func mount(dir string, options string) (connection *os.File, err error) { ...@@ -124,7 +124,7 @@ func mount(dir string, options string) (connection *os.File, err error) {
if *errp != nil { if *errp != nil {
return nil, mountError(C.GoString(*errp)) return nil, mountError(C.GoString(*errp))
} }
return os.NewFile(uintptr(fd), "<fuseConnection>"), nil return fd, nil
} }
......
...@@ -26,7 +26,7 @@ func unixgramSocketpair() (l, r *os.File, err error) { ...@@ -26,7 +26,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) (f *os.File, err error) { func mount(mountPoint string, options string) (fd int, err error) {
local, remote, err := unixgramSocketpair() local, remote, err := unixgramSocketpair()
if err != nil { if err != nil {
return return
...@@ -98,7 +98,7 @@ func unmount(mountPoint string) (err error) { ...@@ -98,7 +98,7 @@ func unmount(mountPoint string) (err error) {
return return
} }
func getConnection(local *os.File) (f *os.File, err error) { func getConnection(local *os.File) (int, error) {
var data [4]byte var data [4]byte
control := make([]byte, 4*256) control := make([]byte, 4*256)
...@@ -107,26 +107,22 @@ func getConnection(local *os.File) (f *os.File, err error) { ...@@ -107,26 +107,22 @@ func getConnection(local *os.File) (f *os.File, err error) {
err := syscall.Recvmsg( err := syscall.Recvmsg(
int(local.Fd()), data[:], control[:], 0) int(local.Fd()), data[:], control[:], 0)
if err != nil { if err != nil {
return return 0, err
} }
message := *(*syscall.Cmsghdr)(unsafe.Pointer(&control[0])) message := *(*syscall.Cmsghdr)(unsafe.Pointer(&control[0]))
fd := *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&control[0])) + syscall.SizeofCmsghdr)) fd := *(*int32)(unsafe.Pointer(uintptr(unsafe.Pointer(&control[0])) + syscall.SizeofCmsghdr))
if message.Type != 1 { if message.Type != 1 {
err = fmt.Errorf("getConnection: recvmsg returned wrong control type: %d", message.Type) return 0, fmt.Errorf("getConnection: recvmsg returned wrong control type: %d", message.Type)
return
} }
if oobn <= syscall.SizeofCmsghdr { if oobn <= syscall.SizeofCmsghdr {
err = fmt.Errorf("getConnection: too short control message. Length: %d", oobn) return 0, fmt.Errorf("getConnection: too short control message. Length: %d", oobn)
return
} }
if fd < 0 { if fd < 0 {
err = fmt.Errorf("getConnection: fd < 0: %d", fd) return 0, fmt.Errorf("getConnection: fd < 0: %d", fd)
return
} }
f = os.NewFile(uintptr(fd), "<fuseConnection>") return int(fd), nil
return
} }
func init() { func init() {
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"sync" "sync"
"syscall"
"time" "time"
"unsafe" "unsafe"
...@@ -26,7 +27,7 @@ type MountState struct { ...@@ -26,7 +27,7 @@ type MountState struct {
fileSystem RawFileSystem fileSystem RawFileSystem
// I/O with kernel and daemon. // I/O with kernel and daemon.
mountFile *os.File mountFd int
// Dump debug info onto stdout. // Dump debug info onto stdout.
Debug bool Debug bool
...@@ -127,7 +128,7 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error { ...@@ -127,7 +128,7 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error {
} }
mountPoint = filepath.Clean(filepath.Join(cwd, mountPoint)) mountPoint = filepath.Clean(filepath.Join(cwd, mountPoint))
} }
file, err := mount(mountPoint, strings.Join(optStrs, ",")) fd, err := mount(mountPoint, strings.Join(optStrs, ","))
if err != nil { if err != nil {
return err return err
} }
...@@ -144,7 +145,7 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error { ...@@ -144,7 +145,7 @@ func (ms *MountState) Mount(mountPoint string, opts *MountOptions) error {
} }
ms.fileSystem.Init(&initParams) ms.fileSystem.Init(&initParams)
ms.mountPoint = mountPoint ms.mountPoint = mountPoint
ms.mountFile = file ms.mountFd = fd
return nil return nil
} }
...@@ -236,7 +237,7 @@ func (ms *MountState) readRequest(exitIdle bool) (req *request, code Status) { ...@@ -236,7 +237,7 @@ func (ms *MountState) readRequest(exitIdle bool) (req *request, code Status) {
ms.reqReaders++ ms.reqReaders++
ms.reqMu.Unlock() ms.reqMu.Unlock()
n, err := ms.mountFile.Read(dest) n, err := syscall.Read(ms.mountFd, dest)
if err != nil { if err != nil {
code = ToStatus(err) code = ToStatus(err)
ms.reqMu.Lock() ms.reqMu.Lock()
...@@ -305,7 +306,7 @@ func (ms *MountState) Loop() { ...@@ -305,7 +306,7 @@ func (ms *MountState) Loop() {
ms.loops.Wait() ms.loops.Wait()
ms.reqMu.Lock() ms.reqMu.Lock()
ms.mountFile.Close() syscall.Close(ms.mountFd)
ms.reqMu.Unlock() ms.reqMu.Unlock()
} }
......
package fuse package fuse
import ( import (
"log" "log"
"syscall"
) )
func (ms *MountState) systemWrite(req *request, header []byte) Status { func (ms *MountState) systemWrite(req *request, header []byte) Status {
if req.flatDataSize() == 0 { if req.flatDataSize() == 0 {
_, err := ms.mountFile.Write(header) _, err := syscall.Write(ms.mountFd, header)
return ToStatus(err) return ToStatus(err)
} }
...@@ -24,7 +27,7 @@ func (ms *MountState) systemWrite(req *request, header []byte) Status { ...@@ -24,7 +27,7 @@ func (ms *MountState) systemWrite(req *request, header []byte) Status {
header = req.serializeHeader(len(req.flatData)) header = req.serializeHeader(len(req.flatData))
} }
_, err := Writev(int(ms.mountFile.Fd()), [][]byte{header, req.flatData}) _, err := Writev(ms.mountFd, [][]byte{header, req.flatData})
if req.readResult != nil { if req.readResult != nil {
req.readResult.Done() req.readResult.Done()
} }
......
...@@ -61,7 +61,7 @@ func (ms *MountState) trySplice(header []byte, req *request, fdData *ReadResultF ...@@ -61,7 +61,7 @@ func (ms *MountState) trySplice(header []byte, req *request, fdData *ReadResultF
return fmt.Errorf("wrote %d, want %d", n, fdData.Size()) return fmt.Errorf("wrote %d, want %d", n, fdData.Size())
} }
_, err = pair.WriteTo(ms.mountFile.Fd(), total) _, err = pair.WriteTo(uintptr(ms.mountFd), total)
if err != nil { if err != nil {
return err return err
} }
......
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