From 49b0c71acd11b26b2f75fd8639c99aebd8cc9ec0 Mon Sep 17 00:00:00 2001 From: "Md. Amdadul Bari Imad" Date: Tue, 1 Dec 2026 09:21:32 +0000 Subject: [PATCH] mountstats: fix the column order of NFS over RDMA transport stats parseNFSTransportStats assigned the RDMA xprt columns in the field order of the kernel's struct rpcrdma_stats, but the kernel prints them in a different order in xprt_rdma_print_stats() (net/sunrpc/xprtrdma/transport.c): read_chunk write_chunk reply_chunk total_rdma_request total_rdma_reply pullup_copy fixup_copy hardway_register failed_marshal bad_reply nomsg_call mrs_recycled mrs_orphaned mrs_allocated local_inv_needed empty_sendctx_q reply_waits_for_send This order has been stable since the RDMA stats were added; later kernels only append columns. Only the first four RDMA columns were read correctly. Every column after total_rdma_request landed in the wrong field, e.g. the total_rdma_reply byte count was reported as PullupCopyCount, and TotalRdmaReply received the mrs_allocated count. Read the columns in the order the kernel prints them. bcall_count is not printed by the kernel, so BcallCount stays zero. Add a test with a distinct value in every column, and correct the expected values of the existing RDMA test case, which encoded the wrong mapping. Signed-off-by: Md. Amdadul Bari Imad --- mountstats.go | 31 ++++++++++++--------- mountstats_test.go | 67 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 75 insertions(+), 23 deletions(-) diff --git a/mountstats.go b/mountstats.go index e503cb3a..7df04650 100644 --- a/mountstats.go +++ b/mountstats.go @@ -688,23 +688,28 @@ func parseNFSTransportStats(ss []string, statVersion string) (*NFSTransportStats // NFS xprt over rdma // And stat Version 1.1 + // + // The order matches the columns printed by xprt_rdma_print_stats() + // in net/sunrpc/xprtrdma/transport.c, which differs from the field + // order of struct rpcrdma_stats. BcallCount is not printed by the + // kernel and is always zero. ReadChunkCount: ns[13], WriteChunkCount: ns[14], ReplyChunkCount: ns[15], TotalRdmaRequest: ns[16], - PullupCopyCount: ns[17], - HardwayRegisterCount: ns[18], - FailedMarshalCount: ns[19], - BadReplyCount: ns[20], - MrsRecovered: ns[21], - MrsOrphaned: ns[22], - MrsAllocated: ns[23], - EmptySendctxQ: ns[24], - TotalRdmaReply: ns[25], - FixupCopyCount: ns[26], - ReplyWaitsForSend: ns[27], - LocalInvNeeded: ns[28], - NomsgCallCount: ns[29], + TotalRdmaReply: ns[17], + PullupCopyCount: ns[18], + FixupCopyCount: ns[19], + HardwayRegisterCount: ns[20], + FailedMarshalCount: ns[21], + BadReplyCount: ns[22], + NomsgCallCount: ns[23], + MrsRecovered: ns[24], + MrsOrphaned: ns[25], + MrsAllocated: ns[26], + LocalInvNeeded: ns[27], + EmptySendctxQ: ns[28], + ReplyWaitsForSend: ns[29], BcallCount: ns[30], }, nil } diff --git a/mountstats_test.go b/mountstats_test.go index 00f49377..8e9939f4 100644 --- a/mountstats_test.go +++ b/mountstats_test.go @@ -462,19 +462,19 @@ func TestMountStats(t *testing.T) { WriteChunkCount: 1226637531, ReplyChunkCount: 2673889, TotalRdmaRequest: 135120843409861, - PullupCopyCount: 135119397156505, - HardwayRegisterCount: 266368832, - FailedMarshalCount: 75716996, + TotalRdmaReply: 135119397156505, + PullupCopyCount: 266368832, + FixupCopyCount: 75716996, + HardwayRegisterCount: 0, + FailedMarshalCount: 7853, BadReplyCount: 0, - MrsRecovered: 7853, + NomsgCallCount: 0, + MrsRecovered: 0, MrsOrphaned: 0, - MrsAllocated: 0, + MrsAllocated: 119328, + LocalInvNeeded: 1336431717, EmptySendctxQ: 0, - TotalRdmaReply: 0, - FixupCopyCount: 119328, - ReplyWaitsForSend: 1336431717, - LocalInvNeeded: 0, - NomsgCallCount: 96, + ReplyWaitsForSend: 96, BcallCount: 0, }, }, @@ -657,3 +657,50 @@ func TestMountStatsExtendedRDMAStats(t *testing.T) { t.Errorf("failed to parse mount stats with extended RDMA statistics: %v", err) } } + +func TestParseNFSTransportStatsRDMAFieldOrder(t *testing.T) { + // Each value is unique so that a field read from the wrong column is + // obvious. The column order follows xprt_rdma_print_stats() in + // net/sunrpc/xprtrdma/transport.c (Linux >= 4.19). + line := "rdma 0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27" + + got, err := parseNFSTransportStats(strings.Fields(line), statVersion11) + if err != nil { + t.Fatalf("failed to parse RDMA transport stats: %v", err) + } + + want := &NFSTransportStats{ + Protocol: "rdma", + Port: 0, + Bind: 2, + Connect: 3, + ConnectIdleTime: 4, + IdleTimeSeconds: 5, + Sends: 6, + Receives: 7, + BadTransactionIDs: 8, + CumulativeActiveRequests: 9, + CumulativeBacklog: 10, + ReadChunkCount: 11, + WriteChunkCount: 12, + ReplyChunkCount: 13, + TotalRdmaRequest: 14, + TotalRdmaReply: 15, + PullupCopyCount: 16, + FixupCopyCount: 17, + HardwayRegisterCount: 18, + FailedMarshalCount: 19, + BadReplyCount: 20, + NomsgCallCount: 21, + MrsRecovered: 22, + MrsOrphaned: 23, + MrsAllocated: 24, + LocalInvNeeded: 25, + EmptySendctxQ: 26, + ReplyWaitsForSend: 27, + } + + if diff := cmp.Diff(want, got); diff != "" { + t.Fatalf("unexpected RDMA transport stats (-want +got):\n%s", diff) + } +}