Bug #5957
openFile locking should be read-preferring
0%
Description
During the discussion in the Austin Group I learned that our generic file locking implementation is not aligned with POSIX. We implement the write-preferring locks, but the standard requires the read-preferring locks:
When a shared lock is set on a segment of a file, other processes shall be able to set shared locks on that segment or a portion of it. A shared lock prevents any other process from setting an exclusive lock on any portion of the protected area. A request for a shared lock shall fail if the file descriptor was not opened with read access.
An exclusive lock shall prevent any other process from setting a shared lock or an exclusive lock on any portion of the protected area. A request for an exclusive lock shall fail if the file descriptor was not opened with write access.
The difference could be reproduced using the attached lock.c file:
# gcc -Wall -o lock lock.c
This is the current write-preferring behavior:
# ./lock r file & F_SETLK: F_RDLCK sleeping [1] 1635 # sleep 2 # ./lock W file & F_SETLKW: F_WRLCK [2] 1638 # sleep 2 # ./lock r file & F_SETLK: F_RDLCK fcntl failed F_GETLK l_type: F_UNLCK sleeping [3] 1645 #
With the read-preferring behavior, the last lock command above should not fail.
Files
Related issues
Updated by Marcel Telka almost 7 years ago
- Related to Bug #6016: Some file locking scenarios does not work as expected added
Updated by Marcel Telka over 6 years ago
- Related to Bug #6225: NFSv4: setlock() can spin forever added