Skip to content

Commit

Permalink
Fix ForgetInode() race condition. Add parent lock to CreateFile() and…
Browse files Browse the repository at this point in the history
… Mkdir()

fixes #410
  • Loading branch information
fly1028 authored and kahing committed May 20, 2019
1 parent 19ff680 commit 2b75cc5
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -694,20 +694,25 @@ func (fs *Goofys) ForgetInode(
op *fuseops.ForgetInodeOp) (err error) {

fs.mu.Lock()

inode := fs.getInodeOrDie(op.Inode)
fs.mu.Unlock()

if inode.Parent != nil {
inode.Parent.mu.Lock()
defer inode.Parent.mu.Unlock()
}
fs.mu.Lock()
defer fs.mu.Unlock()

stale := inode.DeRef(op.N)

if stale {
delete(fs.inodes, op.Inode)
fs.forgotCnt += 1
fs.mu.Unlock()

if inode.Parent != nil {
inode.Parent.removeChild(inode)
inode.Parent.removeChildUnlocked(inode)
}
} else {
fs.mu.Unlock()
}

return
Expand Down Expand Up @@ -977,11 +982,14 @@ func (fs *Goofys) CreateFile(

inode, fh := parent.Create(op.Name)

parent.mu.Lock()

fs.mu.Lock()
defer fs.mu.Unlock()

fs.insertInode(parent, inode)

parent.mu.Unlock()

op.Entry.Child = inode.Id
op.Entry.Attributes = inode.InflateAttributes()
op.Entry.AttributesExpiration = time.Now().Add(fs.flags.StatCacheTTL)
Expand Down Expand Up @@ -1014,11 +1022,14 @@ func (fs *Goofys) MkDir(
return err
}

parent.mu.Lock()

fs.mu.Lock()
defer fs.mu.Unlock()

fs.insertInode(parent, inode)

parent.mu.Unlock()

op.Entry.Child = inode.Id
op.Entry.Attributes = inode.InflateAttributes()
op.Entry.AttributesExpiration = time.Now().Add(fs.flags.StatCacheTTL)
Expand Down

0 comments on commit 2b75cc5

Please sign in to comment.