Skip to content

Commit

Permalink
Fixing the creation of multiple inode creation for the same name when…
Browse files Browse the repository at this point in the history
… MkDir or CreateFile executed simultaneously.

Get parent lock before creating inode from `Goofys.MkDir` or `Goofys.CreateFile` to avoid creating a duplicate inode.
Remove get lock from `Inode.Create` and `Inode.MkDir` since it lock already acquired by the caller.
  • Loading branch information
skuppa-veeva authored and skuppa committed Oct 27, 2020
1 parent 45b8d78 commit 1ff2c07
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
6 changes: 0 additions & 6 deletions internal/dir.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,6 @@ func (parent *Inode) Create(

fs := parent.fs

parent.mu.Lock()
defer parent.mu.Unlock()

now := time.Now()
inode = NewInode(fs, parent, &name)
inode.Attributes = InodeAttributes{
Expand Down Expand Up @@ -948,9 +945,6 @@ func (parent *Inode) MkDir(
return
}

parent.mu.Lock()
defer parent.mu.Unlock()

inode = NewInode(fs, parent, &name)
inode.ToDir()
inode.touch()
Expand Down
8 changes: 4 additions & 4 deletions internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,10 @@ func (fs *Goofys) CreateFile(
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

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

parent.mu.Lock()

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

fs.mu.Lock()
defer fs.mu.Unlock()
fs.insertInode(parent, inode)
Expand Down Expand Up @@ -1049,14 +1049,14 @@ func (fs *Goofys) MkDir(
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

parent.mu.Lock()

// ignore op.Mode for now
inode, err := parent.MkDir(op.Name)
if err != nil {
return err
}

parent.mu.Lock()

fs.mu.Lock()
defer fs.mu.Unlock()
fs.insertInode(parent, inode)
Expand Down

0 comments on commit 1ff2c07

Please sign in to comment.