nfsd: Add a mutex to protect the NFSv4.0 open owner replay cache
We don't want to rely on the client_mutex for protection in the case of NFSv4 open owners. Instead, we add a mutex that will only be taken for NFSv4.0 state mutating operations, and that will be released once the entire compound is done. Also, ensure that nfsd4_cstate_assign_replay/nfsd4_cstate_clear_replay take a reference to the stateowner when they are using it for NFSv4.0 open and lock replay caching. Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com> Signed-off-by: Jeff Layton <jlayton@primarydata.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
This commit is contained in:
parent
6b180f0b57
commit
58fb12e6a4
|
@ -469,11 +469,8 @@ out:
|
||||||
fh_put(resfh);
|
fh_put(resfh);
|
||||||
kfree(resfh);
|
kfree(resfh);
|
||||||
}
|
}
|
||||||
nfsd4_cleanup_open_state(open, status);
|
nfsd4_cleanup_open_state(cstate, open, status);
|
||||||
if (open->op_openowner && !nfsd4_has_session(cstate))
|
|
||||||
cstate->replay_owner = &open->op_openowner->oo_owner;
|
|
||||||
nfsd4_bump_seqid(cstate, status);
|
nfsd4_bump_seqid(cstate, status);
|
||||||
if (!cstate->replay_owner)
|
|
||||||
nfs4_unlock_state();
|
nfs4_unlock_state();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1395,10 +1392,7 @@ encode_op:
|
||||||
args->ops, args->opcnt, resp->opcnt, op->opnum,
|
args->ops, args->opcnt, resp->opcnt, op->opnum,
|
||||||
be32_to_cpu(status));
|
be32_to_cpu(status));
|
||||||
|
|
||||||
if (cstate->replay_owner) {
|
nfsd4_cstate_clear_replay(cstate);
|
||||||
nfs4_unlock_state();
|
|
||||||
cstate->replay_owner = NULL;
|
|
||||||
}
|
|
||||||
/* XXX Ugh, we need to get rid of this kind of special case: */
|
/* XXX Ugh, we need to get rid of this kind of special case: */
|
||||||
if (op->opnum == OP_READ && op->u.read.rd_filp)
|
if (op->opnum == OP_READ && op->u.read.rd_filp)
|
||||||
fput(op->u.read.rd_filp);
|
fput(op->u.read.rd_filp);
|
||||||
|
|
|
@ -1069,7 +1069,7 @@ void nfsd4_bump_seqid(struct nfsd4_compound_state *cstate, __be32 nfserr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!seqid_mutating_err(ntohl(nfserr))) {
|
if (!seqid_mutating_err(ntohl(nfserr))) {
|
||||||
cstate->replay_owner = NULL;
|
nfsd4_cstate_clear_replay(cstate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!so)
|
if (!so)
|
||||||
|
@ -2940,6 +2940,28 @@ static void init_nfs4_replay(struct nfs4_replay *rp)
|
||||||
rp->rp_status = nfserr_serverfault;
|
rp->rp_status = nfserr_serverfault;
|
||||||
rp->rp_buflen = 0;
|
rp->rp_buflen = 0;
|
||||||
rp->rp_buf = rp->rp_ibuf;
|
rp->rp_buf = rp->rp_ibuf;
|
||||||
|
mutex_init(&rp->rp_mutex);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void nfsd4_cstate_assign_replay(struct nfsd4_compound_state *cstate,
|
||||||
|
struct nfs4_stateowner *so)
|
||||||
|
{
|
||||||
|
if (!nfsd4_has_session(cstate)) {
|
||||||
|
mutex_lock(&so->so_replay.rp_mutex);
|
||||||
|
cstate->replay_owner = so;
|
||||||
|
atomic_inc(&so->so_count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate)
|
||||||
|
{
|
||||||
|
struct nfs4_stateowner *so = cstate->replay_owner;
|
||||||
|
|
||||||
|
if (so != NULL) {
|
||||||
|
cstate->replay_owner = NULL;
|
||||||
|
mutex_unlock(&so->so_replay.rp_mutex);
|
||||||
|
nfs4_put_stateowner(so);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void *alloc_stateowner(struct kmem_cache *slab, struct xdr_netobj *owner, struct nfs4_client *clp)
|
static inline void *alloc_stateowner(struct kmem_cache *slab, struct xdr_netobj *owner, struct nfs4_client *clp)
|
||||||
|
@ -3855,7 +3877,8 @@ out:
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void nfsd4_cleanup_open_state(struct nfsd4_open *open, __be32 status)
|
void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate,
|
||||||
|
struct nfsd4_open *open, __be32 status)
|
||||||
{
|
{
|
||||||
if (open->op_openowner) {
|
if (open->op_openowner) {
|
||||||
struct nfs4_openowner *oo = open->op_openowner;
|
struct nfs4_openowner *oo = open->op_openowner;
|
||||||
|
@ -3869,6 +3892,8 @@ void nfsd4_cleanup_open_state(struct nfsd4_open *open, __be32 status)
|
||||||
} else
|
} else
|
||||||
oo->oo_flags &= ~NFS4_OO_NEW;
|
oo->oo_flags &= ~NFS4_OO_NEW;
|
||||||
}
|
}
|
||||||
|
if (open->op_openowner)
|
||||||
|
nfsd4_cstate_assign_replay(cstate, &oo->oo_owner);
|
||||||
}
|
}
|
||||||
if (open->op_file)
|
if (open->op_file)
|
||||||
nfsd4_free_file(open->op_file);
|
nfsd4_free_file(open->op_file);
|
||||||
|
@ -4399,8 +4424,7 @@ nfs4_preprocess_seqid_op(struct nfsd4_compound_state *cstate, u32 seqid,
|
||||||
if (status)
|
if (status)
|
||||||
return status;
|
return status;
|
||||||
stp = openlockstateid(s);
|
stp = openlockstateid(s);
|
||||||
if (!nfsd4_has_session(cstate))
|
nfsd4_cstate_assign_replay(cstate, stp->st_stateowner);
|
||||||
cstate->replay_owner = stp->st_stateowner;
|
|
||||||
|
|
||||||
status = nfs4_seqid_op_checks(cstate, stateid, seqid, stp);
|
status = nfs4_seqid_op_checks(cstate, stateid, seqid, stp);
|
||||||
if (!status)
|
if (!status)
|
||||||
|
@ -4469,7 +4493,6 @@ put_stateid:
|
||||||
nfs4_put_stid(&stp->st_stid);
|
nfs4_put_stid(&stp->st_stid);
|
||||||
out:
|
out:
|
||||||
nfsd4_bump_seqid(cstate, status);
|
nfsd4_bump_seqid(cstate, status);
|
||||||
if (!cstate->replay_owner)
|
|
||||||
nfs4_unlock_state();
|
nfs4_unlock_state();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -4544,7 +4567,6 @@ put_stateid:
|
||||||
nfs4_put_stid(&stp->st_stid);
|
nfs4_put_stid(&stp->st_stid);
|
||||||
out:
|
out:
|
||||||
nfsd4_bump_seqid(cstate, status);
|
nfsd4_bump_seqid(cstate, status);
|
||||||
if (!cstate->replay_owner)
|
|
||||||
nfs4_unlock_state();
|
nfs4_unlock_state();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -4610,7 +4632,6 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
|
||||||
/* put reference from nfs4_preprocess_seqid_op */
|
/* put reference from nfs4_preprocess_seqid_op */
|
||||||
nfs4_put_stid(&stp->st_stid);
|
nfs4_put_stid(&stp->st_stid);
|
||||||
out:
|
out:
|
||||||
if (!cstate->replay_owner)
|
|
||||||
nfs4_unlock_state();
|
nfs4_unlock_state();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -5071,7 +5092,6 @@ out:
|
||||||
if (status && new_state)
|
if (status && new_state)
|
||||||
release_lock_stateid(lock_stp);
|
release_lock_stateid(lock_stp);
|
||||||
nfsd4_bump_seqid(cstate, status);
|
nfsd4_bump_seqid(cstate, status);
|
||||||
if (!cstate->replay_owner)
|
|
||||||
nfs4_unlock_state();
|
nfs4_unlock_state();
|
||||||
if (file_lock)
|
if (file_lock)
|
||||||
locks_free_lock(file_lock);
|
locks_free_lock(file_lock);
|
||||||
|
@ -5236,7 +5256,6 @@ put_stateid:
|
||||||
nfs4_put_stid(&stp->st_stid);
|
nfs4_put_stid(&stp->st_stid);
|
||||||
out:
|
out:
|
||||||
nfsd4_bump_seqid(cstate, status);
|
nfsd4_bump_seqid(cstate, status);
|
||||||
if (!cstate->replay_owner)
|
|
||||||
nfs4_unlock_state();
|
nfs4_unlock_state();
|
||||||
if (file_lock)
|
if (file_lock)
|
||||||
locks_free_lock(file_lock);
|
locks_free_lock(file_lock);
|
||||||
|
|
|
@ -3925,8 +3925,6 @@ status:
|
||||||
*
|
*
|
||||||
* XDR note: do not encode rp->rp_buflen: the buffer contains the
|
* XDR note: do not encode rp->rp_buflen: the buffer contains the
|
||||||
* previously sent already encoded operation.
|
* previously sent already encoded operation.
|
||||||
*
|
|
||||||
* called with nfs4_lock_state() held
|
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)
|
nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)
|
||||||
|
|
|
@ -328,6 +328,7 @@ struct nfs4_replay {
|
||||||
unsigned int rp_buflen;
|
unsigned int rp_buflen;
|
||||||
char *rp_buf;
|
char *rp_buf;
|
||||||
struct knfsd_fh rp_openfh;
|
struct knfsd_fh rp_openfh;
|
||||||
|
struct mutex rp_mutex;
|
||||||
char rp_ibuf[NFSD4_REPLAY_ISIZE];
|
char rp_ibuf[NFSD4_REPLAY_ISIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -599,7 +599,9 @@ extern __be32 nfsd4_process_open1(struct nfsd4_compound_state *,
|
||||||
struct nfsd4_open *open, struct nfsd_net *nn);
|
struct nfsd4_open *open, struct nfsd_net *nn);
|
||||||
extern __be32 nfsd4_process_open2(struct svc_rqst *rqstp,
|
extern __be32 nfsd4_process_open2(struct svc_rqst *rqstp,
|
||||||
struct svc_fh *current_fh, struct nfsd4_open *open);
|
struct svc_fh *current_fh, struct nfsd4_open *open);
|
||||||
extern void nfsd4_cleanup_open_state(struct nfsd4_open *open, __be32 status);
|
extern void nfsd4_cstate_clear_replay(struct nfsd4_compound_state *cstate);
|
||||||
|
extern void nfsd4_cleanup_open_state(struct nfsd4_compound_state *cstate,
|
||||||
|
struct nfsd4_open *open, __be32 status);
|
||||||
extern __be32 nfsd4_open_confirm(struct svc_rqst *rqstp,
|
extern __be32 nfsd4_open_confirm(struct svc_rqst *rqstp,
|
||||||
struct nfsd4_compound_state *, struct nfsd4_open_confirm *oc);
|
struct nfsd4_compound_state *, struct nfsd4_open_confirm *oc);
|
||||||
extern __be32 nfsd4_close(struct svc_rqst *rqstp,
|
extern __be32 nfsd4_close(struct svc_rqst *rqstp,
|
||||||
|
@ -630,6 +632,7 @@ extern __be32 nfsd4_test_stateid(struct svc_rqst *rqstp,
|
||||||
extern __be32 nfsd4_free_stateid(struct svc_rqst *rqstp,
|
extern __be32 nfsd4_free_stateid(struct svc_rqst *rqstp,
|
||||||
struct nfsd4_compound_state *, struct nfsd4_free_stateid *free_stateid);
|
struct nfsd4_compound_state *, struct nfsd4_free_stateid *free_stateid);
|
||||||
extern void nfsd4_bump_seqid(struct nfsd4_compound_state *, __be32 nfserr);
|
extern void nfsd4_bump_seqid(struct nfsd4_compound_state *, __be32 nfserr);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue