diff options
author | dfr <dfr@FreeBSD.org> | 1997-04-18 16:23:10 +0000 |
---|---|---|
committer | dfr <dfr@FreeBSD.org> | 1997-04-18 16:23:10 +0000 |
commit | 2166a1b3013a39697f83c2a9effd23d7bf4a78d8 (patch) | |
tree | 95a3aac0b6723c8f367f7cd86c5aa0f3686ec9a5 /sbin | |
parent | 16ac81a5c5a3fec0f0cb4ff7456a1833d5cb437d (diff) | |
download | FreeBSD-src-2166a1b3013a39697f83c2a9effd23d7bf4a78d8.zip FreeBSD-src-2166a1b3013a39697f83c2a9effd23d7bf4a78d8.tar.gz |
Use v3 protocol by default if it is supported by the server. Allow the
user to force v2 protocol even if the server supports v3.
Obtained from: NetBSD but with a slightly different implementation
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/mount_nfs/mount_nfs.8 | 12 | ||||
-rw-r--r-- | sbin/mount_nfs/mount_nfs.c | 48 |
2 files changed, 49 insertions, 11 deletions
diff --git a/sbin/mount_nfs/mount_nfs.8 b/sbin/mount_nfs/mount_nfs.8 index cf28059..e81b017 100644 --- a/sbin/mount_nfs/mount_nfs.8 +++ b/sbin/mount_nfs/mount_nfs.8 @@ -31,7 +31,7 @@ .\" .\" @(#)mount_nfs.8 8.3 (Berkeley) 3/29/95 .\" -.\" $Id: mount_nfs.8,v 1.7 1997/02/22 14:32:47 peter Exp $ +.\" $Id: mount_nfs.8,v 1.8 1997/03/11 12:31:54 peter Exp $ .\"" .Dd March 29, 1995 .Dt MOUNT_NFS 8 @@ -41,7 +41,7 @@ .Nd mount nfs file systems .Sh SYNOPSIS .Nm mount_nfs -.Op Fl 3KPTUbcdilqs +.Op Fl 23KPTUbcdilqs .Op Fl D Ar deadthresh .Op Fl I Ar readdirsize .Op Fl L Ar leaseterm @@ -72,8 +72,11 @@ Appendix I. .Pp The options are: .Bl -tag -width indent +.It Fl 2 +Use the NFS Version 2 protocol (the default is to try version 3 first +then version 2). .It Fl 3 -Use the NFS Version 3 protocol (Version 2 is the default). +Use the NFS Version 3 protocol. .It Fl D Used with NQNFS to set the .Dq "dead server threshold" @@ -200,6 +203,9 @@ Same as .It kerb Same as .Fl K . +.It nfsv2 +Same as +.Fl 2 . .It nfsv3 Same as .Fl 3 . diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c index e5009e6..6f8b9c5 100644 --- a/sbin/mount_nfs/mount_nfs.c +++ b/sbin/mount_nfs/mount_nfs.c @@ -45,7 +45,7 @@ static char copyright[] = static char sccsid[] = "@(#)mount_nfs.c 8.11 (Berkeley) 5/4/95"; */ static const char rcsid[] = - "$Id: mount_nfs.c,v 1.19 1997/04/01 17:20:17 guido Exp $"; + "$Id: mount_nfs.c,v 1.20 1997/04/02 11:30:44 dfr Exp $"; #endif /* not lint */ #include <sys/param.h> @@ -105,6 +105,7 @@ static const char rcsid[] = #define ALTF_SOFT 0x800 #define ALTF_TCP 0x1000 #define ALTF_PORT 0x2000 +#define ALTF_NFSV2 0x4000 struct mntopt mopts[] = { MOPT_STDOPTS, @@ -128,6 +129,7 @@ struct mntopt mopts[] = { { "soft", 0, ALTF_SOFT, 1 }, { "tcp", 0, ALTF_TCP, 1 }, { "port=", 0, ALTF_PORT, 1 }, + { "nfsv2", 0, ALTF_NFSV2, 1 }, { NULL } }; @@ -167,6 +169,11 @@ int opflags = 0; int nfsproto = IPPROTO_UDP; int mnttcp_ok = 1; u_short port_no = 0; +enum { + ANY, + V2, + V3 +} mountmode = ANY; #ifdef NFSKERB char inst[INST_SZ]; @@ -221,7 +228,6 @@ setflags(int* altflags, int* nfsflags, int dir) #ifdef NFSKERB F(KERB); #endif - F(NFSV3); F(RDIRPLUS); F(RESVPORT); F(NQNFS); @@ -262,10 +268,13 @@ main(argc, argv) nfsargs = nfsdefargs; nfsargsp = &nfsargs; while ((c = getopt(argc, argv, - "3a:bcdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:U")) != -1) + "23a:bcdD:g:I:iKL:lm:o:PpqR:r:sTt:w:x:U")) != -1) switch (c) { + case '2': + mountmode = V2; + break; case '3': - nfsargsp->flags |= NFSMNT_NFSV3; + mountmode = V3; break; case 'a': num = strtol(optarg, &p, 10); @@ -334,6 +343,10 @@ main(argc, argv) case 'o': altflags = 0; setflags(&altflags, &nfsargsp->flags, TRUE); + if (mountmode == V2) + altflags |= ALTF_NFSV2; + else if (mountmode == V3) + altflags |= ALTF_NFSV3; getmntopts(optarg, mopts, &mntflags, &altflags); setflags(&altflags, &nfsargsp->flags, FALSE); /* @@ -354,6 +367,11 @@ main(argc, argv) } if(altflags & ALTF_PORT) port_no = atoi(strstr(optarg, "port=") + 5); + mountmode = ANY; + if(altflags & ALTF_NFSV2) + mountmode = V2; + if(altflags & ALTF_NFSV3) + mountmode = V3; break; case 'P': nfsargsp->flags |= NFSMNT_RESVPORT; @@ -364,7 +382,8 @@ main(argc, argv) break; #endif case 'q': - nfsargsp->flags |= (NFSMNT_NQNFS | NFSMNT_NFSV3); + mountmode = V3; + nfsargsp->flags |= NFSMNT_NQNFS; break; case 'R': num = strtol(optarg, &p, 10); @@ -564,7 +583,7 @@ getnfsargs(spec, nfsargsp) #endif struct timeval pertry, try; enum clnt_stat clnt_stat; - int so = RPC_ANYSOCK, i, nfsvers, mntvers; + int so = RPC_ANYSOCK, i, nfsvers, mntvers, orgcnt; char *hostp, *delimp; #ifdef NFSKERB char *cp; @@ -645,12 +664,16 @@ getnfsargs(spec, nfsargsp) } #endif /* NFSKERB */ - if (nfsargsp->flags & NFSMNT_NFSV3) { + orgcnt = retrycnt; +tryagain: + if (mountmode == ANY || mountmode == V3) { nfsvers = 3; mntvers = 3; + nfsargsp->flags |= NFSMNT_NFSV3; } else { nfsvers = 2; mntvers = 1; + nfsargsp->flags &= ~NFSMNT_NFSV3; } nfhret.stat = EACCES; /* Mark not yet successful */ while (retrycnt > 0) { @@ -686,6 +709,15 @@ getnfsargs(spec, nfsargsp) clnt_stat = clnt_call(clp, RPCMNT_MOUNT, xdr_dir, spec, xdr_fh, &nfhret, try); if (clnt_stat != RPC_SUCCESS) { + if (clnt_stat == RPC_PROGVERSMISMATCH) { + if (mountmode == ANY) { + mountmode = V2; + goto tryagain; + } else { + errx(1, "%s", + clnt_sperror(clp, "MNT RPC")); + } + } if ((opflags & ISBGRND) == 0) warnx("%s", clnt_sperror(clp, "bad MNT RPC")); @@ -794,7 +826,7 @@ void usage() { (void)fprintf(stderr, "\ -usage: mount_nfs [-3KPTUbcdilqs] [-D deadthresh] [-I readdirsize]\n\ +usage: mount_nfs [-23KPTUbcdilqs] [-D deadthresh] [-I readdirsize]\n\ [-L leaseterm] [-R retrycnt] [-a maxreadahead] [-g maxgroups]\n\ [-m realm] [-o options] [-r readsize] [-t timeout] [-w writesize]\n\ [-x retrans] rhost:path node\n"); |