mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-05 05:42:36 +00:00
locks: __break_lease cleanup in preparation of allowing direct removal of leases
Eliminate an unneeded "flock" variable. We can use "fl" as a loop cursor everywhere. Add a any_leases_conflict helper function as well to consolidate a bit of code. Signed-off-by: Jeff Layton <jlayton@primarydata.com> Reviewed-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
parent
843c6b2f4c
commit
03d12ddf84
1 changed files with 25 additions and 24 deletions
49
fs/locks.c
49
fs/locks.c
|
@ -1351,6 +1351,20 @@ static bool leases_conflict(struct file_lock *lease, struct file_lock *breaker)
|
||||||
return locks_conflict(breaker, lease);
|
return locks_conflict(breaker, lease);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
any_leases_conflict(struct inode *inode, struct file_lock *breaker)
|
||||||
|
{
|
||||||
|
struct file_lock *fl;
|
||||||
|
|
||||||
|
lockdep_assert_held(&inode->i_lock);
|
||||||
|
|
||||||
|
for (fl = inode->i_flock ; fl && IS_LEASE(fl); fl = fl->fl_next) {
|
||||||
|
if (leases_conflict(fl, breaker))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __break_lease - revoke all outstanding leases on file
|
* __break_lease - revoke all outstanding leases on file
|
||||||
* @inode: the inode of the file to return
|
* @inode: the inode of the file to return
|
||||||
|
@ -1367,10 +1381,9 @@ static bool leases_conflict(struct file_lock *lease, struct file_lock *breaker)
|
||||||
int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
|
int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
|
||||||
{
|
{
|
||||||
int error = 0;
|
int error = 0;
|
||||||
struct file_lock *new_fl, *flock;
|
struct file_lock *new_fl;
|
||||||
struct file_lock *fl;
|
struct file_lock *fl;
|
||||||
unsigned long break_time;
|
unsigned long break_time;
|
||||||
bool lease_conflict = false;
|
|
||||||
int want_write = (mode & O_ACCMODE) != O_RDONLY;
|
int want_write = (mode & O_ACCMODE) != O_RDONLY;
|
||||||
LIST_HEAD(dispose);
|
LIST_HEAD(dispose);
|
||||||
|
|
||||||
|
@ -1383,17 +1396,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
|
||||||
|
|
||||||
time_out_leases(inode, &dispose);
|
time_out_leases(inode, &dispose);
|
||||||
|
|
||||||
flock = inode->i_flock;
|
if (!any_leases_conflict(inode, new_fl))
|
||||||
if ((flock == NULL) || !IS_LEASE(flock))
|
|
||||||
goto out;
|
|
||||||
|
|
||||||
for (fl = flock; fl && IS_LEASE(fl); fl = fl->fl_next) {
|
|
||||||
if (leases_conflict(fl, new_fl)) {
|
|
||||||
lease_conflict = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!lease_conflict)
|
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
break_time = 0;
|
break_time = 0;
|
||||||
|
@ -1403,7 +1406,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
|
||||||
break_time++; /* so that 0 means no break time */
|
break_time++; /* so that 0 means no break time */
|
||||||
}
|
}
|
||||||
|
|
||||||
for (fl = flock; fl && IS_LEASE(fl); fl = fl->fl_next) {
|
for (fl = inode->i_flock; fl && IS_LEASE(fl); fl = fl->fl_next) {
|
||||||
if (!leases_conflict(fl, new_fl))
|
if (!leases_conflict(fl, new_fl))
|
||||||
continue;
|
continue;
|
||||||
if (want_write) {
|
if (want_write) {
|
||||||
|
@ -1412,7 +1415,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
|
||||||
fl->fl_flags |= FL_UNLOCK_PENDING;
|
fl->fl_flags |= FL_UNLOCK_PENDING;
|
||||||
fl->fl_break_time = break_time;
|
fl->fl_break_time = break_time;
|
||||||
} else {
|
} else {
|
||||||
if (lease_breaking(flock))
|
if (lease_breaking(inode->i_flock))
|
||||||
continue;
|
continue;
|
||||||
fl->fl_flags |= FL_DOWNGRADE_PENDING;
|
fl->fl_flags |= FL_DOWNGRADE_PENDING;
|
||||||
fl->fl_downgrade_time = break_time;
|
fl->fl_downgrade_time = break_time;
|
||||||
|
@ -1427,12 +1430,12 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
|
||||||
}
|
}
|
||||||
|
|
||||||
restart:
|
restart:
|
||||||
break_time = flock->fl_break_time;
|
break_time = inode->i_flock->fl_break_time;
|
||||||
if (break_time != 0)
|
if (break_time != 0)
|
||||||
break_time -= jiffies;
|
break_time -= jiffies;
|
||||||
if (break_time == 0)
|
if (break_time == 0)
|
||||||
break_time++;
|
break_time++;
|
||||||
locks_insert_block(flock, new_fl);
|
locks_insert_block(inode->i_flock, new_fl);
|
||||||
trace_break_lease_block(inode, new_fl);
|
trace_break_lease_block(inode, new_fl);
|
||||||
spin_unlock(&inode->i_lock);
|
spin_unlock(&inode->i_lock);
|
||||||
locks_dispose_list(&dispose);
|
locks_dispose_list(&dispose);
|
||||||
|
@ -1442,17 +1445,15 @@ restart:
|
||||||
trace_break_lease_unblock(inode, new_fl);
|
trace_break_lease_unblock(inode, new_fl);
|
||||||
locks_delete_block(new_fl);
|
locks_delete_block(new_fl);
|
||||||
if (error >= 0) {
|
if (error >= 0) {
|
||||||
if (error == 0)
|
|
||||||
time_out_leases(inode, &dispose);
|
|
||||||
/*
|
/*
|
||||||
* Wait for the next conflicting lease that has not been
|
* Wait for the next conflicting lease that has not been
|
||||||
* broken yet
|
* broken yet
|
||||||
*/
|
*/
|
||||||
for (flock = inode->i_flock; flock && IS_LEASE(flock);
|
if (error == 0)
|
||||||
flock = flock->fl_next) {
|
time_out_leases(inode, &dispose);
|
||||||
if (leases_conflict(new_fl, flock))
|
if (any_leases_conflict(inode, new_fl))
|
||||||
goto restart;
|
goto restart;
|
||||||
}
|
|
||||||
error = 0;
|
error = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue