Skip to contentSkip to conversation

NFS: Make v2 configurable

PATCH New [email protected] 1 participant 3 messages Mar 21, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover NFS: Make v2 configurable

From: Bryan Schumaker <[email protected]>

These patches were initially part of my modules patchset, but since they work on their own I figured I would resend them as a standalone patch set while I work on responding to comments for everything else.

- Bryan

Bryan Schumaker (2):
NFS: Relocate the stat_to_errno() function
NFS: Make v2 configurable

 fs/nfs/Kconfig   |    9 +++++++
 fs/nfs/Makefile  |    5 ++--
 fs/nfs/client.c  |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 fs/nfs/nfs2xdr.c |   67 -----------------------------------------------
 fs/nfs/nfs3xdr.c |    3 ---
 5 files changed, 88 insertions(+), 73 deletions(-)
Signature · 1 line
1.7.9.4
#1 lore raw

PATCH 1/2 NFS: Relocate the stat_to_errno() function

From: Bryan Schumaker <[email protected]>

This was located in a file belonging to NFS v2, but it is also used by v3. I moved it to a generic NFS client file to keep it from disappearing once v2 becomes configurable.

---
 fs/nfs/client.c  |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 fs/nfs/nfs2xdr.c |   67 ------------------------------------------------------
 fs/nfs/nfs3xdr.c |    3 ---
 3 files changed, 66 insertions(+), 70 deletions(-)
fs/nfs/client.c +66 -0
index 2f37848..08e7f24 100644
@@ -2072,6 +2072,72 @@ void nfs_fs_proc_exit(void)
 
 #endif /* CONFIG_PROC_FS */
 
+/* Mapping from NFS error code to "errno" error code. */
+#define errno_NFSERR_IO		EIO
+
+/*
+ * 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;
+	}
+	dprintk("NFS: Unrecognized nfs status value: %u\n", status);
+	return nfs_errtbl[i].errno;
+}
+
 module_param(nfs4_disable_idmapping, bool, 0644);
 MODULE_PARM_DESC(nfs4_disable_idmapping,
 		"Turn off NFSv4 idmapping when using 'sec=sys'");
fs/nfs/nfs2xdr.c +0 -67

79 lines not on this page · raw message

fs/nfs/nfs3xdr.c +0 -3
index a77cc9a..cee070a 100644
@@ -24,9 +24,6 @@
 
 #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
Signature · 1 line
1.7.9.4
#2 lore raw

PATCH 2/2 NFS: Make v2 configurable

In reply to [email protected]

From: Bryan Schumaker <[email protected]>

With this patch NFS v2 will no longer be automatically compiled in. Instead, users will have to select NFS_V2 during Kconfig if they want to use it.

---
 fs/nfs/Kconfig  |    9 +++++++++
 fs/nfs/Makefile |    5 +++--
 fs/nfs/client.c |   11 ++++++++++-
 3 files changed, 22 insertions(+), 3 deletions(-)
fs/nfs/Kconfig +9 -0
index 2a0e6c5..4995b24 100644
@@ -29,6 +29,15 @@ config NFS_FS
 
 	  If unsure, say N.
 
+config NFS_V2
+	bool "NFS client support for NFS version 2"
+	depends on NFS_FS
+	help
+	  This option enables support for version 2 of the NFS protocol
+	  (RFC 1094) in the kernel's NFS client.
+
+	  If unsure, say Y.
+
 config NFS_V3
 	bool "NFS client support for NFS version 3"
 	depends on NFS_FS
fs/nfs/Makefile +3 -2
index b58613d..7ddd45d 100644
@@ -4,11 +4,12 @@
 
 obj-$(CONFIG_NFS_FS) += nfs.o
 
-nfs-y 			:= client.o dir.o file.o getroot.o inode.o super.o nfs2xdr.o \
-			   direct.o pagelist.o proc.o read.o symlink.o unlink.o \
+nfs-y 			:= client.o dir.o file.o getroot.o inode.o super.o \
+			   direct.o pagelist.o read.o symlink.o unlink.o \
 			   write.o namespace.o mount_clnt.o \
 			   dns_resolve.o cache_lib.o
 nfs-$(CONFIG_ROOT_NFS)	+= nfsroot.o
+nfs-$(CONFIG_NFS_V2)	+= proc.o nfs2xdr.o
 nfs-$(CONFIG_NFS_V3)	+= nfs3proc.o nfs3xdr.o
 nfs-$(CONFIG_NFS_V3_ACL)	+= nfs3acl.o
 nfs-$(CONFIG_NFS_V4)	+= nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \
fs/nfs/client.c +10 -1
index 08e7f24..4d793b2 100644
@@ -90,7 +90,9 @@ static bool nfs4_disable_idmapping = true;
  * RPC cruft for NFS
  */
 static const struct rpc_version *nfs_version[5] = {
+#ifdef CONFIG_NFS_V2
 	[2]			= &nfs_version2,
+#endif
 #ifdef CONFIG_NFS_V3
 	[3]			= &nfs_version3,
 #endif
@@ -847,7 +849,7 @@ static int nfs_init_server(struct nfs_server *server,
 		.hostname = data->nfs_server.hostname,
 		.addr = (const struct sockaddr *)&data->nfs_server.address,
 		.addrlen = data->nfs_server.addrlen,
-		.rpc_ops = &nfs_v2_clientops,
+		.rpc_ops = NULL,
 		.proto = data->nfs_server.protocol,
 		.net = data->net,
 	};
@@ -857,10 +859,17 @@ static int nfs_init_server(struct nfs_server *server,
 
 	dprintk("--> nfs_init_server()\n");
 
+
+#ifdef CONFIG_NFS_V2
+	if (data->version == 2)
+		cl_init.rpc_ops = &nfs_v2_clientops;
+#endif
 #ifdef CONFIG_NFS_V3
 	if (data->version == 3)
 		cl_init.rpc_ops = &nfs_v3_clientops;
 #endif
+	if (cl_init.rpc_ops == NULL)
+		return -EPROTONOSUPPORT;
 
 	nfs_init_timeout_values(&timeparms, data->nfs_server.protocol,
 			data->timeo, data->retrans);
Signature · 1 line
1.7.9.4