aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
diff options
context:
space:
mode:
authorBryan Schumaker <bjschuma@netapp.com>2012-05-10 16:47:18 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2012-05-14 20:42:21 -0400
commit5e7e5a0da28216fb9d0a49e93ee27668ef4f04f7 (patch)
tree866a46d16889cdf7a64eeabfab952707c1b45397 /fs/nfs
parent87c7083dc3eba802d6e9f312ec520a4814f59871 (diff)
NFS: Create an NFS v3 stat_to_errno()
In theory, NFS v3 can have different error versions than NFS v2. v4 is already using its own nfs4_stat_to_errno() to map error codes, so rather than create something in the generic client for v2 and v3 to share I instead give v3 its own function. Signed-off-by: Bryan Schumaker <bjschuma@netapp.com> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs')
-rw-r--r--fs/nfs/internal.h1
-rw-r--r--fs/nfs/nfs2xdr.c3
-rw-r--r--fs/nfs/nfs3xdr.c103
3 files changed, 87 insertions, 20 deletions
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 4e9b0ff30f66..bf64095f850d 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -208,7 +208,6 @@ extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
208void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos); 208void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
209 209
210/* nfs2xdr.c */ 210/* nfs2xdr.c */
211extern int nfs_stat_to_errno(enum nfs_stat);
212extern struct rpc_procinfo nfs_procedures[]; 211extern struct rpc_procinfo nfs_procedures[];
213extern int nfs2_decode_dirent(struct xdr_stream *, 212extern int nfs2_decode_dirent(struct xdr_stream *,
214 struct nfs_entry *, int); 213 struct nfs_entry *, int);
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index c99008e9d8a4..baf759bccd05 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -61,6 +61,7 @@
61#define NFS_readdirres_sz (1) 61#define NFS_readdirres_sz (1)
62#define NFS_statfsres_sz (1+NFS_info_sz) 62#define NFS_statfsres_sz (1+NFS_info_sz)
63 63
64static int nfs_stat_to_errno(enum nfs_stat);
64 65
65/* 66/*
66 * While encoding arguments, set up the reply buffer in advance to 67 * While encoding arguments, set up the reply buffer in advance to
@@ -1111,7 +1112,7 @@ static const struct {
1111 * Returns a local errno value, or -EIO if the NFS status code is 1112 * Returns a local errno value, or -EIO if the NFS status code is
1112 * not recognized. This function is used jointly by NFSv2 and NFSv3. 1113 * not recognized. This function is used jointly by NFSv2 and NFSv3.
1113 */ 1114 */
1114int nfs_stat_to_errno(enum nfs_stat status) 1115static int nfs_stat_to_errno(enum nfs_stat status)
1115{ 1116{
1116 int i; 1117 int i;
1117 1118
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index ee284c2b2757..902de489ec9b 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -86,6 +86,8 @@
86 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE)) 86 XDR_QUADLEN(NFS_ACL_INLINE_BUFSIZE))
87#define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz) 87#define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
88 88
89static int nfs3_stat_to_errno(enum nfs_stat);
90
89/* 91/*
90 * Map file type to S_IFMT bits 92 * Map file type to S_IFMT bits
91 */ 93 */
@@ -1388,7 +1390,7 @@ static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
1388out: 1390out:
1389 return error; 1391 return error;
1390out_default: 1392out_default:
1391 return nfs_stat_to_errno(status); 1393 return nfs3_stat_to_errno(status);
1392} 1394}
1393 1395
1394/* 1396/*
@@ -1427,7 +1429,7 @@ static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
1427out: 1429out:
1428 return error; 1430 return error;
1429out_status: 1431out_status:
1430 return nfs_stat_to_errno(status); 1432 return nfs3_stat_to_errno(status);
1431} 1433}
1432 1434
1433/* 1435/*
@@ -1475,7 +1477,7 @@ out_default:
1475 error = decode_post_op_attr(xdr, result->dir_attr); 1477 error = decode_post_op_attr(xdr, result->dir_attr);
1476 if (unlikely(error)) 1478 if (unlikely(error))
1477 goto out; 1479 goto out;
1478 return nfs_stat_to_errno(status); 1480 return nfs3_stat_to_errno(status);
1479} 1481}
1480 1482
1481/* 1483/*
@@ -1516,7 +1518,7 @@ static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
1516out: 1518out:
1517 return error; 1519 return error;
1518out_default: 1520out_default:
1519 return nfs_stat_to_errno(status); 1521 return nfs3_stat_to_errno(status);
1520} 1522}
1521 1523
1522/* 1524/*
@@ -1557,7 +1559,7 @@ static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
1557out: 1559out:
1558 return error; 1560 return error;
1559out_default: 1561out_default:
1560 return nfs_stat_to_errno(status); 1562 return nfs3_stat_to_errno(status);
1561} 1563}
1562 1564
1563/* 1565/*
@@ -1639,7 +1641,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1639out: 1641out:
1640 return error; 1642 return error;
1641out_status: 1643out_status:
1642 return nfs_stat_to_errno(status); 1644 return nfs3_stat_to_errno(status);
1643} 1645}
1644 1646
1645/* 1647/*
@@ -1709,7 +1711,7 @@ static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1709out: 1711out:
1710 return error; 1712 return error;
1711out_status: 1713out_status:
1712 return nfs_stat_to_errno(status); 1714 return nfs3_stat_to_errno(status);
1713} 1715}
1714 1716
1715/* 1717/*
@@ -1773,7 +1775,7 @@ out_default:
1773 error = decode_wcc_data(xdr, result->dir_attr); 1775 error = decode_wcc_data(xdr, result->dir_attr);
1774 if (unlikely(error)) 1776 if (unlikely(error))
1775 goto out; 1777 goto out;
1776 return nfs_stat_to_errno(status); 1778 return nfs3_stat_to_errno(status);
1777} 1779}
1778 1780
1779/* 1781/*
@@ -1812,7 +1814,7 @@ static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
1812out: 1814out:
1813 return error; 1815 return error;
1814out_status: 1816out_status:
1815 return nfs_stat_to_errno(status); 1817 return nfs3_stat_to_errno(status);
1816} 1818}
1817 1819
1818/* 1820/*
@@ -1856,7 +1858,7 @@ static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
1856out: 1858out:
1857 return error; 1859 return error;
1858out_status: 1860out_status:
1859 return nfs_stat_to_errno(status); 1861 return nfs3_stat_to_errno(status);
1860} 1862}
1861 1863
1862/* 1864/*
@@ -1899,7 +1901,7 @@ static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
1899out: 1901out:
1900 return error; 1902 return error;
1901out_status: 1903out_status:
1902 return nfs_stat_to_errno(status); 1904 return nfs3_stat_to_errno(status);
1903} 1905}
1904 1906
1905/** 1907/**
@@ -2091,7 +2093,7 @@ out_default:
2091 error = decode_post_op_attr(xdr, result->dir_attr); 2093 error = decode_post_op_attr(xdr, result->dir_attr);
2092 if (unlikely(error)) 2094 if (unlikely(error))
2093 goto out; 2095 goto out;
2094 return nfs_stat_to_errno(status); 2096 return nfs3_stat_to_errno(status);
2095} 2097}
2096 2098
2097/* 2099/*
@@ -2159,7 +2161,7 @@ static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
2159out: 2161out:
2160 return error; 2162 return error;
2161out_status: 2163out_status:
2162 return nfs_stat_to_errno(status); 2164 return nfs3_stat_to_errno(status);
2163} 2165}
2164 2166
2165/* 2167/*
@@ -2235,7 +2237,7 @@ static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
2235out: 2237out:
2236 return error; 2238 return error;
2237out_status: 2239out_status:
2238 return nfs_stat_to_errno(status); 2240 return nfs3_stat_to_errno(status);
2239} 2241}
2240 2242
2241/* 2243/*
@@ -2298,7 +2300,7 @@ static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
2298out: 2300out:
2299 return error; 2301 return error;
2300out_status: 2302out_status:
2301 return nfs_stat_to_errno(status); 2303 return nfs3_stat_to_errno(status);
2302} 2304}
2303 2305
2304/* 2306/*
@@ -2339,7 +2341,7 @@ static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
2339out: 2341out:
2340 return error; 2342 return error;
2341out_status: 2343out_status:
2342 return nfs_stat_to_errno(status); 2344 return nfs3_stat_to_errno(status);
2343} 2345}
2344 2346
2345#ifdef CONFIG_NFS_V3_ACL 2347#ifdef CONFIG_NFS_V3_ACL
@@ -2404,7 +2406,7 @@ static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
2404out: 2406out:
2405 return error; 2407 return error;
2406out_default: 2408out_default:
2407 return nfs_stat_to_errno(status); 2409 return nfs3_stat_to_errno(status);
2408} 2410}
2409 2411
2410static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req, 2412static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
@@ -2423,11 +2425,76 @@ static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
2423out: 2425out:
2424 return error; 2426 return error;
2425out_default: 2427out_default:
2426 return nfs_stat_to_errno(status); 2428 return nfs3_stat_to_errno(status);
2427} 2429}
2428 2430
2429#endif /* CONFIG_NFS_V3_ACL */ 2431#endif /* CONFIG_NFS_V3_ACL */
2430 2432
2433
2434/*
2435 * We need to translate between nfs status return values and
2436 * the local errno values which may not be the same.
2437 */
2438static const struct {
2439 int stat;
2440 int errno;
2441} nfs_errtbl[] = {
2442 { NFS_OK, 0 },
2443 { NFSERR_PERM, -EPERM },
2444 { NFSERR_NOENT, -ENOENT },
2445 { NFSERR_IO, -errno_NFSERR_IO},
2446 { NFSERR_NXIO, -ENXIO },
2447/* { NFSERR_EAGAIN, -EAGAIN }, */
2448 { NFSERR_ACCES, -EACCES },
2449 { NFSERR_EXIST, -EEXIST },
2450 { NFSERR_XDEV, -EXDEV },
2451 { NFSERR_NODEV, -ENODEV },
2452 { NFSERR_NOTDIR, -ENOTDIR },
2453 { NFSERR_ISDIR, -EISDIR },
2454 { NFSERR_INVAL, -EINVAL },
2455 { NFSERR_FBIG, -EFBIG },
2456 { NFSERR_NOSPC, -ENOSPC },
2457 { NFSERR_ROFS, -EROFS },
2458 { NFSERR_MLINK, -EMLINK },
2459 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
2460 { NFSERR_NOTEMPTY, -ENOTEMPTY },
2461 { NFSERR_DQUOT, -EDQUOT },
2462 { NFSERR_STALE, -ESTALE },
2463 { NFSERR_REMOTE, -EREMOTE },
2464#ifdef EWFLUSH
2465 { NFSERR_WFLUSH, -EWFLUSH },
2466#endif
2467 { NFSERR_BADHANDLE, -EBADHANDLE },
2468 { NFSERR_NOT_SYNC, -ENOTSYNC },
2469 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
2470 { NFSERR_NOTSUPP, -ENOTSUPP },
2471 { NFSERR_TOOSMALL, -ETOOSMALL },
2472 { NFSERR_SERVERFAULT, -EREMOTEIO },
2473 { NFSERR_BADTYPE, -EBADTYPE },
2474 { NFSERR_JUKEBOX, -EJUKEBOX },
2475 { -1, -EIO }
2476};
2477
2478/**
2479 * nfs3_stat_to_errno - convert an NFS status code to a local errno
2480 * @status: NFS status code to convert
2481 *
2482 * Returns a local errno value, or -EIO if the NFS status code is
2483 * not recognized. This function is used jointly by NFSv2 and NFSv3.
2484 */
2485static int nfs3_stat_to_errno(enum nfs_stat status)
2486{
2487 int i;
2488
2489 for (i = 0; nfs_errtbl[i].stat != -1; i++) {
2490 if (nfs_errtbl[i].stat == (int)status)
2491 return nfs_errtbl[i].errno;
2492 }
2493 dprintk("NFS: Unrecognized nfs status value: %u\n", status);
2494 return nfs_errtbl[i].errno;
2495}
2496
2497
2431#define PROC(proc, argtype, restype, timer) \ 2498#define PROC(proc, argtype, restype, timer) \
2432[NFS3PROC_##proc] = { \ 2499[NFS3PROC_##proc] = { \
2433 .p_proc = NFS3PROC_##proc, \ 2500 .p_proc = NFS3PROC_##proc, \