Skip to content

Commit

Permalink
Move LookUpCached to dir.go
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Jun 9, 2023
1 parent 533e178 commit 2688d6d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 58 deletions.
60 changes: 60 additions & 0 deletions internal/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -1711,6 +1711,66 @@ func (parent *Inode) findChildMaxTime() (maxMtime, maxCtime time.Time) {
return
}

func (parent *Inode) LookUpCached(name string) (inode *Inode, err error) {
parent.mu.Lock()
ok := false
inode = parent.findChildUnlocked(name)
if inode != nil {
ok = true
if expired(inode.AttrTime, parent.fs.flags.StatCacheTTL) {
ok = false
if inode.CacheState != ST_CACHED ||
inode.isDir() && atomic.LoadInt64(&inode.dir.ModifiedChildren) > 0 {
// we have an open file handle, object
// in S3 may not represent the true
// state of the file anyway, so just
// return what we know which is
// potentially more accurate
ok = true
} else {
inode.logFuse("lookup expired")
}
}
} else {
ok = false
if parent.dir.DeletedChildren != nil {
if _, ok := parent.dir.DeletedChildren[name]; ok {
// File is deleted locally
parent.mu.Unlock()
return nil, syscall.ENOENT
}
}
if !expired(parent.dir.DirTime, parent.fs.flags.StatCacheTTL) {
// Don't recheck from the server if directory cache is actual
parent.mu.Unlock()
return nil, syscall.ENOENT
}
}
parent.mu.Unlock()
if !ok {
inode, err = parent.recheckInode(inode, name)
err = mapAwsError(err)
if err != nil {
return nil, err
}
if inode == nil {
return nil, syscall.ENOENT
}
}
return inode, nil
}

func (parent *Inode) recheckInode(inode *Inode, name string) (newInode *Inode, err error) {
newInode, err = parent.LookUp(name, inode == nil)
if err != nil {
if inode != nil {
parent.removeChild(inode)
}
return nil, err
}
return newInode, nil
}

func (parent *Inode) LookUp(name string, doSlurp bool) (*Inode, error) {
_, parentKey := parent.cloud()
key := appendChildName(parentKey, name)
Expand Down
62 changes: 4 additions & 58 deletions internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ func (fs *Goofys) RefreshInodeCache(inode *Inode) error {
}
return mappedErr
}
inode, err := fs.recheckInode(parent, inode, name)
inode, err := parent.recheckInode(inode, name)
mappedErr = mapAwsError(err)
if fs.connection != nil {
// Send notifications from another goroutine to prevent deadlocks
Expand Down Expand Up @@ -1127,58 +1127,15 @@ func (fs *Goofys) LookUpInode(

atomic.AddInt64(&fs.stats.metadataReads, 1)

var inode *Inode
var ok bool
defer func() { fuseLog.Debugf("<-- LookUpInode %v %v %v", op.Parent, op.Name, err) }()

fs.mu.RLock()
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

parent.mu.Lock()
inode = parent.findChildUnlocked(op.Name)
if inode != nil {
ok = true
if expired(inode.AttrTime, fs.flags.StatCacheTTL) {
ok = false
if inode.CacheState != ST_CACHED ||
inode.isDir() && atomic.LoadInt64(&inode.dir.ModifiedChildren) > 0 {
// we have an open file handle, object
// in S3 may not represent the true
// state of the file anyway, so just
// return what we know which is
// potentially more accurate
ok = true
} else {
inode.logFuse("lookup expired")
}
}
} else {
ok = false
if parent.dir.DeletedChildren != nil {
if _, ok := parent.dir.DeletedChildren[op.Name]; ok {
// File is deleted locally
parent.mu.Unlock()
return syscall.ENOENT
}
}
if !expired(parent.dir.DirTime, fs.flags.StatCacheTTL) {
// Don't recheck from the server if directory cache is actual
parent.mu.Unlock()
return syscall.ENOENT
}
}
parent.mu.Unlock()

if !ok {
inode, err = fs.recheckInode(parent, inode, op.Name)
err = mapAwsError(err)
if err != nil {
return
}
if inode == nil {
return syscall.ENOENT
}
inode, err := parent.LookUpCached(op.Name)
if err != nil {
return err
}

inode.Ref()
Expand All @@ -1190,17 +1147,6 @@ func (fs *Goofys) LookUpInode(
return
}

func (fs *Goofys) recheckInode(parent *Inode, inode *Inode, name string) (newInode *Inode, err error) {
newInode, err = parent.LookUp(name, inode == nil)
if err != nil {
if inode != nil {
parent.removeChild(inode)
}
return nil, err
}
return newInode, nil
}

// LOCKS_REQUIRED(parent.mu)
// LOCKS_EXCLUDED(fs.mu)
func (fs *Goofys) insertInode(parent *Inode, inode *Inode) {
Expand Down

0 comments on commit 2688d6d

Please sign in to comment.