Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/golang.org/x/net-0.17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Lencerf authored Oct 13, 2023
2 parents 45227f7 + e638df8 commit 10b2091
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
5 changes: 0 additions & 5 deletions client/cpu9p.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,6 @@ func (l *CPU9P) RemoveXattr(attr string) error {
return unix.Removexattr(l.path, attr)
}

func (l *CPU9P) Lock(pid int, locktype p9.LockType, flags p9.LockFlags, start, length uint64, client string) (p9.LockStatus, error) {
verbose("Lock: not implemented")
return p9.LockStatusError, syscall.ENOSYS
}

// Walk implements p9.File.Walk.
func (l *CPU9P) Walk(names []string) ([]p9.QID, p9.File, error) {
var qids []p9.QID
Expand Down
37 changes: 37 additions & 0 deletions client/cpu9p_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,40 @@ func (l *CPU9P) SetAttr(mask p9.SetAttrMask, attr p9.SetAttr) error {
}
return err
}

// Lock implements p9.File.Lock.
func (l *CPU9P) Lock(pid int, locktype p9.LockType, flags p9.LockFlags, start, length uint64, client string) (p9.LockStatus, error) {
var cmd int
switch flags {
case p9.LockFlagsBlock:
cmd = unix.F_SETLKW
case p9.LockFlagsReclaim:
return p9.LockStatusError, unix.ENOSYS
default:
cmd = unix.F_SETLK
}
var t int16
switch locktype {
case p9.ReadLock:
t = unix.F_RDLCK
case p9.WriteLock:
t = unix.F_WRLCK
case p9.Unlock:
t = unix.F_UNLCK
default:
return p9.LockStatusError, unix.ENOSYS
}
lk := &unix.Flock_t{
Type: t,
Whence: unix.SEEK_SET,
Start: int64(start),
Len: int64(length),
}
if err := unix.FcntlFlock(l.file.Fd(), cmd, lk); err != nil {
if errors.Is(err, unix.EAGAIN) {
return p9.LockStatusBlocked, nil
}
return p9.LockStatusError, err
}
return p9.LockStatusOK, nil
}

0 comments on commit 10b2091

Please sign in to comment.