xref: /titanic_44/usr/src/cmd/fs.d/cachefs/umount/umount.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * -----------------------------------------------------------------
24*7c478bd9Sstevel@tonic-gate  *
25*7c478bd9Sstevel@tonic-gate  *			umount.c
26*7c478bd9Sstevel@tonic-gate  *
27*7c478bd9Sstevel@tonic-gate  * CFS specific umount command.
28*7c478bd9Sstevel@tonic-gate  */
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate /*
33*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
34*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
35*7c478bd9Sstevel@tonic-gate  */
36*7c478bd9Sstevel@tonic-gate 
37*7c478bd9Sstevel@tonic-gate #include <locale.h>
38*7c478bd9Sstevel@tonic-gate #include <stdio.h>
39*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
40*7c478bd9Sstevel@tonic-gate #include <string.h>
41*7c478bd9Sstevel@tonic-gate #include <stdarg.h>
42*7c478bd9Sstevel@tonic-gate #include <unistd.h>
43*7c478bd9Sstevel@tonic-gate #include <limits.h>
44*7c478bd9Sstevel@tonic-gate #include <errno.h>
45*7c478bd9Sstevel@tonic-gate #include <wait.h>
46*7c478bd9Sstevel@tonic-gate #include <ctype.h>
47*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
48*7c478bd9Sstevel@tonic-gate #include <signal.h>
49*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
50*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
51*7c478bd9Sstevel@tonic-gate #include <sys/stat.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/fcntl.h>
53*7c478bd9Sstevel@tonic-gate #include <sys/mount.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
55*7c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
56*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
57*7c478bd9Sstevel@tonic-gate #include <fslib.h>
58*7c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
59*7c478bd9Sstevel@tonic-gate #include <rpc/rpc.h>
60*7c478bd9Sstevel@tonic-gate #include "../common/subr.h"
61*7c478bd9Sstevel@tonic-gate #include "../common/cachefsd.h"
62*7c478bd9Sstevel@tonic-gate 
63*7c478bd9Sstevel@tonic-gate /* forward references */
64*7c478bd9Sstevel@tonic-gate void pr_err(char *fmt, ...);
65*7c478bd9Sstevel@tonic-gate void usage(char *msgp);
66*7c478bd9Sstevel@tonic-gate int daemon_unmount(char *mntptp, int);
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate /*
69*7c478bd9Sstevel@tonic-gate  *
70*7c478bd9Sstevel@tonic-gate  *			main
71*7c478bd9Sstevel@tonic-gate  *
72*7c478bd9Sstevel@tonic-gate  * Description:
73*7c478bd9Sstevel@tonic-gate  *	Main routine for the cfs umount program.
74*7c478bd9Sstevel@tonic-gate  * Arguments:
75*7c478bd9Sstevel@tonic-gate  *	argc	number of command line arguments
76*7c478bd9Sstevel@tonic-gate  *	argv	list of command line arguments
77*7c478bd9Sstevel@tonic-gate  * Returns:
78*7c478bd9Sstevel@tonic-gate  *	Returns 0 for success or 1 if an error occurs.
79*7c478bd9Sstevel@tonic-gate  * Preconditions:
80*7c478bd9Sstevel@tonic-gate  */
81*7c478bd9Sstevel@tonic-gate 
82*7c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)83*7c478bd9Sstevel@tonic-gate main(int argc, char **argv)
84*7c478bd9Sstevel@tonic-gate {
85*7c478bd9Sstevel@tonic-gate 	char *strp;
86*7c478bd9Sstevel@tonic-gate 	int xx;
87*7c478bd9Sstevel@tonic-gate 	int ret;
88*7c478bd9Sstevel@tonic-gate 	struct mnttab mget;
89*7c478bd9Sstevel@tonic-gate 	struct mnttab mref;
90*7c478bd9Sstevel@tonic-gate 	FILE *finp;
91*7c478bd9Sstevel@tonic-gate 	char mnt_front[PATH_MAX];
92*7c478bd9Sstevel@tonic-gate 	char mnt_back[PATH_MAX];
93*7c478bd9Sstevel@tonic-gate 	char *p, mnt_frontns[PATH_MAX];
94*7c478bd9Sstevel@tonic-gate 	pid_t pid;
95*7c478bd9Sstevel@tonic-gate 	int stat_loc;
96*7c478bd9Sstevel@tonic-gate 	char *cachedirp, *s;
97*7c478bd9Sstevel@tonic-gate 	int ufd, c;
98*7c478bd9Sstevel@tonic-gate 	int flag = 0;
99*7c478bd9Sstevel@tonic-gate 
100*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
101*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)
102*7c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN	"SYS_TEST"
103*7c478bd9Sstevel@tonic-gate #endif
104*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
105*7c478bd9Sstevel@tonic-gate 
106*7c478bd9Sstevel@tonic-gate 	/*
107*7c478bd9Sstevel@tonic-gate 	 * Set options
108*7c478bd9Sstevel@tonic-gate 	 */
109*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "f")) != EOF) {
110*7c478bd9Sstevel@tonic-gate 		switch (c) {
111*7c478bd9Sstevel@tonic-gate 		case 'f':
112*7c478bd9Sstevel@tonic-gate 			flag |= MS_FORCE; /* forced unmount is desired */
113*7c478bd9Sstevel@tonic-gate 			break;
114*7c478bd9Sstevel@tonic-gate 		default:
115*7c478bd9Sstevel@tonic-gate 			usage("Incorrect number of arguments specified");
116*7c478bd9Sstevel@tonic-gate 			return (1);
117*7c478bd9Sstevel@tonic-gate 		}
118*7c478bd9Sstevel@tonic-gate 	}
119*7c478bd9Sstevel@tonic-gate 	if (flag & MS_FORCE)
120*7c478bd9Sstevel@tonic-gate 		strcpy(mnt_front, argv[2]);
121*7c478bd9Sstevel@tonic-gate 	else
122*7c478bd9Sstevel@tonic-gate 		strcpy(mnt_front, argv[1]);
123*7c478bd9Sstevel@tonic-gate 	mnt_back[0] = '\0';
124*7c478bd9Sstevel@tonic-gate 
125*7c478bd9Sstevel@tonic-gate 	if (strlen(argv[1]) >= (size_t)PATH_MAX) {
126*7c478bd9Sstevel@tonic-gate 		pr_err(gettext("name too long"));
127*7c478bd9Sstevel@tonic-gate 		return (1);
128*7c478bd9Sstevel@tonic-gate 	}
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	/*
131*7c478bd9Sstevel@tonic-gate 	 * An unmount from autofs may have a
132*7c478bd9Sstevel@tonic-gate 	 * space appended to the path.
133*7c478bd9Sstevel@tonic-gate 	 * Trim it off before attempting to
134*7c478bd9Sstevel@tonic-gate 	 * match the mountpoint in mnttab
135*7c478bd9Sstevel@tonic-gate 	 */
136*7c478bd9Sstevel@tonic-gate 	strcpy(mnt_frontns, mnt_front);
137*7c478bd9Sstevel@tonic-gate 	p = &mnt_frontns[strlen(mnt_frontns) - 1];
138*7c478bd9Sstevel@tonic-gate 	if (*p == ' ')
139*7c478bd9Sstevel@tonic-gate 		*p = '\0';
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate 	/* get the mount point and the back file system mount point */
142*7c478bd9Sstevel@tonic-gate 	finp = fopen(MNTTAB, "r");
143*7c478bd9Sstevel@tonic-gate 	if (finp) {
144*7c478bd9Sstevel@tonic-gate 		mntnull(&mref);
145*7c478bd9Sstevel@tonic-gate 		mref.mnt_mountp = mnt_frontns;
146*7c478bd9Sstevel@tonic-gate 		mref.mnt_fstype = "cachefs";
147*7c478bd9Sstevel@tonic-gate 		ret = getmntany(finp, &mget, &mref);
148*7c478bd9Sstevel@tonic-gate 
149*7c478bd9Sstevel@tonic-gate 		cachedirp = (char *)malloc(strlen(mget.mnt_special) + 1);
150*7c478bd9Sstevel@tonic-gate 		strcpy(cachedirp, mget.mnt_special);
151*7c478bd9Sstevel@tonic-gate 		/*
152*7c478bd9Sstevel@tonic-gate 		 * AutoClient mounts do not have .cfs_mnt_points string in
153*7c478bd9Sstevel@tonic-gate 		 * them, so strstr would return NULL. So .cfs_unmnt file
154*7c478bd9Sstevel@tonic-gate 		 * is not updated.
155*7c478bd9Sstevel@tonic-gate 		 */
156*7c478bd9Sstevel@tonic-gate 		if ((s = strstr(cachedirp, ".cfs_mnt_points")) != NULL) {
157*7c478bd9Sstevel@tonic-gate 			time32_t btime;
158*7c478bd9Sstevel@tonic-gate 
159*7c478bd9Sstevel@tonic-gate 			xx = -1;
160*7c478bd9Sstevel@tonic-gate 			cachedirp[s-cachedirp] = '\0';
161*7c478bd9Sstevel@tonic-gate 			strcat(cachedirp, CACHEFS_UNMNT_FILE);
162*7c478bd9Sstevel@tonic-gate 			if ((ufd = open(cachedirp, O_WRONLY|O_CREAT|O_TRUNC,
163*7c478bd9Sstevel@tonic-gate 					0600)) > 0) {
164*7c478bd9Sstevel@tonic-gate 				if ((btime = get_boottime()) != -1)
165*7c478bd9Sstevel@tonic-gate 				    xx = write(ufd, &btime, sizeof (time32_t));
166*7c478bd9Sstevel@tonic-gate 				close(ufd);
167*7c478bd9Sstevel@tonic-gate 			}
168*7c478bd9Sstevel@tonic-gate 			if (xx < 0)
169*7c478bd9Sstevel@tonic-gate 				pr_err(gettext(".cfs_unmnt error"));
170*7c478bd9Sstevel@tonic-gate 		}
171*7c478bd9Sstevel@tonic-gate 
172*7c478bd9Sstevel@tonic-gate 		if (ret != -1) {
173*7c478bd9Sstevel@tonic-gate 			if (mget.mnt_special)
174*7c478bd9Sstevel@tonic-gate 				strcpy(mnt_back, mget.mnt_special);
175*7c478bd9Sstevel@tonic-gate 		} else {
176*7c478bd9Sstevel@tonic-gate 			mref.mnt_special = mref.mnt_mountp;
177*7c478bd9Sstevel@tonic-gate 			mref.mnt_mountp = NULL;
178*7c478bd9Sstevel@tonic-gate 			rewind(finp);
179*7c478bd9Sstevel@tonic-gate 			ret = getmntany(finp, &mget, &mref);
180*7c478bd9Sstevel@tonic-gate 			if (ret != -1) {
181*7c478bd9Sstevel@tonic-gate 				strcpy(mnt_front, mget.mnt_mountp);
182*7c478bd9Sstevel@tonic-gate 				if (mget.mnt_special)
183*7c478bd9Sstevel@tonic-gate 					strcpy(mnt_back, mget.mnt_special);
184*7c478bd9Sstevel@tonic-gate 			} else {
185*7c478bd9Sstevel@tonic-gate 				pr_err(gettext("warning: %s not in mnttab"),
186*7c478bd9Sstevel@tonic-gate 				    mref.mnt_special);
187*7c478bd9Sstevel@tonic-gate 			}
188*7c478bd9Sstevel@tonic-gate 		}
189*7c478bd9Sstevel@tonic-gate 		fclose(finp);
190*7c478bd9Sstevel@tonic-gate 	}
191*7c478bd9Sstevel@tonic-gate 
192*7c478bd9Sstevel@tonic-gate 	/* try to get the daemon to unmount this file system for us */
193*7c478bd9Sstevel@tonic-gate 	xx = daemon_unmount(mnt_front, flag);
194*7c478bd9Sstevel@tonic-gate 	if (xx == ENOTSUP)
195*7c478bd9Sstevel@tonic-gate 		return (1);
196*7c478bd9Sstevel@tonic-gate 	if (xx == EBUSY) {
197*7c478bd9Sstevel@tonic-gate 		pr_err(gettext("%s %s"), mnt_front, strerror(xx));
198*7c478bd9Sstevel@tonic-gate 		return (1);
199*7c478bd9Sstevel@tonic-gate 	}
200*7c478bd9Sstevel@tonic-gate 	if (xx == EIO) {
201*7c478bd9Sstevel@tonic-gate 		/* try to unmount the file system directly */
202*7c478bd9Sstevel@tonic-gate 		if (umount2(mnt_front, flag) == -1) {
203*7c478bd9Sstevel@tonic-gate 			pr_err(gettext("%s %s"), mnt_front, strerror(errno));
204*7c478bd9Sstevel@tonic-gate 			return (1);
205*7c478bd9Sstevel@tonic-gate 		}
206*7c478bd9Sstevel@tonic-gate 	}
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate 	/* if we do not know the name of the back file system mount point */
209*7c478bd9Sstevel@tonic-gate 	if (mnt_back[0] == '\0') {
210*7c478bd9Sstevel@tonic-gate 		/* all done */
211*7c478bd9Sstevel@tonic-gate 		return (0);
212*7c478bd9Sstevel@tonic-gate 	}
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate 	/*
215*7c478bd9Sstevel@tonic-gate 	 * If the back file system was mounted on a directory with a
216*7c478bd9Sstevel@tonic-gate 	 * parent name of BACKMNT_NAME then we assume that we
217*7c478bd9Sstevel@tonic-gate 	 * mounted it and that it is okay to try to umount it.
218*7c478bd9Sstevel@tonic-gate 	 */
219*7c478bd9Sstevel@tonic-gate 	if (strstr(mnt_back, BACKMNT_NAME) == NULL)
220*7c478bd9Sstevel@tonic-gate 		return (0);
221*7c478bd9Sstevel@tonic-gate 
222*7c478bd9Sstevel@tonic-gate 	/* if no back file system mounted */
223*7c478bd9Sstevel@tonic-gate 	if (strcmp(mnt_back, "nobackfs") == 0)
224*7c478bd9Sstevel@tonic-gate 		return (0);
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate 	/* fork */
227*7c478bd9Sstevel@tonic-gate 	if ((pid = fork()) == -1) {
228*7c478bd9Sstevel@tonic-gate 		pr_err(gettext("could not fork %s"), strerror(errno));
229*7c478bd9Sstevel@tonic-gate 		return (1);
230*7c478bd9Sstevel@tonic-gate 	}
231*7c478bd9Sstevel@tonic-gate 
232*7c478bd9Sstevel@tonic-gate 	/* if the child */
233*7c478bd9Sstevel@tonic-gate 	if (pid == 0) {
234*7c478bd9Sstevel@tonic-gate 		/* invoke the umount command on the back file system */
235*7c478bd9Sstevel@tonic-gate 		xx = execl("/sbin/umount", "/sbin/umount", mnt_back, NULL);
236*7c478bd9Sstevel@tonic-gate 		pr_err(gettext("could not exec /sbin/umount"
237*7c478bd9Sstevel@tonic-gate 		    " on back file system %s"), strerror(errno));
238*7c478bd9Sstevel@tonic-gate 	}
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate 	/* else if the parent */
241*7c478bd9Sstevel@tonic-gate 	else {
242*7c478bd9Sstevel@tonic-gate 		/* wait for the child to exit */
243*7c478bd9Sstevel@tonic-gate 		if (wait(&stat_loc) == -1) {
244*7c478bd9Sstevel@tonic-gate 			pr_err(gettext("wait failed %s"), strerror(errno));
245*7c478bd9Sstevel@tonic-gate 			return (1);
246*7c478bd9Sstevel@tonic-gate 		}
247*7c478bd9Sstevel@tonic-gate 
248*7c478bd9Sstevel@tonic-gate 		if (!WIFEXITED(stat_loc)) {
249*7c478bd9Sstevel@tonic-gate 			pr_err(gettext("back umount did not exit"));
250*7c478bd9Sstevel@tonic-gate 			return (1);
251*7c478bd9Sstevel@tonic-gate 		}
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 		xx = WEXITSTATUS(stat_loc);
254*7c478bd9Sstevel@tonic-gate 		if (xx) {
255*7c478bd9Sstevel@tonic-gate 			pr_err(gettext("back umount failed"));
256*7c478bd9Sstevel@tonic-gate 			return (xx);
257*7c478bd9Sstevel@tonic-gate 		}
258*7c478bd9Sstevel@tonic-gate 	}
259*7c478bd9Sstevel@tonic-gate 
260*7c478bd9Sstevel@tonic-gate 	/* delete the back file system mount point since we created it */
261*7c478bd9Sstevel@tonic-gate 	rmdir(mnt_back);
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate 	return (xx);
264*7c478bd9Sstevel@tonic-gate }
265*7c478bd9Sstevel@tonic-gate 
266*7c478bd9Sstevel@tonic-gate /*
267*7c478bd9Sstevel@tonic-gate  *
268*7c478bd9Sstevel@tonic-gate  *			pr_err
269*7c478bd9Sstevel@tonic-gate  *
270*7c478bd9Sstevel@tonic-gate  * Description:
271*7c478bd9Sstevel@tonic-gate  *	Prints an error message to stderr.
272*7c478bd9Sstevel@tonic-gate  * Arguments:
273*7c478bd9Sstevel@tonic-gate  *	fmt	printf style format
274*7c478bd9Sstevel@tonic-gate  *	...	arguments for fmt
275*7c478bd9Sstevel@tonic-gate  * Returns:
276*7c478bd9Sstevel@tonic-gate  * Preconditions:
277*7c478bd9Sstevel@tonic-gate  *	precond(fmt)
278*7c478bd9Sstevel@tonic-gate  */
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate void
pr_err(char * fmt,...)281*7c478bd9Sstevel@tonic-gate pr_err(char *fmt, ...)
282*7c478bd9Sstevel@tonic-gate {
283*7c478bd9Sstevel@tonic-gate 	va_list ap;
284*7c478bd9Sstevel@tonic-gate 
285*7c478bd9Sstevel@tonic-gate 	va_start(ap, fmt);
286*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("umount -F cachefs: "));
287*7c478bd9Sstevel@tonic-gate 	(void) vfprintf(stderr, fmt, ap);
288*7c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "\n");
289*7c478bd9Sstevel@tonic-gate 	va_end(ap);
290*7c478bd9Sstevel@tonic-gate }
291*7c478bd9Sstevel@tonic-gate 
292*7c478bd9Sstevel@tonic-gate /*
293*7c478bd9Sstevel@tonic-gate  *
294*7c478bd9Sstevel@tonic-gate  *			usage
295*7c478bd9Sstevel@tonic-gate  *
296*7c478bd9Sstevel@tonic-gate  * Description:
297*7c478bd9Sstevel@tonic-gate  *	Prints a usage message.
298*7c478bd9Sstevel@tonic-gate  * Arguments:
299*7c478bd9Sstevel@tonic-gate  *	An optional additional message to be displayed.
300*7c478bd9Sstevel@tonic-gate  * Returns:
301*7c478bd9Sstevel@tonic-gate  * Preconditions:
302*7c478bd9Sstevel@tonic-gate  */
303*7c478bd9Sstevel@tonic-gate 
304*7c478bd9Sstevel@tonic-gate void
usage(char * msgp)305*7c478bd9Sstevel@tonic-gate usage(char *msgp)
306*7c478bd9Sstevel@tonic-gate {
307*7c478bd9Sstevel@tonic-gate 	if (msgp)
308*7c478bd9Sstevel@tonic-gate 		pr_err(gettext("%s"), msgp);
309*7c478bd9Sstevel@tonic-gate 	fprintf(stderr, gettext("Usage: umount -F cachefs dir"));
310*7c478bd9Sstevel@tonic-gate }
311*7c478bd9Sstevel@tonic-gate 
312*7c478bd9Sstevel@tonic-gate /*
313*7c478bd9Sstevel@tonic-gate  *
314*7c478bd9Sstevel@tonic-gate  *			daemon_unmount
315*7c478bd9Sstevel@tonic-gate  *
316*7c478bd9Sstevel@tonic-gate  * Description:
317*7c478bd9Sstevel@tonic-gate  *	Notifies the cachefsd of an unmount request.
318*7c478bd9Sstevel@tonic-gate  * Arguments:
319*7c478bd9Sstevel@tonic-gate  *	Mount point to unmount.
320*7c478bd9Sstevel@tonic-gate  * Returns:
321*7c478bd9Sstevel@tonic-gate  *	Returns 0 if the cachefsd unmounted the file system
322*7c478bd9Sstevel@tonic-gate  *		EIO if should try unmount directly
323*7c478bd9Sstevel@tonic-gate  *		EBUSY if did not unmount because busy
324*7c478bd9Sstevel@tonic-gate  *		EAGAIN if umounted but should not unmount nfs mount
325*7c478bd9Sstevel@tonic-gate  *
326*7c478bd9Sstevel@tonic-gate  * Preconditions:
327*7c478bd9Sstevel@tonic-gate  *	precond(mntptp)
328*7c478bd9Sstevel@tonic-gate  */
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate int
daemon_unmount(char * mntptp,int flag)331*7c478bd9Sstevel@tonic-gate daemon_unmount(char *mntptp, int flag)
332*7c478bd9Sstevel@tonic-gate {
333*7c478bd9Sstevel@tonic-gate 	CLIENT *clnt;
334*7c478bd9Sstevel@tonic-gate 	enum clnt_stat retval;
335*7c478bd9Sstevel@tonic-gate 	int xx;
336*7c478bd9Sstevel@tonic-gate 	int result;
337*7c478bd9Sstevel@tonic-gate 	char *hostp;
338*7c478bd9Sstevel@tonic-gate 	struct utsname info;
339*7c478bd9Sstevel@tonic-gate 	static struct timeval TIMEOUT = { 60*60, 0 };
340*7c478bd9Sstevel@tonic-gate 	static struct timeval create_timeout = { 5, 0};
341*7c478bd9Sstevel@tonic-gate 	struct cachefsd_fs_unmounted uargs;
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate 	/* get the host name */
344*7c478bd9Sstevel@tonic-gate 	xx = uname(&info);
345*7c478bd9Sstevel@tonic-gate 	if (xx == -1) {
346*7c478bd9Sstevel@tonic-gate 		pr_err(gettext("cannot get host name, errno %d"), errno);
347*7c478bd9Sstevel@tonic-gate 		return (EIO);
348*7c478bd9Sstevel@tonic-gate 	}
349*7c478bd9Sstevel@tonic-gate 	hostp = info.nodename;
350*7c478bd9Sstevel@tonic-gate 	uargs.mntpt = mntptp;
351*7c478bd9Sstevel@tonic-gate 	uargs.flag = flag;
352*7c478bd9Sstevel@tonic-gate 
353*7c478bd9Sstevel@tonic-gate 	/* creat the connection to the daemon */
354*7c478bd9Sstevel@tonic-gate 	clnt = clnt_create_timed(hostp, CACHEFSDPROG, CACHEFSDVERS, "local",
355*7c478bd9Sstevel@tonic-gate 	    &create_timeout);
356*7c478bd9Sstevel@tonic-gate 	if (clnt == NULL) {
357*7c478bd9Sstevel@tonic-gate 		pr_err(gettext("cachefsd is not running"));
358*7c478bd9Sstevel@tonic-gate 		return (EIO);
359*7c478bd9Sstevel@tonic-gate 	}
360*7c478bd9Sstevel@tonic-gate 	clnt_control(clnt, CLSET_TIMEOUT, (char *)&TIMEOUT);
361*7c478bd9Sstevel@tonic-gate 
362*7c478bd9Sstevel@tonic-gate 	retval = cachefsd_fs_unmounted_1(&uargs, &result, clnt);
363*7c478bd9Sstevel@tonic-gate 	if (retval != RPC_SUCCESS) {
364*7c478bd9Sstevel@tonic-gate 		clnt_perror(clnt, gettext("cachefsd is not responding"));
365*7c478bd9Sstevel@tonic-gate 		clnt_destroy(clnt);
366*7c478bd9Sstevel@tonic-gate 		return (EIO);
367*7c478bd9Sstevel@tonic-gate 	}
368*7c478bd9Sstevel@tonic-gate 
369*7c478bd9Sstevel@tonic-gate 	clnt_destroy(clnt);
370*7c478bd9Sstevel@tonic-gate 
371*7c478bd9Sstevel@tonic-gate 	return (result);
372*7c478bd9Sstevel@tonic-gate }
373