Skip to contentSkip to conversation

kNFSD: fixed '-p port' arg to rpc.nfsd and enables the defining proto versions and transpots

PATCH New Steve Dickson 1 participant 1 message Jul 11, 2005

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

PATCH 1/1 kNFSD: fixed '-p port' arg to rpc.nfsd and enables the defining proto versions and transpots

Here is an other attempt to make the '-p port' command line argument to rpc.nfsd work plus define which network transports should be advertised as well as define the protocol versions that should be advertised.

The difference between these patches and the prior ones is I've broken up the setting of the versions and ports/transports into two different files.

To set the port and transport you write a string in the format of "family transport address port" to the /proc/fs/nfsd/ports file. An example would be echo "ipv4 tcp 192.168.0.1 2049" > /proc/fs/nfsd/ports. Currently only the transport and port are looked at.

To set the protocol version you write a string in the format of "[+/-]vers [+/-]vers" to the proc/fs/nfsd/versions file. An example would be echo "+2 +3 -4" > /proc/fs/nfsd/versions which would turn off version 4.

These patches also added the command line arguments to rpc.nfsd:

-N or --no-nfs-version vers
This option can be used to request that rpc.nfsd does not offer certain versions of NFS. The current version of rpc.nfsd can support both NFS version 2,3 and the newer version 4.

-T or --no-tcp
Disable rpc.nfsd from accepting TCP connections from clients.

-U or --no-udp
Disable rpc.nfsd from accepting UDP connections from clients.

I've been getting a lot of requests for this type of functionality both on the Fedora Core and RHEL fronts, so I'm hopeful this these patches will be consider for inclusion in a upstream kernel and nfs-utils package.

steved.

This kernel patch allows the setting of the port and network transport on which kNFSD will listen on and which protocol version will be advertised.

Signed-off: Steve Dickson <[email protected]>
-------------------------------

fs/nfsd/nfs4state.c renamed from fs/nfsd/nfs4state.c.orig +3 -0
@@ -3256,6 +3256,9 @@ __nfs4_state_shutdown(void)
 void
 nfs4_state_shutdown(void)
 {
+	if (!nfs4_init)
+		return;
+
 	nfs4_lock_state();
 	nfs4_release_reclaim();
 	__nfs4_state_shutdown();
fs/nfsd/nfsctl.c renamed from fs/nfsd/nfsctl.c.orig +100 -3

163 lines not on this page · raw message

fs/nfsd/nfssvc.c renamed from fs/nfsd/nfssvc.c.orig +60 -36

145 lines not on this page · raw message

include/linux/nfsd/syscall.h renamed from include/linux/nfsd/syscall.h.orig +19 -0
@@ -39,6 +39,22 @@
 #define NFSCTL_GETFD		7	/* get an fh by path (used by mountd) */
 #define	NFSCTL_GETFS		8	/* get an fh by path with max FH len */
 
+/*
+ * Macros used to set version and protocol
+ */
+#define NFSCTL_VERSET(_cltbits, _v)   ((_cltbits) |=  (1 << ((_v) - 1)))
+#define NFSCTL_VERUNSET(_cltbits, _v) ((_cltbits) &= ~(1 << ((_v) - 1)))
+#define NFSCTL_VERISSET(_cltbits, _v) ((_cltbits) & (1 << ((_v) - 1)))
+
+#define NFSCTL_UDPSET(_cltbits)       ((_cltbits) |=  (1 << (17 - 1)))
+#define NFSCTL_UDPUNSET(_cltbits)     ((_cltbits) &= ~(1 << (17 - 1)))
+#define NFSCTL_UDPISSET(_cltbits)     ((_cltbits) & (1 << (17 - 1)))
+
+#define NFSCTL_TCPSET(_cltbits)       ((_cltbits) |=  (1 << (18 - 1)))
+#define NFSCTL_TCPUNSET(_cltbits)     ((_cltbits) &= ~(1 << (18 - 1)))
+#define NFSCTL_TCPISSET(_cltbits)     ((_cltbits) & (1 << (18 - 1)))
+
+
 /* SVC */
 struct nfsctl_svc {
 	unsigned short		svc_port;
@@ -120,6 +136,9 @@ extern int		exp_delclient(struct nfsctl_
 extern int		exp_export(struct nfsctl_export *nxp);
 extern int		exp_unexport(struct nfsctl_export *nxp);
 
+extern int nfsd_port;
+extern unsigned int nfsd_versbits, nfsd_portbits;
+
 #endif /* __KERNEL__ */
 
 #endif /* NFSD_SYSCALL_H */

This patch added the following aruments to rpc.nfsd:

-N or --no-nfs-version vers
This option can be used to request that rpc.nfsd does not offer certain versions of NFS. The current version of rpc.nfsd can support both NFS version 2,3 and the newer version 4.

-T or --no-tcp
Disable rpc.nfsd from accepting TCP connections from clients.

-U or --no-udp
Disable rpc.nfsd from accepting UDP connections from clients.

Signed-off: Steve Dickson <[email protected]>
-------------------------------

support/include/nfs/nfs.h renamed from support/include/nfs/nfs.h.orig +11 -0
@@ -10,6 +10,9 @@
 #define	NFS3_FHSIZE	64
 #define	NFS_FHSIZE	32
 
+#define NFSD_MINVERS 2
+#define NFSD_MAXVERS 4
+
 struct nfs_fh_len {
 	int		fh_size;
 	u_int8_t	fh_handle[NFS3_FHSIZE];
@@ -40,7 +43,15 @@ struct nfs_fh_old {
 #define NFSCTL_LOCKD		0x10000
 #define LOCKDCTL_SVC		NFSCTL_LOCKD
 
+#define NFSCTL_VERUNSET(_cltbits, _v) ((_cltbits) &= ~(1 << ((_v) - 1))) 
+#define NFSCTL_UDPUNSET(_cltbits)     ((_cltbits) &= ~(1 << (17 - 1))) 
+#define NFSCTL_TCPUNSET(_cltbits)     ((_cltbits) &= ~(1 << (18 - 1))) 
+
+#define NFSCTL_VERISSET(_cltbits, _v) ((_cltbits) & (1 << ((_v) - 1))) 
+#define NFSCTL_UDPISSET(_cltbits)     ((_cltbits) & (1 << (17 - 1))) 
+#define NFSCTL_TCPISSET(_cltbits)     ((_cltbits) & (1 << (18 - 1))) 
 
+#define NFSCTL_ALLBITS (~0)
 
 /* SVC */
 struct nfsctl_svc {
support/include/nfslib.h renamed from support/include/nfslib.h.orig +1 -1
@@ -118,7 +118,7 @@ int			wildmat(char *text, char *pattern)
  * nfsd library functions.
  */
 int			nfsctl(int, struct nfsctl_arg *, union nfsctl_res *);
-int			nfssvc(int port, int nrservs);
+int			nfssvc(int port, int nrservs, unsigned int versbits, unsigned int portbits);
 int			nfsaddclient(struct nfsctl_client *clp);
 int			nfsdelclient(struct nfsctl_client *clp);
 int			nfsexport(struct nfsctl_export *exp);
support/nfs/nfssvc.c renamed from support/nfs/nfssvc.c.orig +65 -2

87 lines not on this page · raw message

utils/nfsd/nfsd.c renamed from utils/nfsd/nfsd.c.orig +59 -8

112 lines not on this page · raw message

utils/nfsd/nfsd.man renamed from utils/nfsd/nfsd.man.orig +19 -2
@@ -6,7 +6,7 @@
 .SH NAME
 rpc.nfsd \- NFS server process
 .SH SYNOPSIS
-.BI "/usr/sbin/rpc.nfsd [-p " port "] " nproc
+.BI "/usr/sbin/rpc.nfsd [" options "]" " "nproc
 .SH DESCRIPTION
 The
 .B rpc.nfsd
@@ -22,11 +22,28 @@ server provides an ancillary service nee
 by NFS clients.
 .SH OPTIONS
 .TP
-.BI \-p " port"
+.B \-p " or " \-\-port  port
 specify a diferent port to listen on for NFS requests. By default,
 .B rpc.nfsd
 will listen on port 2049.
 .TP
+.B \-N " or " \-\-no-nfs-version vers
+This option can be used to request that 
+.B rpc.nfsd
+does not offer certain versions of NFS. The current version of
+.B rpc.nfsd
+can support both NFS version 2,3 and the newer version 4.
+.TP
+.B \-T " or " \-\-no-tcp
+Disable 
+.B rpc.nfsd 
+from accepting TCP connections from clients.
+.TP
+.B \-U " or " \-\-no-udp
+Disable
+.B rpc.nfsd
+from accepting UDP connections from clients.
+.TP
 .I nproc
 specify the number of NFS server threads. By default, just one
 thread is started. However, for optimum performance several threads