Commit fcbcd75e authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

fs: reduce scope of locking in loopbackFile.setAttr

This avoids a deadlock on Darwin, because futimens calls
loopbackFile.Getattr again.

Fixes #419

Change-Id: Ia45a0ec3c0ea06c0419913e34b3415808f9349da
parent 8363cf88
...@@ -155,13 +155,26 @@ func (f *loopbackFile) Setattr(ctx context.Context, in *fuse.SetAttrIn, out *fus ...@@ -155,13 +155,26 @@ func (f *loopbackFile) Setattr(ctx context.Context, in *fuse.SetAttrIn, out *fus
return f.Getattr(ctx, out) return f.Getattr(ctx, out)
} }
func (f *loopbackFile) setAttr(ctx context.Context, in *fuse.SetAttrIn) syscall.Errno { func (f *loopbackFile) fchmod(mode uint32) syscall.Errno {
f.mu.Lock() f.mu.Lock()
defer f.mu.Unlock() defer f.mu.Unlock()
return ToErrno(syscall.Fchmod(f.fd, mode))
}
func (f *loopbackFile) fchown(uid, gid int) syscall.Errno {
f.mu.Lock()
defer f.mu.Unlock()
return ToErrno(syscall.Fchown(f.fd, uid, gid))
}
func (f *loopbackFile) ftruncate(sz uint64) syscall.Errno {
return ToErrno(syscall.Ftruncate(f.fd, int64(sz)))
}
func (f *loopbackFile) setAttr(ctx context.Context, in *fuse.SetAttrIn) syscall.Errno {
var errno syscall.Errno var errno syscall.Errno
if mode, ok := in.GetMode(); ok { if mode, ok := in.GetMode(); ok {
errno = ToErrno(syscall.Fchmod(f.fd, mode)) if errno := f.fchmod(mode); errno != 0 {
if errno != 0 {
return errno return errno
} }
} }
...@@ -178,8 +191,7 @@ func (f *loopbackFile) setAttr(ctx context.Context, in *fuse.SetAttrIn) syscall. ...@@ -178,8 +191,7 @@ func (f *loopbackFile) setAttr(ctx context.Context, in *fuse.SetAttrIn) syscall.
if gOk { if gOk {
gid = int(gid32) gid = int(gid32)
} }
errno = ToErrno(syscall.Fchown(f.fd, uid, gid)) if errno := f.fchown(uid, gid); errno != 0 {
if errno != 0 {
return errno return errno
} }
} }
...@@ -203,8 +215,7 @@ func (f *loopbackFile) setAttr(ctx context.Context, in *fuse.SetAttrIn) syscall. ...@@ -203,8 +215,7 @@ func (f *loopbackFile) setAttr(ctx context.Context, in *fuse.SetAttrIn) syscall.
} }
if sz, ok := in.GetSize(); ok { if sz, ok := in.GetSize(); ok {
errno = ToErrno(syscall.Ftruncate(f.fd, int64(sz))) if errno := f.ftruncate(sz); errno != 0 {
if errno != 0 {
return errno return errno
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment