Project

General

Profile

Actions

Bug #5957

open

File locking should be read-preferring

Added by Marcel Telka almost 7 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
kernel
Start date:
2015-05-26
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:

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

lock.c (1.41 KB) lock.c Marcel Telka, 2015-05-26 06:36 PM

Related issues

Related to illumos gate - Bug #6016: Some file locking scenarios does not work as expectedNew2015-06-18

Actions
Related to illumos gate - Bug #6225: NFSv4: setlock() can spin foreverClosedMarcel Telka2015-09-12

Actions
Actions #1

Updated by Marcel Telka almost 7 years ago

  • Related to Bug #6016: Some file locking scenarios does not work as expected added
Actions #2

Updated by Marcel Telka over 6 years ago

  • Related to Bug #6225: NFSv4: setlock() can spin forever added
Actions

Also available in: Atom PDF