mirror of
https://github.com/FEX-Emu/linux.git
synced 2024-12-14 12:49:08 +00:00
locks: cleanup code duplication
Extract common code into a function. Signed-off-by: Miklos Szeredi <mszeredi@suse.cz> Cc: "J. Bruce Fields" <bfields@fieldses.org> Cc: Trond Myklebust <trond.myklebust@fys.uio.no> Cc: Matthew Wilcox <matthew@wil.cx> Cc: David Teigland <teigland@redhat.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
bde74e4bc6
commit
b648a6de00
71
fs/locks.c
71
fs/locks.c
@ -1738,6 +1738,35 @@ int vfs_lock_file(struct file *filp, unsigned int cmd, struct file_lock *fl, str
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(vfs_lock_file);
|
||||
|
||||
static int do_lock_file_wait(struct file *filp, unsigned int cmd,
|
||||
struct file_lock *fl)
|
||||
{
|
||||
int error;
|
||||
|
||||
error = security_file_lock(filp, fl->fl_type);
|
||||
if (error)
|
||||
return error;
|
||||
|
||||
if (filp->f_op && filp->f_op->lock != NULL)
|
||||
error = filp->f_op->lock(filp, cmd, fl);
|
||||
else {
|
||||
for (;;) {
|
||||
error = posix_lock_file(filp, fl, NULL);
|
||||
if (error != FILE_LOCK_DEFERRED)
|
||||
break;
|
||||
error = wait_event_interruptible(fl->fl_wait,
|
||||
!fl->fl_next);
|
||||
if (!error)
|
||||
continue;
|
||||
|
||||
locks_delete_block(fl);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
|
||||
/* Apply the lock described by l to an open file descriptor.
|
||||
* This implements both the F_SETLK and F_SETLKW commands of fcntl().
|
||||
*/
|
||||
@ -1795,26 +1824,7 @@ again:
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = security_file_lock(filp, file_lock->fl_type);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
if (filp->f_op && filp->f_op->lock != NULL)
|
||||
error = filp->f_op->lock(filp, cmd, file_lock);
|
||||
else {
|
||||
for (;;) {
|
||||
error = posix_lock_file(filp, file_lock, NULL);
|
||||
if (error != FILE_LOCK_DEFERRED)
|
||||
break;
|
||||
error = wait_event_interruptible(file_lock->fl_wait,
|
||||
!file_lock->fl_next);
|
||||
if (!error)
|
||||
continue;
|
||||
|
||||
locks_delete_block(file_lock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
error = do_lock_file_wait(filp, cmd, file_lock);
|
||||
|
||||
/*
|
||||
* Attempt to detect a close/fcntl race and recover by
|
||||
@ -1932,26 +1942,7 @@ again:
|
||||
goto out;
|
||||
}
|
||||
|
||||
error = security_file_lock(filp, file_lock->fl_type);
|
||||
if (error)
|
||||
goto out;
|
||||
|
||||
if (filp->f_op && filp->f_op->lock != NULL)
|
||||
error = filp->f_op->lock(filp, cmd, file_lock);
|
||||
else {
|
||||
for (;;) {
|
||||
error = posix_lock_file(filp, file_lock, NULL);
|
||||
if (error != FILE_LOCK_DEFERRED)
|
||||
break;
|
||||
error = wait_event_interruptible(file_lock->fl_wait,
|
||||
!file_lock->fl_next);
|
||||
if (!error)
|
||||
continue;
|
||||
|
||||
locks_delete_block(file_lock);
|
||||
break;
|
||||
}
|
||||
}
|
||||
error = do_lock_file_wait(filp, cmd, file_lock);
|
||||
|
||||
/*
|
||||
* Attempt to detect a close/fcntl race and recover by
|
||||
|
Loading…
Reference in New Issue
Block a user