Page MenuHomeFreeBSD

Add -w option to lockf(1)
ClosedPublic

Authored by cperciva on Aug 8 2020, 1:27 AM.

Details

Reviewers
rmacklem
Group Reviewers
manpages
Commits
rS364831: Add -w option to lockf(1).
Summary

By default, lockf(1) opens its lock file O_RDONLY|O_EXLOCK. On NFS, if the file already exists, this is split into opening the file read-only and then requesting an exclusive lock -- and the second step fails because NFS does not permit exclusive locking on files which are opened read-only.

This patch adds -w option which changes the open flags to O_WRONLY|O_EXLOCK, allowing it to work on NFS -- at the cost of not working if the file cannot be opened for writing.

(Whether the traditional BSD behaviour of allowing exclusive locks to be obtained on a file which cannot be opened for writing is a good idea is perhaps questionable since it may allow less-privileged users to perform a local denial of service; however this behaviour has been present for a long time and changing it now seems like it would cause problems.)

Test Plan

Works in Amazon EFS. Would be good to have confirmation that it works with other NFS environments.

Diff Detail

Repository
rS FreeBSD src repository
Lint
Lint Skipped
Unit
Unit Tests Skipped
Build Status
Buildable 32869

Event Timeline

I'm away from home for a few days, but I'll test in against a FreeBSD
and fairly current Linux server early next week.

No rush -- this has been sitting on my to-do list ever since we discussed it in mid-June.

I tested this with both FreeBSD and Linux NFSv4 servers
and the "-w" option fixed the problem for both of them.

usr.bin/lockf/lockf.1
132

It might be more technically correct to say "including NFSv4".
NFSv3 does not have an Open and, therefore, is not affected
by this.

This revision is now accepted and ready to land.Aug 23 2020, 2:28 AM
usr.bin/lockf/lockf.1
132

Thanks, fixed.

This revision was automatically updated to reflect the committed changes.