locks: add a dedicated spinlock to protect i_flctx lists

We can now add a dedicated spinlock without expanding struct inode.
Change to using that to protect the various i_flctx lists.

Signed-off-by: Jeff Layton <jlayton@primarydata.com>
Acked-by: Christoph Hellwig <hch@lst.de>
This commit is contained in:
Jeff Layton 2015-01-16 15:05:57 -05:00 committed by Jeff Layton
parent a7231a9746
commit 6109c85037
9 changed files with 71 additions and 69 deletions

View File

@ -255,12 +255,12 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count)
ctx = inode->i_flctx; ctx = inode->i_flctx;
if (ctx) { if (ctx) {
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
list_for_each_entry(lock, &ctx->flc_posix, fl_list) list_for_each_entry(lock, &ctx->flc_posix, fl_list)
++(*fcntl_count); ++(*fcntl_count);
list_for_each_entry(lock, &ctx->flc_flock, fl_list) list_for_each_entry(lock, &ctx->flc_flock, fl_list)
++(*flock_count); ++(*flock_count);
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
} }
dout("counted %d flock locks and %d fcntl locks", dout("counted %d flock locks and %d fcntl locks",
*flock_count, *fcntl_count); *flock_count, *fcntl_count);
@ -288,7 +288,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
if (!ctx) if (!ctx)
return 0; return 0;
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
list_for_each_entry(lock, &ctx->flc_flock, fl_list) { list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
++seen_fcntl; ++seen_fcntl;
if (seen_fcntl > num_fcntl_locks) { if (seen_fcntl > num_fcntl_locks) {
@ -312,7 +312,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
++l; ++l;
} }
fail: fail:
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
return err; return err;
} }

View File

@ -1136,11 +1136,11 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
if (!flctx) if (!flctx)
goto out; goto out;
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
list_for_each(el, &flctx->flc_posix) { list_for_each(el, &flctx->flc_posix) {
count++; count++;
} }
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
INIT_LIST_HEAD(&locks_to_send); INIT_LIST_HEAD(&locks_to_send);
@ -1159,7 +1159,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
} }
el = locks_to_send.next; el = locks_to_send.next;
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
list_for_each_entry(flock, &flctx->flc_posix, fl_list) { list_for_each_entry(flock, &flctx->flc_posix, fl_list) {
if (el == &locks_to_send) { if (el == &locks_to_send) {
/* /*
@ -1181,7 +1181,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
lck->type = type; lck->type = type;
lck->offset = flock->fl_start; lck->offset = flock->fl_start;
} }
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
list_for_each_entry_safe(lck, tmp, &locks_to_send, llist) { list_for_each_entry_safe(lck, tmp, &locks_to_send, llist) {
int stored_rc; int stored_rc;

View File

@ -171,7 +171,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
return 0; return 0;
again: again:
file->f_locks = 0; file->f_locks = 0;
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
list_for_each_entry(fl, &flctx->flc_posix, fl_list) { list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
if (fl->fl_lmops != &nlmsvc_lock_operations) if (fl->fl_lmops != &nlmsvc_lock_operations)
continue; continue;
@ -183,7 +183,7 @@ again:
if (match(lockhost, host)) { if (match(lockhost, host)) {
struct file_lock lock = *fl; struct file_lock lock = *fl;
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
lock.fl_type = F_UNLCK; lock.fl_type = F_UNLCK;
lock.fl_start = 0; lock.fl_start = 0;
lock.fl_end = OFFSET_MAX; lock.fl_end = OFFSET_MAX;
@ -195,7 +195,7 @@ again:
goto again; goto again;
} }
} }
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
return 0; return 0;
} }
@ -232,14 +232,14 @@ nlm_file_inuse(struct nlm_file *file)
return 1; return 1;
if (flctx && !list_empty_careful(&flctx->flc_posix)) { if (flctx && !list_empty_careful(&flctx->flc_posix)) {
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
list_for_each_entry(fl, &flctx->flc_posix, fl_list) { list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
if (fl->fl_lmops == &nlmsvc_lock_operations) { if (fl->fl_lmops == &nlmsvc_lock_operations) {
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
return 1; return 1;
} }
} }
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
} }
file->f_locks = 0; file->f_locks = 0;
return 0; return 0;

View File

@ -161,7 +161,7 @@ int lease_break_time = 45;
* The global file_lock_list is only used for displaying /proc/locks, so we * The global file_lock_list is only used for displaying /proc/locks, so we
* keep a list on each CPU, with each list protected by its own spinlock via * keep a list on each CPU, with each list protected by its own spinlock via
* the file_lock_lglock. Note that alterations to the list also require that * the file_lock_lglock. Note that alterations to the list also require that
* the relevant i_lock is held. * the relevant flc_lock is held.
*/ */
DEFINE_STATIC_LGLOCK(file_lock_lglock); DEFINE_STATIC_LGLOCK(file_lock_lglock);
static DEFINE_PER_CPU(struct hlist_head, file_lock_list); static DEFINE_PER_CPU(struct hlist_head, file_lock_list);
@ -189,13 +189,13 @@ static DEFINE_HASHTABLE(blocked_hash, BLOCKED_HASH_BITS);
* contrast to those that are acting as records of acquired locks). * contrast to those that are acting as records of acquired locks).
* *
* Note that when we acquire this lock in order to change the above fields, * Note that when we acquire this lock in order to change the above fields,
* we often hold the i_lock as well. In certain cases, when reading the fields * we often hold the flc_lock as well. In certain cases, when reading the fields
* protected by this lock, we can skip acquiring it iff we already hold the * protected by this lock, we can skip acquiring it iff we already hold the
* i_lock. * flc_lock.
* *
* In particular, adding an entry to the fl_block list requires that you hold * In particular, adding an entry to the fl_block list requires that you hold
* both the i_lock and the blocked_lock_lock (acquired in that order). Deleting * both the flc_lock and the blocked_lock_lock (acquired in that order).
* an entry from the list however only requires the file_lock_lock. * Deleting an entry from the list however only requires the file_lock_lock.
*/ */
static DEFINE_SPINLOCK(blocked_lock_lock); static DEFINE_SPINLOCK(blocked_lock_lock);
@ -214,6 +214,7 @@ locks_get_lock_context(struct inode *inode)
if (!new) if (!new)
goto out; goto out;
spin_lock_init(&new->flc_lock);
INIT_LIST_HEAD(&new->flc_flock); INIT_LIST_HEAD(&new->flc_flock);
INIT_LIST_HEAD(&new->flc_posix); INIT_LIST_HEAD(&new->flc_posix);
INIT_LIST_HEAD(&new->flc_lease); INIT_LIST_HEAD(&new->flc_lease);
@ -557,7 +558,7 @@ static int posix_same_owner(struct file_lock *fl1, struct file_lock *fl2)
return fl1->fl_owner == fl2->fl_owner; return fl1->fl_owner == fl2->fl_owner;
} }
/* Must be called with the i_lock held! */ /* Must be called with the flc_lock held! */
static void locks_insert_global_locks(struct file_lock *fl) static void locks_insert_global_locks(struct file_lock *fl)
{ {
lg_local_lock(&file_lock_lglock); lg_local_lock(&file_lock_lglock);
@ -566,12 +567,12 @@ static void locks_insert_global_locks(struct file_lock *fl)
lg_local_unlock(&file_lock_lglock); lg_local_unlock(&file_lock_lglock);
} }
/* Must be called with the i_lock held! */ /* Must be called with the flc_lock held! */
static void locks_delete_global_locks(struct file_lock *fl) static void locks_delete_global_locks(struct file_lock *fl)
{ {
/* /*
* Avoid taking lock if already unhashed. This is safe since this check * Avoid taking lock if already unhashed. This is safe since this check
* is done while holding the i_lock, and new insertions into the list * is done while holding the flc_lock, and new insertions into the list
* also require that it be held. * also require that it be held.
*/ */
if (hlist_unhashed(&fl->fl_link)) if (hlist_unhashed(&fl->fl_link))
@ -623,10 +624,10 @@ static void locks_delete_block(struct file_lock *waiter)
* the order they blocked. The documentation doesn't require this but * the order they blocked. The documentation doesn't require this but
* it seems like the reasonable thing to do. * it seems like the reasonable thing to do.
* *
* Must be called with both the i_lock and blocked_lock_lock held. The fl_block * Must be called with both the flc_lock and blocked_lock_lock held. The
* list itself is protected by the blocked_lock_lock, but by ensuring that the * fl_block list itself is protected by the blocked_lock_lock, but by ensuring
* i_lock is also held on insertions we can avoid taking the blocked_lock_lock * that the flc_lock is also held on insertions we can avoid taking the
* in some cases when we see that the fl_block list is empty. * blocked_lock_lock in some cases when we see that the fl_block list is empty.
*/ */
static void __locks_insert_block(struct file_lock *blocker, static void __locks_insert_block(struct file_lock *blocker,
struct file_lock *waiter) struct file_lock *waiter)
@ -638,7 +639,7 @@ static void __locks_insert_block(struct file_lock *blocker,
locks_insert_global_blocked(waiter); locks_insert_global_blocked(waiter);
} }
/* Must be called with i_lock held. */ /* Must be called with flc_lock held. */
static void locks_insert_block(struct file_lock *blocker, static void locks_insert_block(struct file_lock *blocker,
struct file_lock *waiter) struct file_lock *waiter)
{ {
@ -650,15 +651,15 @@ static void locks_insert_block(struct file_lock *blocker,
/* /*
* Wake up processes blocked waiting for blocker. * Wake up processes blocked waiting for blocker.
* *
* Must be called with the inode->i_lock held! * Must be called with the inode->flc_lock held!
*/ */
static void locks_wake_up_blocks(struct file_lock *blocker) static void locks_wake_up_blocks(struct file_lock *blocker)
{ {
/* /*
* Avoid taking global lock if list is empty. This is safe since new * Avoid taking global lock if list is empty. This is safe since new
* blocked requests are only added to the list under the i_lock, and * blocked requests are only added to the list under the flc_lock, and
* the i_lock is always held here. Note that removal from the fl_block * the flc_lock is always held here. Note that removal from the fl_block
* list does not require the i_lock, so we must recheck list_empty() * list does not require the flc_lock, so we must recheck list_empty()
* after acquiring the blocked_lock_lock. * after acquiring the blocked_lock_lock.
*/ */
if (list_empty(&blocker->fl_block)) if (list_empty(&blocker->fl_block))
@ -768,7 +769,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
return; return;
} }
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
list_for_each_entry(cfl, &ctx->flc_posix, fl_list) { list_for_each_entry(cfl, &ctx->flc_posix, fl_list) {
if (posix_locks_conflict(fl, cfl)) { if (posix_locks_conflict(fl, cfl)) {
locks_copy_conflock(fl, cfl); locks_copy_conflock(fl, cfl);
@ -779,7 +780,7 @@ posix_test_lock(struct file *filp, struct file_lock *fl)
} }
fl->fl_type = F_UNLCK; fl->fl_type = F_UNLCK;
out: out:
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
return; return;
} }
EXPORT_SYMBOL(posix_test_lock); EXPORT_SYMBOL(posix_test_lock);
@ -880,7 +881,7 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
return -ENOMEM; return -ENOMEM;
} }
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
if (request->fl_flags & FL_ACCESS) if (request->fl_flags & FL_ACCESS)
goto find_conflict; goto find_conflict;
@ -905,9 +906,9 @@ static int flock_lock_file(struct file *filp, struct file_lock *request)
* give it the opportunity to lock the file. * give it the opportunity to lock the file.
*/ */
if (found) { if (found) {
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
cond_resched(); cond_resched();
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
} }
find_conflict: find_conflict:
@ -929,7 +930,7 @@ find_conflict:
error = 0; error = 0;
out: out:
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
if (new_fl) if (new_fl)
locks_free_lock(new_fl); locks_free_lock(new_fl);
locks_dispose_list(&dispose); locks_dispose_list(&dispose);
@ -965,7 +966,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
new_fl2 = locks_alloc_lock(); new_fl2 = locks_alloc_lock();
} }
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
/* /*
* New lock request. Walk all POSIX locks and look for conflicts. If * New lock request. Walk all POSIX locks and look for conflicts. If
* there are any, either return error or put the request on the * there are any, either return error or put the request on the
@ -1136,7 +1137,7 @@ static int __posix_lock_file(struct inode *inode, struct file_lock *request, str
locks_wake_up_blocks(left); locks_wake_up_blocks(left);
} }
out: out:
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
/* /*
* Free any unused locks. * Free any unused locks.
*/ */
@ -1218,7 +1219,7 @@ int locks_mandatory_locked(struct file *file)
/* /*
* Search the lock list for this inode for any POSIX locks. * Search the lock list for this inode for any POSIX locks.
*/ */
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
ret = 0; ret = 0;
list_for_each_entry(fl, &ctx->flc_posix, fl_list) { list_for_each_entry(fl, &ctx->flc_posix, fl_list) {
if (fl->fl_owner != current->files && if (fl->fl_owner != current->files &&
@ -1227,7 +1228,7 @@ int locks_mandatory_locked(struct file *file)
break; break;
} }
} }
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
return ret; return ret;
} }
@ -1346,7 +1347,7 @@ static void time_out_leases(struct inode *inode, struct list_head *dispose)
struct file_lock_context *ctx = inode->i_flctx; struct file_lock_context *ctx = inode->i_flctx;
struct file_lock *fl, *tmp; struct file_lock *fl, *tmp;
lockdep_assert_held(&inode->i_lock); lockdep_assert_held(&ctx->flc_lock);
list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) { list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) {
trace_time_out_leases(inode, fl); trace_time_out_leases(inode, fl);
@ -1370,7 +1371,7 @@ any_leases_conflict(struct inode *inode, struct file_lock *breaker)
struct file_lock_context *ctx = inode->i_flctx; struct file_lock_context *ctx = inode->i_flctx;
struct file_lock *fl; struct file_lock *fl;
lockdep_assert_held(&inode->i_lock); lockdep_assert_held(&ctx->flc_lock);
list_for_each_entry(fl, &ctx->flc_lease, fl_list) { list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
if (leases_conflict(fl, breaker)) if (leases_conflict(fl, breaker))
@ -1413,7 +1414,7 @@ int __break_lease(struct inode *inode, unsigned int mode, unsigned int type)
return error; return error;
} }
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
time_out_leases(inode, &dispose); time_out_leases(inode, &dispose);
@ -1463,11 +1464,11 @@ restart:
break_time++; break_time++;
locks_insert_block(fl, new_fl); locks_insert_block(fl, new_fl);
trace_break_lease_block(inode, new_fl); trace_break_lease_block(inode, new_fl);
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
locks_dispose_list(&dispose); locks_dispose_list(&dispose);
error = wait_event_interruptible_timeout(new_fl->fl_wait, error = wait_event_interruptible_timeout(new_fl->fl_wait,
!new_fl->fl_next, break_time); !new_fl->fl_next, break_time);
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
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) {
@ -1482,7 +1483,7 @@ restart:
error = 0; error = 0;
} }
out: out:
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
locks_dispose_list(&dispose); locks_dispose_list(&dispose);
locks_free_lock(new_fl); locks_free_lock(new_fl);
return error; return error;
@ -1506,14 +1507,14 @@ void lease_get_mtime(struct inode *inode, struct timespec *time)
struct file_lock *fl; struct file_lock *fl;
if (ctx && !list_empty_careful(&ctx->flc_lease)) { if (ctx && !list_empty_careful(&ctx->flc_lease)) {
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
if (!list_empty(&ctx->flc_lease)) { if (!list_empty(&ctx->flc_lease)) {
fl = list_first_entry(&ctx->flc_lease, fl = list_first_entry(&ctx->flc_lease,
struct file_lock, fl_list); struct file_lock, fl_list);
if (fl->fl_type == F_WRLCK) if (fl->fl_type == F_WRLCK)
has_lease = true; has_lease = true;
} }
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
} }
if (has_lease) if (has_lease)
@ -1556,7 +1557,7 @@ int fcntl_getlease(struct file *filp)
LIST_HEAD(dispose); LIST_HEAD(dispose);
if (ctx && !list_empty_careful(&ctx->flc_lease)) { if (ctx && !list_empty_careful(&ctx->flc_lease)) {
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
time_out_leases(file_inode(filp), &dispose); time_out_leases(file_inode(filp), &dispose);
list_for_each_entry(fl, &ctx->flc_lease, fl_list) { list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
if (fl->fl_file != filp) if (fl->fl_file != filp)
@ -1564,7 +1565,7 @@ int fcntl_getlease(struct file *filp)
type = target_leasetype(fl); type = target_leasetype(fl);
break; break;
} }
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
locks_dispose_list(&dispose); locks_dispose_list(&dispose);
} }
return type; return type;
@ -1632,7 +1633,7 @@ generic_add_lease(struct file *filp, long arg, struct file_lock **flp, void **pr
return -EINVAL; return -EINVAL;
} }
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
time_out_leases(inode, &dispose); time_out_leases(inode, &dispose);
error = check_conflicting_open(dentry, arg); error = check_conflicting_open(dentry, arg);
if (error) if (error)
@ -1699,7 +1700,7 @@ out_setup:
if (lease->fl_lmops->lm_setup) if (lease->fl_lmops->lm_setup)
lease->fl_lmops->lm_setup(lease, priv); lease->fl_lmops->lm_setup(lease, priv);
out: out:
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
locks_dispose_list(&dispose); locks_dispose_list(&dispose);
if (is_deleg) if (is_deleg)
mutex_unlock(&inode->i_mutex); mutex_unlock(&inode->i_mutex);
@ -1722,7 +1723,7 @@ static int generic_delete_lease(struct file *filp)
return error; return error;
} }
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
list_for_each_entry(fl, &ctx->flc_lease, fl_list) { list_for_each_entry(fl, &ctx->flc_lease, fl_list) {
if (fl->fl_file == filp) { if (fl->fl_file == filp) {
victim = fl; victim = fl;
@ -1732,7 +1733,7 @@ static int generic_delete_lease(struct file *filp)
trace_generic_delete_lease(inode, fl); trace_generic_delete_lease(inode, fl);
if (victim) if (victim)
error = fl->fl_lmops->lm_change(&victim, F_UNLCK, &dispose); error = fl->fl_lmops->lm_change(&victim, F_UNLCK, &dispose);
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
locks_dispose_list(&dispose); locks_dispose_list(&dispose);
return error; return error;
} }
@ -2423,10 +2424,10 @@ locks_remove_lease(struct file *filp)
if (!ctx || list_empty(&ctx->flc_lease)) if (!ctx || list_empty(&ctx->flc_lease))
return; return;
spin_lock(&inode->i_lock); spin_lock(&ctx->flc_lock);
list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list) list_for_each_entry_safe(fl, tmp, &ctx->flc_lease, fl_list)
lease_modify(&fl, F_UNLCK, &dispose); lease_modify(&fl, F_UNLCK, &dispose);
spin_unlock(&inode->i_lock); spin_unlock(&ctx->flc_lock);
locks_dispose_list(&dispose); locks_dispose_list(&dispose);
} }

View File

@ -93,22 +93,22 @@ static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_
goto out; goto out;
list = &flctx->flc_posix; list = &flctx->flc_posix;
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
restart: restart:
list_for_each_entry(fl, list, fl_list) { list_for_each_entry(fl, list, fl_list) {
if (nfs_file_open_context(fl->fl_file) != ctx) if (nfs_file_open_context(fl->fl_file) != ctx)
continue; continue;
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
status = nfs4_lock_delegation_recall(fl, state, stateid); status = nfs4_lock_delegation_recall(fl, state, stateid);
if (status < 0) if (status < 0)
goto out; goto out;
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
} }
if (list == &flctx->flc_posix) { if (list == &flctx->flc_posix) {
list = &flctx->flc_flock; list = &flctx->flc_flock;
goto restart; goto restart;
} }
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
out: out:
return status; return status;
} }

View File

@ -1376,12 +1376,12 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
/* Guard against delegation returns and new lock/unlock calls */ /* Guard against delegation returns and new lock/unlock calls */
down_write(&nfsi->rwsem); down_write(&nfsi->rwsem);
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
restart: restart:
list_for_each_entry(fl, list, fl_list) { list_for_each_entry(fl, list, fl_list) {
if (nfs_file_open_context(fl->fl_file)->state != state) if (nfs_file_open_context(fl->fl_file)->state != state)
continue; continue;
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
status = ops->recover_lock(state, fl); status = ops->recover_lock(state, fl);
switch (status) { switch (status) {
case 0: case 0:
@ -1408,13 +1408,13 @@ restart:
/* kill_proc(fl->fl_pid, SIGLOST, 1); */ /* kill_proc(fl->fl_pid, SIGLOST, 1); */
status = 0; status = 0;
} }
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
} }
if (list == &flctx->flc_posix) { if (list == &flctx->flc_posix) {
list = &flctx->flc_flock; list = &flctx->flc_flock;
goto restart; goto restart;
} }
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
out: out:
up_write(&nfsi->rwsem); up_write(&nfsi->rwsem);
return status; return status;

View File

@ -1206,7 +1206,7 @@ static int nfs_can_extend_write(struct file *file, struct page *page, struct ino
/* Check to see if there are whole file write locks */ /* Check to see if there are whole file write locks */
ret = 0; ret = 0;
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
if (!list_empty(&flctx->flc_posix)) { if (!list_empty(&flctx->flc_posix)) {
fl = list_first_entry(&flctx->flc_posix, struct file_lock, fl = list_first_entry(&flctx->flc_posix, struct file_lock,
fl_list); fl_list);
@ -1218,7 +1218,7 @@ static int nfs_can_extend_write(struct file *file, struct page *page, struct ino
if (fl->fl_type == F_WRLCK) if (fl->fl_type == F_WRLCK)
ret = 1; ret = 1;
} }
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
return ret; return ret;
} }

View File

@ -5572,14 +5572,14 @@ check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner)
flctx = inode->i_flctx; flctx = inode->i_flctx;
if (flctx && !list_empty_careful(&flctx->flc_posix)) { if (flctx && !list_empty_careful(&flctx->flc_posix)) {
spin_lock(&inode->i_lock); spin_lock(&flctx->flc_lock);
list_for_each_entry(fl, &flctx->flc_posix, fl_list) { list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
if (fl->fl_owner == (fl_owner_t)lowner) { if (fl->fl_owner == (fl_owner_t)lowner) {
status = true; status = true;
break; break;
} }
} }
spin_unlock(&inode->i_lock); spin_unlock(&flctx->flc_lock);
} }
fput(filp); fput(filp);
return status; return status;

View File

@ -968,6 +968,7 @@ struct file_lock {
}; };
struct file_lock_context { struct file_lock_context {
spinlock_t flc_lock;
struct list_head flc_flock; struct list_head flc_flock;
struct list_head flc_posix; struct list_head flc_posix;
struct list_head flc_lease; struct list_head flc_lease;