Skip to content

Commit 36ffa3d

Browse files
neilbrownchucklever
authored andcommitted
nfsd: be more systematic about selecting error codes for internal use.
Rather than using ad hoc values for internal errors (30000, 11000, ...) use 'enum' to sequentially allocate numbers starting from the first known available number - now visible as NFS4ERR_FIRST_FREE. The goal is values that are distinct from all be32 error codes. To get those we must first select integers that are not already used, then convert them with cpu_to_be32(). Signed-off-by: NeilBrown <[email protected]> Reviewed-by: Jeff Layton <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Chuck Lever <[email protected]>
1 parent 1459ad5 commit 36ffa3d

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

fs/nfsd/nfsd.h

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,17 +330,31 @@ void nfsd_lockd_shutdown(void);
330330
#define nfserr_xattr2big cpu_to_be32(NFS4ERR_XATTR2BIG)
331331
#define nfserr_noxattr cpu_to_be32(NFS4ERR_NOXATTR)
332332

333-
/* error codes for internal use */
333+
/*
334+
* Error codes for internal use. We use enum to choose numbers that are
335+
* not already assigned, then covert to be32 resulting in a number that
336+
* cannot conflict with any existing be32 nfserr value.
337+
*/
338+
enum {
339+
NFSERR_DROPIT = NFS4ERR_FIRST_FREE,
334340
/* if a request fails due to kmalloc failure, it gets dropped.
335341
* Client should resend eventually
336342
*/
337-
#define nfserr_dropit cpu_to_be32(30000)
343+
#define nfserr_dropit cpu_to_be32(NFSERR_DROPIT)
344+
338345
/* end-of-file indicator in readdir */
339-
#define nfserr_eof cpu_to_be32(30001)
346+
NFSERR_EOF,
347+
#define nfserr_eof cpu_to_be32(NFSERR_EOF)
348+
340349
/* replay detected */
341-
#define nfserr_replay_me cpu_to_be32(11001)
350+
NFSERR_REPLAY_ME,
351+
#define nfserr_replay_me cpu_to_be32(NFSERR_REPLAY_ME)
352+
342353
/* nfs41 replay detected */
343-
#define nfserr_replay_cache cpu_to_be32(11002)
354+
NFSERR_REPLAY_CACHE,
355+
#define nfserr_replay_cache cpu_to_be32(NFSERR_REPLAY_CACHE)
356+
357+
};
344358

345359
/* Check for dir entries '.' and '..' */
346360
#define isdotent(n, l) (l < 3 && n[0] == '.' && (l == 1 || n[1] == '.'))

include/linux/nfs4.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,18 @@ enum nfsstat4 {
281281
/* nfs42 */
282282
NFS4ERR_PARTNER_NOTSUPP = 10088,
283283
NFS4ERR_PARTNER_NO_AUTH = 10089,
284-
NFS4ERR_UNION_NOTSUPP = 10090,
285-
NFS4ERR_OFFLOAD_DENIED = 10091,
286-
NFS4ERR_WRONG_LFS = 10092,
287-
NFS4ERR_BADLABEL = 10093,
288-
NFS4ERR_OFFLOAD_NO_REQS = 10094,
284+
NFS4ERR_UNION_NOTSUPP = 10090,
285+
NFS4ERR_OFFLOAD_DENIED = 10091,
286+
NFS4ERR_WRONG_LFS = 10092,
287+
NFS4ERR_BADLABEL = 10093,
288+
NFS4ERR_OFFLOAD_NO_REQS = 10094,
289289

290290
/* xattr (RFC8276) */
291-
NFS4ERR_NOXATTR = 10095,
292-
NFS4ERR_XATTR2BIG = 10096,
291+
NFS4ERR_NOXATTR = 10095,
292+
NFS4ERR_XATTR2BIG = 10096,
293+
294+
/* can be used for internal errors */
295+
NFS4ERR_FIRST_FREE
293296
};
294297

295298
/* error codes for internal client use */

0 commit comments

Comments
 (0)