Commit 6109c850 authored by Jeff Layton's avatar Jeff Layton Committed by Jeff Layton

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: default avatarJeff Layton <jlayton@primarydata.com>
Acked-by: default avatarChristoph Hellwig <hch@lst.de>
parent a7231a97
...@@ -255,12 +255,12 @@ void ceph_count_locks(struct inode *inode, int *fcntl_count, int *flock_count) ...@@ -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, ...@@ -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, ...@@ -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;
} }
......
...@@ -1136,11 +1136,11 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile) ...@@ -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) ...@@ -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) ...@@ -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;
......
...@@ -171,7 +171,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *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 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, ...@@ -183,7 +183,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
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 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file, ...@@ -195,7 +195,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
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) ...@@ -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;
......
This diff is collapsed.
...@@ -93,22 +93,22 @@ static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_ ...@@ -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;
} }
......
...@@ -1376,12 +1376,12 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_ ...@@ -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 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_ ...@@ -1408,13 +1408,13 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
/* 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;
......
...@@ -1206,7 +1206,7 @@ static int nfs_can_extend_write(struct file *file, struct page *page, struct ino ...@@ -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 ...@@ -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;
} }
......
...@@ -5572,14 +5572,14 @@ check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner) ...@@ -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;
......
...@@ -968,6 +968,7 @@ struct file_lock { ...@@ -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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment