]> www.infradead.org Git - users/hch/misc.git/commitdiff
nfs_common: factor out nfs_errtbl and nfs_stat_to_errno
authorMike Snitzer <snitzer@kernel.org>
Thu, 5 Sep 2024 19:09:35 +0000 (15:09 -0400)
committerAnna Schumaker <anna.schumaker@oracle.com>
Mon, 23 Sep 2024 19:03:29 +0000 (15:03 -0400)
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>
fs/nfs/Kconfig
fs/nfs/nfs2xdr.c
fs/nfs/nfs3xdr.c
fs/nfs/nfs4xdr.c
fs/nfs_common/Makefile
fs/nfs_common/common.c [new file with mode: 0644]
fs/nfsd/Kconfig
include/linux/nfs_common.h [new file with mode: 0644]

index 57249f040dfcf3d98495128e2b6535dcd9fdc0cf..0eb20012792f070aea268937f34cbff792761811 100644 (file)
@@ -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
index c190938142960effe42c5731e24b69a90ebbbcae..6e75c6c2d2347ef8ebd0353de9960c7ef7bcecc2 100644 (file)
 #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,                                  \
index 60f032be805ae5dc1a123d49f5098a4dfe95c045..4ae01c10b7e284fff1fe5fc05452cfba7e9dcc8e 100644 (file)
 #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,                                 \
index 88bcbcba1381ae7def194b66d7c7be0b2e5beeb7..b61ffe6b9851489a3270b608ad40339c633a8b70 100644 (file)
@@ -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,
index 119c75ab9fd08e56f5f94842385963991417b158..e58b01bb8dda63867b6a6beb3be833ca925edefa 100644 (file)
@@ -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
diff --git a/fs/nfs_common/common.c b/fs/nfs_common/common.c
new file mode 100644 (file)
index 0000000..a4ee95d
--- /dev/null
@@ -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);
index ec2ab6429e00ba6c181a8f97b96334951fec3370..c0bd1509ccd48060406c78008260e62647ed953a 100644 (file)
@@ -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
diff --git a/include/linux/nfs_common.h b/include/linux/nfs_common.h
new file mode 100644 (file)
index 0000000..3395c4a
--- /dev/null
@@ -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 */