Commit f22d6d79 authored by Chuck Lever's avatar Chuck Lever Committed by Trond Myklebust

NFS: Save the value of the "port=" mount option

During a remount based on the mount options displayed in /proc/mounts, we
want to preserve the original behavior of the mount request.  Let's save
the original setting of the "port=" mount option in the mount's nfs_server
structure.

This allows us to simplify the default behavior of port setting for NFSv4
mounts: by default, NFSv2/3 mounts first try an RPC bind to determine the
NFS server's port, unless the user specified the "port=" mount option;
Users can force the client to skip the RPC bind by explicitly specifying
"port=<value>".

NFSv4, by contrast, assumes the NFS server port is 2049 and skips the RPC
bind, unless the user specifies "port=".  Users can force an RPC bind for
NFSv4 by explicitly specifying "port=0".

I added a couple of extra comments to clarify this behavior.
Signed-off-by: default avatarChuck Lever <chuck.lever@oracle.com>
Cc: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: default avatarTrond Myklebust <Trond.Myklebust@netapp.com>
parent 78fa701f
...@@ -682,6 +682,8 @@ static int nfs_init_server(struct nfs_server *server, ...@@ -682,6 +682,8 @@ static int nfs_init_server(struct nfs_server *server,
if (error < 0) if (error < 0)
goto error; goto error;
server->port = data->nfs_server.port;
error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
if (error < 0) if (error < 0)
goto error; goto error;
...@@ -1064,6 +1066,8 @@ static int nfs4_init_server(struct nfs_server *server, ...@@ -1064,6 +1066,8 @@ static int nfs4_init_server(struct nfs_server *server,
server->acdirmin = data->acdirmin * HZ; server->acdirmin = data->acdirmin * HZ;
server->acdirmax = data->acdirmax * HZ; server->acdirmax = data->acdirmax * HZ;
server->port = data->nfs_server.port;
error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
error: error:
......
...@@ -56,6 +56,7 @@ struct nfs_parsed_mount_data { ...@@ -56,6 +56,7 @@ struct nfs_parsed_mount_data {
size_t addrlen; size_t addrlen;
char *hostname; char *hostname;
char *export_path; char *export_path;
unsigned short port;
unsigned short protocol; unsigned short protocol;
} nfs_server; } nfs_server;
......
...@@ -685,7 +685,6 @@ static int nfs_parse_mount_options(char *raw, ...@@ -685,7 +685,6 @@ static int nfs_parse_mount_options(char *raw,
struct nfs_parsed_mount_data *mnt) struct nfs_parsed_mount_data *mnt)
{ {
char *p, *string, *secdata; char *p, *string, *secdata;
unsigned short port = 0;
int rc; int rc;
if (!raw) { if (!raw) {
...@@ -800,7 +799,7 @@ static int nfs_parse_mount_options(char *raw, ...@@ -800,7 +799,7 @@ static int nfs_parse_mount_options(char *raw,
return 0; return 0;
if (option < 0 || option > 65535) if (option < 0 || option > 65535)
return 0; return 0;
port = option; mnt->nfs_server.port = option;
break; break;
case Opt_rsize: case Opt_rsize:
if (match_int(args, &mnt->rsize)) if (match_int(args, &mnt->rsize))
...@@ -1050,7 +1049,8 @@ static int nfs_parse_mount_options(char *raw, ...@@ -1050,7 +1049,8 @@ static int nfs_parse_mount_options(char *raw,
} }
} }
nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, port); nfs_set_port((struct sockaddr *)&mnt->nfs_server.address,
mnt->nfs_server.port);
return 1; return 1;
...@@ -1171,7 +1171,9 @@ static int nfs_validate_mount_data(void *options, ...@@ -1171,7 +1171,9 @@ static int nfs_validate_mount_data(void *options,
args->acregmax = 60; args->acregmax = 60;
args->acdirmin = 30; args->acdirmin = 30;
args->acdirmax = 60; args->acdirmax = 60;
args->mount_server.port = 0; /* autobind unless user sets port */
args->mount_server.protocol = XPRT_TRANSPORT_UDP; args->mount_server.protocol = XPRT_TRANSPORT_UDP;
args->nfs_server.port = 0; /* autobind unless user sets port */
args->nfs_server.protocol = XPRT_TRANSPORT_TCP; args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
switch (data->version) { switch (data->version) {
...@@ -1707,28 +1709,6 @@ static void nfs4_fill_super(struct super_block *sb) ...@@ -1707,28 +1709,6 @@ static void nfs4_fill_super(struct super_block *sb)
nfs_initialise_sb(sb); nfs_initialise_sb(sb);
} }
/*
* If the user didn't specify a port, set the port number to
* the NFS version 4 default port.
*/
static void nfs4_default_port(struct sockaddr *sap)
{
switch (sap->sa_family) {
case AF_INET: {
struct sockaddr_in *ap = (struct sockaddr_in *)sap;
if (ap->sin_port == 0)
ap->sin_port = htons(NFS_PORT);
break;
}
case AF_INET6: {
struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
if (ap->sin6_port == 0)
ap->sin6_port = htons(NFS_PORT);
break;
}
}
}
/* /*
* Validate NFSv4 mount options * Validate NFSv4 mount options
*/ */
...@@ -1753,6 +1733,7 @@ static int nfs4_validate_mount_data(void *options, ...@@ -1753,6 +1733,7 @@ static int nfs4_validate_mount_data(void *options,
args->acregmax = 60; args->acregmax = 60;
args->acdirmin = 30; args->acdirmin = 30;
args->acdirmax = 60; args->acdirmax = 60;
args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
args->nfs_server.protocol = XPRT_TRANSPORT_TCP; args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
switch (data->version) { switch (data->version) {
...@@ -1769,9 +1750,6 @@ static int nfs4_validate_mount_data(void *options, ...@@ -1769,9 +1750,6 @@ static int nfs4_validate_mount_data(void *options,
&args->nfs_server.address)) &args->nfs_server.address))
goto out_no_address; goto out_no_address;
nfs4_default_port((struct sockaddr *)
&args->nfs_server.address);
switch (data->auth_flavourlen) { switch (data->auth_flavourlen) {
case 0: case 0:
args->auth_flavors[0] = RPC_AUTH_UNIX; args->auth_flavors[0] = RPC_AUTH_UNIX;
...@@ -1829,9 +1807,6 @@ static int nfs4_validate_mount_data(void *options, ...@@ -1829,9 +1807,6 @@ static int nfs4_validate_mount_data(void *options,
&args->nfs_server.address)) &args->nfs_server.address))
return -EINVAL; return -EINVAL;
nfs4_default_port((struct sockaddr *)
&args->nfs_server.address);
switch (args->auth_flavor_len) { switch (args->auth_flavor_len) {
case 0: case 0:
args->auth_flavors[0] = RPC_AUTH_UNIX; args->auth_flavors[0] = RPC_AUTH_UNIX;
......
...@@ -93,6 +93,7 @@ struct nfs_server { ...@@ -93,6 +93,7 @@ struct nfs_server {
unsigned int wpages; /* write size (in pages) */ unsigned int wpages; /* write size (in pages) */
unsigned int wtmult; /* server disk block size */ unsigned int wtmult; /* server disk block size */
unsigned int dtsize; /* readdir size */ unsigned int dtsize; /* readdir size */
unsigned short port; /* "port=" setting */
unsigned int bsize; /* server block size */ unsigned int bsize; /* server block size */
unsigned int acregmin; /* attr cache timeouts */ unsigned int acregmin; /* attr cache timeouts */
unsigned int acregmax; unsigned int acregmax;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment