Skip to content

Commit f23f658

Browse files
chuckleveramschuma-ntap
authored andcommitted
NFS: Add trace events to report non-zero NFS status codes
These can help field troubleshooting without needing the overhead of a full network capture (ie, tcpdump). Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Anna Schumaker <Anna.Schumaker@Netapp.com>
1 parent eb72f48 commit f23f658

File tree

6 files changed

+133
-4
lines changed

6 files changed

+133
-4
lines changed

fs/nfs/nfs2xdr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <linux/nfs.h>
2323
#include <linux/nfs2.h>
2424
#include <linux/nfs_fs.h>
25+
#include "nfstrace.h"
2526
#include "internal.h"
2627

2728
#define NFSDBG_FACILITY NFSDBG_XDR
@@ -145,7 +146,13 @@ static int decode_stat(struct xdr_stream *xdr, enum nfs_stat *status)
145146
p = xdr_inline_decode(xdr, 4);
146147
if (unlikely(!p))
147148
return -EIO;
149+
if (unlikely(*p != cpu_to_be32(NFS_OK)))
150+
goto out_status;
151+
*status = 0;
152+
return 0;
153+
out_status:
148154
*status = be32_to_cpup(p);
155+
trace_nfs_xdr_status((int)*status);
149156
return 0;
150157
}
151158

fs/nfs/nfs3xdr.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <linux/nfs3.h>
2222
#include <linux/nfs_fs.h>
2323
#include <linux/nfsacl.h>
24+
#include "nfstrace.h"
2425
#include "internal.h"
2526

2627
#define NFSDBG_FACILITY NFSDBG_XDR
@@ -337,7 +338,13 @@ static int decode_nfsstat3(struct xdr_stream *xdr, enum nfs_stat *status)
337338
p = xdr_inline_decode(xdr, 4);
338339
if (unlikely(!p))
339340
return -EIO;
341+
if (unlikely(*p != cpu_to_be32(NFS3_OK)))
342+
goto out_status;
343+
*status = 0;
344+
return 0;
345+
out_status:
340346
*status = be32_to_cpup(p);
347+
trace_nfs_xdr_status((int)*status);
341348
return 0;
342349
}
343350

fs/nfs/nfs4trace.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,31 @@ TRACE_EVENT(nfs4_setup_sequence,
524524
)
525525
);
526526

527+
TRACE_EVENT(nfs4_xdr_status,
528+
TP_PROTO(
529+
u32 op,
530+
int error
531+
),
532+
533+
TP_ARGS(op, error),
534+
535+
TP_STRUCT__entry(
536+
__field(u32, op)
537+
__field(int, error)
538+
),
539+
540+
TP_fast_assign(
541+
__entry->op = op;
542+
__entry->error = -error;
543+
),
544+
545+
TP_printk(
546+
"operation %d: nfs status %d (%s)",
547+
__entry->op,
548+
__entry->error, show_nfsv4_errors(__entry->error)
549+
)
550+
);
551+
527552
DECLARE_EVENT_CLASS(nfs4_open_event,
528553
TP_PROTO(
529554
const struct nfs_open_context *ctx,

fs/nfs/nfs4xdr.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <linux/nfs_fs.h>
5555

5656
#include "nfs4_fs.h"
57+
#include "nfs4trace.h"
5758
#include "internal.h"
5859
#include "nfs4idmap.h"
5960
#include "nfs4session.h"
@@ -3188,11 +3189,14 @@ static bool __decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected,
31883189
opnum = be32_to_cpup(p++);
31893190
if (unlikely(opnum != expected))
31903191
goto out_bad_operation;
3192+
if (unlikely(*p != cpu_to_be32(NFS_OK)))
3193+
goto out_status;
3194+
*nfs_retval = 0;
3195+
return true;
3196+
out_status:
31913197
nfserr = be32_to_cpup(p);
3192-
if (nfserr == NFS_OK)
3193-
*nfs_retval = 0;
3194-
else
3195-
*nfs_retval = nfs4_stat_to_errno(nfserr);
3198+
trace_nfs4_xdr_status(opnum, nfserr);
3199+
*nfs_retval = nfs4_stat_to_errno(nfserr);
31963200
return true;
31973201
out_bad_operation:
31983202
dprintk("nfs: Server returned operation"

fs/nfs/nfstrace.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111

1212
EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_fsync_enter);
1313
EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_fsync_exit);
14+
EXPORT_TRACEPOINT_SYMBOL_GPL(nfs_xdr_status);

fs/nfs/nfstrace.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,91 @@ TRACE_EVENT(nfs_commit_done,
969969
)
970970
);
971971

972+
TRACE_DEFINE_ENUM(NFS_OK);
973+
TRACE_DEFINE_ENUM(NFSERR_PERM);
974+
TRACE_DEFINE_ENUM(NFSERR_NOENT);
975+
TRACE_DEFINE_ENUM(NFSERR_IO);
976+
TRACE_DEFINE_ENUM(NFSERR_NXIO);
977+
TRACE_DEFINE_ENUM(NFSERR_ACCES);
978+
TRACE_DEFINE_ENUM(NFSERR_EXIST);
979+
TRACE_DEFINE_ENUM(NFSERR_XDEV);
980+
TRACE_DEFINE_ENUM(NFSERR_NODEV);
981+
TRACE_DEFINE_ENUM(NFSERR_NOTDIR);
982+
TRACE_DEFINE_ENUM(NFSERR_ISDIR);
983+
TRACE_DEFINE_ENUM(NFSERR_INVAL);
984+
TRACE_DEFINE_ENUM(NFSERR_FBIG);
985+
TRACE_DEFINE_ENUM(NFSERR_NOSPC);
986+
TRACE_DEFINE_ENUM(NFSERR_ROFS);
987+
TRACE_DEFINE_ENUM(NFSERR_MLINK);
988+
TRACE_DEFINE_ENUM(NFSERR_NAMETOOLONG);
989+
TRACE_DEFINE_ENUM(NFSERR_NOTEMPTY);
990+
TRACE_DEFINE_ENUM(NFSERR_DQUOT);
991+
TRACE_DEFINE_ENUM(NFSERR_STALE);
992+
TRACE_DEFINE_ENUM(NFSERR_REMOTE);
993+
TRACE_DEFINE_ENUM(NFSERR_WFLUSH);
994+
TRACE_DEFINE_ENUM(NFSERR_BADHANDLE);
995+
TRACE_DEFINE_ENUM(NFSERR_NOT_SYNC);
996+
TRACE_DEFINE_ENUM(NFSERR_BAD_COOKIE);
997+
TRACE_DEFINE_ENUM(NFSERR_NOTSUPP);
998+
TRACE_DEFINE_ENUM(NFSERR_TOOSMALL);
999+
TRACE_DEFINE_ENUM(NFSERR_SERVERFAULT);
1000+
TRACE_DEFINE_ENUM(NFSERR_BADTYPE);
1001+
TRACE_DEFINE_ENUM(NFSERR_JUKEBOX);
1002+
1003+
#define nfs_show_status(x) \
1004+
__print_symbolic(x, \
1005+
{ NFS_OK, "OK" }, \
1006+
{ NFSERR_PERM, "PERM" }, \
1007+
{ NFSERR_NOENT, "NOENT" }, \
1008+
{ NFSERR_IO, "IO" }, \
1009+
{ NFSERR_NXIO, "NXIO" }, \
1010+
{ NFSERR_ACCES, "ACCES" }, \
1011+
{ NFSERR_EXIST, "EXIST" }, \
1012+
{ NFSERR_XDEV, "XDEV" }, \
1013+
{ NFSERR_NODEV, "NODEV" }, \
1014+
{ NFSERR_NOTDIR, "NOTDIR" }, \
1015+
{ NFSERR_ISDIR, "ISDIR" }, \
1016+
{ NFSERR_INVAL, "INVAL" }, \
1017+
{ NFSERR_FBIG, "FBIG" }, \
1018+
{ NFSERR_NOSPC, "NOSPC" }, \
1019+
{ NFSERR_ROFS, "ROFS" }, \
1020+
{ NFSERR_MLINK, "MLINK" }, \
1021+
{ NFSERR_NAMETOOLONG, "NAMETOOLONG" }, \
1022+
{ NFSERR_NOTEMPTY, "NOTEMPTY" }, \
1023+
{ NFSERR_DQUOT, "DQUOT" }, \
1024+
{ NFSERR_STALE, "STALE" }, \
1025+
{ NFSERR_REMOTE, "REMOTE" }, \
1026+
{ NFSERR_WFLUSH, "WFLUSH" }, \
1027+
{ NFSERR_BADHANDLE, "BADHANDLE" }, \
1028+
{ NFSERR_NOT_SYNC, "NOTSYNC" }, \
1029+
{ NFSERR_BAD_COOKIE, "BADCOOKIE" }, \
1030+
{ NFSERR_NOTSUPP, "NOTSUPP" }, \
1031+
{ NFSERR_TOOSMALL, "TOOSMALL" }, \
1032+
{ NFSERR_SERVERFAULT, "REMOTEIO" }, \
1033+
{ NFSERR_BADTYPE, "BADTYPE" }, \
1034+
{ NFSERR_JUKEBOX, "JUKEBOX" })
1035+
1036+
TRACE_EVENT(nfs_xdr_status,
1037+
TP_PROTO(
1038+
int error
1039+
),
1040+
1041+
TP_ARGS(error),
1042+
1043+
TP_STRUCT__entry(
1044+
__field(int, error)
1045+
),
1046+
1047+
TP_fast_assign(
1048+
__entry->error = error;
1049+
),
1050+
1051+
TP_printk(
1052+
"error=%d (%s)",
1053+
__entry->error, nfs_show_status(__entry->error)
1054+
)
1055+
);
1056+
9721057
#endif /* _TRACE_NFS_H */
9731058

9741059
#undef TRACE_INCLUDE_PATH

0 commit comments

Comments
 (0)