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

fuse: wire up passthrough support

The passthrough feature lets a filesystem register an open file
descriptor with the kernel to avoid roundtrips for read/write
operations.

Change-Id: Ia8bde502a3450028f4d87ba61fa9c76ea3ea6c63
parent 1224fbcf
......@@ -103,7 +103,7 @@ func doInit(server *Server, req *request) {
server.reqMu.Lock()
server.kernelSettings = *input
kernelFlags &= (CAP_ASYNC_READ | CAP_BIG_WRITES | CAP_FILE_OPS |
CAP_READDIRPLUS | CAP_NO_OPEN_SUPPORT | CAP_PARALLEL_DIROPS | CAP_MAX_PAGES | CAP_RENAME_SWAP)
CAP_READDIRPLUS | CAP_NO_OPEN_SUPPORT | CAP_PARALLEL_DIROPS | CAP_MAX_PAGES | CAP_RENAME_SWAP | CAP_PASSTHROUGH)
if server.opts.EnableLocks {
kernelFlags |= CAP_FLOCK_LOCKS | CAP_POSIX_LOCKS
......@@ -154,6 +154,7 @@ func doInit(server *Server, req *request) {
CongestionThreshold: uint16(server.opts.MaxBackground * 3 / 4),
MaxBackground: uint16(server.opts.MaxBackground),
MaxPages: uint16(maxPages),
MaxStackDepth: 1,
}
out.setFlags(kernelFlags)
if server.opts.MaxReadAhead != 0 && uint32(server.opts.MaxReadAhead) < out.MaxReadAhead {
......
// Copyright 2024 the Go-FUSE Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package fuse
import (
"syscall"
"unsafe"
)
const (
_DEV_IOC_BACKING_OPEN = 0x4010e501
_DEV_IOC_BACKING_CLOSE = 0x4004e502
)
type backingMap struct {
Fd int32
Flags uint32
padding uint64
}
// RegisterBackingFd registers the given file descriptor in the
// kernel, so the kernel can bypass FUSE and access the backing file
// directly for read and write calls. On success a backing ID is
// returned. The backing ID should unregistered using
// UnregisterBackingFd() once the file is released. For now, the flags
// argument is unused, and should be 0.
func (ms *Server) RegisterBackingFd(fd int, flags uint32) (int32, syscall.Errno) {
m := backingMap{
Fd: int32(fd),
Flags: flags,
}
ms.writeMu.Lock()
id, _, errno := syscall.Syscall(syscall.SYS_IOCTL, uintptr(ms.mountFd), uintptr(_DEV_IOC_BACKING_OPEN), uintptr(unsafe.Pointer(&m)))
ms.writeMu.Unlock()
return int32(id), errno
}
// UnregisterBackingFd unregisters the given ID in the kernel. The ID
// should have been acquired before using RegisterBackingFd.
func (ms *Server) UnregisterBackingFd(id int32) syscall.Errno {
ms.writeMu.Lock()
_, _, ep := syscall.Syscall(syscall.SYS_IOCTL, uintptr(ms.mountFd), uintptr(_DEV_IOC_BACKING_CLOSE), uintptr(unsafe.Pointer(&id)))
ms.writeMu.Unlock()
return ep
}
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