Skip to content

Commit

Permalink
try to support OFD lock (#4083)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies authored Nov 30, 2023
1 parent 6acbfc3 commit 73dfd51
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/vfs/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions pkg/vfs/vfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions pkg/vfs/vfs_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 73dfd51

Please sign in to comment.