xref: /titanic_44/usr/src/cmd/fs.d/nfs/umount/umount.c (revision 1ce1951135b81c803c8dcf2f3c756009b1b0170a)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
592373f0aSrica  * Common Development and Distribution License (the "License").
692373f0aSrica  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
21*1ce19511Sth199096 
227c478bd9Sstevel@tonic-gate /*
2392373f0aSrica  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
287c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate /*
317c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
327c478bd9Sstevel@tonic-gate  * The Regents of the University of California
337c478bd9Sstevel@tonic-gate  * All Rights Reserved
347c478bd9Sstevel@tonic-gate  *
357c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
367c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
377c478bd9Sstevel@tonic-gate  * contributors.
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate /*
437c478bd9Sstevel@tonic-gate  * nfs umount
447c478bd9Sstevel@tonic-gate  */
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate #include <stdio.h>
477c478bd9Sstevel@tonic-gate #include <stdlib.h>
487c478bd9Sstevel@tonic-gate #include <string.h>
497c478bd9Sstevel@tonic-gate #include <stdarg.h>
507c478bd9Sstevel@tonic-gate #include <signal.h>
517c478bd9Sstevel@tonic-gate #include <unistd.h>
527c478bd9Sstevel@tonic-gate #include <kstat.h>
537c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
547c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
557c478bd9Sstevel@tonic-gate #include <sys/mount.h>
567c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
577c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
587c478bd9Sstevel@tonic-gate #include <nfs/nfs_clnt.h>
597c478bd9Sstevel@tonic-gate #include <rpcsvc/mount.h>
607c478bd9Sstevel@tonic-gate #include <errno.h>
617c478bd9Sstevel@tonic-gate #include <locale.h>
627c478bd9Sstevel@tonic-gate #include <fslib.h>
637c478bd9Sstevel@tonic-gate #include <priv.h>
6492373f0aSrica #include <tsol/label.h>
657c478bd9Sstevel@tonic-gate #include "replica.h"
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #define	RET_OK	0
687c478bd9Sstevel@tonic-gate #define	RET_ERR	32
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate #ifdef __STDC__
717c478bd9Sstevel@tonic-gate static void pr_err(const char *fmt, ...);
727c478bd9Sstevel@tonic-gate #else
737c478bd9Sstevel@tonic-gate static void pr_err(char *fmt, va_dcl);
747c478bd9Sstevel@tonic-gate #endif
757c478bd9Sstevel@tonic-gate static	void	usage();
767c478bd9Sstevel@tonic-gate static	int	nfs_unmount(char *, int);
777c478bd9Sstevel@tonic-gate static	void	inform_server(char *, char *, bool_t);
787c478bd9Sstevel@tonic-gate static	struct extmnttab *mnttab_find();
79*1ce19511Sth199096 extern int __clnt_bindresvport(CLIENT *);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate static	int is_v4_mount(struct extmnttab *);
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate static char *myname;
847c478bd9Sstevel@tonic-gate static char typename[64];
857c478bd9Sstevel@tonic-gate 
8611606941Sjwahlig int
main(int argc,char * argv[])8711606941Sjwahlig main(int argc, char *argv[])
887c478bd9Sstevel@tonic-gate {
897c478bd9Sstevel@tonic-gate 	extern int optind;
907c478bd9Sstevel@tonic-gate 	int c;
917c478bd9Sstevel@tonic-gate 	int umnt_flag = 0;
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
967c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
977c478bd9Sstevel@tonic-gate #endif
987c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	myname = strrchr(argv[0], '/');
1017c478bd9Sstevel@tonic-gate 	myname = myname ? myname+1 : argv[0];
102*1ce19511Sth199096 	(void) snprintf(typename, sizeof (typename), "nfs %s", myname);
1037c478bd9Sstevel@tonic-gate 	argv[0] = typename;
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	/*
1067c478bd9Sstevel@tonic-gate 	 * Set options
1077c478bd9Sstevel@tonic-gate 	 */
1087c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "f")) != EOF) {
1097c478bd9Sstevel@tonic-gate 		switch (c) {
1107c478bd9Sstevel@tonic-gate 		case 'f':
1117c478bd9Sstevel@tonic-gate 			umnt_flag |= MS_FORCE; /* forced unmount is desired */
1127c478bd9Sstevel@tonic-gate 			break;
1137c478bd9Sstevel@tonic-gate 		default:
1147c478bd9Sstevel@tonic-gate 			usage();
1157c478bd9Sstevel@tonic-gate 			exit(RET_ERR);
1167c478bd9Sstevel@tonic-gate 		}
1177c478bd9Sstevel@tonic-gate 	}
1187c478bd9Sstevel@tonic-gate 	if (argc - optind != 1) {
1197c478bd9Sstevel@tonic-gate 		usage();
1207c478bd9Sstevel@tonic-gate 		exit(RET_ERR);
1217c478bd9Sstevel@tonic-gate 	}
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	if (!priv_ineffect(PRIV_SYS_MOUNT) ||
1247c478bd9Sstevel@tonic-gate 	    !priv_ineffect(PRIV_NET_PRIVADDR)) {
1257c478bd9Sstevel@tonic-gate 		pr_err(gettext("insufficient privileges\n"));
1267c478bd9Sstevel@tonic-gate 		exit(RET_ERR);
1277c478bd9Sstevel@tonic-gate 	}
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	/*
13092373f0aSrica 	 * On a labeled system, a MAC flag may be needed if the mount is
13192373f0aSrica 	 * read-down, so attempt to assert it but ignore errors in any case.
13292373f0aSrica 	 */
13392373f0aSrica 	if (is_system_labeled())
13492373f0aSrica 		(void) setpflags(NET_MAC_AWARE, 1);
13592373f0aSrica 
13692373f0aSrica 	/*
1377c478bd9Sstevel@tonic-gate 	 * exit, really
1387c478bd9Sstevel@tonic-gate 	 */
1397c478bd9Sstevel@tonic-gate 	return (nfs_unmount(argv[optind], umnt_flag));
1407c478bd9Sstevel@tonic-gate }
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate static void
pr_err(const char * fmt,...)1437c478bd9Sstevel@tonic-gate pr_err(const char *fmt, ...)
1447c478bd9Sstevel@tonic-gate {
1457c478bd9Sstevel@tonic-gate 	va_list ap;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	va_start(ap, fmt);
1487c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: ", typename);
1497c478bd9Sstevel@tonic-gate 	(void) vfprintf(stderr, fmt, ap);
1507c478bd9Sstevel@tonic-gate 	(void) fflush(stderr);
1517c478bd9Sstevel@tonic-gate 	va_end(ap);
1527c478bd9Sstevel@tonic-gate }
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate static void
usage()1557c478bd9Sstevel@tonic-gate usage()
1567c478bd9Sstevel@tonic-gate {
1577c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
158*1ce19511Sth199096 	    gettext("Usage: nfs umount [-f] {server:path | dir}\n"));
1597c478bd9Sstevel@tonic-gate 	exit(RET_ERR);
1607c478bd9Sstevel@tonic-gate }
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate static int
nfs_unmount(char * pathname,int umnt_flag)1637c478bd9Sstevel@tonic-gate nfs_unmount(char *pathname, int umnt_flag)
1647c478bd9Sstevel@tonic-gate {
1657c478bd9Sstevel@tonic-gate 	struct extmnttab *mntp;
1667c478bd9Sstevel@tonic-gate 	bool_t quick = FALSE;
1677c478bd9Sstevel@tonic-gate 	int is_v4 = FALSE;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	mntp = mnttab_find(pathname);
1707c478bd9Sstevel@tonic-gate 	if (mntp) {
1717c478bd9Sstevel@tonic-gate 		pathname = mntp->mnt_mountp;
1727c478bd9Sstevel@tonic-gate 	}
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 	if (mntp)
1757c478bd9Sstevel@tonic-gate 		is_v4 = is_v4_mount(mntp);
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	/* Forced unmount will almost always be successful */
1787c478bd9Sstevel@tonic-gate 	if (umount2(pathname, umnt_flag) < 0) {
1797c478bd9Sstevel@tonic-gate 		if (errno == EBUSY) {
1807c478bd9Sstevel@tonic-gate 			pr_err(gettext("%s: is busy\n"), pathname);
1817c478bd9Sstevel@tonic-gate 		} else {
1827c478bd9Sstevel@tonic-gate 			pr_err(gettext("%s: not mounted\n"), pathname);
1837c478bd9Sstevel@tonic-gate 		}
1847c478bd9Sstevel@tonic-gate 		return (RET_ERR);
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	/* All done if it's v4 */
1887c478bd9Sstevel@tonic-gate 	if (is_v4 == TRUE)
1897c478bd9Sstevel@tonic-gate 		return (RET_OK);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/* Inform server quickly in case of forced unmount */
1927c478bd9Sstevel@tonic-gate 	if (umnt_flag & MS_FORCE)
1937c478bd9Sstevel@tonic-gate 		quick = TRUE;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	if (mntp) {
1967c478bd9Sstevel@tonic-gate 		inform_server(mntp->mnt_special, mntp->mnt_mntopts, quick);
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	return (RET_OK);
2007c478bd9Sstevel@tonic-gate }
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  *  Find the mnttab entry that corresponds to "name".
2047c478bd9Sstevel@tonic-gate  *  We're not sure what the name represents: either
2057c478bd9Sstevel@tonic-gate  *  a mountpoint name, or a special name (server:/path).
2067c478bd9Sstevel@tonic-gate  *  Return the last entry in the file that matches.
2077c478bd9Sstevel@tonic-gate  */
2087c478bd9Sstevel@tonic-gate static struct extmnttab *
mnttab_find(dirname)2097c478bd9Sstevel@tonic-gate mnttab_find(dirname)
2107c478bd9Sstevel@tonic-gate 	char *dirname;
2117c478bd9Sstevel@tonic-gate {
2127c478bd9Sstevel@tonic-gate 	FILE *fp;
2137c478bd9Sstevel@tonic-gate 	struct extmnttab mnt;
2147c478bd9Sstevel@tonic-gate 	struct extmnttab *res = NULL;
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate 	fp = fopen(MNTTAB, "r");
2177c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
2187c478bd9Sstevel@tonic-gate 		pr_err("%s: %s\n", MNTTAB, strerror(errno));
2197c478bd9Sstevel@tonic-gate 		return (NULL);
2207c478bd9Sstevel@tonic-gate 	}
2217c478bd9Sstevel@tonic-gate 	while (getextmntent(fp, &mnt, sizeof (struct extmnttab)) == 0) {
2227c478bd9Sstevel@tonic-gate 		if (strcmp(mnt.mnt_mountp, dirname) == 0 ||
2237c478bd9Sstevel@tonic-gate 		    strcmp(mnt.mnt_special, dirname) == 0) {
2247c478bd9Sstevel@tonic-gate 			if (res)
2257c478bd9Sstevel@tonic-gate 				fsfreemnttab(res);
2267c478bd9Sstevel@tonic-gate 			res = fsdupmnttab(&mnt);
2277c478bd9Sstevel@tonic-gate 		}
2287c478bd9Sstevel@tonic-gate 	}
2297c478bd9Sstevel@tonic-gate 
230*1ce19511Sth199096 	(void) fclose(fp);
2317c478bd9Sstevel@tonic-gate 	return (res);
2327c478bd9Sstevel@tonic-gate }
2337c478bd9Sstevel@tonic-gate 
2347c478bd9Sstevel@tonic-gate /*
2357c478bd9Sstevel@tonic-gate  * If quick is TRUE, it will try to inform server quickly
2367c478bd9Sstevel@tonic-gate  * as possible.
2377c478bd9Sstevel@tonic-gate  */
2387c478bd9Sstevel@tonic-gate static void
inform_server(char * string,char * opts,bool_t quick)2397c478bd9Sstevel@tonic-gate inform_server(char *string, char *opts, bool_t quick)
2407c478bd9Sstevel@tonic-gate {
2417c478bd9Sstevel@tonic-gate 	struct timeval timeout;
2427c478bd9Sstevel@tonic-gate 	CLIENT *cl;
2437c478bd9Sstevel@tonic-gate 	enum clnt_stat rpc_stat;
2447c478bd9Sstevel@tonic-gate 	struct replica *list;
2457c478bd9Sstevel@tonic-gate 	int i, n;
2467c478bd9Sstevel@tonic-gate 	char *p = NULL;
2477c478bd9Sstevel@tonic-gate 	static struct timeval create_timeout = {5, 0};
2487c478bd9Sstevel@tonic-gate 	static struct timeval *timep;
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	list = parse_replica(string, &n);
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	if (list == NULL) {
2537c478bd9Sstevel@tonic-gate 		if (n < 0)
2547c478bd9Sstevel@tonic-gate 			pr_err(gettext("%s is not hostname:path format\n"),
2557c478bd9Sstevel@tonic-gate 			    string);
2567c478bd9Sstevel@tonic-gate 		else
2577c478bd9Sstevel@tonic-gate 			pr_err(gettext("no memory\n"));
2587c478bd9Sstevel@tonic-gate 		return;
2597c478bd9Sstevel@tonic-gate 	}
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate 	/*
2627c478bd9Sstevel@tonic-gate 	 * If mounted with -o public, then no need to contact server
2637c478bd9Sstevel@tonic-gate 	 * because mount protocol was not used.
2647c478bd9Sstevel@tonic-gate 	 */
2657c478bd9Sstevel@tonic-gate 	if (opts != NULL)
2667c478bd9Sstevel@tonic-gate 		p = strstr(opts, MNTOPT_PUBLIC);
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	if (p != NULL) {
2697c478bd9Sstevel@tonic-gate 		i = strlen(MNTOPT_PUBLIC);
2707c478bd9Sstevel@tonic-gate 		/*
2717c478bd9Sstevel@tonic-gate 		 * Now make sure the match of "public" isn't a substring
2727c478bd9Sstevel@tonic-gate 		 * of another option.
2737c478bd9Sstevel@tonic-gate 		 */
2747c478bd9Sstevel@tonic-gate 		if (((p == opts) || (*(p-1) == ',')) &&
2757c478bd9Sstevel@tonic-gate 		    ((p[i] == ',') || (p[i] == '\0')))
2767c478bd9Sstevel@tonic-gate 			return;
2777c478bd9Sstevel@tonic-gate 	}
2787c478bd9Sstevel@tonic-gate 
2797c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
2807c478bd9Sstevel@tonic-gate 		int vers;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 		/*
2837c478bd9Sstevel@tonic-gate 		 * Skip file systems mounted using WebNFS, because mount
2847c478bd9Sstevel@tonic-gate 		 * protocol was not used.
2857c478bd9Sstevel@tonic-gate 		 */
2867c478bd9Sstevel@tonic-gate 		if (strcmp(list[i].host, "nfs") == 0 && strncmp(list[i].path,
2877c478bd9Sstevel@tonic-gate 		    "//", 2) == 0)
2887c478bd9Sstevel@tonic-gate 			continue;
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 		vers =  MOUNTVERS;
2917c478bd9Sstevel@tonic-gate retry:
2927c478bd9Sstevel@tonic-gate 		/*
2937c478bd9Sstevel@tonic-gate 		 * Use 5 sec. timeout if file system is forced unmounted,
2947c478bd9Sstevel@tonic-gate 		 * otherwise use default timeout to create a client handle.
2957c478bd9Sstevel@tonic-gate 		 * This would minimize the time to force unmount a file
2967c478bd9Sstevel@tonic-gate 		 * system reside on a server that is down.
2977c478bd9Sstevel@tonic-gate 		 */
2987c478bd9Sstevel@tonic-gate 		timep = (quick ? &create_timeout : NULL);
2997c478bd9Sstevel@tonic-gate 		cl = clnt_create_timed(list[i].host, MOUNTPROG, vers,
3007c478bd9Sstevel@tonic-gate 		    "datagram_n", timep);
3017c478bd9Sstevel@tonic-gate 		/*
3027c478bd9Sstevel@tonic-gate 		 * Do not print any error messages in case of forced
3037c478bd9Sstevel@tonic-gate 		 * unmount.
3047c478bd9Sstevel@tonic-gate 		 */
3057c478bd9Sstevel@tonic-gate 		if (cl == NULL) {
3067c478bd9Sstevel@tonic-gate 			if (!quick)
3077c478bd9Sstevel@tonic-gate 				pr_err("%s:%s %s\n", list[i].host, list[i].path,
3087c478bd9Sstevel@tonic-gate 				    clnt_spcreateerror(
3097c478bd9Sstevel@tonic-gate 				    "server not responding"));
3107c478bd9Sstevel@tonic-gate 			continue;
3117c478bd9Sstevel@tonic-gate 		}
3127c478bd9Sstevel@tonic-gate 		/*
3137c478bd9Sstevel@tonic-gate 		 * Now it is most likely that the NFS client will be able
3147c478bd9Sstevel@tonic-gate 		 * to contact the server since rpcbind is running on
3157c478bd9Sstevel@tonic-gate 		 * the server. There is still a small window in which
3167c478bd9Sstevel@tonic-gate 		 * server can be unreachable.
3177c478bd9Sstevel@tonic-gate 		 */
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 		if (__clnt_bindresvport(cl) < 0) {
3207c478bd9Sstevel@tonic-gate 			if (!quick)
3217c478bd9Sstevel@tonic-gate 				pr_err(gettext(
3227c478bd9Sstevel@tonic-gate 				    "couldn't bind to reserved port\n"));
3237c478bd9Sstevel@tonic-gate 			clnt_destroy(cl);
3247c478bd9Sstevel@tonic-gate 			return;
3257c478bd9Sstevel@tonic-gate 		}
3267c478bd9Sstevel@tonic-gate 		if ((cl->cl_auth = authsys_create_default()) == NULL) {
3277c478bd9Sstevel@tonic-gate 			if (!quick)
3287c478bd9Sstevel@tonic-gate 				pr_err(gettext(
3297c478bd9Sstevel@tonic-gate 				    "couldn't create authsys structure\n"));
3307c478bd9Sstevel@tonic-gate 			clnt_destroy(cl);
3317c478bd9Sstevel@tonic-gate 			return;
3327c478bd9Sstevel@tonic-gate 		}
3337c478bd9Sstevel@tonic-gate 		timeout.tv_usec = 0;
3347c478bd9Sstevel@tonic-gate 		timeout.tv_sec = 5;
3357c478bd9Sstevel@tonic-gate 		clnt_control(cl, CLSET_RETRY_TIMEOUT, (char *)&timeout);
3367c478bd9Sstevel@tonic-gate 		timeout.tv_sec = 25;
3377c478bd9Sstevel@tonic-gate 		rpc_stat = clnt_call(cl, MOUNTPROC_UMNT, xdr_dirpath,
3387c478bd9Sstevel@tonic-gate 		    (char *)&list[i].path, xdr_void, (char *)NULL,
3397c478bd9Sstevel@tonic-gate 		    timeout);
3407c478bd9Sstevel@tonic-gate 		AUTH_DESTROY(cl->cl_auth);
3417c478bd9Sstevel@tonic-gate 		clnt_destroy(cl);
3427c478bd9Sstevel@tonic-gate 		if (rpc_stat == RPC_PROGVERSMISMATCH && vers == MOUNTVERS) {
3437c478bd9Sstevel@tonic-gate 			/*
3447c478bd9Sstevel@tonic-gate 			 * The rare case of a v3-only server
3457c478bd9Sstevel@tonic-gate 			 */
3467c478bd9Sstevel@tonic-gate 			vers = MOUNTVERS3;
3477c478bd9Sstevel@tonic-gate 			goto retry;
3487c478bd9Sstevel@tonic-gate 		}
3497c478bd9Sstevel@tonic-gate 		if (rpc_stat != RPC_SUCCESS)
3507c478bd9Sstevel@tonic-gate 			pr_err("%s\n", clnt_sperror(cl, "unmount"));
3517c478bd9Sstevel@tonic-gate 	}
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 	free_replica(list, n);
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate /*
3577c478bd9Sstevel@tonic-gate  * This function's behavior is taken from nfsstat.
3587c478bd9Sstevel@tonic-gate  * Trying to determine what NFS version was used for the mount.
3597c478bd9Sstevel@tonic-gate  */
3607c478bd9Sstevel@tonic-gate int
is_v4_mount(struct extmnttab * mntp)3617c478bd9Sstevel@tonic-gate is_v4_mount(struct extmnttab *mntp)
3627c478bd9Sstevel@tonic-gate {
3637c478bd9Sstevel@tonic-gate 	kstat_ctl_t *kc = NULL;		/* libkstat cookie */
3647c478bd9Sstevel@tonic-gate 	kstat_t *ksp;
3657c478bd9Sstevel@tonic-gate 	struct mntinfo_kstat mik;
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	if (mntp == NULL)
3687c478bd9Sstevel@tonic-gate 		return (FALSE);
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate 	if ((kc = kstat_open()) == NULL)
3717c478bd9Sstevel@tonic-gate 		return (FALSE);
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate 	for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
3747c478bd9Sstevel@tonic-gate 		if (ksp->ks_type != KSTAT_TYPE_RAW)
3757c478bd9Sstevel@tonic-gate 			continue;
3767c478bd9Sstevel@tonic-gate 		if (strcmp(ksp->ks_module, "nfs") != 0)
3777c478bd9Sstevel@tonic-gate 			continue;
3787c478bd9Sstevel@tonic-gate 		if (strcmp(ksp->ks_name, "mntinfo") != 0)
3797c478bd9Sstevel@tonic-gate 			continue;
3807c478bd9Sstevel@tonic-gate 		if (mntp->mnt_minor != ksp->ks_instance)
3817c478bd9Sstevel@tonic-gate 			continue;
3827c478bd9Sstevel@tonic-gate 
3837c478bd9Sstevel@tonic-gate 		if (kstat_read(kc, ksp, &mik) == -1)
3847c478bd9Sstevel@tonic-gate 			continue;
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 		if (mik.mik_vers == 4)
3877c478bd9Sstevel@tonic-gate 			return (TRUE);
3887c478bd9Sstevel@tonic-gate 		else
3897c478bd9Sstevel@tonic-gate 			return (FALSE);
3907c478bd9Sstevel@tonic-gate 	}
3917c478bd9Sstevel@tonic-gate 	return (FALSE);
3927c478bd9Sstevel@tonic-gate }
393