-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The passthrough feature lets a filesystem register an open file descriptor with the kernel to avoid roundtrips for read/write operations. Change-Id: Ia8bde502a3450028f4d87ba61fa9c76ea3ea6c63
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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 | ||
} |