Skip to content

Commit fceb873

Browse files
neilbrownchucklever
authored andcommitted
nfsd: stop pretending that we cache the SEQUENCE reply.
nfsd does not cache the reply to a SEQUENCE. As the comment above nfsd4_replay_cache_entry() says: * The sequence operation is not cached because we can use the slot and * session values. The comment above nfsd4_cache_this() suggests otherwise. * The session reply cache only needs to cache replies that the client * actually asked us to. But it's almost free for us to cache compounds * consisting of only a SEQUENCE op, so we may as well cache those too. * Also, the protocol doesn't give us a convenient response in the case * of a replay of a solo SEQUENCE op that wasn't cached The code in nfsd4_store_cache_entry() makes it clear that only responses beyond 'cstate.data_offset' are actually cached, and data_offset is set at the end of nfsd4_encode_sequence() *after* the sequence response has been encoded. This patch simplifies code and removes the confusing comments. - nfsd4_is_solo_sequence() is discarded as not-useful. - nfsd4_cache_this() is now trivial so it too is discarded with the code placed in-line at the one call-site in nfsd4_store_cache_entry(). - nfsd4_enc_sequence_replay() is open-coded in to nfsd4_replay_cache_entry(), and then simplified to (hopefully) make the process of replaying a reply clearer. Signed-off-by: NeilBrown <neil@brown.name> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
1 parent 8320b75 commit fceb873

2 files changed

Lines changed: 18 additions & 61 deletions

File tree

fs/nfsd/nfs4state.c

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3508,7 +3508,7 @@ nfsd4_store_cache_entry(struct nfsd4_compoundres *resp)
35083508
free_svc_cred(&slot->sl_cred);
35093509
copy_cred(&slot->sl_cred, &resp->rqstp->rq_cred);
35103510

3511-
if (!nfsd4_cache_this(resp)) {
3511+
if (!(resp->cstate.slot->sl_flags & NFSD4_SLOT_CACHETHIS)) {
35123512
slot->sl_flags &= ~NFSD4_SLOT_CACHED;
35133513
return;
35143514
}
@@ -3522,41 +3522,6 @@ nfsd4_store_cache_entry(struct nfsd4_compoundres *resp)
35223522
return;
35233523
}
35243524

3525-
/*
3526-
* Encode the replay sequence operation from the slot values.
3527-
* If cachethis is FALSE encode the uncached rep error on the next
3528-
* operation which sets resp->p and increments resp->opcnt for
3529-
* nfs4svc_encode_compoundres.
3530-
*
3531-
*/
3532-
static __be32
3533-
nfsd4_enc_sequence_replay(struct nfsd4_compoundargs *args,
3534-
struct nfsd4_compoundres *resp)
3535-
{
3536-
struct nfsd4_op *op;
3537-
struct nfsd4_slot *slot = resp->cstate.slot;
3538-
3539-
/* Encode the replayed sequence operation */
3540-
op = &args->ops[resp->opcnt - 1];
3541-
nfsd4_encode_operation(resp, op);
3542-
3543-
if (slot->sl_flags & NFSD4_SLOT_CACHED)
3544-
return op->status;
3545-
if (args->opcnt == 1) {
3546-
/*
3547-
* The original operation wasn't a solo sequence--we
3548-
* always cache those--so this retry must not match the
3549-
* original:
3550-
*/
3551-
op->status = nfserr_seq_false_retry;
3552-
} else {
3553-
op = &args->ops[resp->opcnt++];
3554-
op->status = nfserr_retry_uncached_rep;
3555-
nfsd4_encode_operation(resp, op);
3556-
}
3557-
return op->status;
3558-
}
3559-
35603525
/*
35613526
* The sequence operation is not cached because we can use the slot and
35623527
* session values.
@@ -3565,17 +3530,30 @@ static __be32
35653530
nfsd4_replay_cache_entry(struct nfsd4_compoundres *resp,
35663531
struct nfsd4_sequence *seq)
35673532
{
3533+
struct nfsd4_compoundargs *args = resp->rqstp->rq_argp;
35683534
struct nfsd4_slot *slot = resp->cstate.slot;
35693535
struct xdr_stream *xdr = resp->xdr;
35703536
__be32 *p;
3571-
__be32 status;
35723537

35733538
dprintk("--> %s slot %p\n", __func__, slot);
35743539

3575-
status = nfsd4_enc_sequence_replay(resp->rqstp->rq_argp, resp);
3576-
if (status)
3577-
return status;
3540+
/* Always encode the SEQUENCE response. */
3541+
nfsd4_encode_operation(resp, &args->ops[0]);
3542+
if (args->opcnt == 1)
3543+
/* A solo SEQUENCE - nothing was cached */
3544+
return args->ops[0].status;
3545+
3546+
if (!(slot->sl_flags & NFSD4_SLOT_CACHED)) {
3547+
/* We weren't asked to cache this. */
3548+
struct nfsd4_op *op;
3549+
3550+
op = &args->ops[resp->opcnt++];
3551+
op->status = nfserr_retry_uncached_rep;
3552+
nfsd4_encode_operation(resp, op);
3553+
return op->status;
3554+
}
35783555

3556+
/* return reply from cache */
35793557
p = xdr_reserve_space(xdr, slot->sl_datalen);
35803558
if (!p) {
35813559
WARN_ON_ONCE(1);

fs/nfsd/xdr4.h

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -924,27 +924,6 @@ struct nfsd4_compoundres {
924924
struct nfsd4_compound_state cstate;
925925
};
926926

927-
static inline bool nfsd4_is_solo_sequence(struct nfsd4_compoundres *resp)
928-
{
929-
struct nfsd4_compoundargs *args = resp->rqstp->rq_argp;
930-
return resp->opcnt == 1 && args->ops[0].opnum == OP_SEQUENCE;
931-
}
932-
933-
/*
934-
* The session reply cache only needs to cache replies that the client
935-
* actually asked us to. But it's almost free for us to cache compounds
936-
* consisting of only a SEQUENCE op, so we may as well cache those too.
937-
* Also, the protocol doesn't give us a convenient response in the case
938-
* of a replay of a solo SEQUENCE op that wasn't cached
939-
* (RETRY_UNCACHED_REP can only be returned in the second op of a
940-
* compound).
941-
*/
942-
static inline bool nfsd4_cache_this(struct nfsd4_compoundres *resp)
943-
{
944-
return (resp->cstate.slot->sl_flags & NFSD4_SLOT_CACHETHIS)
945-
|| nfsd4_is_solo_sequence(resp);
946-
}
947-
948927
static inline bool nfsd4_last_compound_op(struct svc_rqst *rqstp)
949928
{
950929
struct nfsd4_compoundres *resp = rqstp->rq_resp;

0 commit comments

Comments
 (0)