Skip to content

Commit

Permalink
Move fs.mu lock into getInodeOrDie()
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalif committed Jun 13, 2023
1 parent 6cc15cc commit a2c3b06
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 48 deletions.
2 changes: 0 additions & 2 deletions internal/cluster_fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,6 @@ func (fs *ClusterFs) setInodeAttributes(inode *Inode, size *uint64, mtime *time.
// getting of inode

func (fs *ClusterFs) inodeById(inodeId fuseops.InodeID) *Inode {
fs.Goofys.mu.RLock()
defer fs.Goofys.mu.RUnlock()
return fs.Goofys.getInodeOrDie(inodeId)
}

Expand Down
10 changes: 3 additions & 7 deletions internal/goofys.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,9 +402,11 @@ func (fs *Goofys) SigUsr1() {

// Find the given inode. Panic if it doesn't exist.
//
// RLOCKS_REQUIRED(fs.mu)
// LOCKS_EXCLUDED(fs.mu)
func (fs *Goofys) getInodeOrDie(id fuseops.InodeID) (inode *Inode) {
fs.mu.RLock()
inode = fs.inodes[id]
fs.mu.RUnlock()
if inode == nil {
panic(fmt.Sprintf("Unknown inode: %v", id))
}
Expand Down Expand Up @@ -784,26 +786,20 @@ func (fs *Goofys) mount(mp *Inode, b *Mount) {
}

func (fs *Goofys) MountAll(mounts []*Mount) {
fs.mu.RLock()
root := fs.getInodeOrDie(fuseops.RootInodeID)
fs.mu.RUnlock()

for _, m := range mounts {
fs.mount(root, m)
}
}

func (fs *Goofys) Mount(mount *Mount) {
fs.mu.RLock()
root := fs.getInodeOrDie(fuseops.RootInodeID)
fs.mu.RUnlock()
fs.mount(root, mount)
}

func (fs *Goofys) Unmount(mountPoint string) {
fs.mu.RLock()
mp := fs.getInodeOrDie(fuseops.RootInodeID)
fs.mu.RUnlock()

fuseLog.Infof("Attempting to unmount %v", mountPoint)
path := strings.Split(strings.Trim(mountPoint, "/"), "/")
Expand Down
41 changes: 2 additions & 39 deletions internal/goofys_fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,7 @@ func (fs *GoofysFuse) GetInodeAttributes(

atomic.AddInt64(&fs.stats.metadataReads, 1)

fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

if atomic.LoadInt32(&inode.refreshed) == -1 {
// Stale inode
Expand All @@ -110,9 +108,7 @@ func (fs *GoofysFuse) GetInodeAttributes(

func (fs *GoofysFuse) GetXattr(ctx context.Context,
op *fuseops.GetXattrOp) (err error) {
fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

atomic.AddInt64(&fs.stats.metadataReads, 1)

Expand Down Expand Up @@ -141,9 +137,7 @@ func (fs *GoofysFuse) GetXattr(ctx context.Context,

func (fs *GoofysFuse) ListXattr(ctx context.Context,
op *fuseops.ListXattrOp) (err error) {
fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

atomic.AddInt64(&fs.stats.metadataReads, 1)

Expand Down Expand Up @@ -179,9 +173,7 @@ func (fs *GoofysFuse) ListXattr(ctx context.Context,

func (fs *GoofysFuse) RemoveXattr(ctx context.Context,
op *fuseops.RemoveXattrOp) (err error) {
fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

atomic.AddInt64(&fs.stats.metadataWrites, 1)

Expand All @@ -196,9 +188,7 @@ func (fs *GoofysFuse) RemoveXattr(ctx context.Context,

func (fs *GoofysFuse) SetXattr(ctx context.Context,
op *fuseops.SetXattrOp) (err error) {
fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

atomic.AddInt64(&fs.stats.metadataWrites, 1)

Expand All @@ -218,9 +208,7 @@ func (fs *GoofysFuse) SetXattr(ctx context.Context,

func (fs *GoofysFuse) CreateSymlink(ctx context.Context,
op *fuseops.CreateSymlinkOp) (err error) {
fs.mu.RLock()
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

atomic.AddInt64(&fs.stats.metadataWrites, 1)

Expand All @@ -242,9 +230,7 @@ func (fs *GoofysFuse) CreateSymlink(ctx context.Context,

func (fs *GoofysFuse) ReadSymlink(ctx context.Context,
op *fuseops.ReadSymlinkOp) (err error) {
fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

atomic.AddInt64(&fs.stats.metadataReads, 1)

Expand All @@ -266,9 +252,7 @@ func (fs *GoofysFuse) LookUpInode(

defer func() { fuseLog.Debugf("<-- LookUpInode %v %v %v", op.Parent, op.Name, err) }()

fs.mu.RLock()
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

inode, err := parent.LookUpCached(op.Name)
if err != nil {
Expand All @@ -290,9 +274,7 @@ func (fs *GoofysFuse) ForgetInode(

atomic.AddInt64(&fs.stats.metadataReads, 1)

fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

inode.mu.Lock()
inode.DeRef(int64(op.N))
Expand All @@ -307,13 +289,14 @@ func (fs *GoofysFuse) OpenDir(

atomic.AddInt64(&fs.stats.noops, 1)

fs.mu.Lock()
in := fs.getInodeOrDie(op.Inode)
if atomic.LoadInt32(&in.refreshed) == -1 {
// Stale inode
fs.mu.Unlock()
return syscall.ESTALE
}

fs.mu.Lock()
handleID := fs.nextHandleID
fs.nextHandleID++
fs.mu.Unlock()
Expand Down Expand Up @@ -428,9 +411,7 @@ func (fs *GoofysFuse) ReleaseDirHandle(
func (fs *GoofysFuse) OpenFile(
ctx context.Context,
op *fuseops.OpenFileOp) (err error) {
fs.mu.RLock()
in := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

atomic.AddInt64(&fs.stats.noops, 1)

Expand Down Expand Up @@ -493,9 +474,7 @@ func (fs *GoofysFuse) SyncFile(
atomic.AddInt64(&fs.stats.metadataWrites, 1)

if !fs.flags.IgnoreFsync {
fs.mu.RLock()
in := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

if in.Id == fuseops.RootInodeID {
err = fs.SyncFS(nil)
Expand Down Expand Up @@ -547,9 +526,7 @@ func (fs *GoofysFuse) CreateFile(

atomic.AddInt64(&fs.stats.metadataWrites, 1)

fs.mu.RLock()
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

if atomic.LoadInt32(&parent.refreshed) == -1 {
// Stale inode
Expand Down Expand Up @@ -600,9 +577,7 @@ func (fs *GoofysFuse) MkNode(
return syscall.ENOTSUP
}

fs.mu.RLock()
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

if atomic.LoadInt32(&parent.refreshed) == -1 {
// Stale inode
Expand Down Expand Up @@ -641,9 +616,7 @@ func (fs *GoofysFuse) MkDir(

atomic.AddInt64(&fs.stats.metadataWrites, 1)

fs.mu.RLock()
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

if atomic.LoadInt32(&parent.refreshed) == -1 {
// Stale inode
Expand Down Expand Up @@ -676,9 +649,7 @@ func (fs *GoofysFuse) RmDir(

atomic.AddInt64(&fs.stats.metadataWrites, 1)

fs.mu.RLock()
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

if atomic.LoadInt32(&parent.refreshed) == -1 {
// Stale inode
Expand All @@ -697,9 +668,7 @@ func (fs *GoofysFuse) SetInodeAttributes(

atomic.AddInt64(&fs.stats.metadataWrites, 1)

fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

if atomic.LoadInt32(&inode.refreshed) == -1 {
// Stale inode
Expand Down Expand Up @@ -748,9 +717,7 @@ func (fs *GoofysFuse) Unlink(

atomic.AddInt64(&fs.stats.metadataWrites, 1)

fs.mu.RLock()
parent := fs.getInodeOrDie(op.Parent)
fs.mu.RUnlock()

if atomic.LoadInt32(&parent.refreshed) == -1 {
// Stale inode
Expand All @@ -770,10 +737,8 @@ func (fs *GoofysFuse) Rename(

atomic.AddInt64(&fs.stats.metadataWrites, 1)

fs.mu.RLock()
parent := fs.getInodeOrDie(op.OldParent)
newParent := fs.getInodeOrDie(op.NewParent)
fs.mu.RUnlock()

if atomic.LoadInt32(&parent.refreshed) == -1 ||
atomic.LoadInt32(&newParent.refreshed) == -1 {
Expand Down Expand Up @@ -817,9 +782,7 @@ func (fs *GoofysFuse) Fallocate(

atomic.AddInt64(&fs.stats.metadataWrites, 1)

fs.mu.RLock()
inode := fs.getInodeOrDie(op.Inode)
fs.mu.RUnlock()

if atomic.LoadInt32(&inode.refreshed) == -1 {
// Stale inode
Expand Down

0 comments on commit a2c3b06

Please sign in to comment.