Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 96109
b: refs/heads/master
c: 0b2bac2
h: refs/heads/master
i:
  96107: 388ae6a
v: v3
  • Loading branch information
Al Viro committed May 6, 2008
1 parent f519880 commit dae3ea2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 33dcdac2df54e66c447ae03f58c95c7251aa5649
refs/heads/master: 0b2bac2f1ea0d33a3621b27ca68b9ae760fca2e9
17 changes: 15 additions & 2 deletions trunk/fs/locks.c
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,7 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
struct file_lock *file_lock = locks_alloc_lock();
struct flock flock;
struct inode *inode;
struct file *f;
int error;

if (file_lock == NULL)
Expand Down Expand Up @@ -1825,7 +1826,15 @@ int fcntl_setlk(unsigned int fd, struct file *filp, unsigned int cmd,
* Attempt to detect a close/fcntl race and recover by
* releasing the lock that was just acquired.
*/
if (!error && fcheck(fd) != filp && flock.l_type != F_UNLCK) {
/*
* we need that spin_lock here - it prevents reordering between
* update of inode->i_flock and check for it done in close().
* rcu_read_lock() wouldn't do.
*/
spin_lock(&current->files->file_lock);
f = fcheck(fd);
spin_unlock(&current->files->file_lock);
if (!error && f != filp && flock.l_type != F_UNLCK) {
flock.l_type = F_UNLCK;
goto again;
}
Expand Down Expand Up @@ -1881,6 +1890,7 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
struct file_lock *file_lock = locks_alloc_lock();
struct flock64 flock;
struct inode *inode;
struct file *f;
int error;

if (file_lock == NULL)
Expand Down Expand Up @@ -1953,7 +1963,10 @@ int fcntl_setlk64(unsigned int fd, struct file *filp, unsigned int cmd,
* Attempt to detect a close/fcntl race and recover by
* releasing the lock that was just acquired.
*/
if (!error && fcheck(fd) != filp && flock.l_type != F_UNLCK) {
spin_lock(&current->files->file_lock);
f = fcheck(fd);
spin_unlock(&current->files->file_lock);
if (!error && f != filp && flock.l_type != F_UNLCK) {
flock.l_type = F_UNLCK;
goto again;
}
Expand Down

0 comments on commit dae3ea2

Please sign in to comment.