Fixed CreateFile concurrency issues in memfs.

geesefs-0-30-9
Aaron Jacobs 2015-05-21 15:15:53 +10:00
commit b82157437e
3 changed files with 21 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import (
const (
// Errors corresponding to kernel error numbers. These may be treated
// specially by fuseops.Op.Respond methods.
EEXIST = bazilfuse.EEXIST
EINVAL = bazilfuse.Errno(syscall.EINVAL)
EIO = bazilfuse.EIO
ENOENT = bazilfuse.ENOENT

View File

@ -341,6 +341,14 @@ func (fs *memFS) CreateFile(
parent := fs.getInodeForModifyingOrDie(op.Parent)
defer parent.mu.Unlock()
// Ensure that the name doesn't alread exist, so we don't wind up with a
// duplicate.
_, exists := parent.LookUpChild(op.Name)
if exists {
err = fuse.EEXIST
return
}
// Set up attributes from the child, using the credentials of the calling
// process as owner (matching inode_init_owner, cf. http://goo.gl/5qavg8).
now := fs.clock.Now()

View File

@ -1251,3 +1251,15 @@ func (t *MemFSTest) DeleteSymlink() {
AssertEq(nil, err)
ExpectThat(entries, ElementsAre())
}
func (t *MemFSTest) CreateInParallel_NoTruncate() {
runCreateInParallelTest_NoTruncate(t.Ctx, t.Dir)
}
func (t *MemFSTest) CreateInParallel_Truncate() {
runCreateInParallelTest_Truncate(t.Ctx, t.Dir)
}
func (t *MemFSTest) CreateInParallel_Exclusive() {
runCreateInParallelTest_Exclusive(t.Ctx, t.Dir)
}