Skip to content

Commit 9b350d3

Browse files
committed
NFSD: Clean up nfsd4_encode_replay()
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 <[email protected]>
1 parent bad4c58 commit 9b350d3

File tree

2 files changed

+31
-16
lines changed

2 files changed

+31
-16
lines changed

fs/nfsd/nfs4xdr.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5732,27 +5732,24 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)
57325732
rqstp->rq_next_page = xdr->page_ptr + 1;
57335733
}
57345734

5735-
/*
5736-
* Encode the reply stored in the stateowner reply cache
5737-
*
5738-
* XDR note: do not encode rp->rp_buflen: the buffer contains the
5739-
* previously sent already encoded operation.
5735+
/**
5736+
* nfsd4_encode_replay - encode a result stored in the stateowner reply cache
5737+
* @xdr: send buffer's XDR stream
5738+
* @op: operation being replayed
5739+
*
5740+
* @op->replay->rp_buf contains the previously-sent already-encoded result.
57405741
*/
5741-
void
5742-
nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)
5742+
void nfsd4_encode_replay(struct xdr_stream *xdr, struct nfsd4_op *op)
57435743
{
5744-
__be32 *p;
57455744
struct nfs4_replay *rp = op->replay;
57465745

5747-
p = xdr_reserve_space(xdr, 8 + rp->rp_buflen);
5748-
if (!p) {
5749-
WARN_ON_ONCE(1);
5750-
return;
5751-
}
5752-
*p++ = cpu_to_be32(op->opnum);
5753-
*p++ = rp->rp_status; /* already xdr'ed */
5746+
trace_nfsd_stateowner_replay(op->opnum, rp);
57545747

5755-
p = xdr_encode_opaque_fixed(p, rp->rp_buf, rp->rp_buflen);
5748+
if (xdr_stream_encode_u32(xdr, op->opnum) != XDR_UNIT)
5749+
return;
5750+
if (xdr_stream_encode_be32(xdr, rp->rp_status) != XDR_UNIT)
5751+
return;
5752+
xdr_stream_encode_opaque_fixed(xdr, rp->rp_buf, rp->rp_buflen);
57565753
}
57575754

57585755
void nfsd4_release_compoundargs(struct svc_rqst *rqstp)

fs/nfsd/trace.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -696,6 +696,24 @@ DEFINE_EVENT(nfsd_stid_class, nfsd_stid_##name, \
696696

697697
DEFINE_STID_EVENT(revoke);
698698

699+
TRACE_EVENT(nfsd_stateowner_replay,
700+
TP_PROTO(
701+
u32 opnum,
702+
const struct nfs4_replay *rp
703+
),
704+
TP_ARGS(opnum, rp),
705+
TP_STRUCT__entry(
706+
__field(unsigned long, status)
707+
__field(u32, opnum)
708+
),
709+
TP_fast_assign(
710+
__entry->status = be32_to_cpu(rp->rp_status);
711+
__entry->opnum = opnum;
712+
),
713+
TP_printk("opnum=%u status=%lu",
714+
__entry->opnum, __entry->status)
715+
);
716+
699717
TRACE_EVENT_CONDITION(nfsd_seq4_status,
700718
TP_PROTO(
701719
const struct svc_rqst *rqstp,

0 commit comments

Comments
 (0)