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)
ctx = inode->i_flctx;
if (ctx) {
spin_lock(&inode->i_lock);
spin_lock(&ctx->flc_lock);
list_for_each_entry(lock, &ctx->flc_posix, fl_list)
++(*fcntl_count);
list_for_each_entry(lock, &ctx->flc_flock, fl_list)
++(*flock_count);
spin_unlock(&inode->i_lock);
spin_unlock(&ctx->flc_lock);
}
dout("counted %d flock locks and %d fcntl locks",
*flock_count, *fcntl_count);
......@@ -288,7 +288,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
if (!ctx)
return 0;
spin_lock(&inode->i_lock);
spin_lock(&ctx->flc_lock);
list_for_each_entry(lock, &ctx->flc_flock, fl_list) {
++seen_fcntl;
if (seen_fcntl > num_fcntl_locks) {
......@@ -312,7 +312,7 @@ int ceph_encode_locks_to_buffer(struct inode *inode,
++l;
}
fail:
spin_unlock(&inode->i_lock);
spin_unlock(&ctx->flc_lock);
return err;
}
......
......@@ -1136,11 +1136,11 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
if (!flctx)
goto out;
spin_lock(&inode->i_lock);
spin_lock(&flctx->flc_lock);
list_for_each(el, &flctx->flc_posix) {
count++;
}
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
INIT_LIST_HEAD(&locks_to_send);
......@@ -1159,7 +1159,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
}
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) {
if (el == &locks_to_send) {
/*
......@@ -1181,7 +1181,7 @@ cifs_push_posix_locks(struct cifsFileInfo *cfile)
lck->type = type;
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) {
int stored_rc;
......
......@@ -171,7 +171,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
return 0;
again:
file->f_locks = 0;
spin_lock(&inode->i_lock);
spin_lock(&flctx->flc_lock);
list_for_each_entry(fl, &flctx->flc_posix, fl_list) {
if (fl->fl_lmops != &nlmsvc_lock_operations)
continue;
......@@ -183,7 +183,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
if (match(lockhost, host)) {
struct file_lock lock = *fl;
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
lock.fl_type = F_UNLCK;
lock.fl_start = 0;
lock.fl_end = OFFSET_MAX;
......@@ -195,7 +195,7 @@ nlm_traverse_locks(struct nlm_host *host, struct nlm_file *file,
goto again;
}
}
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
return 0;
}
......@@ -232,14 +232,14 @@ nlm_file_inuse(struct nlm_file *file)
return 1;
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) {
if (fl->fl_lmops == &nlmsvc_lock_operations) {
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
return 1;
}
}
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
}
file->f_locks = 0;
return 0;
......
This diff is collapsed.
......@@ -93,22 +93,22 @@ static int nfs_delegation_claim_locks(struct nfs_open_context *ctx, struct nfs4_
goto out;
list = &flctx->flc_posix;
spin_lock(&inode->i_lock);
spin_lock(&flctx->flc_lock);
restart:
list_for_each_entry(fl, list, fl_list) {
if (nfs_file_open_context(fl->fl_file) != ctx)
continue;
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
status = nfs4_lock_delegation_recall(fl, state, stateid);
if (status < 0)
goto out;
spin_lock(&inode->i_lock);
spin_lock(&flctx->flc_lock);
}
if (list == &flctx->flc_posix) {
list = &flctx->flc_flock;
goto restart;
}
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
out:
return status;
}
......
......@@ -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 */
down_write(&nfsi->rwsem);
spin_lock(&inode->i_lock);
spin_lock(&flctx->flc_lock);
restart:
list_for_each_entry(fl, list, fl_list) {
if (nfs_file_open_context(fl->fl_file)->state != state)
continue;
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
status = ops->recover_lock(state, fl);
switch (status) {
case 0:
......@@ -1408,13 +1408,13 @@ static int nfs4_reclaim_locks(struct nfs4_state *state, const struct nfs4_state_
/* kill_proc(fl->fl_pid, SIGLOST, 1); */
status = 0;
}
spin_lock(&inode->i_lock);
spin_lock(&flctx->flc_lock);
}
if (list == &flctx->flc_posix) {
list = &flctx->flc_flock;
goto restart;
}
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
out:
up_write(&nfsi->rwsem);
return status;
......
......@@ -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 */
ret = 0;
spin_lock(&inode->i_lock);
spin_lock(&flctx->flc_lock);
if (!list_empty(&flctx->flc_posix)) {
fl = list_first_entry(&flctx->flc_posix, struct file_lock,
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)
ret = 1;
}
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
return ret;
}
......
......@@ -5572,14 +5572,14 @@ check_for_locks(struct nfs4_file *fp, struct nfs4_lockowner *lowner)
flctx = inode->i_flctx;
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) {
if (fl->fl_owner == (fl_owner_t)lowner) {
status = true;
break;
}
}
spin_unlock(&inode->i_lock);
spin_unlock(&flctx->flc_lock);
}
fput(filp);
return status;
......
......@@ -968,6 +968,7 @@ struct file_lock {
};
struct file_lock_context {
spinlock_t flc_lock;
struct list_head flc_flock;
struct list_head flc_posix;
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