Skip to content

Commit 6c9007f

Browse files
stspjtlayton
authored andcommitted
fs/locks: F_UNLCK extension for F_OFD_GETLK
Currently F_UNLCK with F_OFD_GETLK returns -EINVAL. This patch changes it such that specifying F_UNLCK returns information only about OFD locks that are owned by the given file description. Cc: Jeff Layton <[email protected]> Cc: Chuck Lever <[email protected]> Cc: Alexander Viro <[email protected]> Cc: Christian Brauner <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Shuah Khan <[email protected]> Cc: [email protected] Cc: [email protected] Signed-off-by: Stas Sergeev <[email protected]> Signed-off-by: Jeff Layton <[email protected]>
1 parent 1ef6663 commit 6c9007f

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

fs/locks.c

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,21 @@ static bool posix_locks_conflict(struct file_lock *caller_fl,
868868
return locks_conflict(caller_fl, sys_fl);
869869
}
870870

871+
/* Determine if lock sys_fl blocks lock caller_fl. Used on xx_GETLK
872+
* path so checks for additional GETLK-specific things like F_UNLCK.
873+
*/
874+
static bool posix_test_locks_conflict(struct file_lock *caller_fl,
875+
struct file_lock *sys_fl)
876+
{
877+
/* F_UNLCK checks any locks on the same fd. */
878+
if (caller_fl->fl_type == F_UNLCK) {
879+
if (!posix_same_owner(caller_fl, sys_fl))
880+
return false;
881+
return locks_overlap(caller_fl, sys_fl);
882+
}
883+
return posix_locks_conflict(caller_fl, sys_fl);
884+
}
885+
871886
/* Determine if lock sys_fl blocks lock caller_fl. FLOCK specific
872887
* checking before calling the locks_conflict().
873888
*/
@@ -901,7 +916,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
901916
retry:
902917
spin_lock(&ctx->flc_lock);
903918
list_for_each_entry(cfl, &ctx->flc_posix, fl_list) {
904-
if (!posix_locks_conflict(fl, cfl))
919+
if (!posix_test_locks_conflict(fl, cfl))
905920
continue;
906921
if (cfl->fl_lmops && cfl->fl_lmops->lm_lock_expirable
907922
&& (*cfl->fl_lmops->lm_lock_expirable)(cfl)) {
@@ -2207,7 +2222,8 @@ int fcntl_getlk(struct file *filp, unsigned int cmd, struct flock *flock)
22072222
if (fl == NULL)
22082223
return -ENOMEM;
22092224
error = -EINVAL;
2210-
if (flock->l_type != F_RDLCK && flock->l_type != F_WRLCK)
2225+
if (cmd != F_OFD_GETLK && flock->l_type != F_RDLCK
2226+
&& flock->l_type != F_WRLCK)
22112227
goto out;
22122228

22132229
error = flock_to_posix_lock(filp, fl, flock);
@@ -2414,7 +2430,8 @@ int fcntl_getlk64(struct file *filp, unsigned int cmd, struct flock64 *flock)
24142430
return -ENOMEM;
24152431

24162432
error = -EINVAL;
2417-
if (flock->l_type != F_RDLCK && flock->l_type != F_WRLCK)
2433+
if (cmd != F_OFD_GETLK && flock->l_type != F_RDLCK
2434+
&& flock->l_type != F_WRLCK)
24182435
goto out;
24192436

24202437
error = flock64_to_posix_lock(filp, fl, flock);

0 commit comments

Comments
 (0)