mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 21:21:41 +00:00
nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
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>
This commit is contained in:
parent
dfb07e990a
commit
4806ded4c1
@ -4,6 +4,7 @@ config NFS_FS
|
||||
depends on INET && FILE_LOCKING && MULTIUSER
|
||||
select LOCKD
|
||||
select SUNRPC
|
||||
select NFS_COMMON
|
||||
select NFS_ACL_SUPPORT if NFS_V3_ACL
|
||||
help
|
||||
Choose Y here if you want to access files residing on other
|
||||
|
@ -22,14 +22,12 @@
|
||||
#include <linux/nfs.h>
|
||||
#include <linux/nfs2.h>
|
||||
#include <linux/nfs_fs.h>
|
||||
#include <linux/nfs_common.h>
|
||||
#include "nfstrace.h"
|
||||
#include "internal.h"
|
||||
|
||||
#define NFSDBG_FACILITY NFSDBG_XDR
|
||||
|
||||
/* Mapping from NFS error code to "errno" error code. */
|
||||
#define errno_NFSERR_IO EIO
|
||||
|
||||
/*
|
||||
* Declare the space requirements for NFS arguments and replies as
|
||||
* number of 32bit-words
|
||||
@ -64,8 +62,6 @@
|
||||
#define NFS_readdirres_sz (1+NFS_pagepad_sz)
|
||||
#define NFS_statfsres_sz (1+NFS_info_sz)
|
||||
|
||||
static int nfs_stat_to_errno(enum nfs_stat);
|
||||
|
||||
/*
|
||||
* Encode/decode NFSv2 basic data types
|
||||
*
|
||||
@ -1054,70 +1050,6 @@ out_default:
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* We need to translate between nfs status return values and
|
||||
* the local errno values which may not be the same.
|
||||
*/
|
||||
static const struct {
|
||||
int stat;
|
||||
int errno;
|
||||
} nfs_errtbl[] = {
|
||||
{ NFS_OK, 0 },
|
||||
{ NFSERR_PERM, -EPERM },
|
||||
{ NFSERR_NOENT, -ENOENT },
|
||||
{ NFSERR_IO, -errno_NFSERR_IO},
|
||||
{ NFSERR_NXIO, -ENXIO },
|
||||
/* { NFSERR_EAGAIN, -EAGAIN }, */
|
||||
{ NFSERR_ACCES, -EACCES },
|
||||
{ NFSERR_EXIST, -EEXIST },
|
||||
{ NFSERR_XDEV, -EXDEV },
|
||||
{ NFSERR_NODEV, -ENODEV },
|
||||
{ NFSERR_NOTDIR, -ENOTDIR },
|
||||
{ NFSERR_ISDIR, -EISDIR },
|
||||
{ NFSERR_INVAL, -EINVAL },
|
||||
{ NFSERR_FBIG, -EFBIG },
|
||||
{ NFSERR_NOSPC, -ENOSPC },
|
||||
{ NFSERR_ROFS, -EROFS },
|
||||
{ NFSERR_MLINK, -EMLINK },
|
||||
{ NFSERR_NAMETOOLONG, -ENAMETOOLONG },
|
||||
{ NFSERR_NOTEMPTY, -ENOTEMPTY },
|
||||
{ NFSERR_DQUOT, -EDQUOT },
|
||||
{ NFSERR_STALE, -ESTALE },
|
||||
{ NFSERR_REMOTE, -EREMOTE },
|
||||
#ifdef EWFLUSH
|
||||
{ NFSERR_WFLUSH, -EWFLUSH },
|
||||
#endif
|
||||
{ NFSERR_BADHANDLE, -EBADHANDLE },
|
||||
{ NFSERR_NOT_SYNC, -ENOTSYNC },
|
||||
{ NFSERR_BAD_COOKIE, -EBADCOOKIE },
|
||||
{ NFSERR_NOTSUPP, -ENOTSUPP },
|
||||
{ NFSERR_TOOSMALL, -ETOOSMALL },
|
||||
{ NFSERR_SERVERFAULT, -EREMOTEIO },
|
||||
{ NFSERR_BADTYPE, -EBADTYPE },
|
||||
{ NFSERR_JUKEBOX, -EJUKEBOX },
|
||||
{ -1, -EIO }
|
||||
};
|
||||
|
||||
/**
|
||||
* nfs_stat_to_errno - convert an NFS status code to a local errno
|
||||
* @status: NFS status code to convert
|
||||
*
|
||||
* Returns a local errno value, or -EIO if the NFS status code is
|
||||
* not recognized. This function is used jointly by NFSv2 and NFSv3.
|
||||
*/
|
||||
static int nfs_stat_to_errno(enum nfs_stat status)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; nfs_errtbl[i].stat != -1; i++) {
|
||||
if (nfs_errtbl[i].stat == (int)status)
|
||||
return nfs_errtbl[i].errno;
|
||||
}
|
||||
dprintk("NFS: Unrecognized nfs status value: %u\n", status);
|
||||
return nfs_errtbl[i].errno;
|
||||
}
|
||||
|
||||
#define PROC(proc, argtype, restype, timer) \
|
||||
[NFSPROC_##proc] = { \
|
||||
.p_proc = NFSPROC_##proc, \
|
||||
|
108
fs/nfs/nfs3xdr.c
108
fs/nfs/nfs3xdr.c
@ -21,14 +21,13 @@
|
||||
#include <linux/nfs3.h>
|
||||
#include <linux/nfs_fs.h>
|
||||
#include <linux/nfsacl.h>
|
||||
#include <linux/nfs_common.h>
|
||||
|
||||
#include "nfstrace.h"
|
||||
#include "internal.h"
|
||||
|
||||
#define NFSDBG_FACILITY NFSDBG_XDR
|
||||
|
||||
/* Mapping from NFS error code to "errno" error code. */
|
||||
#define errno_NFSERR_IO EIO
|
||||
|
||||
/*
|
||||
* Declare the space requirements for NFS arguments and replies as
|
||||
* number of 32bit-words
|
||||
@ -91,8 +90,6 @@
|
||||
NFS3_pagepad_sz)
|
||||
#define ACL3_setaclres_sz (1+NFS3_post_op_attr_sz)
|
||||
|
||||
static int nfs3_stat_to_errno(enum nfs_stat);
|
||||
|
||||
/*
|
||||
* Map file type to S_IFMT bits
|
||||
*/
|
||||
@ -1406,7 +1403,7 @@ static int nfs3_xdr_dec_getattr3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_default:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1445,7 +1442,7 @@ static int nfs3_xdr_dec_setattr3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1495,7 +1492,7 @@ out_default:
|
||||
error = decode_post_op_attr(xdr, result->dir_attr, userns);
|
||||
if (unlikely(error))
|
||||
goto out;
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1537,7 +1534,7 @@ static int nfs3_xdr_dec_access3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_default:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1578,7 +1575,7 @@ static int nfs3_xdr_dec_readlink3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_default:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1658,7 +1655,7 @@ static int nfs3_xdr_dec_read3res(struct rpc_rqst *req, struct xdr_stream *xdr,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1728,7 +1725,7 @@ static int nfs3_xdr_dec_write3res(struct rpc_rqst *req, struct xdr_stream *xdr,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1795,7 +1792,7 @@ out_default:
|
||||
error = decode_wcc_data(xdr, result->dir_attr, userns);
|
||||
if (unlikely(error))
|
||||
goto out;
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1835,7 +1832,7 @@ static int nfs3_xdr_dec_remove3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1881,7 +1878,7 @@ static int nfs3_xdr_dec_rename3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1926,7 +1923,7 @@ static int nfs3_xdr_dec_link3res(struct rpc_rqst *req, struct xdr_stream *xdr,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2101,7 +2098,7 @@ out_default:
|
||||
error = decode_post_op_attr(xdr, result->dir_attr, rpc_rqst_userns(req));
|
||||
if (unlikely(error))
|
||||
goto out;
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2167,7 +2164,7 @@ static int nfs3_xdr_dec_fsstat3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2243,7 +2240,7 @@ static int nfs3_xdr_dec_fsinfo3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2304,7 +2301,7 @@ static int nfs3_xdr_dec_pathconf3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -2350,7 +2347,7 @@ static int nfs3_xdr_dec_commit3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_status:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NFS_V3_ACL
|
||||
@ -2416,7 +2413,7 @@ static int nfs3_xdr_dec_getacl3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_default:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
|
||||
@ -2435,76 +2432,11 @@ static int nfs3_xdr_dec_setacl3res(struct rpc_rqst *req,
|
||||
out:
|
||||
return error;
|
||||
out_default:
|
||||
return nfs3_stat_to_errno(status);
|
||||
return nfs_stat_to_errno(status);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NFS_V3_ACL */
|
||||
|
||||
|
||||
/*
|
||||
* We need to translate between nfs status return values and
|
||||
* the local errno values which may not be the same.
|
||||
*/
|
||||
static const struct {
|
||||
int stat;
|
||||
int errno;
|
||||
} nfs_errtbl[] = {
|
||||
{ NFS_OK, 0 },
|
||||
{ NFSERR_PERM, -EPERM },
|
||||
{ NFSERR_NOENT, -ENOENT },
|
||||
{ NFSERR_IO, -errno_NFSERR_IO},
|
||||
{ NFSERR_NXIO, -ENXIO },
|
||||
/* { NFSERR_EAGAIN, -EAGAIN }, */
|
||||
{ NFSERR_ACCES, -EACCES },
|
||||
{ NFSERR_EXIST, -EEXIST },
|
||||
{ NFSERR_XDEV, -EXDEV },
|
||||
{ NFSERR_NODEV, -ENODEV },
|
||||
{ NFSERR_NOTDIR, -ENOTDIR },
|
||||
{ NFSERR_ISDIR, -EISDIR },
|
||||
{ NFSERR_INVAL, -EINVAL },
|
||||
{ NFSERR_FBIG, -EFBIG },
|
||||
{ NFSERR_NOSPC, -ENOSPC },
|
||||
{ NFSERR_ROFS, -EROFS },
|
||||
{ NFSERR_MLINK, -EMLINK },
|
||||
{ NFSERR_NAMETOOLONG, -ENAMETOOLONG },
|
||||
{ NFSERR_NOTEMPTY, -ENOTEMPTY },
|
||||
{ NFSERR_DQUOT, -EDQUOT },
|
||||
{ NFSERR_STALE, -ESTALE },
|
||||
{ NFSERR_REMOTE, -EREMOTE },
|
||||
#ifdef EWFLUSH
|
||||
{ NFSERR_WFLUSH, -EWFLUSH },
|
||||
#endif
|
||||
{ NFSERR_BADHANDLE, -EBADHANDLE },
|
||||
{ NFSERR_NOT_SYNC, -ENOTSYNC },
|
||||
{ NFSERR_BAD_COOKIE, -EBADCOOKIE },
|
||||
{ NFSERR_NOTSUPP, -ENOTSUPP },
|
||||
{ NFSERR_TOOSMALL, -ETOOSMALL },
|
||||
{ NFSERR_SERVERFAULT, -EREMOTEIO },
|
||||
{ NFSERR_BADTYPE, -EBADTYPE },
|
||||
{ NFSERR_JUKEBOX, -EJUKEBOX },
|
||||
{ -1, -EIO }
|
||||
};
|
||||
|
||||
/**
|
||||
* nfs3_stat_to_errno - convert an NFS status code to a local errno
|
||||
* @status: NFS status code to convert
|
||||
*
|
||||
* Returns a local errno value, or -EIO if the NFS status code is
|
||||
* not recognized. This function is used jointly by NFSv2 and NFSv3.
|
||||
*/
|
||||
static int nfs3_stat_to_errno(enum nfs_stat status)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; nfs_errtbl[i].stat != -1; i++) {
|
||||
if (nfs_errtbl[i].stat == (int)status)
|
||||
return nfs_errtbl[i].errno;
|
||||
}
|
||||
dprintk("NFS: Unrecognized nfs status value: %u\n", status);
|
||||
return nfs_errtbl[i].errno;
|
||||
}
|
||||
|
||||
|
||||
#define PROC(proc, argtype, restype, timer) \
|
||||
[NFS3PROC_##proc] = { \
|
||||
.p_proc = NFS3PROC_##proc, \
|
||||
|
@ -52,6 +52,7 @@
|
||||
#include <linux/nfs.h>
|
||||
#include <linux/nfs4.h>
|
||||
#include <linux/nfs_fs.h>
|
||||
#include <linux/nfs_common.h>
|
||||
|
||||
#include "nfs4_fs.h"
|
||||
#include "nfs4trace.h"
|
||||
@ -63,9 +64,6 @@
|
||||
|
||||
#define NFSDBG_FACILITY NFSDBG_XDR
|
||||
|
||||
/* Mapping from NFS error code to "errno" error code. */
|
||||
#define errno_NFSERR_IO EIO
|
||||
|
||||
struct compound_hdr;
|
||||
static int nfs4_stat_to_errno(int);
|
||||
static void encode_layoutget(struct xdr_stream *xdr,
|
||||
|
@ -8,3 +8,5 @@ nfs_acl-objs := nfsacl.o
|
||||
|
||||
obj-$(CONFIG_GRACE_PERIOD) += grace.o
|
||||
obj-$(CONFIG_NFS_V4_2_SSC_HELPER) += nfs_ssc.o
|
||||
|
||||
obj-$(CONFIG_NFS_COMMON) += common.o
|
||||
|
67
fs/nfs_common/common.c
Normal file
67
fs/nfs_common/common.c
Normal file
@ -0,0 +1,67 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/nfs_common.h>
|
||||
|
||||
/*
|
||||
* We need to translate between nfs status return values and
|
||||
* the local errno values which may not be the same.
|
||||
*/
|
||||
static const struct {
|
||||
int stat;
|
||||
int errno;
|
||||
} nfs_errtbl[] = {
|
||||
{ NFS_OK, 0 },
|
||||
{ NFSERR_PERM, -EPERM },
|
||||
{ NFSERR_NOENT, -ENOENT },
|
||||
{ NFSERR_IO, -errno_NFSERR_IO},
|
||||
{ NFSERR_NXIO, -ENXIO },
|
||||
/* { NFSERR_EAGAIN, -EAGAIN }, */
|
||||
{ NFSERR_ACCES, -EACCES },
|
||||
{ NFSERR_EXIST, -EEXIST },
|
||||
{ NFSERR_XDEV, -EXDEV },
|
||||
{ NFSERR_NODEV, -ENODEV },
|
||||
{ NFSERR_NOTDIR, -ENOTDIR },
|
||||
{ NFSERR_ISDIR, -EISDIR },
|
||||
{ NFSERR_INVAL, -EINVAL },
|
||||
{ NFSERR_FBIG, -EFBIG },
|
||||
{ NFSERR_NOSPC, -ENOSPC },
|
||||
{ NFSERR_ROFS, -EROFS },
|
||||
{ NFSERR_MLINK, -EMLINK },
|
||||
{ NFSERR_NAMETOOLONG, -ENAMETOOLONG },
|
||||
{ NFSERR_NOTEMPTY, -ENOTEMPTY },
|
||||
{ NFSERR_DQUOT, -EDQUOT },
|
||||
{ NFSERR_STALE, -ESTALE },
|
||||
{ NFSERR_REMOTE, -EREMOTE },
|
||||
#ifdef EWFLUSH
|
||||
{ NFSERR_WFLUSH, -EWFLUSH },
|
||||
#endif
|
||||
{ NFSERR_BADHANDLE, -EBADHANDLE },
|
||||
{ NFSERR_NOT_SYNC, -ENOTSYNC },
|
||||
{ NFSERR_BAD_COOKIE, -EBADCOOKIE },
|
||||
{ NFSERR_NOTSUPP, -ENOTSUPP },
|
||||
{ NFSERR_TOOSMALL, -ETOOSMALL },
|
||||
{ NFSERR_SERVERFAULT, -EREMOTEIO },
|
||||
{ NFSERR_BADTYPE, -EBADTYPE },
|
||||
{ NFSERR_JUKEBOX, -EJUKEBOX },
|
||||
{ -1, -EIO }
|
||||
};
|
||||
|
||||
/**
|
||||
* nfs_stat_to_errno - convert an NFS status code to a local errno
|
||||
* @status: NFS status code to convert
|
||||
*
|
||||
* Returns a local errno value, or -EIO if the NFS status code is
|
||||
* not recognized. This function is used jointly by NFSv2 and NFSv3.
|
||||
*/
|
||||
int nfs_stat_to_errno(enum nfs_stat status)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; nfs_errtbl[i].stat != -1; i++) {
|
||||
if (nfs_errtbl[i].stat == (int)status)
|
||||
return nfs_errtbl[i].errno;
|
||||
}
|
||||
return nfs_errtbl[i].errno;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(nfs_stat_to_errno);
|
@ -7,6 +7,7 @@ config NFSD
|
||||
select LOCKD
|
||||
select SUNRPC
|
||||
select EXPORTFS
|
||||
select NFS_COMMON
|
||||
select NFS_ACL_SUPPORT if NFSD_V2_ACL
|
||||
select NFS_ACL_SUPPORT if NFSD_V3_ACL
|
||||
depends on MULTIUSER
|
||||
|
16
include/linux/nfs_common.h
Normal file
16
include/linux/nfs_common.h
Normal file
@ -0,0 +1,16 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0 */
|
||||
/*
|
||||
* This file contains constants and methods used by both NFS client and server.
|
||||
*/
|
||||
#ifndef _LINUX_NFS_COMMON_H
|
||||
#define _LINUX_NFS_COMMON_H
|
||||
|
||||
#include <linux/errno.h>
|
||||
#include <uapi/linux/nfs.h>
|
||||
|
||||
/* Mapping from NFS error code to "errno" error code. */
|
||||
#define errno_NFSERR_IO EIO
|
||||
|
||||
int nfs_stat_to_errno(enum nfs_stat status);
|
||||
|
||||
#endif /* _LINUX_NFS_COMMON_H */
|
Loading…
Reference in New Issue
Block a user