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

Use file descriptor in mounstate.

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