Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the creation of multiple inode creation for the same name when… #572

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()

Comment on lines -908 to -910
Copy link
Author

@skuppa-veeva skuppa-veeva Oct 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to parent lock since it is already locked from caller.

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()

Comment on lines -951 to -953
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need lock here as well, since caller already has a lock.

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()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder creation is moved after acquiring the parent lock. This lock needs to be atomic between creating inode and inserting into map of inodes.

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()

Comment on lines -1058 to -1059
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The folder creation is moved after acquiring the parent lock. This lock needs to be atomic between creating inode and inserting into map of inodes.

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