summaryrefslogtreecommitdiffstats
path: root/sbin/mount_nfs/mount_nfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/mount_nfs/mount_nfs.c')
-rw-r--r--sbin/mount_nfs/mount_nfs.c255
1 files changed, 4 insertions, 251 deletions
diff --git a/sbin/mount_nfs/mount_nfs.c b/sbin/mount_nfs/mount_nfs.c
index a2f5e89..102c51d 100644
--- a/sbin/mount_nfs/mount_nfs.c
+++ b/sbin/mount_nfs/mount_nfs.c
@@ -1,28 +1,4 @@
/*
- * copyright (c) 2003
- * the regents of the university of michigan
- * all rights reserved
- *
- * permission is granted to use, copy, create derivative works and redistribute
- * this software and such derivative works for any purpose, so long as the name
- * of the university of michigan is not used in any advertising or publicity
- * pertaining to the use or distribution of this software without specific,
- * written prior authorization. if the above copyright notice or any other
- * identification of the university of michigan is included in any copy of any
- * portion of this software, then the disclaimer below must also be included.
- *
- * this software is provided as is, without representation from the university
- * of michigan as to its fitness for any purpose, and without warranty by the
- * university of michigan of any kind, either express or implied, including
- * without limitation the implied warranties of merchantability and fitness for
- * a particular purpose. the regents of the university of michigan shall not be
- * liable for any damages, including special, indirect, incidental, or
- * consequential damages, with respect to any claim arising out of or in
- * connection with the use of the software, even if it has been or is hereafter
- * advised of the possibility of such damages.
- */
-
-/*
* Copyright (c) 1992, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
@@ -140,7 +116,6 @@ enum mountmode {
ANY,
V2,
V3,
- V4
} mountmode = ANY;
/* Return codes for nfs_tryproto. */
@@ -155,7 +130,6 @@ int fallback_mount(struct iovec *iov, int iovlen, int mntflags);
int sec_name_to_num(char *sec);
char *sec_num_to_name(int num);
int getnfsargs(char *, struct iovec **iov, int *iovlen);
-int getnfs4args(char *, struct iovec **iov, int *iovlen);
/* void set_rpc_maxgrouplist(int); */
struct netconfig *getnetconf_cached(const char *netid);
const char *netidbytype(int af, int sotype);
@@ -164,8 +138,6 @@ int xdr_dir(XDR *, char *);
int xdr_fh(XDR *, struct nfhret *);
enum tryret nfs_tryproto(struct addrinfo *ai, char *hostp, char *spec,
char **errstr, struct iovec **iov, int *iovlen);
-enum tryret nfs4_tryproto(struct addrinfo *ai, char *hostp, char *spec,
- char **errstr);
enum tryret returncode(enum clnt_stat stat, struct rpc_err *rpcerr);
extern int getosreldate(void);
@@ -190,15 +162,8 @@ main(int argc, char *argv[])
++fstype;
- if (strcmp(fstype, "nfs4") == 0) {
- nfsproto = IPPROTO_TCP;
- portspec = "2049";
- build_iovec(&iov, &iovlen, "tcp", NULL, 0);
- mountmode = V4;
- }
-
while ((c = getopt(argc, argv,
- "234a:bcdD:g:I:iLlNo:PR:r:sTt:w:x:U")) != -1)
+ "23a:bcdD:g:I:iLlNo:PR:r:sTt:w:x:U")) != -1)
switch (c) {
case '2':
mountmode = V2;
@@ -206,10 +171,6 @@ main(int argc, char *argv[])
case '3':
mountmode = V3;
break;
- case '4':
- mountmode = V4;
- fstype = "nfs4";
- break;
case 'a':
printf("-a deprecated, use -o readhead=<value>\n");
build_iovec(&iov, &iovlen, "readahead", optarg, (size_t)-1);
@@ -301,10 +262,6 @@ main(int argc, char *argv[])
mountmode = V2;
} else if (strcmp(opt, "nfsv3") == 0) {
mountmode = V3;
- } else if (strcmp(opt, "nfsv4") == 0) {
- pass_flag_to_nmount=0;
- mountmode = V4;
- fstype = "nfs4";
} else if (strcmp(opt, "port") == 0) {
pass_flag_to_nmount=0;
asprintf(&portspec, "%d",
@@ -406,13 +363,8 @@ main(int argc, char *argv[])
/* The default is to keep retrying forever. */
retrycnt = 0;
- if (mountmode == V4) {
- if (!getnfs4args(spec, &iov, &iovlen))
- exit(1);
- } else {
- if (!getnfsargs(spec, &iov, &iovlen))
- exit(1);
- }
+ if (!getnfsargs(spec, &iov, &iovlen))
+ exit(1);
/* resolve the mountpoint with realpath(3) */
(void)checkpath(name, mntpath);
@@ -814,129 +766,6 @@ getnfsargs(char *spec, struct iovec **iov, int *iovlen)
return (1);
}
-
-int
-getnfs4args(char *spec, struct iovec **iov, int *iovlen)
-{
- struct addrinfo hints, *ai_nfs, *ai;
- enum tryret ret;
- int ecode, speclen, remoteerr, sotype;
- char *hostp, *delimp, *errstr;
- size_t len;
- static char nam[MNAMELEN + 1];
-
- if (nfsproto == IPPROTO_TCP)
- sotype = SOCK_STREAM;
- else if (nfsproto == IPPROTO_UDP)
- sotype = SOCK_DGRAM;
-
-
- if ((delimp = strrchr(spec, ':')) != NULL) {
- hostp = spec;
- spec = delimp + 1;
- } else if ((delimp = strrchr(spec, '@')) != NULL) {
- warnx("path@server syntax is deprecated, use server:path");
- hostp = delimp + 1;
- } else {
- warnx("no <host>:<dirpath> nfs-name");
- return (0);
- }
- *delimp = '\0';
-
- /*
- * If there has been a trailing slash at mounttime it seems
- * that some mountd implementations fail to remove the mount
- * entries from their mountlist while unmounting.
- */
- for (speclen = strlen(spec);
- speclen > 1 && spec[speclen - 1] == '/';
- speclen--)
- spec[speclen - 1] = '\0';
- if (strlen(hostp) + strlen(spec) + 1 > MNAMELEN) {
- warnx("%s:%s: %s", hostp, spec, strerror(ENAMETOOLONG));
- return (0);
- }
- /* Make both '@' and ':' notations equal */
- if (*hostp != '\0') {
- len = strlen(hostp);
- memmove(nam, hostp, len);
- nam[len] = ':';
- memmove(nam + len + 1, spec, speclen);
- nam[len + speclen + 1] = '\0';
- }
-
- /*
- * Handle an internet host address.
- */
- memset(&hints, 0, sizeof hints);
- hints.ai_flags = AI_NUMERICHOST;
- hints.ai_socktype = sotype;
- if (getaddrinfo(hostp, portspec, &hints, &ai_nfs) != 0) {
- hints.ai_flags = 0;
- if ((ecode = getaddrinfo(hostp, portspec, &hints, &ai_nfs))
- != 0) {
- if (portspec == NULL)
- errx(1, "%s: %s", hostp, gai_strerror(ecode));
- else
- errx(1, "%s:%s: %s", hostp, portspec,
- gai_strerror(ecode));
- return (0);
- }
- }
-
- ret = TRYRET_LOCALERR;
- for (;;) {
- /*
- * Try each entry returned by getaddrinfo(). Note the
- * occurence of remote errors by setting `remoteerr'.
- */
- remoteerr = 0;
- for (ai = ai_nfs; ai != NULL; ai = ai->ai_next) {
- if ((ai->ai_family == AF_INET6) &&
- (opflags & OF_NOINET6))
- continue;
- if ((ai->ai_family == AF_INET) &&
- (opflags & OF_NOINET4))
- continue;
- ret = nfs4_tryproto(ai, hostp, spec, &errstr);
- if (ret == TRYRET_SUCCESS)
- break;
- if (ret != TRYRET_LOCALERR)
- remoteerr = 1;
- if ((opflags & ISBGRND) == 0)
- fprintf(stderr, "%s\n", errstr);
- }
- if (ret == TRYRET_SUCCESS)
- break;
-
- /* Exit if all errors were local. */
- if (!remoteerr)
- exit(1);
-
- /*
- * If retrycnt == 0, we are to keep retrying forever.
- * Otherwise decrement it, and exit if it hits zero.
- */
- if (retrycnt != 0 && --retrycnt == 0)
- exit(1);
-
- if ((opflags & (BGRND | ISBGRND)) == BGRND) {
- warnx("Cannot immediately mount %s:%s, backgrounding",
- hostp, spec);
- opflags |= ISBGRND;
- if (daemon(0, 0) != 0)
- err(1, "daemon");
- }
- sleep(60);
- }
- freeaddrinfo(ai_nfs);
- build_iovec(iov, iovlen, "hostname", nam, (size_t)-1);
- /* Add mounted file system to PATH_MOUNTTAB */
- if (!add_mtab(hostp, spec))
- warnx("can't update %s for %s:%s", PATH_MOUNTTAB, hostp, spec);
- return (1);
-}
-
/*
* Try to set up the NFS arguments according to the address
* family, protocol (and possibly port) specified in `ai'.
@@ -1142,82 +971,6 @@ tryagain:
return (TRYRET_SUCCESS);
}
-
-/*
- * Try to set up the NFS arguments according to the address
- * family, protocol (and possibly port) specified in `ai'.
- *
- * Returns TRYRET_SUCCESS if successful, or:
- * TRYRET_TIMEOUT The server did not respond.
- * TRYRET_REMOTEERR The server reported an error.
- * TRYRET_LOCALERR Local failure.
- *
- * In all error cases, *errstr will be set to a statically-allocated string
- * describing the error.
- */
-enum tryret
-nfs4_tryproto(struct addrinfo *ai, char *hostp, char *spec, char **errstr)
-{
- static char errbuf[256];
- struct sockaddr_storage nfs_ss;
- struct netbuf nfs_nb;
- struct netconfig *nconf;
- const char *netid;
- int nfsvers, sotype;
-
- errbuf[0] = '\0';
- *errstr = errbuf;
-
- if (nfsproto == IPPROTO_TCP)
- sotype = SOCK_STREAM;
- else if (nfsproto == IPPROTO_UDP)
- sotype = SOCK_DGRAM;
-
- if ((netid = netidbytype(ai->ai_family, sotype)) == NULL) {
- snprintf(errbuf, sizeof errbuf,
- "af %d sotype %d not supported", ai->ai_family, sotype);
- return (TRYRET_LOCALERR);
- }
- if ((nconf = getnetconf_cached(netid)) == NULL) {
- snprintf(errbuf, sizeof errbuf, "%s: %s", netid, nc_sperror());
- return (TRYRET_LOCALERR);
- }
-
- nfsvers = 4;
-
- if (portspec != NULL && atoi(portspec) != 0) {
- /* `ai' contains the complete nfsd sockaddr. */
- nfs_nb.buf = ai->ai_addr;
- nfs_nb.len = nfs_nb.maxlen = ai->ai_addrlen;
- } else {
- /* Ask the remote rpcbind. */
- nfs_nb.buf = &nfs_ss;
- nfs_nb.len = nfs_nb.maxlen = sizeof nfs_ss;
-
- if (!rpcb_getaddr(RPCPROG_NFS, nfsvers, nconf, &nfs_nb,
- hostp)) {
- snprintf(errbuf, sizeof errbuf, "[%s] %s:%s: %s",
- netid, hostp, spec,
- clnt_spcreateerror("RPCPROG_NFS"));
- return (returncode(rpc_createerr.cf_stat,
- &rpc_createerr.cf_error));
- }
- }
-
- /*
- * Store the filehandle and server address in nfsargsp, making
- * sure to copy any locally allocated structures.
- */
- addrlen = nfs_nb.len;
- addr = malloc(addrlen);
-
- if (addr == NULL)
- err(1, "malloc");
- bcopy(nfs_nb.buf, addr, addrlen);
-
- return (TRYRET_SUCCESS);
-}
-
/*
* Catagorise a RPC return status and error into an `enum tryret'
* return code.
@@ -1361,7 +1114,7 @@ void
usage()
{
(void)fprintf(stderr, "%s\n%s\n%s\n%s\n",
-"usage: mount_nfs [-234bcdiLlNPsTU] [-a maxreadahead] [-D deadthresh]",
+"usage: mount_nfs [-23bcdiLlNPsTU] [-a maxreadahead] [-D deadthresh]",
" [-g maxgroups] [-I readdirsize] [-o options] [-R retrycnt]",
" [-r readsize] [-t timeout] [-w writesize] [-x retrans]",
" rhost:path node");
OpenPOWER on IntegriCloud