2008-04-30 16:00:14

by Chuck Lever

[permalink] [raw]
Subject: [PATCH 5/6] NFS: "proto=tcp" implies "mountproto=tcp"

If a user specifies "proto=tcp" via the legacy mount API, the mount command
also uses TCP to contact the server's mount daemon. Ditto for "proto=udp".
This makes it easier to mount through firewalls that block one or the other
transport protocol.

Make the in-kernel NFS mount option parser emulate this behavior.

Signed-off-by: Chuck Lever <[email protected]>
---

fs/nfs/super.c | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index 1f3fa91..e2cadd9 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -749,6 +749,7 @@ static int nfs_parse_mount_options(char *raw,
{
char *p, *string, *secdata;
int timeo = 0, retrans = 0;
+ unsigned short mount_protocol = 0;
int rc;

if (!raw) {
@@ -821,6 +822,8 @@ static int nfs_parse_mount_options(char *raw,
case Opt_udp:
mnt->flags &= ~NFS_MOUNT_TCP;
mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
+ if (mount_protocol == 0)
+ mount_protocol = XPRT_TRANSPORT_UDP;
if (timeo == 0)
timeo = NFS_DEF_UDP_TIMEO;
if (retrans == 0)
@@ -829,6 +832,8 @@ static int nfs_parse_mount_options(char *raw,
case Opt_tcp:
mnt->flags |= NFS_MOUNT_TCP;
mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
+ if (mount_protocol == 0)
+ mount_protocol = XPRT_TRANSPORT_TCP;
if (timeo == 0)
timeo = NFS_DEF_TCP_TIMEO;
if (retrans == 0)
@@ -1040,6 +1045,8 @@ static int nfs_parse_mount_options(char *raw,
case Opt_xprt_udp:
mnt->flags &= ~NFS_MOUNT_TCP;
mnt->nfs_server.protocol = XPRT_TRANSPORT_UDP;
+ if (mount_protocol == 0)
+ mount_protocol = XPRT_TRANSPORT_UDP;
if (timeo == 0)
timeo = NFS_DEF_UDP_TIMEO;
if (retrans == 0)
@@ -1048,6 +1055,8 @@ static int nfs_parse_mount_options(char *raw,
case Opt_xprt_tcp:
mnt->flags |= NFS_MOUNT_TCP;
mnt->nfs_server.protocol = XPRT_TRANSPORT_TCP;
+ if (mount_protocol == 0)
+ mount_protocol = XPRT_TRANSPORT_TCP;
if (timeo == 0)
timeo = NFS_DEF_TCP_TIMEO;
if (retrans == 0)
@@ -1076,10 +1085,10 @@ static int nfs_parse_mount_options(char *raw,

switch (token) {
case Opt_xprt_udp:
- mnt->mount_server.protocol = XPRT_TRANSPORT_UDP;
+ mount_protocol = XPRT_TRANSPORT_UDP;
break;
case Opt_xprt_tcp:
- mnt->mount_server.protocol = XPRT_TRANSPORT_TCP;
+ mount_protocol = XPRT_TRANSPORT_TCP;
break;
case Opt_xprt_rdma: /* not used for side protocols */
default:
@@ -1137,6 +1146,9 @@ static int nfs_parse_mount_options(char *raw,
if (retrans != 0)
mnt->retrans = retrans;

+ if (mount_protocol)
+ mnt->mount_server.protocol = mount_protocol;
+
return 1;

out_nomem: