mirror of https://gitee.com/openkylin/linux.git
locks: setlease cleanup
There's an incorrect comment here. Also clean up the logic: the "rdlease" and "wrlease" locals are confusingly named, and don't really add anything since we can make a decision as soon as we hit one of these cases. Signed-off-by: J. Bruce Fields <bfields@redhat.com>
This commit is contained in:
parent
778fc546f7
commit
c1f24ef4ed
33
fs/locks.c
33
fs/locks.c
|
@ -1368,7 +1368,7 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
|
||||||
struct file_lock *fl, **before, **my_before = NULL, *lease;
|
struct file_lock *fl, **before, **my_before = NULL, *lease;
|
||||||
struct dentry *dentry = filp->f_path.dentry;
|
struct dentry *dentry = filp->f_path.dentry;
|
||||||
struct inode *inode = dentry->d_inode;
|
struct inode *inode = dentry->d_inode;
|
||||||
int error, rdlease_count = 0, wrlease_count = 0;
|
int error;
|
||||||
|
|
||||||
lease = *flp;
|
lease = *flp;
|
||||||
|
|
||||||
|
@ -1404,27 +1404,28 @@ int generic_setlease(struct file *filp, long arg, struct file_lock **flp)
|
||||||
* then the file is not open by anyone (including us)
|
* then the file is not open by anyone (including us)
|
||||||
* except for this filp.
|
* except for this filp.
|
||||||
*/
|
*/
|
||||||
|
error = -EAGAIN;
|
||||||
for (before = &inode->i_flock;
|
for (before = &inode->i_flock;
|
||||||
((fl = *before) != NULL) && IS_LEASE(fl);
|
((fl = *before) != NULL) && IS_LEASE(fl);
|
||||||
before = &fl->fl_next) {
|
before = &fl->fl_next) {
|
||||||
if (fl->fl_file == filp)
|
if (fl->fl_file == filp) {
|
||||||
my_before = before;
|
my_before = before;
|
||||||
else if (fl->fl_flags & FL_UNLOCK_PENDING)
|
continue;
|
||||||
/*
|
}
|
||||||
* Someone is in the process of opening this
|
/*
|
||||||
* file for writing so we may not take an
|
* No exclusive leases if someone else has a lease on
|
||||||
* exclusive lease on it.
|
* this file:
|
||||||
*/
|
*/
|
||||||
wrlease_count++;
|
if (arg == F_WRLCK)
|
||||||
else
|
goto out;
|
||||||
rdlease_count++;
|
/*
|
||||||
|
* Modifying our existing lease is OK, but no getting a
|
||||||
|
* new lease if someone else is opening for write:
|
||||||
|
*/
|
||||||
|
if (fl->fl_flags & FL_UNLOCK_PENDING)
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = -EAGAIN;
|
|
||||||
if ((arg == F_RDLCK && (wrlease_count > 0)) ||
|
|
||||||
(arg == F_WRLCK && ((rdlease_count + wrlease_count) > 0)))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
if (my_before != NULL) {
|
if (my_before != NULL) {
|
||||||
error = lease->fl_lmops->lm_change(my_before, arg);
|
error = lease->fl_lmops->lm_change(my_before, arg);
|
||||||
if (!error)
|
if (!error)
|
||||||
|
|
Loading…
Reference in New Issue