Commit e6dfa553 authored by Trond Myklebust's avatar Trond Myklebust

NFSv4: Remove obsolete state_owner and lock_owner semaphores

 OPEN, CLOSE, etc no longer need these semaphores to ensure ordering of
 requests.
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 9512135d
...@@ -125,16 +125,11 @@ static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status ...@@ -125,16 +125,11 @@ static inline void nfs_confirm_seqid(struct nfs_seqid_counter *seqid, int status
* NFS4 state_owners and lock_owners are simply labels for ordered * NFS4 state_owners and lock_owners are simply labels for ordered
* sequences of RPC calls. Their sole purpose is to provide once-only * sequences of RPC calls. Their sole purpose is to provide once-only
* semantics by allowing the server to identify replayed requests. * semantics by allowing the server to identify replayed requests.
*
* The ->so_sema is held during all state_owner seqid-mutating operations:
* OPEN, OPEN_DOWNGRADE, and CLOSE. Its purpose is to properly serialize
* so_seqid.
*/ */
struct nfs4_state_owner { struct nfs4_state_owner {
struct list_head so_list; /* per-clientid list of state_owners */ struct list_head so_list; /* per-clientid list of state_owners */
struct nfs4_client *so_client; struct nfs4_client *so_client;
u32 so_id; /* 32-bit identifier, unique */ u32 so_id; /* 32-bit identifier, unique */
struct semaphore so_sema;
atomic_t so_count; atomic_t so_count;
struct rpc_cred *so_cred; /* Associated cred */ struct rpc_cred *so_cred; /* Associated cred */
...@@ -183,7 +178,6 @@ struct nfs4_state { ...@@ -183,7 +178,6 @@ struct nfs4_state {
struct inode *inode; /* Pointer to the inode */ struct inode *inode; /* Pointer to the inode */
unsigned long flags; /* Do we hold any locks? */ unsigned long flags; /* Do we hold any locks? */
struct semaphore lock_sema; /* Serializes file locking operations */
spinlock_t state_lock; /* Protects the lock_states list */ spinlock_t state_lock; /* Protects the lock_states list */
nfs4_stateid stateid; nfs4_stateid stateid;
......
...@@ -224,7 +224,6 @@ static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid, ...@@ -224,7 +224,6 @@ static void update_open_stateid(struct nfs4_state *state, nfs4_stateid *stateid,
/* /*
* OPEN_RECLAIM: * OPEN_RECLAIM:
* reclaim state on the server after a reboot. * reclaim state on the server after a reboot.
* Assumes caller is holding the sp->so_sem
*/ */
static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state) static int _nfs4_open_reclaim(struct nfs4_state_owner *sp, struct nfs4_state *state)
{ {
...@@ -322,7 +321,6 @@ static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state ...@@ -322,7 +321,6 @@ static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state
}; };
int status = 0; int status = 0;
down(&sp->so_sema);
if (!test_bit(NFS_DELEGATED_STATE, &state->flags)) if (!test_bit(NFS_DELEGATED_STATE, &state->flags))
goto out; goto out;
if (state->state == 0) if (state->state == 0)
...@@ -342,7 +340,6 @@ static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state ...@@ -342,7 +340,6 @@ static int _nfs4_open_delegation_recall(struct dentry *dentry, struct nfs4_state
} }
nfs_free_seqid(arg.seqid); nfs_free_seqid(arg.seqid);
out: out:
up(&sp->so_sema);
dput(parent); dput(parent);
return status; return status;
} }
...@@ -595,7 +592,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred ...@@ -595,7 +592,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__); dprintk("%s: nfs4_get_state_owner failed!\n", __FUNCTION__);
goto out_err; goto out_err;
} }
down(&sp->so_sema);
state = nfs4_get_open_state(inode, sp); state = nfs4_get_open_state(inode, sp);
if (state == NULL) if (state == NULL)
goto out_err; goto out_err;
...@@ -620,7 +616,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred ...@@ -620,7 +616,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
set_bit(NFS_DELEGATED_STATE, &state->flags); set_bit(NFS_DELEGATED_STATE, &state->flags);
update_open_stateid(state, &delegation->stateid, open_flags); update_open_stateid(state, &delegation->stateid, open_flags);
out_ok: out_ok:
up(&sp->so_sema);
nfs4_put_state_owner(sp); nfs4_put_state_owner(sp);
up_read(&nfsi->rwsem); up_read(&nfsi->rwsem);
up_read(&clp->cl_sem); up_read(&clp->cl_sem);
...@@ -631,7 +626,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred ...@@ -631,7 +626,6 @@ static int _nfs4_open_delegated(struct inode *inode, int flags, struct rpc_cred
if (sp != NULL) { if (sp != NULL) {
if (state != NULL) if (state != NULL)
nfs4_put_open_state(state); nfs4_put_open_state(state);
up(&sp->so_sema);
nfs4_put_state_owner(sp); nfs4_put_state_owner(sp);
} }
up_read(&nfsi->rwsem); up_read(&nfsi->rwsem);
...@@ -696,7 +690,6 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st ...@@ -696,7 +690,6 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st
} else } else
o_arg.u.attrs = sattr; o_arg.u.attrs = sattr;
/* Serialization for the sequence id */ /* Serialization for the sequence id */
down(&sp->so_sema);
o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid); o_arg.seqid = nfs_alloc_seqid(&sp->so_seqid);
if (o_arg.seqid == NULL) if (o_arg.seqid == NULL)
...@@ -716,7 +709,6 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st ...@@ -716,7 +709,6 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st
if (o_res.delegation_type != 0) if (o_res.delegation_type != 0)
nfs_inode_set_delegation(inode, cred, &o_res); nfs_inode_set_delegation(inode, cred, &o_res);
nfs_free_seqid(o_arg.seqid); nfs_free_seqid(o_arg.seqid);
up(&sp->so_sema);
nfs4_put_state_owner(sp); nfs4_put_state_owner(sp);
up_read(&clp->cl_sem); up_read(&clp->cl_sem);
*res = state; *res = state;
...@@ -726,7 +718,6 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st ...@@ -726,7 +718,6 @@ static int _nfs4_do_open(struct inode *dir, struct dentry *dentry, int flags, st
if (state != NULL) if (state != NULL)
nfs4_put_open_state(state); nfs4_put_open_state(state);
nfs_free_seqid(o_arg.seqid); nfs_free_seqid(o_arg.seqid);
up(&sp->so_sema);
nfs4_put_state_owner(sp); nfs4_put_state_owner(sp);
} }
/* Note: clp->cl_sem must be released before nfs4_put_open_state()! */ /* Note: clp->cl_sem must be released before nfs4_put_open_state()! */
...@@ -833,7 +824,6 @@ static void nfs4_free_closedata(struct nfs4_closedata *calldata) ...@@ -833,7 +824,6 @@ static void nfs4_free_closedata(struct nfs4_closedata *calldata)
nfs4_put_open_state(calldata->state); nfs4_put_open_state(calldata->state);
nfs_free_seqid(calldata->arg.seqid); nfs_free_seqid(calldata->arg.seqid);
up(&sp->so_sema);
nfs4_put_state_owner(sp); nfs4_put_state_owner(sp);
up_read(&server->nfs4_state->cl_sem); up_read(&server->nfs4_state->cl_sem);
kfree(calldata); kfree(calldata);
...@@ -2702,7 +2692,6 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock ...@@ -2702,7 +2692,6 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock
down_read(&clp->cl_sem); down_read(&clp->cl_sem);
nlo.clientid = clp->cl_clientid; nlo.clientid = clp->cl_clientid;
down(&state->lock_sema);
status = nfs4_set_lock_state(state, request); status = nfs4_set_lock_state(state, request);
if (status != 0) if (status != 0)
goto out; goto out;
...@@ -2729,7 +2718,6 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock ...@@ -2729,7 +2718,6 @@ static int _nfs4_proc_getlk(struct nfs4_state *state, int cmd, struct file_lock
status = 0; status = 0;
} }
out: out:
up(&state->lock_sema);
up_read(&clp->cl_sem); up_read(&clp->cl_sem);
return status; return status;
} }
...@@ -2791,7 +2779,6 @@ static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock ...@@ -2791,7 +2779,6 @@ static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock
int status; int status;
down_read(&clp->cl_sem); down_read(&clp->cl_sem);
down(&state->lock_sema);
status = nfs4_set_lock_state(state, request); status = nfs4_set_lock_state(state, request);
if (status != 0) if (status != 0)
goto out; goto out;
...@@ -2813,7 +2800,6 @@ static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock ...@@ -2813,7 +2800,6 @@ static int _nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock
sizeof(lsp->ls_stateid.data)); sizeof(lsp->ls_stateid.data));
nfs_free_seqid(luargs.seqid); nfs_free_seqid(luargs.seqid);
out: out:
up(&state->lock_sema);
if (status == 0) if (status == 0)
do_vfs_lock(request->fl_file, request); do_vfs_lock(request->fl_file, request);
up_read(&clp->cl_sem); up_read(&clp->cl_sem);
...@@ -2877,7 +2863,6 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r ...@@ -2877,7 +2863,6 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r
largs.u.open_lock = &otl; largs.u.open_lock = &otl;
largs.new_lock_owner = 1; largs.new_lock_owner = 1;
arg.u.lock = &largs; arg.u.lock = &largs;
down(&owner->so_sema);
otl.open_seqid = nfs_alloc_seqid(&owner->so_seqid); otl.open_seqid = nfs_alloc_seqid(&owner->so_seqid);
if (otl.open_seqid != NULL) { if (otl.open_seqid != NULL) {
status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR); status = rpc_call_sync(server->client, &msg, RPC_TASK_NOINTR);
...@@ -2885,7 +2870,6 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r ...@@ -2885,7 +2870,6 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *r
nfs_increment_open_seqid(status, otl.open_seqid); nfs_increment_open_seqid(status, otl.open_seqid);
nfs_free_seqid(otl.open_seqid); nfs_free_seqid(otl.open_seqid);
} }
up(&owner->so_sema);
if (status == 0) if (status == 0)
nfs_confirm_seqid(&lsp->ls_seqid, 0); nfs_confirm_seqid(&lsp->ls_seqid, 0);
} else { } else {
...@@ -2944,11 +2928,9 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock ...@@ -2944,11 +2928,9 @@ static int _nfs4_proc_setlk(struct nfs4_state *state, int cmd, struct file_lock
int status; int status;
down_read(&clp->cl_sem); down_read(&clp->cl_sem);
down(&state->lock_sema);
status = nfs4_set_lock_state(state, request); status = nfs4_set_lock_state(state, request);
if (status == 0) if (status == 0)
status = _nfs4_do_setlk(state, cmd, request, 0); status = _nfs4_do_setlk(state, cmd, request, 0);
up(&state->lock_sema);
if (status == 0) { if (status == 0) {
/* Note: we always want to sleep here! */ /* Note: we always want to sleep here! */
request->fl_flags |= FL_SLEEP; request->fl_flags |= FL_SLEEP;
......
...@@ -267,7 +267,6 @@ nfs4_alloc_state_owner(void) ...@@ -267,7 +267,6 @@ nfs4_alloc_state_owner(void)
sp = kzalloc(sizeof(*sp),GFP_KERNEL); sp = kzalloc(sizeof(*sp),GFP_KERNEL);
if (!sp) if (!sp)
return NULL; return NULL;
init_MUTEX(&sp->so_sema);
INIT_LIST_HEAD(&sp->so_states); INIT_LIST_HEAD(&sp->so_states);
INIT_LIST_HEAD(&sp->so_delegations); INIT_LIST_HEAD(&sp->so_delegations);
rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue"); rpc_init_wait_queue(&sp->so_sequence.wait, "Seqid_waitqueue");
...@@ -362,7 +361,6 @@ nfs4_alloc_open_state(void) ...@@ -362,7 +361,6 @@ nfs4_alloc_open_state(void)
memset(state->stateid.data, 0, sizeof(state->stateid.data)); memset(state->stateid.data, 0, sizeof(state->stateid.data));
atomic_set(&state->count, 1); atomic_set(&state->count, 1);
INIT_LIST_HEAD(&state->lock_states); INIT_LIST_HEAD(&state->lock_states);
init_MUTEX(&state->lock_sema);
spin_lock_init(&state->state_lock); spin_lock_init(&state->state_lock);
return state; return state;
} }
...@@ -444,7 +442,6 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner) ...@@ -444,7 +442,6 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
state = __nfs4_find_state_byowner(inode, owner); state = __nfs4_find_state_byowner(inode, owner);
if (state == NULL && new != NULL) { if (state == NULL && new != NULL) {
state = new; state = new;
/* Caller *must* be holding owner->so_sem */
/* Note: The reclaim code dictates that we add stateless /* Note: The reclaim code dictates that we add stateless
* and read-only stateids to the end of the list */ * and read-only stateids to the end of the list */
list_add_tail(&state->open_states, &owner->so_states); list_add_tail(&state->open_states, &owner->so_states);
...@@ -464,7 +461,7 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner) ...@@ -464,7 +461,7 @@ nfs4_get_open_state(struct inode *inode, struct nfs4_state_owner *owner)
/* /*
* Beware! Caller must be holding exactly one * Beware! Caller must be holding exactly one
* reference to clp->cl_sem and owner->so_sema! * reference to clp->cl_sem!
*/ */
void nfs4_put_open_state(struct nfs4_state *state) void nfs4_put_open_state(struct nfs4_state *state)
{ {
...@@ -485,7 +482,6 @@ void nfs4_put_open_state(struct nfs4_state *state) ...@@ -485,7 +482,6 @@ void nfs4_put_open_state(struct nfs4_state *state)
/* /*
* Beware! Caller must be holding no references to clp->cl_sem! * Beware! Caller must be holding no references to clp->cl_sem!
* of owner->so_sema!
*/ */
void nfs4_close_state(struct nfs4_state *state, mode_t mode) void nfs4_close_state(struct nfs4_state *state, mode_t mode)
{ {
...@@ -496,7 +492,6 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode) ...@@ -496,7 +492,6 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode)
atomic_inc(&owner->so_count); atomic_inc(&owner->so_count);
down_read(&clp->cl_sem); down_read(&clp->cl_sem);
down(&owner->so_sema);
/* Protect against nfs4_find_state() */ /* Protect against nfs4_find_state() */
spin_lock(&inode->i_lock); spin_lock(&inode->i_lock);
if (mode & FMODE_READ) if (mode & FMODE_READ)
...@@ -527,7 +522,6 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode) ...@@ -527,7 +522,6 @@ void nfs4_close_state(struct nfs4_state *state, mode_t mode)
} }
out: out:
nfs4_put_open_state(state); nfs4_put_open_state(state);
up(&owner->so_sema);
nfs4_put_state_owner(owner); nfs4_put_state_owner(owner);
up_read(&clp->cl_sem); up_read(&clp->cl_sem);
} }
...@@ -553,7 +547,6 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) ...@@ -553,7 +547,6 @@ __nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
* Return a compatible lock_state. If no initialized lock_state structure * Return a compatible lock_state. If no initialized lock_state structure
* exists, return an uninitialized one. * exists, return an uninitialized one.
* *
* The caller must be holding state->lock_sema
*/ */
static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner) static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t fl_owner)
{ {
...@@ -577,7 +570,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f ...@@ -577,7 +570,7 @@ static struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, f
* Return a compatible lock_state. If no initialized lock_state structure * Return a compatible lock_state. If no initialized lock_state structure
* exists, return an uninitialized one. * exists, return an uninitialized one.
* *
* The caller must be holding state->lock_sema and clp->cl_sem * The caller must be holding clp->cl_sem
*/ */
static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner) static struct nfs4_lock_state *nfs4_get_lock_state(struct nfs4_state *state, fl_owner_t owner)
{ {
...@@ -711,7 +704,7 @@ void nfs_free_seqid(struct nfs_seqid *seqid) ...@@ -711,7 +704,7 @@ void nfs_free_seqid(struct nfs_seqid *seqid)
} }
/* /*
* Called with sp->so_sema and clp->cl_sem held. * Called with clp->cl_sem held.
* *
* Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or * Increment the seqid if the OPEN/OPEN_DOWNGRADE/CLOSE succeeded, or
* failed with a seqid incrementing error - * failed with a seqid incrementing error -
...@@ -750,7 +743,7 @@ void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid) ...@@ -750,7 +743,7 @@ void nfs_increment_open_seqid(int status, struct nfs_seqid *seqid)
} }
/* /*
* Called with ls->lock_sema and clp->cl_sem held. * Called with clp->cl_sem held.
* *
* Increment the seqid if the LOCK/LOCKU succeeded, or * Increment the seqid if the LOCK/LOCKU succeeded, or
* failed with a seqid incrementing error - * failed with a seqid incrementing error -
......
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