Skip to content

Commit 249d45c

Browse files
Mike Snitzergregkh
authored andcommitted
nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
[ Upstream commit 4806ded ] Common nfs_stat_to_errno() is used by both fs/nfs/nfs2xdr.c and fs/nfs/nfs3xdr.c Will also be used by fs/nfsd/localio.c Signed-off-by: Mike Snitzer <snitzer@kernel.org> Reviewed-by: Jeff Layton <jlayton@kernel.org> Reviewed-by: NeilBrown <neilb@suse.de> Signed-off-by: Anna Schumaker <anna.schumaker@oracle.com> Stable-dep-of: c6c209ceb87f ("NFSD: Remove NFSERR_EAGAIN") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 93a2e7e commit 249d45c

8 files changed

Lines changed: 109 additions & 160 deletions

File tree

fs/nfs/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config NFS_FS
55
select CRC32
66
select LOCKD
77
select SUNRPC
8+
select NFS_COMMON
89
select NFS_ACL_SUPPORT if NFS_V3_ACL
910
help
1011
Choose Y here if you want to access files residing on other

fs/nfs/nfs2xdr.c

Lines changed: 1 addition & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@
2222
#include <linux/nfs.h>
2323
#include <linux/nfs2.h>
2424
#include <linux/nfs_fs.h>
25+
#include <linux/nfs_common.h>
2526
#include "nfstrace.h"
2627
#include "internal.h"
2728

2829
#define NFSDBG_FACILITY NFSDBG_XDR
2930

30-
/* Mapping from NFS error code to "errno" error code. */
31-
#define errno_NFSERR_IO EIO
32-
3331
/*
3432
* Declare the space requirements for NFS arguments and replies as
3533
* number of 32bit-words
@@ -64,8 +62,6 @@
6462
#define NFS_readdirres_sz (1+NFS_pagepad_sz)
6563
#define NFS_statfsres_sz (1+NFS_info_sz)
6664

67-
static int nfs_stat_to_errno(enum nfs_stat);
68-
6965
/*
7066
* Encode/decode NFSv2 basic data types
7167
*
@@ -1054,70 +1050,6 @@ static int nfs2_xdr_dec_statfsres(struct rpc_rqst *req, struct xdr_stream *xdr,
10541050
return nfs_stat_to_errno(status);
10551051
}
10561052

1057-
1058-
/*
1059-
* We need to translate between nfs status return values and
1060-
* the local errno values which may not be the same.
1061-
*/
1062-
static const struct {
1063-
int stat;
1064-
int errno;
1065-
} nfs_errtbl[] = {
1066-
{ NFS_OK, 0 },
1067-
{ NFSERR_PERM, -EPERM },
1068-
{ NFSERR_NOENT, -ENOENT },
1069-
{ NFSERR_IO, -errno_NFSERR_IO},
1070-
{ NFSERR_NXIO, -ENXIO },
1071-
/* { NFSERR_EAGAIN, -EAGAIN }, */
1072-
{ NFSERR_ACCES, -EACCES },
1073-
{ NFSERR_EXIST, -EEXIST },
1074-
{ NFSERR_XDEV, -EXDEV },
1075-
{ NFSERR_NODEV, -ENODEV },
1076-
{ NFSERR_NOTDIR, -ENOTDIR },
1077-
{ NFSERR_ISDIR, -EISDIR },
1078-
{ NFSERR_INVAL, -EINVAL },
1079-
{ NFSERR_FBIG, -EFBIG },
1080-
{ NFSERR_NOSPC, -ENOSPC },
1081-
{ NFSERR_ROFS, -EROFS },
1082-
{ NFSERR_MLINK, -EMLINK },
1083-
{ NFSERR_NAMETOOLONG, -ENAMETOOLONG },
1084-
{ NFSERR_NOTEMPTY, -ENOTEMPTY },
1085-
{ NFSERR_DQUOT, -EDQUOT },
1086-
{ NFSERR_STALE, -ESTALE },
1087-
{ NFSERR_REMOTE, -EREMOTE },
1088-
#ifdef EWFLUSH
1089-
{ NFSERR_WFLUSH, -EWFLUSH },
1090-
#endif
1091-
{ NFSERR_BADHANDLE, -EBADHANDLE },
1092-
{ NFSERR_NOT_SYNC, -ENOTSYNC },
1093-
{ NFSERR_BAD_COOKIE, -EBADCOOKIE },
1094-
{ NFSERR_NOTSUPP, -ENOTSUPP },
1095-
{ NFSERR_TOOSMALL, -ETOOSMALL },
1096-
{ NFSERR_SERVERFAULT, -EREMOTEIO },
1097-
{ NFSERR_BADTYPE, -EBADTYPE },
1098-
{ NFSERR_JUKEBOX, -EJUKEBOX },
1099-
{ -1, -EIO }
1100-
};
1101-
1102-
/**
1103-
* nfs_stat_to_errno - convert an NFS status code to a local errno
1104-
* @status: NFS status code to convert
1105-
*
1106-
* Returns a local errno value, or -EIO if the NFS status code is
1107-
* not recognized. This function is used jointly by NFSv2 and NFSv3.
1108-
*/
1109-
static int nfs_stat_to_errno(enum nfs_stat status)
1110-
{
1111-
int i;
1112-
1113-
for (i = 0; nfs_errtbl[i].stat != -1; i++) {
1114-
if (nfs_errtbl[i].stat == (int)status)
1115-
return nfs_errtbl[i].errno;
1116-
}
1117-
dprintk("NFS: Unrecognized nfs status value: %u\n", status);
1118-
return nfs_errtbl[i].errno;
1119-
}
1120-
11211053
#define PROC(proc, argtype, restype, timer) \
11221054
[NFSPROC_##proc] = { \
11231055
.p_proc = NFSPROC_##proc, \

fs/nfs/nfs3xdr.c

Lines changed: 20 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@
2121
#include <linux/nfs3.h>
2222
#include <linux/nfs_fs.h>
2323
#include <linux/nfsacl.h>
24+
#include <linux/nfs_common.h>
25+
2426
#include "nfstrace.h"
2527
#include "internal.h"
2628

2729
#define NFSDBG_FACILITY NFSDBG_XDR
2830

29-
/* Mapping from NFS error code to "errno" error code. */
30-
#define errno_NFSERR_IO EIO
31-
3231
/*
3332
* Declare the space requirements for NFS arguments and replies as
3433
* number of 32bit-words
@@ -91,8 +90,6 @@
9190
NFS3_pagepad_sz)
9291
#define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
9392

94-
static int nfs3_stat_to_errno(enum nfs_stat);
95-
9693
/*
9794
* Map file type to S_IFMT bits
9895
*/
@@ -1406,7 +1403,7 @@ static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
14061403
out:
14071404
return error;
14081405
out_default:
1409-
return nfs3_stat_to_errno(status);
1406+
return nfs_stat_to_errno(status);
14101407
}
14111408

14121409
/*
@@ -1445,7 +1442,7 @@ static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
14451442
out:
14461443
return error;
14471444
out_status:
1448-
return nfs3_stat_to_errno(status);
1445+
return nfs_stat_to_errno(status);
14491446
}
14501447

14511448
/*
@@ -1495,7 +1492,7 @@ static int nfs3_xdr_dec_lookup3res(struct rpc_rqst *req,
14951492
error = decode_post_op_attr(xdr, result->dir_attr, userns);
14961493
if (unlikely(error))
14971494
goto out;
1498-
return nfs3_stat_to_errno(status);
1495+
return nfs_stat_to_errno(status);
14991496
}
15001497

15011498
/*
@@ -1537,7 +1534,7 @@ static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
15371534
out:
15381535
return error;
15391536
out_default:
1540-
return nfs3_stat_to_errno(status);
1537+
return nfs_stat_to_errno(status);
15411538
}
15421539

15431540
/*
@@ -1578,7 +1575,7 @@ static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
15781575
out:
15791576
return error;
15801577
out_default:
1581-
return nfs3_stat_to_errno(status);
1578+
return nfs_stat_to_errno(status);
15821579
}
15831580

15841581
/*
@@ -1658,7 +1655,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
16581655
out:
16591656
return error;
16601657
out_status:
1661-
return nfs3_stat_to_errno(status);
1658+
return nfs_stat_to_errno(status);
16621659
}
16631660

16641661
/*
@@ -1728,7 +1725,7 @@ static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
17281725
out:
17291726
return error;
17301727
out_status:
1731-
return nfs3_stat_to_errno(status);
1728+
return nfs_stat_to_errno(status);
17321729
}
17331730

17341731
/*
@@ -1795,7 +1792,7 @@ static int nfs3_xdr_dec_create3res(struct rpc_rqst *req,
17951792
error = decode_wcc_data(xdr, result->dir_attr, userns);
17961793
if (unlikely(error))
17971794
goto out;
1798-
return nfs3_stat_to_errno(status);
1795+
return nfs_stat_to_errno(status);
17991796
}
18001797

18011798
/*
@@ -1835,7 +1832,7 @@ static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
18351832
out:
18361833
return error;
18371834
out_status:
1838-
return nfs3_stat_to_errno(status);
1835+
return nfs_stat_to_errno(status);
18391836
}
18401837

18411838
/*
@@ -1881,7 +1878,7 @@ static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
18811878
out:
18821879
return error;
18831880
out_status:
1884-
return nfs3_stat_to_errno(status);
1881+
return nfs_stat_to_errno(status);
18851882
}
18861883

18871884
/*
@@ -1926,7 +1923,7 @@ static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
19261923
out:
19271924
return error;
19281925
out_status:
1929-
return nfs3_stat_to_errno(status);
1926+
return nfs_stat_to_errno(status);
19301927
}
19311928

19321929
/**
@@ -2101,7 +2098,7 @@ static int nfs3_xdr_dec_readdir3res(struct rpc_rqst *req,
21012098
error = decode_post_op_attr(xdr, result->dir_attr, rpc_rqst_userns(req));
21022099
if (unlikely(error))
21032100
goto out;
2104-
return nfs3_stat_to_errno(status);
2101+
return nfs_stat_to_errno(status);
21052102
}
21062103

21072104
/*
@@ -2167,7 +2164,7 @@ static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
21672164
out:
21682165
return error;
21692166
out_status:
2170-
return nfs3_stat_to_errno(status);
2167+
return nfs_stat_to_errno(status);
21712168
}
21722169

21732170
/*
@@ -2243,7 +2240,7 @@ static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
22432240
out:
22442241
return error;
22452242
out_status:
2246-
return nfs3_stat_to_errno(status);
2243+
return nfs_stat_to_errno(status);
22472244
}
22482245

22492246
/*
@@ -2304,7 +2301,7 @@ static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
23042301
out:
23052302
return error;
23062303
out_status:
2307-
return nfs3_stat_to_errno(status);
2304+
return nfs_stat_to_errno(status);
23082305
}
23092306

23102307
/*
@@ -2350,7 +2347,7 @@ static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
23502347
out:
23512348
return error;
23522349
out_status:
2353-
return nfs3_stat_to_errno(status);
2350+
return nfs_stat_to_errno(status);
23542351
}
23552352

23562353
#ifdef CONFIG_NFS_V3_ACL
@@ -2416,7 +2413,7 @@ static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
24162413
out:
24172414
return error;
24182415
out_default:
2419-
return nfs3_stat_to_errno(status);
2416+
return nfs_stat_to_errno(status);
24202417
}
24212418

24222419
static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
@@ -2435,76 +2432,11 @@ static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
24352432
out:
24362433
return error;
24372434
out_default:
2438-
return nfs3_stat_to_errno(status);
2435+
return nfs_stat_to_errno(status);
24392436
}
24402437

24412438
#endif /* CONFIG_NFS_V3_ACL */
24422439

2443-
2444-
/*
2445-
* We need to translate between nfs status return values and
2446-
* the local errno values which may not be the same.
2447-
*/
2448-
static const struct {
2449-
int stat;
2450-
int errno;
2451-
} nfs_errtbl[] = {
2452-
{ NFS_OK, 0 },
2453-
{ NFSERR_PERM, -EPERM },
2454-
{ NFSERR_NOENT, -ENOENT },
2455-
{ NFSERR_IO, -errno_NFSERR_IO},
2456-
{ NFSERR_NXIO, -ENXIO },
2457-
/* { NFSERR_EAGAIN, -EAGAIN }, */
2458-
{ NFSERR_ACCES, -EACCES },
2459-
{ NFSERR_EXIST, -EEXIST },
2460-
{ NFSERR_XDEV, -EXDEV },
2461-
{ NFSERR_NODEV, -ENODEV },
2462-
{ NFSERR_NOTDIR, -ENOTDIR },
2463-
{ NFSERR_ISDIR, -EISDIR },
2464-
{ NFSERR_INVAL, -EINVAL },
2465-
{ NFSERR_FBIG, -EFBIG },
2466-
{ NFSERR_NOSPC, -ENOSPC },
2467-
{ NFSERR_ROFS, -EROFS },
2468-
{ NFSERR_MLINK, -EMLINK },
2469-
{ NFSERR_NAMETOOLONG, -ENAMETOOLONG },
2470-
{ NFSERR_NOTEMPTY, -ENOTEMPTY },
2471-
{ NFSERR_DQUOT, -EDQUOT },
2472-
{ NFSERR_STALE, -ESTALE },
2473-
{ NFSERR_REMOTE, -EREMOTE },
2474-
#ifdef EWFLUSH
2475-
{ NFSERR_WFLUSH, -EWFLUSH },
2476-
#endif
2477-
{ NFSERR_BADHANDLE, -EBADHANDLE },
2478-
{ NFSERR_NOT_SYNC, -ENOTSYNC },
2479-
{ NFSERR_BAD_COOKIE, -EBADCOOKIE },
2480-
{ NFSERR_NOTSUPP, -ENOTSUPP },
2481-
{ NFSERR_TOOSMALL, -ETOOSMALL },
2482-
{ NFSERR_SERVERFAULT, -EREMOTEIO },
2483-
{ NFSERR_BADTYPE, -EBADTYPE },
2484-
{ NFSERR_JUKEBOX, -EJUKEBOX },
2485-
{ -1, -EIO }
2486-
};
2487-
2488-
/**
2489-
* nfs3_stat_to_errno - convert an NFS status code to a local errno
2490-
* @status: NFS status code to convert
2491-
*
2492-
* Returns a local errno value, or -EIO if the NFS status code is
2493-
* not recognized. This function is used jointly by NFSv2 and NFSv3.
2494-
*/
2495-
static int nfs3_stat_to_errno(enum nfs_stat status)
2496-
{
2497-
int i;
2498-
2499-
for (i = 0; nfs_errtbl[i].stat != -1; i++) {
2500-
if (nfs_errtbl[i].stat == (int)status)
2501-
return nfs_errtbl[i].errno;
2502-
}
2503-
dprintk("NFS: Unrecognized nfs status value: %u\n", status);
2504-
return nfs_errtbl[i].errno;
2505-
}
2506-
2507-
25082440
#define PROC(proc, argtype, restype, timer) \
25092441
[NFS3PROC_##proc] = { \
25102442
.p_proc = NFS3PROC_##proc, \

fs/nfs/nfs4xdr.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <linux/nfs.h>
5353
#include <linux/nfs4.h>
5454
#include <linux/nfs_fs.h>
55+
#include <linux/nfs_common.h>
5556

5657
#include "nfs4_fs.h"
5758
#include "nfs4trace.h"
@@ -63,9 +64,6 @@
6364

6465
#define NFSDBG_FACILITY NFSDBG_XDR
6566

66-
/* Mapping from NFS error code to "errno" error code. */
67-
#define errno_NFSERR_IO EIO
68-
6967
struct compound_hdr;
7068
static int nfs4_stat_to_errno(int);
7169
static void encode_layoutget(struct xdr_stream *xdr,

fs/nfs_common/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ nfs_acl-objs := nfsacl.o
88

99
obj-$(CONFIG_GRACE_PERIOD) += grace.o
1010
obj-$(CONFIG_NFS_V4_2_SSC_HELPER) += nfs_ssc.o
11+
12+
obj-$(CONFIG_NFS_COMMON) += common.o

0 commit comments

Comments
 (0)