Skip to content

Commit 1ff2c07

Browse files
skuppa-veevaskuppa
authored andcommitted
Fixing the creation of multiple inode creation for the same name when 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.
1 parent 45b8d78 commit 1ff2c07

File tree

2 files changed

+4
-10
lines changed

2 files changed

+4
-10
lines changed

internal/dir.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,6 @@ func (parent *Inode) Create(
905905

906906
fs := parent.fs
907907

908-
parent.mu.Lock()
909-
defer parent.mu.Unlock()
910-
911908
now := time.Now()
912909
inode = NewInode(fs, parent, &name)
913910
inode.Attributes = InodeAttributes{
@@ -948,9 +945,6 @@ func (parent *Inode) MkDir(
948945
return
949946
}
950947

951-
parent.mu.Lock()
952-
defer parent.mu.Unlock()
953-
954948
inode = NewInode(fs, parent, &name)
955949
inode.ToDir()
956950
inode.touch()

internal/goofys.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,10 +1013,10 @@ func (fs *Goofys) CreateFile(
10131013
parent := fs.getInodeOrDie(op.Parent)
10141014
fs.mu.RUnlock()
10151015

1016-
inode, fh := parent.Create(op.Name, op.Metadata)
1017-
10181016
parent.mu.Lock()
10191017

1018+
inode, fh := parent.Create(op.Name, op.Metadata)
1019+
10201020
fs.mu.Lock()
10211021
defer fs.mu.Unlock()
10221022
fs.insertInode(parent, inode)
@@ -1049,14 +1049,14 @@ func (fs *Goofys) MkDir(
10491049
parent := fs.getInodeOrDie(op.Parent)
10501050
fs.mu.RUnlock()
10511051

1052+
parent.mu.Lock()
1053+
10521054
// ignore op.Mode for now
10531055
inode, err := parent.MkDir(op.Name)
10541056
if err != nil {
10551057
return err
10561058
}
10571059

1058-
parent.mu.Lock()
1059-
10601060
fs.mu.Lock()
10611061
defer fs.mu.Unlock()
10621062
fs.insertInode(parent, inode)

0 commit comments

Comments
 (0)