Skip to content

Commit

Permalink
NFSD: Clean up nfsd4_encode_replay()
Browse files Browse the repository at this point in the history
Replace open-coded encoding logic with the use of conventional XDR
utility functions. Add a tracepoint to make replays observable in
field troubleshooting situations.

The WARN_ON is removed. A stack trace is of little use, as there is
only one call site for nfsd4_encode_replay(), and a buffer length
shortage here is unlikely.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
  • Loading branch information
Chuck Lever committed Mar 9, 2024
1 parent bad4c58 commit 9b350d3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 16 deletions.
29 changes: 13 additions & 16 deletions fs/nfsd/nfs4xdr.c
Original file line number Diff line number Diff line change
Expand Up @@ -5732,27 +5732,24 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
rqstp->rq_next_page = xdr->page_ptr + 1;
}

/*
* Encode the reply stored in the stateowner reply cache
*
* XDR note: do not encode rp->rp_buflen: the buffer contains the
* previously sent already encoded operation.
/**
* nfsd4_encode_replay - encode a result stored in the stateowner reply cache
* @xdr: send buffer's XDR stream
* @op: operation being replayed
*
* @op->replay->rp_buf contains the previously-sent already-encoded result.
*/
void
nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)
void nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)
{
__be32 *p;
struct nfs4_replay *rp = op->replay;

p = xdr_reserve_space(xdr, 8 + rp->rp_buflen);
if (!p) {
WARN_ON_ONCE(1);
return;
}
*p++ = cpu_to_be32(op->opnum);
*p++ = rp->rp_status; /* already xdr'ed */
trace_nfsd_stateowner_replay(op->opnum, rp);

p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen);
if (xdr_stream_encode_u32(xdr, op->opnum) != XDR_UNIT)
return;
if (xdr_stream_encode_be32(xdr, rp->rp_status) != XDR_UNIT)
return;
xdr_stream_encode_opaque_fixed(xdr, rp->rp_buf, rp->rp_buflen);
}

void nfsd4_release_compoundargs(struct svc_rqst *rqstp)
Expand Down
18 changes: 18 additions & 0 deletions fs/nfsd/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,24 @@ DEFINE_EVENT(nfsd_stid_class, nfsd_stid_##name, \

DEFINE_STID_EVENT(revoke);

TRACE_EVENT(nfsd_stateowner_replay,
TP_PROTO(
u32 opnum,
const struct nfs4_replay *rp
),
TP_ARGS(opnum, rp),
TP_STRUCT__entry(
__field(unsigned long, status)
__field(u32, opnum)
),
TP_fast_assign(
__entry->status = be32_to_cpu(rp->rp_status);
__entry->opnum = opnum;
),
TP_printk("opnum=%u status=%lu",
__entry->opnum, __entry->status)
);

TRACE_EVENT_CONDITION(nfsd_seq4_status,
TP_PROTO(
const struct svc_rqst *rqstp,
Expand Down

0 comments on commit 9b350d3

Please sign in to comment.