Skip to contentSkip to conversation

fixed '-p port' arg to rpc.nfsd plus more.

PATCH In review Steve Dickson 5 participants 13 messages Mar 21, 2005 – Mar 23, 2005

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

PATCH 1/1 fixed '-p port' arg to rpc.nfsd plus more.

Hello,

The following patches fix the '-p port' command line argument to rpc.nfsd as well as adds following flags that control the NFS versions and transports that rpc.nfsd will use.

-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.

The first patch is for nfs-utils and the second one is for the kernel. Although I'm posting these patch together, they are not dependent on each other. Meaning, a patched kernel will work with an unpatched nfs-utils and visa-versa..

Is this something the upstream kernels would be interested in?

steved.

support/include/nfs/nfs.h renamed from support/include/nfs/nfs.h.orig +7 -1
@@ -40,7 +40,13 @@ 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))) 
 
 /* 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 ctlbits);
 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 +12 -7
@@ -14,7 +14,7 @@
 #include "nfslib.h"
 
 int
-nfssvc(int port, int nrservs)
+nfssvc(int port, int nrservs, unsigned ctlbits)
 {
 	struct nfsctl_arg	arg;
 	int fd;
@@ -25,16 +25,21 @@ nfssvc(int port, int nrservs)
 	if (fd >= 0) {
 		/* 2.5+ kernel with nfsd filesystem mounted.
 		 * Just write the number in.
-		 * Cannot handle port number yet, but does anyone care?
 		 */
-		char buf[20];
+		char buf[40];
 		int n;
-		snprintf(buf, 20,"%d\n", nrservs);
+		snprintf(buf, 40,"%d %d %d\n", nrservs, port, ctlbits);
 		n = write(fd, buf, strlen(buf));
 		close(fd);
-		if (n != strlen(buf))
-			return -1;
-		else
+		if (n != strlen(buf)) {
+			/*
+			 * See if this an older kernel that does not
+			 * have the ctlbits support
+			 */
+			snprintf(buf, 40, "%d\n", nrservs);
+			if (n != strlen(buf))
+				return -1;
+		} else
 			return 0;
 	}
 
utils/mountd/mountd.c renamed from utils/mountd/mountd.c.orig +3 -0
@@ -255,6 +255,9 @@ mount_mnt_3_svc(struct svc_req *rqstp, d
 			= sizeof(flavors)/sizeof(flavors[0]);
 		ok->auth_flavors.auth_flavors_val = flavors;
 	}
+	if (fh == NULL || res->fhs_status)
+		xlog(D_CALL, "MNT3(%s) failed: status %d\n", res->fhs_status);
+
 	return 1;
 }
 
utils/nfsd/nfsd.c renamed from utils/nfsd/nfsd.c.orig +57 -7

109 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
fs/nfsd/nfs4state.c renamed from fs/nfsd/nfs4state.c.orig +2 -0
@@ -3250,6 +3250,8 @@ __nfs4_state_shutdown(void)
 void
 nfs4_state_shutdown(void)
 {
+	if (!nfs4_init)
+		return;
 	nfs4_lock_state();
 	nfs4_release_reclaim();
 	__nfs4_state_shutdown();
fs/nfsd/nfssvc.c renamed from fs/nfsd/nfssvc.c.orig +63 -33

136 lines not on this page · raw message

fs/nfsd/nfsctl.c renamed from fs/nfsd/nfsctl.c.orig +26 -4
@@ -133,7 +133,7 @@ static ssize_t write_svc(struct file *fi
 	if (size < sizeof(*data))
 		return -EINVAL;
 	data = (struct nfsctl_svc*) buf;
-	return nfsd_svc(data->svc_port, data->svc_nthreads);
+	return nfsd_svc(data->svc_port, data->svc_nthreads, 0);
 }
 
 static ssize_t write_add(struct file *file, char *buf, size_t size)
@@ -311,6 +311,9 @@ static ssize_t write_threads(struct file
 	 */
 	char *mesg = buf;
 	int rv;
+	unsigned int ctlbits = 0;
+	unsigned int port = 0;
+
 	if (size > 0) {
 		int newthreads;
 		rv = get_int(&mesg, &newthreads);
@@ -318,11 +321,30 @@ static ssize_t write_threads(struct file
 			return rv;
 		if (newthreads <0)
 			return -EINVAL;
-		rv = nfsd_svc(2049, newthreads);
+		rv = get_int(&mesg, &port);
+		if (rv) {
+			/*
+			 * its possible the rpc.nfsd does not 
+			 * have the ctlbits support, so just 
+			 * fill in with default values 
+			 */
+			port = 2049;
+			ctlbits = ~0;
+			sprintf(buf, "%d\n", newthreads);
+		} else {
+			rv = get_int(&mesg, &ctlbits);
+			if (rv) {
+				ctlbits = ~0;
+				sprintf(buf, "%d %d\n", nfsd_nrthreads(), port);
+			} else
+				sprintf(buf, "%d %d %d\n", nfsd_nrthreads(), port, ctlbits);
+		}
+		rv = nfsd_svc((unsigned short)port, newthreads, ctlbits);
 		if (rv)
 			return rv;
-	}
-	sprintf(buf, "%d\n", nfsd_nrthreads());
+	} else 
+		sprintf(buf, "%d\n", nfsd_nrthreads());
+
 	return strlen(buf);
 }
 
include/linux/nfsd/syscall.h renamed from include/linux/nfsd/syscall.h.orig +8 -0
@@ -39,6 +39,14 @@
 #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 */
 
+#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)))
+
 /* SVC */
 struct nfsctl_svc {
 	unsigned short		svc_port;
include/linux/nfsd/nfsd.h renamed from include/linux/nfsd/nfsd.h.orig +1 -1
@@ -63,7 +63,7 @@ extern struct svc_version	nfsd_version2,
 /*
  * Function prototypes.
  */
-int		nfsd_svc(unsigned short port, int nrservs);
+int		nfsd_svc(unsigned short port, int nrservs, unsigned int ctlbits);
 int		nfsd_dispatch(struct svc_rqst *rqstp, u32 *statp);
 
 /* nfsd/vfs.c */
#1 lore raw
Quoted 4 lines · Steve Dickson

-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.

We definitely need something like this, thanks! Though I would have thought something like "--min-version" and "--max-version" would be more natural. (What do other OS's do?)

--b.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#2 lore raw

m=E5 den 21.03.2005 Klokka 09:56 (-0500) skreiv J. Bruce Fields:

Quoted 3 lines · Steve Dickson
Quoted 2 lines

-N or --no-nfs-version vers
This option can be used to request that rpc.nfsd does not offe=

r

Quoted 6 lines
Quoted 2 lines

certain versions of NFS. The current version of rpc.nfsd can support both NFS version 2,3 and the newer version 4.

=20
We definitely need something like this, thanks! Though I would have thought something like "--min-version" and "--max-version" would be more natural. (What do other OS's do?)

--min-version and --max-version are indeed more in line with the RPC
model: the PROG_MISMATCH error offers a single range of supported versions, and was never designed to say that you are offering NFSv2 and v4, but not NFSv3.

That said, we have already added the -N option to rpc.mountd, so if we fix rpc.nfsd, then we should also fix rpc.mountd.

Cheers,
Trond

--=20
Trond Myklebust <[email protected]>

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#4 lore raw
In reply to Steve Dickson

According to Steve Dickson:

Quoted 4 lines

-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.

Thanks very much for the patches, but would you please add on support for the '-V' flag specifying the versions that should be allowed?

Quoted 5 lines

-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.

And could you please document when (if ever) these options would be useful to an end user?

adTHANKSvance

Signature · 13 lines
Chip Salzenberg            - a.k.a. -            <[email protected]>
         Open Source is not an excuse to write fun code
            then leave the actual work to others.


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
#3 lore raw
In reply to J. Bruce Fields
Quoted 11 lines · J. Bruce Fields
Quoted 4 lines · Steve Dickson

-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.

We definitely need something like this, thanks! Though I would have thought something like "--min-version" and "--max-version" would be more natural. (What do other OS's do?)

I was trying to keep the syntax similar to
what rpc.mountd uses. I figured it would be
easier to turn things on and off from a init
script point of view....

But if it makes more sense to do a min/max
type of thing, that could work too...

steved.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#5 lore raw
In reply to Chip Salzenberg
Quoted 10 lines · Chip Salzenberg

According to Steve Dickson:

Quoted 4 lines

-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.

Thanks very much for the patches, but would you please add on support for the '-V' flag specifying the versions that should be allowed?

Well since everything is on by default, I figured all that was needed was a way to turn things off, but it would be a non-issue to add.

Quoted 11 lines
Quoted 7 lines

-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.

And could you please document when (if ever) these options would be useful to an end user?

I was thinking servers behind firewalls might want to explicitly define one protocol or the other, just to keep things simple and I know other servers have these options.

steved.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#6 lore raw

According to Steve Dickson:

Quoted 6 lines
Quoted 2 lines · Chip Salzenberg

Thanks very much for the patches, but would you please add on support for the '-V' flag specifying the versions that should be allowed?

Well since everything is on by default, I figured all that was needed was a way to turn things off, but it would be a non-issue to add.

It's for future-proofing. Suppose you only wanted to export NFSv3, that's all. You could say "-N 2" and that would be fine ... until NFSv4 was invented, when you'd need "-N 2,4". Spelling it as "-V 3" is more stable for the long term.

Quoted 2 lines

I was thinking servers behind firewalls might want to explicitly define one protocol or the other, just to keep things simple [...]

OK thanks. A little doc patch might be helpful, if only along the lines of "if you're not setting up firewall rules, these options probably won't matter to you".

Signature · 13 lines
Chip Salzenberg            - a.k.a. -            <[email protected]>
         Open Source is not an excuse to write fun code
            then leave the actual work to others.


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist  -  [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs
#7 lore raw
In reply to Steve Dickson
Quoted 6 lines · On Monday March 21, [email protected] wrote:

Hello,

The following patches fix the '-p port' command line argument to rpc.nfsd as well as adds following flags that control the NFS versions and transports that rpc.nfsd will use.

While this is all very good in principle, there are some details I'm not comfortable with....
In particular, the kernel interface.
You have changed
/proc/fs/nfsd/threads
to contain not just threads information, but also port, protocol and version information.

This is not good.

I would rather (I think) have two new files
/proc/fs/nfsd/version
and
/proc/fs/nfsd/ports

"version" should give a list of available versions, and which are enabled, on read, and should enable or disable version on write. e.g.

   # cat version
   -2 +3 -4

This means that versions 2, 3, and 4 are available. Only 3 is enabled.

   # echo +4 > version

This enables version 4 (if it is available).

"ports".... should we allow different protocols to use different
ports? 2049 for tcp, but use 5123 for udp ???
I think we should probably allow for distinguishing between ipv4 and ipv6.
And would we also want to allow binding to particular IP addresses ???? or multiple ports???

Maybe a better interface is to open and bind a socket in userspace, and pass it down to the kernel. Maybe not..

How about the "ports" file contains lines:
family:proto:address:port
e.g.
ipv4:udp:*:2049

Where new entries can added one line at a time:
echo "ipv4:tcp:*:5123" > /proc/fs/nfsd/ports
and are all read at once.

   # cat  /proc/fs/nfsd/ports
   ipv4:udp:*:2049
   ipv4:tcp:*:2049
   #
 Initially, the only recognised address would be "*", and multiple
 ports of the same protocol would not be permitted (i.e. write(2)
 returns and error).

A port could be disabled with
echo "-ipv4:udp:*:2049" > /proc/fs/nfsd/ports
maybe.

When the first thread is started, if no ports are open, the default ports (2049 for ipv4:udp and ipv4:tcp) are openned, otherwise the current ports are used.

I'm happy to consider changes in syntax, but I really don't like merging these very different concepts in the one file.

NeilBrown

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#8 lore raw
Quoted 2 lines · Neil Brown

I'm happy to consider changes in syntax, but I really don't like merging these very different concepts in the one file.

My initial thought is this adds much more complexity that really needed... All that's needed is to set the port, version and protocol. As soon as you added in address and address types, it adds a hole new level complexity that may not be needed, to solve this particular problem.

but let me take a closer took to see how much is truly need to create a couple more proc files and well as the parsing routines to handle theses type of syntaxes....

steved.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#9 lore raw
In reply to Neil Brown
Quoted 5 lines · Neil Brown

I would rather (I think) have two new files
/proc/fs/nfsd/version
and
/proc/fs/nfsd/ports

Hmm... I think there is a timing issue here.
These have to be set before threads since
write_threads() does the nfsd_svc(), true?

How about changing the name of the file rpc.nfsd writes to? To something like /proc/fs/nfsd/config?

rpc.nfsd could write to nfsd/config which then could cause the version, ports and threads files to have the correct information....

steved.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#10 lore raw
In reply to Neil Brown
Quoted 3 lines · Neil Brown

"ports".... should we allow different protocols to use different
ports? 2049 for tcp, but use 5123 for udp ???

I would not think so... How often has something like this been needed in the past?

Quoted 3 lines

Maybe a better interface is to open and bind a socket in userspace, and pass it down to the kernel. Maybe not..

True.... ;-)

Quoted 5 lines

How about the "ports" file contains lines:
family:proto:address:port
e.g.
ipv4:udp:*:2049

Maybe a better name for the file should be 'address'? since thats what we are defining....

Quoted 4 lines

A port could be disabled with
echo "-ipv4:udp:*:2049" > /proc/fs/nfsd/ports
maybe.

hmm... I think I would rather just restart the server verses disable something.... I just doesn't sound good ;-)

steved.

-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
_______________________________________________
NFS maillist - [email protected]
https://lists.sourceforge.net/lists/listinfo/nfs

#11 lore raw
In reply to Steve Dickson
Quoted 4 lines · Steve Dickson

The following patches fix the '-p port' command line argument to rpc.nfsd as well as adds following flags that control the NFS versions and transports that rpc.nfsd will use.

Just for the sake of completion on this proposal, I've updated the patches to introduce the -V flag and changed the name of the file rpc.nfsd uses from threads, to config (i.e. /proc/fs/nfsd/config), which does more accurately describes what is happening....

steved.

support/include/nfs/nfs.h renamed from support/include/nfs/nfs.h.orig +8 -1
@@ -40,7 +40,14 @@ struct nfs_fh_old {
 #define NFSCTL_LOCKD		0x10000
 #define LOCKDCTL_SVC		NFSCTL_LOCKD
 
-
+#define NFSCTL_VERSET(_cltbits, _v)   ((_cltbits) |= (1 << ((_v) - 1)))
+#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))) 
 
 /* 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 ctlbits);
 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 +13 -8
@@ -14,27 +14,32 @@
 #include "nfslib.h"
 
 int
-nfssvc(int port, int nrservs)
+nfssvc(int port, int nrservs, unsigned ctlbits)
 {
 	struct nfsctl_arg	arg;
 	int fd;
 
-	fd = open("/proc/fs/nfsd/threads", O_WRONLY);
+	fd = open("/proc/fs/nfsd/config", O_WRONLY);
 	if (fd < 0)
 		fd = open("/proc/fs/nfs/threads", O_WRONLY);
 	if (fd >= 0) {
 		/* 2.5+ kernel with nfsd filesystem mounted.
 		 * Just write the number in.
-		 * Cannot handle port number yet, but does anyone care?
 		 */
-		char buf[20];
+		char buf[40];
 		int n;
-		snprintf(buf, 20,"%d\n", nrservs);
+		snprintf(buf, 40,"%d %d %d\n", nrservs, port, ctlbits);
 		n = write(fd, buf, strlen(buf));
 		close(fd);
-		if (n != strlen(buf))
-			return -1;
-		else
+		if (n != strlen(buf)) {
+			/*
+			 * See if this an older kernel that does not
+			 * have the ctlbits support
+			 */
+			snprintf(buf, 40, "%d\n", nrservs);
+			if (n != strlen(buf))
+				return -1;
+		} else
 			return 0;
 	}
 
utils/mountd/mountd.c renamed from utils/mountd/mountd.c.orig +3 -0
@@ -255,6 +255,9 @@ mount_mnt_3_svc(struct svc_req *rqstp, d
 			= sizeof(flavors)/sizeof(flavors[0]);
 		ok->auth_flavors.auth_flavors_val = flavors;
 	}
+	if (fh == NULL || res->fhs_status)
+		xlog(D_CALL, "MNT3(%s) failed: status %d\n", res->fhs_status);
+
 	return 1;
 }
 
utils/nfsd/nfsd.c renamed from utils/nfsd/nfsd.c.orig +78 -6

123 lines not on this page · raw message

utils/nfsd/nfsd.man renamed from utils/nfsd/nfsd.man.orig +26 -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,35 @@ 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
+do 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
+.B \-V " or " \-\-nfs-version
+This option can be used to request that
+.B rpc.nfsd
+offer certain versions of NFS. The current version of
+.B rpc.nfsd
+can support NFS version 2,3 and the newer version 4.
+.TP
 .I nproc
 specify the number of NFS server threads. By default, just one
 thread is started. However, for optimum performance several threads
fs/nfsd/nfs4state.c renamed from fs/nfsd/nfs4state.c.orig +2 -0
@@ -3250,6 +3250,8 @@ __nfs4_state_shutdown(void)
 void
 nfs4_state_shutdown(void)
 {
+	if (!nfs4_init)
+		return;
 	nfs4_lock_state();
 	nfs4_release_reclaim();
 	__nfs4_state_shutdown();
fs/nfsd/nfssvc.c renamed from fs/nfsd/nfssvc.c.orig +63 -33

136 lines not on this page · raw message

fs/nfsd/nfsctl.c renamed from fs/nfsd/nfsctl.c.orig +31 -9
@@ -49,7 +49,7 @@ enum {
 	NFSD_Getfs,
 	NFSD_List,
 	NFSD_Fh,
-	NFSD_Threads,
+	NFSD_Config,
 	NFSD_Leasetime,
 };
 
@@ -64,7 +64,7 @@ static ssize_t write_unexport(struct fil
 static ssize_t write_getfd(struct file *file, char *buf, size_t size);
 static ssize_t write_getfs(struct file *file, char *buf, size_t size);
 static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
-static ssize_t write_threads(struct file *file, char *buf, size_t size);
+static ssize_t write_config(struct file *file, char *buf, size_t size);
 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
 
 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
@@ -76,7 +76,7 @@ static ssize_t (*write_op[])(struct file
 	[NFSD_Getfd] = write_getfd,
 	[NFSD_Getfs] = write_getfs,
 	[NFSD_Fh] = write_filehandle,
-	[NFSD_Threads] = write_threads,
+	[NFSD_Config] = write_config,
 	[NFSD_Leasetime] = write_leasetime,
 };
 
@@ -133,7 +133,7 @@ static ssize_t write_svc(struct file *fi
 	if (size < sizeof(*data))
 		return -EINVAL;
 	data = (struct nfsctl_svc*) buf;
-	return nfsd_svc(data->svc_port, data->svc_nthreads);
+	return nfsd_svc(data->svc_port, data->svc_nthreads, 0);
 }
 
 static ssize_t write_add(struct file *file, char *buf, size_t size)
@@ -304,13 +304,16 @@ static ssize_t write_filehandle(struct f
 
 extern int nfsd_nrthreads(void);
 
-static ssize_t write_threads(struct file *file, char *buf, size_t size)
+static ssize_t write_config(struct file *file, char *buf, size_t size)
 {
 	/* if size > 0, look for a number of threads and call nfsd_svc
 	 * then write out number of threads as reply
 	 */
 	char *mesg = buf;
 	int rv;
+	unsigned int ctlbits = 0;
+	unsigned int port = 0;
+
 	if (size > 0) {
 		int newthreads;
 		rv = get_int(&mesg, &newthreads);
@@ -318,11 +321,30 @@ static ssize_t write_threads(struct file
 			return rv;
 		if (newthreads <0)
 			return -EINVAL;
-		rv = nfsd_svc(2049, newthreads);
+		rv = get_int(&mesg, &port);
+		if (rv) {
+			/*
+			 * its possible the rpc.nfsd does not 
+			 * have the ctlbits support, so just 
+			 * fill in with default values 
+			 */
+			port = 2049;
+			ctlbits = ~0;
+			sprintf(buf, "%d\n", newthreads);
+		} else {
+			rv = get_int(&mesg, &ctlbits);
+			if (rv) {
+				ctlbits = ~0;
+				sprintf(buf, "%d %d\n", nfsd_nrthreads(), port);
+			} else
+				sprintf(buf, "%d %d %d\n", nfsd_nrthreads(), port, ctlbits);
+		}
+		rv = nfsd_svc((unsigned short)port, newthreads, ctlbits);
 		if (rv)
 			return rv;
-	}
-	sprintf(buf, "%d\n", nfsd_nrthreads());
+	} else 
+		sprintf(buf, "%d\n", nfsd_nrthreads());
+
 	return strlen(buf);
 }
 
@@ -366,7 +388,7 @@ static int nfsd_fill_super(struct super_
 		[NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
 		[NFSD_List] = {"exports", &exports_operations, S_IRUGO},
 		[NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
-		[NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
+		[NFSD_Config] = {"config", &transaction_ops, S_IWUSR|S_IRUSR},
 #ifdef CONFIG_NFSD_V4
 		[NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
 #endif
include/linux/nfsd/syscall.h renamed from include/linux/nfsd/syscall.h.orig +8 -0
@@ -39,6 +39,14 @@
 #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 */
 
+#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)))
+
 /* SVC */
 struct nfsctl_svc {
 	unsigned short		svc_port;
include/linux/nfsd/nfsd.h renamed from include/linux/nfsd/nfsd.h.orig +1 -1
@@ -63,7 +63,7 @@ extern struct svc_version	nfsd_version2,
 /*
  * Function prototypes.
  */
-int		nfsd_svc(unsigned short port, int nrservs);
+int		nfsd_svc(unsigned short port, int nrservs, unsigned int ctlbits);
 int		nfsd_dispatch(struct svc_rqst *rqstp, u32 *statp);
 
 /* nfsd/vfs.c */
#12 lore raw
In reply to Steve Dickson
Quoted 4 lines · Steve Dickson

The following patches fix the '-p port' command line argument to rpc.nfsd as well as adds following flags that control the NFS versions and transports that rpc.nfsd will use.

Just for the sake of completion on this proposal, I've updated the patches to introduce the -V flag and changed the name of the file rpc.nfsd uses from threads, to config (i.e. /proc/fs/nfsd/config), which does more accurately describes what is happening....

steved.

support/include/nfs/nfs.h renamed from support/include/nfs/nfs.h.orig +8 -1
@@ -40,7 +40,14 @@ struct nfs_fh_old {
 #define NFSCTL_LOCKD		0x10000
 #define LOCKDCTL_SVC		NFSCTL_LOCKD
 
-
+#define NFSCTL_VERSET(_cltbits, _v)   ((_cltbits) |= (1 << ((_v) - 1)))
+#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))) 
 
 /* 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 ctlbits);
 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 +13 -8
@@ -14,27 +14,32 @@
 #include "nfslib.h"
 
 int
-nfssvc(int port, int nrservs)
+nfssvc(int port, int nrservs, unsigned ctlbits)
 {
 	struct nfsctl_arg	arg;
 	int fd;
 
-	fd = open("/proc/fs/nfsd/threads", O_WRONLY);
+	fd = open("/proc/fs/nfsd/config", O_WRONLY);
 	if (fd < 0)
 		fd = open("/proc/fs/nfs/threads", O_WRONLY);
 	if (fd >= 0) {
 		/* 2.5+ kernel with nfsd filesystem mounted.
 		 * Just write the number in.
-		 * Cannot handle port number yet, but does anyone care?
 		 */
-		char buf[20];
+		char buf[40];
 		int n;
-		snprintf(buf, 20,"%d\n", nrservs);
+		snprintf(buf, 40,"%d %d %d\n", nrservs, port, ctlbits);
 		n = write(fd, buf, strlen(buf));
 		close(fd);
-		if (n != strlen(buf))
-			return -1;
-		else
+		if (n != strlen(buf)) {
+			/*
+			 * See if this an older kernel that does not
+			 * have the ctlbits support
+			 */
+			snprintf(buf, 40, "%d\n", nrservs);
+			if (n != strlen(buf))
+				return -1;
+		} else
 			return 0;
 	}
 
utils/mountd/mountd.c renamed from utils/mountd/mountd.c.orig +3 -0
@@ -255,6 +255,9 @@ mount_mnt_3_svc(struct svc_req *rqstp, d
 			= sizeof(flavors)/sizeof(flavors[0]);
 		ok->auth_flavors.auth_flavors_val = flavors;
 	}
+	if (fh == NULL || res->fhs_status)
+		xlog(D_CALL, "MNT3(%s) failed: status %d\n", res->fhs_status);
+
 	return 1;
 }
 
utils/nfsd/nfsd.c renamed from utils/nfsd/nfsd.c.orig +78 -6

123 lines not on this page · raw message

utils/nfsd/nfsd.man renamed from utils/nfsd/nfsd.man.orig +26 -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,35 @@ 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
+do 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
+.B \-V " or " \-\-nfs-version
+This option can be used to request that
+.B rpc.nfsd
+offer certain versions of NFS. The current version of
+.B rpc.nfsd
+can support NFS version 2,3 and the newer version 4.
+.TP
 .I nproc
 specify the number of NFS server threads. By default, just one
 thread is started. However, for optimum performance several threads
fs/nfsd/nfs4state.c renamed from fs/nfsd/nfs4state.c.orig +2 -0
@@ -3250,6 +3250,8 @@ __nfs4_state_shutdown(void)
 void
 nfs4_state_shutdown(void)
 {
+	if (!nfs4_init)
+		return;
 	nfs4_lock_state();
 	nfs4_release_reclaim();
 	__nfs4_state_shutdown();
fs/nfsd/nfssvc.c renamed from fs/nfsd/nfssvc.c.orig +63 -33

136 lines not on this page · raw message

fs/nfsd/nfsctl.c renamed from fs/nfsd/nfsctl.c.orig +31 -9
@@ -49,7 +49,7 @@ enum {
 	NFSD_Getfs,
 	NFSD_List,
 	NFSD_Fh,
-	NFSD_Threads,
+	NFSD_Config,
 	NFSD_Leasetime,
 };
 
@@ -64,7 +64,7 @@ static ssize_t write_unexport(struct fil
 static ssize_t write_getfd(struct file *file, char *buf, size_t size);
 static ssize_t write_getfs(struct file *file, char *buf, size_t size);
 static ssize_t write_filehandle(struct file *file, char *buf, size_t size);
-static ssize_t write_threads(struct file *file, char *buf, size_t size);
+static ssize_t write_config(struct file *file, char *buf, size_t size);
 static ssize_t write_leasetime(struct file *file, char *buf, size_t size);
 
 static ssize_t (*write_op[])(struct file *, char *, size_t) = {
@@ -76,7 +76,7 @@ static ssize_t (*write_op[])(struct file
 	[NFSD_Getfd] = write_getfd,
 	[NFSD_Getfs] = write_getfs,
 	[NFSD_Fh] = write_filehandle,
-	[NFSD_Threads] = write_threads,
+	[NFSD_Config] = write_config,
 	[NFSD_Leasetime] = write_leasetime,
 };
 
@@ -133,7 +133,7 @@ static ssize_t write_svc(struct file *fi
 	if (size < sizeof(*data))
 		return -EINVAL;
 	data = (struct nfsctl_svc*) buf;
-	return nfsd_svc(data->svc_port, data->svc_nthreads);
+	return nfsd_svc(data->svc_port, data->svc_nthreads, 0);
 }
 
 static ssize_t write_add(struct file *file, char *buf, size_t size)
@@ -304,13 +304,16 @@ static ssize_t write_filehandle(struct f
 
 extern int nfsd_nrthreads(void);
 
-static ssize_t write_threads(struct file *file, char *buf, size_t size)
+static ssize_t write_config(struct file *file, char *buf, size_t size)
 {
 	/* if size > 0, look for a number of threads and call nfsd_svc
 	 * then write out number of threads as reply
 	 */
 	char *mesg = buf;
 	int rv;
+	unsigned int ctlbits = 0;
+	unsigned int port = 0;
+
 	if (size > 0) {
 		int newthreads;
 		rv = get_int(&mesg, &newthreads);
@@ -318,11 +321,30 @@ static ssize_t write_threads(struct file
 			return rv;
 		if (newthreads <0)
 			return -EINVAL;
-		rv = nfsd_svc(2049, newthreads);
+		rv = get_int(&mesg, &port);
+		if (rv) {
+			/*
+			 * its possible the rpc.nfsd does not 
+			 * have the ctlbits support, so just 
+			 * fill in with default values 
+			 */
+			port = 2049;
+			ctlbits = ~0;
+			sprintf(buf, "%d\n", newthreads);
+		} else {
+			rv = get_int(&mesg, &ctlbits);
+			if (rv) {
+				ctlbits = ~0;
+				sprintf(buf, "%d %d\n", nfsd_nrthreads(), port);
+			} else
+				sprintf(buf, "%d %d %d\n", nfsd_nrthreads(), port, ctlbits);
+		}
+		rv = nfsd_svc((unsigned short)port, newthreads, ctlbits);
 		if (rv)
 			return rv;
-	}
-	sprintf(buf, "%d\n", nfsd_nrthreads());
+	} else 
+		sprintf(buf, "%d\n", nfsd_nrthreads());
+
 	return strlen(buf);
 }
 
@@ -366,7 +388,7 @@ static int nfsd_fill_super(struct super_
 		[NFSD_Getfs] = {".getfs", &transaction_ops, S_IWUSR|S_IRUSR},
 		[NFSD_List] = {"exports", &exports_operations, S_IRUGO},
 		[NFSD_Fh] = {"filehandle", &transaction_ops, S_IWUSR|S_IRUSR},
-		[NFSD_Threads] = {"threads", &transaction_ops, S_IWUSR|S_IRUSR},
+		[NFSD_Config] = {"config", &transaction_ops, S_IWUSR|S_IRUSR},
 #ifdef CONFIG_NFSD_V4
 		[NFSD_Leasetime] = {"nfsv4leasetime", &transaction_ops, S_IWUSR|S_IRUSR},
 #endif
include/linux/nfsd/syscall.h renamed from include/linux/nfsd/syscall.h.orig +8 -0
@@ -39,6 +39,14 @@
 #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 */
 
+#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)))
+
 /* SVC */
 struct nfsctl_svc {
 	unsigned short		svc_port;
include/linux/nfsd/nfsd.h renamed from include/linux/nfsd/nfsd.h.orig +1 -1
@@ -63,7 +63,7 @@ extern struct svc_version	nfsd_version2,
 /*
  * Function prototypes.
  */
-int		nfsd_svc(unsigned short port, int nrservs);
+int		nfsd_svc(unsigned short port, int nrservs, unsigned int ctlbits);
 int		nfsd_dispatch(struct svc_rqst *rqstp, u32 *statp);
 
 /* nfsd/vfs.c */