fusefrontend: use DirIVCache in OpenDir()

Previously, OpenDir() did not use the cache at all, missing
an opportunity to speed up repeated directory reads.
This commit is contained in:
Jakob Unterwurzacher 2017-09-03 13:56:11 +02:00
parent 7da0e97c8b
commit 276567eb13
1 changed files with 16 additions and 10 deletions

View File

@ -260,18 +260,24 @@ func (fs *FS) OpenDir(dirName string, context *fuse.Context) ([]fuse.DirEntry, f
// Get DirIV (stays nil if PlaintextNames is used)
var cachedIV []byte
if !fs.args.PlaintextNames {
// Read the DirIV once and use it for all later name decryptions
cachedIV, err = nametransform.ReadDirIV(cDirAbsPath)
if err != nil {
// This can happen during normal operation when the directory has
// been deleted concurrently. But it can also mean that the
// gocryptfs.diriv is missing due to an error, so log the event
// at "info" level.
tlog.Info.Printf("OpenDir: %v", err)
return nil, fuse.ToStatus(err)
cachedIV, _ = fs.nameTransform.DirIVCache.Lookup(dirName)
if cachedIV == nil {
// Read the DirIV from disk and store it in the cache
fs.dirIVLock.RLock()
cachedIV, err = nametransform.ReadDirIV(cDirAbsPath)
if err != nil {
fs.dirIVLock.RUnlock()
// This can happen during normal operation when the directory has
// been deleted concurrently. But it can also mean that the
// gocryptfs.diriv is missing due to an error, so log the event
// at "info" level.
tlog.Info.Printf("OpenDir: %v", err)
return nil, fuse.ToStatus(err)
}
fs.nameTransform.DirIVCache.Store(dirName, cachedIV, cDirName)
fs.dirIVLock.RUnlock()
}
}
// Decrypted directory entries
var plain []fuse.DirEntry
var errorCount int