Skip to content

Commit 129a84d

Browse files
bfieldsLinus Torvalds
authored andcommitted
locks: fix F_GETLK regression (failure to find conflicts)
In 9d6a8c5 we changed posix_test_lock to modify its single file_lock argument instead of taking separate input and output arguments. This makes it no longer safe to set the output lock's fl_type to F_UNLCK before looking for a conflict, since that means searching for a conflict against a lock with type F_UNLCK. This fixes a regression which causes F_GETLK to incorrectly report no conflict on most filesystems (including any filesystem that doesn't do its own locking). Also fix posix_lock_to_flock() to copy the lock type. This isn't strictly necessary, since the caller already does this; but it seems less likely to cause confusion in the future. Thanks to Doug Chapman for the bug report. Signed-off-by: "J. Bruce Fields" <bfields@citi.umich.edu> Acked-by: Doug Chapman <doug.chapman@hp.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent a9deecb commit 129a84d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

fs/locks.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,6 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
669669
{
670670
struct file_lock *cfl;
671671

672-
fl->fl_type = F_UNLCK;
673672
lock_kernel();
674673
for (cfl = filp->f_path.dentry->d_inode->i_flock; cfl; cfl = cfl->fl_next) {
675674
if (!IS_POSIX(cfl))
@@ -681,7 +680,8 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
681680
__locks_copy_lock(fl, cfl);
682681
unlock_kernel();
683682
return 1;
684-
}
683+
} else
684+
fl->fl_type = F_UNLCK;
685685
unlock_kernel();
686686
return 0;
687687
}
@@ -1632,6 +1632,7 @@ static int posix_lock_to_flock(struct flock *flock, struct file_lock *fl)
16321632
flock->l_len = fl->fl_end == OFFSET_MAX ? 0 :
16331633
fl->fl_end - fl->fl_start + 1;
16341634
flock->l_whence = 0;
1635+
flock->l_type = fl->fl_type;
16351636
return 0;
16361637
}
16371638

0 commit comments

Comments
 (0)