diff --git a/pkg/vfs/handle.go b/pkg/vfs/handle.go index 98fe7e73461a..b8d785f98fff 100644 --- a/pkg/vfs/handle.go +++ b/pkg/vfs/handle.go @@ -37,6 +37,7 @@ type handle struct { // for file locks uint8 flockOwner uint64 // kernel 3.1- does not pass lock_owner in release() + ofdOwner uint64 // OFD lock reader FileReader writer FileWriter ops []Context diff --git a/pkg/vfs/vfs.go b/pkg/vfs/vfs.go index 8f270816b62f..9750fea4a220 100644 --- a/pkg/vfs/vfs.go +++ b/pkg/vfs/vfs.go @@ -522,14 +522,18 @@ func (v *VFS) Release(ctx Context, ino Ino, fh uint64) { } } locks := f.locks - owner := f.flockOwner + fowner := f.flockOwner + powner := f.ofdOwner f.Unlock() if f.writer != nil { _ = f.writer.Flush(ctx) v.invalidateLength(ino) } if locks&1 != 0 { - _ = v.Meta.Flock(ctx, ino, owner, F_UNLCK, false) + _ = v.Meta.Flock(ctx, ino, fowner, F_UNLCK, false) + } + if locks&2 != 0 && powner != 0 { + _ = v.Meta.Setlk(ctx, ino, powner, false, F_UNLCK, 0, 0x7FFFFFFFFFFFFFFF, 0) } } _ = v.Meta.Close(ctx, ino) @@ -808,6 +812,9 @@ func (v *VFS) Flush(ctx Context, ino Ino, fh uint64, lockOwner uint64) (err sysc h.Lock() locks := h.locks + if lockOwner == h.ofdOwner { + h.ofdOwner = 0 + } h.Unlock() if locks&2 != 0 { _ = v.Meta.Setlk(ctx, ino, lockOwner, false, F_UNLCK, 0, 0x7FFFFFFFFFFFFFFF, 0) diff --git a/pkg/vfs/vfs_unix.go b/pkg/vfs/vfs_unix.go index 701d3e57099d..440416cdf735 100644 --- a/pkg/vfs/vfs_unix.go +++ b/pkg/vfs/vfs_unix.go @@ -260,6 +260,9 @@ func (v *VFS) Setlk(ctx Context, ino Ino, fh uint64, owner uint64, start, end ui h.Lock() if typ != syscall.F_UNLCK { h.locks |= 2 + if h.ofdOwner == 0 { + h.ofdOwner = owner + } } h.Unlock() }