From 39cd459bcb9932a8ed279f41837d23a74d2d86bd Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Thu, 23 Jul 2009 15:41:41 -0700 Subject: [PATCH] NFS - Change the mount default from udp to tcp, add "udp" option. * Mount_nfs now mounts TCP by default. * Added "udp" option, and the -U option now works similarly to -T, but for udp instead of tcp. --- sbin/mount_nfs/mount_nfs.8 | 32 ++++++++++----------- sbin/mount_nfs/mount_nfs.c | 58 ++++++++++++++++++-------------------- 2 files changed, 43 insertions(+), 47 deletions(-) diff --git a/sbin/mount_nfs/mount_nfs.8 b/sbin/mount_nfs/mount_nfs.8 index 356dc0fc51..2aeb30a6ff 100644 --- a/sbin/mount_nfs/mount_nfs.8 +++ b/sbin/mount_nfs/mount_nfs.8 @@ -147,15 +147,17 @@ There is a 60 second delay between each attempt. .It Fl T Use TCP transport instead of UDP. This is recommended for servers that are not on the same LAN cable as -the client. -(NB: This is NOT supported by most -.No non- Ns Bx -servers.) +the client. This is the default. .It Fl U -Force the mount protocol to use UDP transport, even for TCP NFS mounts. -(Necessary for some old -.Bx -servers.) +Use UDP transport instead of TCP. +This is not recommended due to the ease of which +.Dx +clients can blow out available socket buffer space on the server, +not to mention the impossibility of accurately calculating the +proper retry interval due to disk I/O backlogs on the server. +If you want to use the option anyway it is recommended that the +server reserve upwards of 2 MBytes of socket buffer space to hold +the received UDP packets. .It Fl a Set the read-ahead count to the specified value. This may be in the range of 0 - 4, and determines how many blocks @@ -233,14 +235,6 @@ upper and lower bounds of the timeouts for ``directory'' attributes and for regular files, and 30 -> 60 seconds for directories. The algorithm to calculate the timeout is based on the age of the file. The older the file, the longer the cache is considered valid, subject to the limits above. -.El -.Pp -.Sy Historic Fl o Sy Options -.Pp -Use of these options is deprecated, they are only mentioned here for -compatibility with historic versions of -.Nm . -.Bl -tag -width "dumbtimerXX" .It bg Same as .Fl b . @@ -267,7 +261,8 @@ Same as .Fl l . .It mntudp Same as -.Fl U . +.Fl U +(obsolete). .It resvport Same as .Fl P . @@ -277,6 +272,9 @@ Same as .It tcp Same as .Fl T . +.It udp +Same as +.Fl U . .El .It Fl r Set the read data size to the specified value. diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index 1d6f48d643..d7f690ec4b 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -76,7 +76,7 @@ #define ALTF_KERB 0x10 #define ALTF_NFSV3 0x20 #define ALTF_RDIRPLUS 0x40 -#define ALTF_MNTUDP 0x80 +#define ALTF_UNUSED080 0x80 #define ALTF_RESVPORT 0x100 #define ALTF_SEQPACKET 0x200 #define ALTF_UNUSED400 0x400 @@ -103,10 +103,11 @@ struct mntopt mopts[] = { #endif { "nfsv3", 0, ALTF_NFSV3, 1 }, { "rdirplus", 0, ALTF_RDIRPLUS, 1 }, - { "mntudp", 0, ALTF_MNTUDP, 1 }, + { "mntudp", 1, ALTF_TCP, 1 }, { "resvport", 0, ALTF_RESVPORT, 1 }, { "soft", 0, ALTF_SOFT, 1 }, { "tcp", 0, ALTF_TCP, 1 }, + { "udp", 1, ALTF_TCP, 1 }, { "port=", 0, ALTF_PORT, 1 }, { "nfsv2", 0, ALTF_NFSV2, 1 }, { "acregmin=", 0, ALTF_ACREGMIN, 1 }, @@ -120,7 +121,7 @@ struct nfs_args nfsdefargs = { NFS_ARGSVERSION, NULL, sizeof (struct sockaddr_in), - SOCK_DGRAM, + 0, 0, NULL, 0, @@ -166,8 +167,7 @@ struct nfhret { #define ISBGRND 2 int retrycnt = -1; int opflags = 0; -int nfsproto = IPPROTO_UDP; -int mnttcp_ok = 1; +int nfsproto; char *portspec = NULL; /* Server nfs port; NULL means look up via rpcbind. */ enum mountmode { ANY, @@ -279,9 +279,16 @@ main(int argc, char **argv) #endif /* NFSKERB */ mntflags = 0; - altflags = 0; + altflags = ALTF_TCP; nfsargs = nfsdefargs; nfsargsp = &nfsargs; + if (altflags & ALTF_TCP) { + nfsproto = IPPROTO_TCP; + nfsargsp->sotype = SOCK_STREAM; + } else { + nfsproto = IPPROTO_UDP; + nfsargsp->sotype = SOCK_DGRAM; + } while ((c = getopt(argc, argv, "23a:bcdD:g:I:iKlm:No:PR:r:sTt:w:x:U")) != -1) switch (c) { @@ -354,6 +361,8 @@ main(int argc, char **argv) case 'o': altflags = 0; set_flags(&altflags, &nfsargsp->flags, TRUE); + if (nfsproto == IPPROTO_TCP) + altflags |= ALTF_TCP; if (mountmode == V2) altflags |= ALTF_NFSV2; else if (mountmode == V3) @@ -366,11 +375,12 @@ main(int argc, char **argv) */ if(altflags & ALTF_BG) opflags |= BGRND; - if(altflags & ALTF_MNTUDP) - mnttcp_ok = 0; - if(altflags & ALTF_TCP) { - nfsargsp->sotype = SOCK_STREAM; + if (altflags & ALTF_TCP) { nfsproto = IPPROTO_TCP; + nfsargsp->sotype = SOCK_STREAM; + } else { + nfsproto = IPPROTO_UDP; + nfsargsp->sotype = SOCK_DGRAM; } if(altflags & ALTF_PORT) { /* @@ -379,7 +389,7 @@ main(int argc, char **argv) * allow /etc/services names. */ asprintf(&portspec, "%d", - atoi(strstr(optarg, "port=") + 5)); + atoi(strstr(optarg, "port=") + 5)); if (portspec == NULL) err(1, "asprintf"); } @@ -423,6 +433,7 @@ main(int argc, char **argv) case 'T': nfsargsp->sotype = SOCK_STREAM; nfsproto = IPPROTO_TCP; + altflags |= ALTF_TCP; break; case 't': num = strtol(optarg, &p, 10); @@ -446,7 +457,9 @@ main(int argc, char **argv) nfsargsp->flags |= NFSMNT_RETRANS; break; case 'U': - mnttcp_ok = 0; + nfsargsp->sotype = SOCK_DGRAM; + nfsproto = IPPROTO_UDP; + altflags &= ~ALTF_TCP; break; default: usage(); @@ -759,24 +772,9 @@ nfs_tryproto(struct nfs_args *nfsargsp, struct addrinfo *ai, char *hostp, snprintf(errbuf, sizeof errbuf, "%s: %s", netid, nc_sperror()); return (TRYRET_LOCALERR); } - /* The RPCPROG_MNT netid may be different. */ - if (mnttcp_ok) { - netid_mnt = netid; - nconf_mnt = nconf; - } else { - if ((netid_mnt = netidbytype(ai->ai_family, SOCK_DGRAM)) - == NULL) { - snprintf(errbuf, sizeof errbuf, - "af %d sotype SOCK_DGRAM not supported", - ai->ai_family); - return (TRYRET_LOCALERR); - } - if ((nconf_mnt = getnetconf_cached(netid_mnt)) == NULL) { - snprintf(errbuf, sizeof errbuf, "%s: %s", netid_mnt, - nc_sperror()); - return (TRYRET_LOCALERR); - } - } + + netid_mnt = netid; + nconf_mnt = nconf; tryagain: if (trymntmode == V2) { -- 2.41.0