xref: /illumos-gate/usr/src/cmd/fs.d/nfs/umount/umount.c (revision 2a8bcb4e)
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*1ce19511Sth 
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 /*
417c478bd9Sstevel@tonic-gate  * nfs umount
427c478bd9Sstevel@tonic-gate  */
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate #include <stdio.h>
457c478bd9Sstevel@tonic-gate #include <stdlib.h>
467c478bd9Sstevel@tonic-gate #include <string.h>
477c478bd9Sstevel@tonic-gate #include <stdarg.h>
487c478bd9Sstevel@tonic-gate #include <signal.h>
497c478bd9Sstevel@tonic-gate #include <unistd.h>
507c478bd9Sstevel@tonic-gate #include <kstat.h>
517c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
527c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
537c478bd9Sstevel@tonic-gate #include <sys/mount.h>
547c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
557c478bd9Sstevel@tonic-gate #include <nfs/nfs.h>
567c478bd9Sstevel@tonic-gate #include <nfs/nfs_clnt.h>
577c478bd9Sstevel@tonic-gate #include <rpcsvc/mount.h>
587c478bd9Sstevel@tonic-gate #include <errno.h>
597c478bd9Sstevel@tonic-gate #include <locale.h>
607c478bd9Sstevel@tonic-gate #include <fslib.h>
617c478bd9Sstevel@tonic-gate #include <priv.h>
6292373f0aSrica #include <tsol/label.h>
637c478bd9Sstevel@tonic-gate #include "replica.h"
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate #define	RET_OK	0
667c478bd9Sstevel@tonic-gate #define	RET_ERR	32
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate #ifdef __STDC__
697c478bd9Sstevel@tonic-gate static void pr_err(const char *fmt, ...);
707c478bd9Sstevel@tonic-gate #else
717c478bd9Sstevel@tonic-gate static void pr_err(char *fmt, va_dcl);
727c478bd9Sstevel@tonic-gate #endif
737c478bd9Sstevel@tonic-gate static	void	usage();
747c478bd9Sstevel@tonic-gate static	int	nfs_unmount(char *, int);
757c478bd9Sstevel@tonic-gate static	void	inform_server(char *, char *, bool_t);
767c478bd9Sstevel@tonic-gate static	struct extmnttab *mnttab_find();
77*1ce19511Sth extern int __clnt_bindresvport(CLIENT *);
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate static	int is_v4_mount(struct extmnttab *);
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate static char *myname;
827c478bd9Sstevel@tonic-gate static char typename[64];
837c478bd9Sstevel@tonic-gate 
8411606941Sjwahlig int
main(int argc,char * argv[])8511606941Sjwahlig main(int argc, char *argv[])
867c478bd9Sstevel@tonic-gate {
877c478bd9Sstevel@tonic-gate 	extern int optind;
887c478bd9Sstevel@tonic-gate 	int c;
897c478bd9Sstevel@tonic-gate 	int umnt_flag = 0;
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
947c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"
957c478bd9Sstevel@tonic-gate #endif
967c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	myname = strrchr(argv[0], '/');
997c478bd9Sstevel@tonic-gate 	myname = myname ? myname+1 : argv[0];
100*1ce19511Sth 	(void) snprintf(typename, sizeof (typename), "nfs %s", myname);
1017c478bd9Sstevel@tonic-gate 	argv[0] = typename;
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	/*
1047c478bd9Sstevel@tonic-gate 	 * Set options
1057c478bd9Sstevel@tonic-gate 	 */
1067c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "f")) != EOF) {
1077c478bd9Sstevel@tonic-gate 		switch (c) {
1087c478bd9Sstevel@tonic-gate 		case 'f':
1097c478bd9Sstevel@tonic-gate 			umnt_flag |= MS_FORCE; /* forced unmount is desired */
1107c478bd9Sstevel@tonic-gate 			break;
1117c478bd9Sstevel@tonic-gate 		default:
1127c478bd9Sstevel@tonic-gate 			usage();
1137c478bd9Sstevel@tonic-gate 			exit(RET_ERR);
1147c478bd9Sstevel@tonic-gate 		}
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 	if (argc - optind != 1) {
1177c478bd9Sstevel@tonic-gate 		usage();
1187c478bd9Sstevel@tonic-gate 		exit(RET_ERR);
1197c478bd9Sstevel@tonic-gate 	}
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	if (!priv_ineffect(PRIV_SYS_MOUNT) ||
1227c478bd9Sstevel@tonic-gate 	    !priv_ineffect(PRIV_NET_PRIVADDR)) {
1237c478bd9Sstevel@tonic-gate 		pr_err(gettext("insufficient privileges\n"));
1247c478bd9Sstevel@tonic-gate 		exit(RET_ERR);
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 
12792373f0aSrica 	/*
12892373f0aSrica 	 * On a labeled system, a MAC flag may be needed if the mount is
12992373f0aSrica 	 * read-down, so attempt to assert it but ignore errors in any case.
13092373f0aSrica 	 */
13192373f0aSrica 	if (is_system_labeled())
13292373f0aSrica 		(void) setpflags(NET_MAC_AWARE, 1);
13392373f0aSrica 
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * exit, really
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 	return (nfs_unmount(argv[optind], umnt_flag));
1387c478bd9Sstevel@tonic-gate }
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate static void
pr_err(const char * fmt,...)1417c478bd9Sstevel@tonic-gate pr_err(const char *fmt, ...)
1427c478bd9Sstevel@tonic-gate {
1437c478bd9Sstevel@tonic-gate 	va_list ap;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 	va_start(ap, fmt);
1467c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s: ", typename);
1477c478bd9Sstevel@tonic-gate 	(void) vfprintf(stderr, fmt, ap);
1487c478bd9Sstevel@tonic-gate 	(void) fflush(stderr);
1497c478bd9Sstevel@tonic-gate 	va_end(ap);
1507c478bd9Sstevel@tonic-gate }
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate static void
usage()1537c478bd9Sstevel@tonic-gate usage()
1547c478bd9Sstevel@tonic-gate {
1557c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr,
156*1ce19511Sth 	    gettext("Usage: nfs umount [-f] {server:path | dir}\n"));
1577c478bd9Sstevel@tonic-gate 	exit(RET_ERR);
1587c478bd9Sstevel@tonic-gate }
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate static int
nfs_unmount(char * pathname,int umnt_flag)1617c478bd9Sstevel@tonic-gate nfs_unmount(char *pathname, int umnt_flag)
1627c478bd9Sstevel@tonic-gate {
1637c478bd9Sstevel@tonic-gate 	struct extmnttab *mntp;
1647c478bd9Sstevel@tonic-gate 	bool_t quick = FALSE;
1657c478bd9Sstevel@tonic-gate 	int is_v4 = FALSE;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	mntp = mnttab_find(pathname);
1687c478bd9Sstevel@tonic-gate 	if (mntp) {
1697c478bd9Sstevel@tonic-gate 		pathname = mntp->mnt_mountp;
1707c478bd9Sstevel@tonic-gate 	}
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	if (mntp)
1737c478bd9Sstevel@tonic-gate 		is_v4 = is_v4_mount(mntp);
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate 	/* Forced unmount will almost always be successful */
1767c478bd9Sstevel@tonic-gate 	if (umount2(pathname, umnt_flag) < 0) {
1777c478bd9Sstevel@tonic-gate 		if (errno == EBUSY) {
1787c478bd9Sstevel@tonic-gate 			pr_err(gettext("%s: is busy\n"), pathname);
1797c478bd9Sstevel@tonic-gate 		} else {
1807c478bd9Sstevel@tonic-gate 			pr_err(gettext("%s: not mounted\n"), pathname);
1817c478bd9Sstevel@tonic-gate 		}
1827c478bd9Sstevel@tonic-gate 		return (RET_ERR);
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	/* All done if it's v4 */
1867c478bd9Sstevel@tonic-gate 	if (is_v4 == TRUE)
1877c478bd9Sstevel@tonic-gate 		return (RET_OK);
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	/* Inform server quickly in case of forced unmount */
1907c478bd9Sstevel@tonic-gate 	if (umnt_flag & MS_FORCE)
1917c478bd9Sstevel@tonic-gate 		quick = TRUE;
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 	if (mntp) {
1947c478bd9Sstevel@tonic-gate 		inform_server(mntp->mnt_special, mntp->mnt_mntopts, quick);
1957c478bd9Sstevel@tonic-gate 	}
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	return (RET_OK);
1987c478bd9Sstevel@tonic-gate }
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate /*
2017c478bd9Sstevel@tonic-gate  *  Find the mnttab entry that corresponds to "name".
2027c478bd9Sstevel@tonic-gate  *  We're not sure what the name represents: either
2037c478bd9Sstevel@tonic-gate  *  a mountpoint name, or a special name (server:/path).
2047c478bd9Sstevel@tonic-gate  *  Return the last entry in the file that matches.
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate static struct extmnttab *
mnttab_find(dirname)2077c478bd9Sstevel@tonic-gate mnttab_find(dirname)
2087c478bd9Sstevel@tonic-gate 	char *dirname;
2097c478bd9Sstevel@tonic-gate {
2107c478bd9Sstevel@tonic-gate 	FILE *fp;
2117c478bd9Sstevel@tonic-gate 	struct extmnttab mnt;
2127c478bd9Sstevel@tonic-gate 	struct extmnttab *res = NULL;
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	fp = fopen(MNTTAB, "r");
2157c478bd9Sstevel@tonic-gate 	if (fp == NULL) {
2167c478bd9Sstevel@tonic-gate 		pr_err("%s: %s\n", MNTTAB, strerror(errno));
2177c478bd9Sstevel@tonic-gate 		return (NULL);
2187c478bd9Sstevel@tonic-gate 	}
2197c478bd9Sstevel@tonic-gate 	while (getextmntent(fp, &mnt, sizeof (struct extmnttab)) == 0) {
2207c478bd9Sstevel@tonic-gate 		if (strcmp(mnt.mnt_mountp, dirname) == 0 ||
2217c478bd9Sstevel@tonic-gate 		    strcmp(mnt.mnt_special, dirname) == 0) {
2227c478bd9Sstevel@tonic-gate 			if (res)
2237c478bd9Sstevel@tonic-gate 				fsfreemnttab(res);
2247c478bd9Sstevel@tonic-gate 			res = fsdupmnttab(&mnt);
2257c478bd9Sstevel@tonic-gate 		}
2267c478bd9Sstevel@tonic-gate 	}
2277c478bd9Sstevel@tonic-gate 
228*1ce19511Sth 	(void) fclose(fp);
2297c478bd9Sstevel@tonic-gate 	return (res);
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate  * If quick is TRUE, it will try to inform server quickly
2347c478bd9Sstevel@tonic-gate  * as possible.
2357c478bd9Sstevel@tonic-gate  */
2367c478bd9Sstevel@tonic-gate static void
inform_server(char * string,char * opts,bool_t quick)2377c478bd9Sstevel@tonic-gate inform_server(char *string, char *opts, bool_t quick)
2387c478bd9Sstevel@tonic-gate {
2397c478bd9Sstevel@tonic-gate 	struct timeval timeout;
2407c478bd9Sstevel@tonic-gate 	CLIENT *cl;
2417c478bd9Sstevel@tonic-gate 	enum clnt_stat rpc_stat;
2427c478bd9Sstevel@tonic-gate 	struct replica *list;
2437c478bd9Sstevel@tonic-gate 	int i, n;
2447c478bd9Sstevel@tonic-gate 	char *p = NULL;
2457c478bd9Sstevel@tonic-gate 	static struct timeval create_timeout = {5, 0};
2467c478bd9Sstevel@tonic-gate 	static struct timeval *timep;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	list = parse_replica(string, &n);
2497c478bd9Sstevel@tonic-gate 
2507c478bd9Sstevel@tonic-gate 	if (list == NULL) {
2517c478bd9Sstevel@tonic-gate 		if (n < 0)
2527c478bd9Sstevel@tonic-gate 			pr_err(gettext("%s is not hostname:path format\n"),
253*1ce19511Sth 			    string);
2547c478bd9Sstevel@tonic-gate 		else
2557c478bd9Sstevel@tonic-gate 			pr_err(gettext("no memory\n"));
2567c478bd9Sstevel@tonic-gate 		return;
2577c478bd9Sstevel@tonic-gate 	}
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	/*
2607c478bd9Sstevel@tonic-gate 	 * If mounted with -o public, then no need to contact server
2617c478bd9Sstevel@tonic-gate 	 * because mount protocol was not used.
2627c478bd9Sstevel@tonic-gate 	 */
2637c478bd9Sstevel@tonic-gate 	if (opts != NULL)
2647c478bd9Sstevel@tonic-gate 		p = strstr(opts, MNTOPT_PUBLIC);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate 	if (p != NULL) {
2677c478bd9Sstevel@tonic-gate 		i = strlen(MNTOPT_PUBLIC);
2687c478bd9Sstevel@tonic-gate 		/*
2697c478bd9Sstevel@tonic-gate 		 * Now make sure the match of "public" isn't a substring
2707c478bd9Sstevel@tonic-gate 		 * of another option.
2717c478bd9Sstevel@tonic-gate 		 */
2727c478bd9Sstevel@tonic-gate 		if (((p == opts) || (*(p-1) == ',')) &&
2737c478bd9Sstevel@tonic-gate 		    ((p[i] == ',') || (p[i] == '\0')))
2747c478bd9Sstevel@tonic-gate 			return;
2757c478bd9Sstevel@tonic-gate 	}
2767c478bd9Sstevel@tonic-gate 
2777c478bd9Sstevel@tonic-gate 	for (i = 0; i < n; i++) {
2787c478bd9Sstevel@tonic-gate 		int vers;
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 		/*
2817c478bd9Sstevel@tonic-gate 		 * Skip file systems mounted using WebNFS, because mount
2827c478bd9Sstevel@tonic-gate 		 * protocol was not used.
2837c478bd9Sstevel@tonic-gate 		 */
2847c478bd9Sstevel@tonic-gate 		if (strcmp(list[i].host, "nfs") == 0 && strncmp(list[i].path,
2857c478bd9Sstevel@tonic-gate 		    "//", 2) == 0)
2867c478bd9Sstevel@tonic-gate 			continue;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 		vers =  MOUNTVERS;
2897c478bd9Sstevel@tonic-gate retry:
2907c478bd9Sstevel@tonic-gate 		/*
2917c478bd9Sstevel@tonic-gate 		 * Use 5 sec. timeout if file system is forced unmounted,
2927c478bd9Sstevel@tonic-gate 		 * otherwise use default timeout to create a client handle.
2937c478bd9Sstevel@tonic-gate 		 * This would minimize the time to force unmount a file
2947c478bd9Sstevel@tonic-gate 		 * system reside on a server that is down.
2957c478bd9Sstevel@tonic-gate 		 */
2967c478bd9Sstevel@tonic-gate 		timep = (quick ? &create_timeout : NULL);
2977c478bd9Sstevel@tonic-gate 		cl = clnt_create_timed(list[i].host, MOUNTPROG, vers,
298*1ce19511Sth 		    "datagram_n", timep);
2997c478bd9Sstevel@tonic-gate 		/*
3007c478bd9Sstevel@tonic-gate 		 * Do not print any error messages in case of forced
3017c478bd9Sstevel@tonic-gate 		 * unmount.
3027c478bd9Sstevel@tonic-gate 		 */
3037c478bd9Sstevel@tonic-gate 		if (cl == NULL) {
3047c478bd9Sstevel@tonic-gate 			if (!quick)
3057c478bd9Sstevel@tonic-gate 				pr_err("%s:%s %s\n", list[i].host, list[i].path,
3067c478bd9Sstevel@tonic-gate 				    clnt_spcreateerror(
307*1ce19511Sth 				    "server not responding"));
3087c478bd9Sstevel@tonic-gate 			continue;
3097c478bd9Sstevel@tonic-gate 		}
3107c478bd9Sstevel@tonic-gate 		/*
3117c478bd9Sstevel@tonic-gate 		 * Now it is most likely that the NFS client will be able
3127c478bd9Sstevel@tonic-gate 		 * to contact the server since rpcbind is running on
3137c478bd9Sstevel@tonic-gate 		 * the server. There is still a small window in which
3147c478bd9Sstevel@tonic-gate 		 * server can be unreachable.
3157c478bd9Sstevel@tonic-gate 		 */
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 		if (__clnt_bindresvport(cl) < 0) {
3187c478bd9Sstevel@tonic-gate 			if (!quick)
3197c478bd9Sstevel@tonic-gate 				pr_err(gettext(
3207c478bd9Sstevel@tonic-gate 				    "couldn't bind to reserved port\n"));
3217c478bd9Sstevel@tonic-gate 			clnt_destroy(cl);
3227c478bd9Sstevel@tonic-gate 			return;
3237c478bd9Sstevel@tonic-gate 		}
3247c478bd9Sstevel@tonic-gate 		if ((cl->cl_auth = authsys_create_default()) == NULL) {
3257c478bd9Sstevel@tonic-gate 			if (!quick)
3267c478bd9Sstevel@tonic-gate 				pr_err(gettext(
3277c478bd9Sstevel@tonic-gate 				    "couldn't create authsys structure\n"));
3287c478bd9Sstevel@tonic-gate 			clnt_destroy(cl);
3297c478bd9Sstevel@tonic-gate 			return;
3307c478bd9Sstevel@tonic-gate 		}
3317c478bd9Sstevel@tonic-gate 		timeout.tv_usec = 0;
3327c478bd9Sstevel@tonic-gate 		timeout.tv_sec = 5;
3337c478bd9Sstevel@tonic-gate 		clnt_control(cl, CLSET_RETRY_TIMEOUT, (char *)&timeout);
3347c478bd9Sstevel@tonic-gate 		timeout.tv_sec = 25;
3357c478bd9Sstevel@tonic-gate 		rpc_stat = clnt_call(cl, MOUNTPROC_UMNT, xdr_dirpath,
336*1ce19511Sth 		    (char *)&list[i].path, xdr_void, (char *)NULL,
337*1ce19511Sth 		    timeout);
3387c478bd9Sstevel@tonic-gate 		AUTH_DESTROY(cl->cl_auth);
3397c478bd9Sstevel@tonic-gate 		clnt_destroy(cl);
3407c478bd9Sstevel@tonic-gate 		if (rpc_stat == RPC_PROGVERSMISMATCH && vers == MOUNTVERS) {
3417c478bd9Sstevel@tonic-gate 			/*
3427c478bd9Sstevel@tonic-gate 			 * The rare case of a v3-only server
3437c478bd9Sstevel@tonic-gate 			 */
3447c478bd9Sstevel@tonic-gate 			vers = MOUNTVERS3;
3457c478bd9Sstevel@tonic-gate 			goto retry;
3467c478bd9Sstevel@tonic-gate 		}
3477c478bd9Sstevel@tonic-gate 		if (rpc_stat != RPC_SUCCESS)
3487c478bd9Sstevel@tonic-gate 			pr_err("%s\n", clnt_sperror(cl, "unmount"));
3497c478bd9Sstevel@tonic-gate 	}
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate 	free_replica(list, n);
3527c478bd9Sstevel@tonic-gate }
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate  * This function's behavior is taken from nfsstat.
3567c478bd9Sstevel@tonic-gate  * Trying to determine what NFS version was used for the mount.
3577c478bd9Sstevel@tonic-gate  */
3587c478bd9Sstevel@tonic-gate int
is_v4_mount(struct extmnttab * mntp)3597c478bd9Sstevel@tonic-gate is_v4_mount(struct extmnttab *mntp)
3607c478bd9Sstevel@tonic-gate {
3617c478bd9Sstevel@tonic-gate 	kstat_ctl_t *kc = NULL;		/* libkstat cookie */
3627c478bd9Sstevel@tonic-gate 	kstat_t *ksp;
3637c478bd9Sstevel@tonic-gate 	struct mntinfo_kstat mik;
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 	if (mntp == NULL)
3667c478bd9Sstevel@tonic-gate 		return (FALSE);
3677c478bd9Sstevel@tonic-gate 
3687c478bd9Sstevel@tonic-gate 	if ((kc = kstat_open()) == NULL)
3697c478bd9Sstevel@tonic-gate 		return (FALSE);
3707c478bd9Sstevel@tonic-gate 
3717c478bd9Sstevel@tonic-gate 	for (ksp = kc->kc_chain; ksp; ksp = ksp->ks_next) {
3727c478bd9Sstevel@tonic-gate 		if (ksp->ks_type != KSTAT_TYPE_RAW)
3737c478bd9Sstevel@tonic-gate 			continue;
3747c478bd9Sstevel@tonic-gate 		if (strcmp(ksp->ks_module, "nfs") != 0)
3757c478bd9Sstevel@tonic-gate 			continue;
3767c478bd9Sstevel@tonic-gate 		if (strcmp(ksp->ks_name, "mntinfo") != 0)
3777c478bd9Sstevel@tonic-gate 			continue;
3787c478bd9Sstevel@tonic-gate 		if (mntp->mnt_minor != ksp->ks_instance)
3797c478bd9Sstevel@tonic-gate 			continue;
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate 		if (kstat_read(kc, ksp, &mik) == -1)
3827c478bd9Sstevel@tonic-gate 			continue;
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 		if (mik.mik_vers == 4)
3857c478bd9Sstevel@tonic-gate 			return (TRUE);
3867c478bd9Sstevel@tonic-gate 		else
3877c478bd9Sstevel@tonic-gate 			return (FALSE);
3887c478bd9Sstevel@tonic-gate 	}
3897c478bd9Sstevel@tonic-gate 	return (FALSE);
3907c478bd9Sstevel@tonic-gate }
391