summaryrefslogtreecommitdiff
path: root/internal/fusefrontend/node_helpers.go
diff options
context:
space:
mode:
authorJakob Unterwurzacher2021-06-25 11:33:18 +0200
committerJakob Unterwurzacher2021-06-25 13:56:53 +0200
commit84e702126ac4f017e12150532bfaed675dee2927 (patch)
treef2062bd585cb10bba1c7fa2204e1829b0d08bb64 /internal/fusefrontend/node_helpers.go
parent05b813f2026ebe6bff33cb600775823ee8a7df6e (diff)
fusefrontend: implement recursive diriv caching
The new contrib/maxlen.bash showed that we have exponential runtime with respect to directory depth. The new recursive diriv caching is a lot smarter as it caches intermediate lookups. maxlen.bash now completes in a few seconds. xfstests results same as https://github.com/rfjakob/fuse-xfstests/blob/2d158e4c82be85c15269af77498e353f928f4fab/screenlog.0 : Failures: generic/035 generic/062 generic/080 generic/093 generic/099 generic/215 generic/285 generic/319 generic/426 generic/444 generic/467 generic/477 generic/523 Failed 13 of 580 tests benchmark.bash results are identical: $ ./benchmark.bash Testing gocryptfs at /tmp/benchmark.bash.BdQ: gocryptfs v2.0.1-17-g6b09bc0; go-fuse v2.1.1-0.20210611132105-24a1dfe6b4f8; 2021-06-25 go1.16.5 linux/amd64 /tmp/benchmark.bash.BdQ.mnt is a mountpoint WRITE: 262144000 bytes (262 MB, 250 MiB) copied, 0,4821 s, 544 MB/s READ: 262144000 bytes (262 MB, 250 MiB) copied, 0,266061 s, 985 MB/s UNTAR: 8,280 MD5: 4,564 LS: 1,745 RM: 2,244
Diffstat (limited to 'internal/fusefrontend/node_helpers.go')
-rw-r--r--internal/fusefrontend/node_helpers.go89
1 files changed, 0 insertions, 89 deletions
diff --git a/internal/fusefrontend/node_helpers.go b/internal/fusefrontend/node_helpers.go
index f2d1e5e..ce2e8a9 100644
--- a/internal/fusefrontend/node_helpers.go
+++ b/internal/fusefrontend/node_helpers.go
@@ -2,16 +2,12 @@ package fusefrontend
import (
"context"
- "log"
- "path/filepath"
- "sync/atomic"
"syscall"
"github.com/hanwen/go-fuse/v2/fs"
"github.com/hanwen/go-fuse/v2/fuse"
- "github.com/rfjakob/gocryptfs/internal/nametransform"
"github.com/rfjakob/gocryptfs/internal/syscallcompat"
"github.com/rfjakob/gocryptfs/internal/tlog"
)
@@ -80,91 +76,6 @@ func (n *Node) rootNode() *RootNode {
return n.Root().Operations().(*RootNode)
}
-// prepareAtSyscall returns a (dirfd, cName) pair that can be used
-// with the "___at" family of system calls (openat, fstatat, unlinkat...) to
-// access the backing encrypted directory.
-//
-// If you pass a `child` file name, the (dirfd, cName) pair will refer to
-// a child of this node.
-// If `child` is empty, the (dirfd, cName) pair refers to this node itself. For
-// the root node, that means (dirfd, ".").
-func (n *Node) prepareAtSyscall(child string) (dirfd int, cName string, errno syscall.Errno) {
- rn := n.rootNode()
- // all filesystem operations go through prepareAtSyscall(), so this is a
- // good place to reset the idle marker.
- atomic.StoreUint32(&rn.IsIdle, 0)
-
- // root node itself is special
- if child == "" && n.IsRoot() {
- var err error
- dirfd, cName, err = rn.openBackingDir("")
- if err != nil {
- errno = fs.ToErrno(err)
- }
- return
- }
-
- // normal node itself can be converted to child of parent node
- if child == "" {
- name, p1 := n.Parent()
- if p1 == nil || name == "" {
- return -1, "", syscall.ENOENT
- }
- p2 := toNode(p1.Operations())
- return p2.prepareAtSyscall(name)
- }
-
- // Cache lookup
- // TODO make it work for plaintextnames as well?
- cacheable := (!rn.args.PlaintextNames)
- if cacheable {
- var iv []byte
- dirfd, iv = rn.dirCache.Lookup(n)
- if dirfd > 0 {
- var cName string
- var err error
- if rn.nameTransform.HaveBadnamePatterns() {
- //BadName allowed, try to determine filenames
- cName, err = rn.nameTransform.EncryptAndHashBadName(child, iv, dirfd)
- } else {
- cName, err = rn.nameTransform.EncryptAndHashName(child, iv)
- }
-
- if err != nil {
- return -1, "", fs.ToErrno(err)
- }
- return dirfd, cName, 0
- }
- }
-
- // Slowpath
- if child == "" {
- log.Panicf("BUG: child name is empty - this cannot happen")
- }
- p := filepath.Join(n.Path(), child)
- if rn.isFiltered(p) {
- errno = syscall.EPERM
- return
- }
- dirfd, cName, err := rn.openBackingDir(p)
- if err != nil {
- errno = fs.ToErrno(err)
- return
- }
-
- // Cache store
- if cacheable {
- // TODO: openBackingDir already calls ReadDirIVAt(). Avoid duplicate work?
- iv, err := nametransform.ReadDirIVAt(dirfd)
- if err != nil {
- syscall.Close(dirfd)
- return -1, "", fs.ToErrno(err)
- }
- rn.dirCache.Store(n, dirfd, iv)
- }
- return
-}
-
// newChild attaches a new child inode to n.
// The passed-in `st` will be modified to get a unique inode number
// (or, in `-sharedstorage` mode, the inode number will be set to zero).