xref: /original-bsd/usr.sbin/amd/amd/nfs_ops.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1990 Jan-Simon Pendry
3  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * Jan-Simon Pendry at Imperial College, London.
9  *
10  * %sccs.include.redist.c%
11  *
12  * $Id: nfs_ops.c,v 5.2.2.2 1992/05/31 16:35:05 jsp Exp $
13  */
14 
15 #ifndef lint
16 static char sccsid[] = "@(#)nfs_ops.c	8.1 (Berkeley) 06/06/93";
17 #endif /* not lint */
18 
19 #include "am.h"
20 #include <sys/stat.h>
21 
22 #ifdef HAS_NFS
23 
24 #define NFS
25 #define NFSCLIENT
26 #ifdef NFS_3
27 typedef nfs_fh fhandle_t;
28 #endif /* NFS_3 */
29 #ifdef NFS_HDR
30 #include NFS_HDR
31 #endif /* NFS_HDR */
32 #include <sys/mount.h>
33 #include "mount.h"
34 
35 /*
36  * Network file system
37  */
38 
39 /*
40  * Convert from nfsstat to UN*X error code
41  */
42 #define unx_error(e)	((int)(e))
43 
44 /*
45  * The NFS layer maintains a cache of file handles.
46  * This is *fundamental* to the implementation and
47  * also allows quick remounting when a filesystem
48  * is accessed soon after timing out.
49  *
50  * The NFS server layer knows to flush this cache
51  * when a server goes down so avoiding stale handles.
52  *
53  * Each cache entry keeps a hard reference to
54  * the corresponding server.  This ensures that
55  * the server keepalive information is maintained.
56  *
57  * The copy of the sockaddr_in here is taken so
58  * that the port can be twiddled to talk to mountd
59  * instead of portmap or the NFS server as used
60  * elsewhere.
61  * The port# is flushed if a server goes down.
62  * The IP address is never flushed - we assume
63  * that the address of a mounted machine never
64  * changes.  If it does, then you have other
65  * problems...
66  */
67 typedef struct fh_cache fh_cache;
68 struct fh_cache {
69 	qelem	fh_q;			/* List header */
70 	voidp	fh_wchan;		/* Wait channel */
71 	int	fh_error;		/* Valid data? */
72 	int	fh_id;			/* Unique id */
73 	int	fh_cid;			/* Callout id */
74 	struct fhstatus fh_handle;	/* Handle on filesystem */
75 	struct sockaddr_in fh_sin;	/* Address of mountd */
76 	fserver *fh_fs;			/* Server holding filesystem */
77 	char	*fh_path;		/* Filesystem on host */
78 };
79 
80 /*
81  * FH_TTL is the time a file handle will remain in the cache since
82  * last being used.  If the file handle becomes invalid, then it
83  * will be flushed anyway.
84  */
85 #define	FH_TTL		(5 * 60)		/* five minutes */
86 #define	FH_TTL_ERROR	(30)			/* 30 seconds */
87 
88 static int fh_id = 0;
89 #define	FHID_ALLOC()	(++fh_id)
90 extern qelem fh_head;
91 qelem fh_head = { &fh_head, &fh_head };
92 
93 static int call_mountd P((fh_cache*, unsigned long, fwd_fun, voidp));
94 
95 AUTH *nfs_auth;
96 
97 static fh_cache *find_nfs_fhandle_cache P((voidp idv, int done));
98 static fh_cache *find_nfs_fhandle_cache(idv, done)
99 voidp idv;
100 int done;
101 {
102 	fh_cache *fp, *fp2 = 0;
103 	int id = (int) idv;
104 
105 	ITER(fp, fh_cache, &fh_head) {
106 		if (fp->fh_id == id) {
107 			fp2 = fp;
108 			break;
109 		}
110 	}
111 
112 #ifdef DEBUG
113 	if (fp2) {
114 		dlog("fh cache gives fp %#x, fs %s", fp2, fp2->fh_path);
115 	} else {
116 		dlog("fh cache search failed");
117 	}
118 #endif /* DEBUG */
119 
120 	if (fp2 && !done) {
121 		fp2->fh_error = ETIMEDOUT;
122 		return 0;
123 	}
124 
125 	return fp2;
126 }
127 
128 /*
129  * Called when a filehandle appears
130  */
131 static void got_nfs_fh P((voidp pkt, int len, struct sockaddr_in *sa,
132 				struct sockaddr_in *ia, voidp idv, int done));
133 static void got_nfs_fh(pkt, len, sa, ia, idv, done)
134 voidp pkt;
135 int len;
136 struct sockaddr_in *sa, *ia;
137 voidp idv;
138 int done;
139 {
140 	fh_cache *fp = find_nfs_fhandle_cache(idv, done);
141 	if (fp) {
142 		fp->fh_error = pickup_rpc_reply(pkt, len, (voidp) &fp->fh_handle, xdr_fhstatus);
143 		if (!fp->fh_error) {
144 #ifdef DEBUG
145 			dlog("got filehandle for %s:%s", fp->fh_fs->fs_host, fp->fh_path);
146 #endif /* DEBUG */
147 			/*
148 			 * Wakeup anything sleeping on this filehandle
149 			 */
150 			if (fp->fh_wchan) {
151 #ifdef DEBUG
152 				dlog("Calling wakeup on %#x", fp->fh_wchan);
153 #endif /* DEBUG */
154 				wakeup(fp->fh_wchan);
155 			}
156 		}
157 	}
158 }
159 
160 void flush_nfs_fhandle_cache P((fserver *fs));
161 void flush_nfs_fhandle_cache(fs)
162 fserver *fs;
163 {
164 	fh_cache *fp;
165 	ITER(fp, fh_cache, &fh_head) {
166 		if (fp->fh_fs == fs || fs == 0) {
167 			fp->fh_sin.sin_port = (u_short) 0;
168 			fp->fh_error = -1;
169 		}
170 	}
171 }
172 
173 static void discard_fh P((fh_cache *fp));
174 static void discard_fh(fp)
175 fh_cache *fp;
176 {
177 	rem_que(&fp->fh_q);
178 #ifdef DEBUG
179 	dlog("Discarding filehandle for %s:%s", fp->fh_fs->fs_host, fp->fh_path);
180 #endif /* DEBUG */
181 	free_srvr(fp->fh_fs);
182 	free((voidp) fp->fh_path);
183 	free((voidp) fp);
184 }
185 
186 /*
187  * Determine the file handle for a node
188  */
189 static int prime_nfs_fhandle_cache P((char *path, fserver *fs, struct fhstatus *fhbuf, voidp wchan));
190 static int prime_nfs_fhandle_cache(path, fs, fhbuf, wchan)
191 char *path;
192 fserver *fs;
193 struct fhstatus *fhbuf;
194 voidp wchan;
195 {
196 	fh_cache *fp, *fp_save = 0;
197 	int error;
198 	int reuse_id = FALSE;
199 
200 #ifdef DEBUG
201 	dlog("Searching cache for %s:%s", fs->fs_host, path);
202 #endif /* DEBUG */
203 
204 	/*
205 	 * First search the cache
206 	 */
207 	ITER(fp, fh_cache, &fh_head) {
208 		if (fs == fp->fh_fs && strcmp(path, fp->fh_path) == 0) {
209 			switch (fp->fh_error) {
210 			case 0:
211 				error = fp->fh_error = unx_error(fp->fh_handle.fhs_status);
212 				if (error == 0) {
213 					if (fhbuf)
214 						bcopy((voidp) &fp->fh_handle, (voidp) fhbuf,
215 							sizeof(fp->fh_handle));
216 					if (fp->fh_cid)
217 						untimeout(fp->fh_cid);
218 					fp->fh_cid = timeout(FH_TTL, discard_fh, (voidp) fp);
219 				} else if (error == EACCES) {
220 					/*
221 					 * Now decode the file handle return code.
222 					 */
223 					plog(XLOG_INFO, "Filehandle denied for \"%s:%s\"",
224 						fs->fs_host, path);
225 				} else {
226 					errno = error;	/* XXX */
227 					plog(XLOG_INFO, "Filehandle error for \"%s:%s\": %m",
228 						fs->fs_host, path);
229 				}
230 
231 				/*
232 				 * The error was returned from the remote mount daemon.
233 				 * Policy: this error will be cached for now...
234 				 */
235 				return error;
236 
237 			case -1:
238 				/*
239 				 * Still thinking about it, but we can re-use.
240 				 */
241 				fp_save = fp;
242 				reuse_id = TRUE;
243 				break;
244 
245 			default:
246 				/*
247 				 * Return the error.
248 				 * Policy: make sure we recompute if required again
249 				 * in case this was caused by a network failure.
250 				 * This can thrash mountd's though...  If you find
251 				 * your mountd going slowly then:
252 				 * 1.  Add a fork() loop to main.
253 				 * 2.  Remove the call to innetgr() and don't use
254 				 *     netgroups, especially if you don't use YP.
255 				 */
256 				error = fp->fh_error;
257 				fp->fh_error = -1;
258 				return error;
259 			}
260 			break;
261 		}
262 	}
263 
264 	/*
265 	 * Not in cache
266 	 */
267 	if (fp_save) {
268 		fp = fp_save;
269 		/*
270 		 * Re-use existing slot
271 		 */
272 		untimeout(fp->fh_cid);
273 		free_srvr(fp->fh_fs);
274 		free(fp->fh_path);
275 	} else {
276 		fp = ALLOC(fh_cache);
277 		bzero((voidp) fp, sizeof(*fp));
278 		ins_que(&fp->fh_q, &fh_head);
279 	}
280 	if (!reuse_id)
281 		fp->fh_id = FHID_ALLOC();
282 	fp->fh_wchan = wchan;
283 	fp->fh_error = -1;
284 	fp->fh_cid = timeout(FH_TTL, discard_fh, (voidp) fp);
285 
286 	/*
287 	 * If the address has changed then don't try to re-use the
288 	 * port information
289 	 */
290 	if (fp->fh_sin.sin_addr.s_addr != fs->fs_ip->sin_addr.s_addr) {
291 		fp->fh_sin = *fs->fs_ip;
292 		fp->fh_sin.sin_port = 0;
293 	}
294 	fp->fh_fs = dup_srvr(fs);
295 	fp->fh_path = strdup(path);
296 
297 	error = call_mountd(fp, MOUNTPROC_MNT, got_nfs_fh, wchan);
298 	if (error) {
299 		/*
300 		 * Local error - cache for a short period
301 		 * just to prevent thrashing.
302 		 */
303 		untimeout(fp->fh_cid);
304 		fp->fh_cid = timeout(error < 0 ? 2 * ALLOWED_MOUNT_TIME : FH_TTL_ERROR,
305 						discard_fh, (voidp) fp);
306 		fp->fh_error = error;
307 	} else {
308 		error = fp->fh_error;
309 	}
310 	return error;
311 }
312 
313 int make_nfs_auth P((void))
314 {
315 #ifdef HAS_NFS_QUALIFIED_NAMES
316 	/*
317 	 * From: Chris Metcalf <metcalf@masala.lcs.mit.edu>
318 	 * Use hostd, not just hostname.  Note that uids
319 	 * and gids and the gidlist are type *int* and not the
320 	 * system uid_t and gid_t types.
321 	 */
322 	static int group_wheel = 0;
323 	nfs_auth = authunix_create(hostd, 0, 0, 1, &group_wheel);
324 #else
325 	nfs_auth = authunix_create_default();
326 #endif
327 	if (!nfs_auth)
328 		return ENOBUFS;
329 	return 0;
330 }
331 
332 static int call_mountd P((fh_cache *fp, u_long proc, fwd_fun f, voidp wchan));
333 static int call_mountd(fp, proc, f, wchan)
334 fh_cache *fp;
335 u_long proc;
336 fwd_fun f;
337 voidp wchan;
338 {
339 	struct rpc_msg mnt_msg;
340 	int len;
341 	char iobuf[8192];
342 	int error;
343 
344 	if (!nfs_auth) {
345 		error = make_nfs_auth();
346 		if (error)
347 			return error;
348 	}
349 
350 	if (fp->fh_sin.sin_port == 0) {
351 		u_short port;
352 		error = nfs_srvr_port(fp->fh_fs, &port, wchan);
353 		if (error)
354 			return error;
355 		fp->fh_sin.sin_port = port;
356 	}
357 
358 	rpc_msg_init(&mnt_msg, MOUNTPROG, MOUNTVERS, (unsigned long) 0);
359 	len = make_rpc_packet(iobuf, sizeof(iobuf), proc,
360 			&mnt_msg, (voidp) &fp->fh_path, xdr_nfspath,  nfs_auth);
361 
362 	if (len > 0) {
363 		error = fwd_packet(MK_RPC_XID(RPC_XID_MOUNTD, fp->fh_id),
364 			(voidp) iobuf, len, &fp->fh_sin, &fp->fh_sin, (voidp) fp->fh_id, f);
365 	} else {
366 		error = -len;
367 	}
368 /*
369  * It may be the case that we're sending to the wrong MOUNTD port.  This
370  * occurs if mountd is restarted on the server after the port has been
371  * looked up and stored in the filehandle cache somewhere.  The correct
372  * solution, if we're going to cache port numbers is to catch the ICMP
373  * port unreachable reply from the server and cause the portmap request
374  * to be redone.  The quick solution here is to invalidate the MOUNTD
375  * port.
376  */
377       fp->fh_sin.sin_port = 0;
378 
379 	return error;
380 }
381 
382 /*-------------------------------------------------------------------------*/
383 
384 /*
385  * NFS needs the local filesystem, remote filesystem
386  * remote hostname.
387  * Local filesystem defaults to remote and vice-versa.
388  */
389 static char *nfs_match(fo)
390 am_opts *fo;
391 {
392 	char *xmtab;
393 	if (fo->opt_fs && !fo->opt_rfs)
394 		fo->opt_rfs = fo->opt_fs;
395 	if (!fo->opt_rfs) {
396 		plog(XLOG_USER, "nfs: no remote filesystem specified");
397 		return FALSE;
398 	}
399 	if (!fo->opt_rhost) {
400 		plog(XLOG_USER, "nfs: no remote host specified");
401 		return FALSE;
402 	}
403 	/*
404 	 * Determine magic cookie to put in mtab
405 	 */
406 	xmtab = (char *) xmalloc(strlen(fo->opt_rhost) + strlen(fo->opt_rfs) + 2);
407 	sprintf(xmtab, "%s:%s", fo->opt_rhost, fo->opt_rfs);
408 #ifdef DEBUG
409 	dlog("NFS: mounting remote server \"%s\", remote fs \"%s\" on \"%s\"",
410 		fo->opt_rhost, fo->opt_rfs, fo->opt_fs);
411 #endif /* DEBUG */
412 
413 	return xmtab;
414 }
415 
416 /*
417  * Initialise am structure for nfs
418  */
419 static int nfs_init(mf)
420 mntfs *mf;
421 {
422 	if (!mf->mf_private) {
423 		int error;
424 		struct fhstatus fhs;
425 
426 		char *colon = strchr(mf->mf_info, ':');
427 		if (colon == 0)
428 			return ENOENT;
429 
430 		error = prime_nfs_fhandle_cache(colon+1, mf->mf_server, &fhs, (voidp) mf);
431 		if (!error) {
432 			mf->mf_private = (voidp) ALLOC(fhstatus);
433 			mf->mf_prfree = (void (*)()) free;
434 			bcopy((voidp) &fhs, mf->mf_private, sizeof(fhs));
435 		}
436 		return error;
437 	}
438 
439 	return 0;
440 }
441 
442 int mount_nfs_fh P((struct fhstatus *fhp, char *dir, char *fs_name, char *opts, mntfs *mf));
443 int mount_nfs_fh(fhp, dir, fs_name, opts, mf)
444 struct fhstatus *fhp;
445 char *dir;
446 char *fs_name;
447 char *opts;
448 mntfs *mf;
449 {
450 	struct nfs_args nfs_args;
451 	struct mntent mnt;
452 	int retry;
453 	char *colon;
454 	/*char *path;*/
455 	char host[MAXHOSTNAMELEN + MAXPATHLEN + 2];
456 	fserver *fs = mf->mf_server;
457 	int flags;
458 	char *xopts;
459 	int error;
460 #ifdef notdef
461 	unsigned short port;
462 #endif /* notdef */
463 
464 	MTYPE_TYPE type = MOUNT_TYPE_NFS;
465 
466 	bzero((voidp) &nfs_args, sizeof(nfs_args));	/* Paranoid */
467 
468 	/*
469 	 * Extract host name to give to kernel
470 	 */
471 	if (!(colon = strchr(fs_name, ':')))
472 		return ENOENT;
473 #ifndef NFS_ARGS_NEEDS_PATH
474 	*colon = '\0';
475 #endif
476 	strncpy(host, fs_name, sizeof(host));
477 #ifndef NFS_ARGS_NEEDS_PATH
478 	*colon = ':';
479 #endif /* NFS_ARGS_NEEDS_PATH */
480 	/*path = colon + 1;*/
481 
482 	if (mf->mf_remopts && *mf->mf_remopts && !islocalnet(fs->fs_ip->sin_addr.s_addr))
483 		xopts = strdup(mf->mf_remopts);
484 	else
485 		xopts = strdup(opts);
486 
487 	bzero((voidp) &nfs_args, sizeof(nfs_args));
488 
489 	mnt.mnt_dir = dir;
490 	mnt.mnt_fsname = fs_name;
491 	mnt.mnt_type = MTAB_TYPE_NFS;
492 	mnt.mnt_opts = xopts;
493 	mnt.mnt_freq = 0;
494 	mnt.mnt_passno = 0;
495 
496 	retry = hasmntval(&mnt, "retry");
497 	if (retry <= 0)
498 		retry = 1;	/* XXX */
499 
500 /*again:*/
501 
502 	/*
503 	 * set mount args
504 	 */
505 	NFS_FH_DREF(nfs_args.fh, (NFS_FH_TYPE) fhp->fhstatus_u.fhs_fhandle);
506 
507 #ifdef ULTRIX_HACK
508 	nfs_args.optstr = mnt.mnt_opts;
509 #endif /* ULTRIX_HACK */
510 
511 	nfs_args.hostname = host;
512 	nfs_args.flags |= NFSMNT_HOSTNAME;
513 #ifdef HOSTNAMESZ
514 	/*
515 	 * Most kernels have a name length restriction.
516 	 */
517 	if (strlen(host) >= HOSTNAMESZ)
518 		strcpy(host + HOSTNAMESZ - 3, "..");
519 #endif /* HOSTNAMESZ */
520 
521 	if (nfs_args.rsize = hasmntval(&mnt, "rsize"))
522 		nfs_args.flags |= NFSMNT_RSIZE;
523 
524 	if (nfs_args.wsize = hasmntval(&mnt, "wsize"))
525 		nfs_args.flags |= NFSMNT_WSIZE;
526 
527 	if (nfs_args.timeo = hasmntval(&mnt, "timeo"))
528 		nfs_args.flags |= NFSMNT_TIMEO;
529 
530 	if (nfs_args.retrans = hasmntval(&mnt, "retrans"))
531 		nfs_args.flags |= NFSMNT_RETRANS;
532 
533 #ifdef NFSMNT_BIODS
534 	if (nfs_args.biods = hasmntval(&mnt, "biods"))
535 		nfs_args.flags |= NFSMNT_BIODS;
536 
537 #endif /* NFSMNT_BIODS */
538 
539 #ifdef NFSMNT_MAXGRPS
540 	if (nfs_args.maxgrouplist = hasmntval(&mnt, "maxgroups"))
541 		nfs_args.flags |= NFSMNT_MAXGRPS;
542 #endif /* NFSMNT_MAXGRPS */
543 
544 #ifdef notdef
545 /*
546  * This isn't supported by the ping algorithm yet.
547  * In any case, it is all done in nfs_init().
548  */
549  	if (port = hasmntval(&mnt, "port"))
550 		sin.sin_port = htons(port);
551 	else
552 		sin.sin_port = htons(NFS_PORT);	/* XXX should use portmapper */
553 #endif /* notdef */
554 
555 	if (hasmntopt(&mnt, MNTOPT_SOFT) != NULL)
556 		nfs_args.flags |= NFSMNT_SOFT;
557 
558 #ifdef NFSMNT_SPONGY
559 	if (hasmntopt(&mnt, "spongy") != NULL) {
560 		nfs_args.flags |= NFSMNT_SPONGY;
561 		if (nfs_args.flags & NFSMNT_SOFT) {
562 			plog(XLOG_USER, "Mount opts soft and spongy are incompatible - soft ignored");
563 			nfs_args.flags &= ~NFSMNT_SOFT;
564 		}
565 	}
566 #endif /* MNTOPT_SPONGY */
567 
568 #ifdef MNTOPT_INTR
569 	if (hasmntopt(&mnt, MNTOPT_INTR) != NULL)
570 		nfs_args.flags |= NFSMNT_INT;
571 #endif /* MNTOPT_INTR */
572 
573 #ifdef MNTOPT_NODEVS
574 	if (hasmntopt(&mnt, MNTOPT_NODEVS) != NULL)
575 		nfs_args.flags |= NFSMNT_NODEVS;
576 #endif /* MNTOPT_NODEVS */
577 
578 #ifdef MNTOPT_COMPRESS
579 	if (hasmntopt(&mnt, "compress") != NULL)
580 		nfs_args.flags |= NFSMNT_COMPRESS;
581 #endif /* MNTOPT_COMPRESS */
582 
583 #ifdef MNTOPT_NOCONN
584 	if (hasmntopt(&mnt, "noconn") != NULL)
585 		nfs_args.flags |= NFSMNT_NOCONN;
586 #endif /* MNTOPT_NOCONN */
587 
588 #ifdef NFSMNT_PGTHRESH
589 	if (nfs_args.pg_thresh = hasmntval(&mnt, "pgthresh"))
590 		nfs_args.flags |= NFSMNT_PGTHRESH;
591 #endif /* NFSMNT_PGTHRESH */
592 
593 	NFS_SA_DREF(nfs_args, fs->fs_ip);
594 
595 	flags = compute_mount_flags(&mnt);
596 
597 #ifdef NFSMNT_NOCTO
598 	if (hasmntopt(&mnt, "nocto") != NULL)
599 		nfs_args.flags |= NFSMNT_NOCTO;
600 #endif /* NFSMNT_NOCTO */
601 
602 #ifdef HAS_TCP_NFS
603 	if (hasmntopt(&mnt, "tcp") != NULL)
604 		nfs_args.sotype = SOCK_STREAM;
605 #endif /* HAS_TCP_NFS */
606 
607 
608 #ifdef ULTRIX_HACK
609 	/*
610 	 * Ultrix passes the flags argument as part of the
611 	 * mount data structure, rather than using the
612 	 * flags argument to the system call.  This is
613 	 * confusing...
614 	 */
615 	if (!(nfs_args.flags & NFSMNT_PGTHRESH)) {
616 		nfs_args.pg_thresh = 64; /* 64k - XXX */
617 		nfs_args.flags |= NFSMNT_PGTHRESH;
618 	}
619 	nfs_args.gfs_flags = flags;
620 	flags &= M_RDONLY;
621 	if (flags & M_RDONLY)
622 		nfs_args.flags |= NFSMNT_RONLY;
623 #endif /* ULTRIX_HACK */
624 
625 	error = mount_fs(&mnt, flags, (caddr_t) &nfs_args, retry, type);
626 	free(xopts);
627 	return error;
628 }
629 
630 static int mount_nfs(dir, fs_name, opts, mf)
631 char *dir;
632 char *fs_name;
633 char *opts;
634 mntfs *mf;
635 {
636 #ifdef notdef
637 	int error;
638 	struct fhstatus fhs;
639 	char *colon;
640 
641 	if (!(colon = strchr(fs_name, ':')))
642 		return ENOENT;
643 
644 #ifdef DEBUG
645 	dlog("locating fhandle for %s", fs_name);
646 #endif /* DEBUG */
647 	error = prime_nfs_fhandle_cache(colon+1, mf->mf_server, &fhs, (voidp) 0);
648 
649 	if (error)
650 		return error;
651 
652 	return mount_nfs_fh(&fhs, dir, fs_name, opts, mf);
653 #endif
654 	if (!mf->mf_private) {
655 		plog(XLOG_ERROR, "Missing filehandle for %s", fs_name);
656 		return EINVAL;
657 	}
658 
659 	return mount_nfs_fh((struct fhstatus *) mf->mf_private, dir, fs_name, opts, mf);
660 }
661 
662 static int nfs_fmount(mf)
663 mntfs *mf;
664 {
665 	int error;
666 
667 	error = mount_nfs(mf->mf_mount, mf->mf_info, mf->mf_mopts, mf);
668 
669 #ifdef DEBUG
670 	if (error) {
671 		errno = error;
672 		dlog("mount_nfs: %m");
673 	}
674 #endif /* DEBUG */
675 	return error;
676 }
677 
678 static int nfs_fumount(mf)
679 mntfs *mf;
680 {
681 	int error = UMOUNT_FS(mf->mf_mount);
682 	if (error)
683 		return error;
684 
685 	return 0;
686 }
687 
688 static void nfs_umounted(mp)
689 am_node *mp;
690 {
691 #ifdef INFORM_MOUNTD
692 	/*
693 	 * Don't bother to inform remote mountd
694 	 * that we are finished.  Until a full
695 	 * track of filehandles is maintained
696 	 * the mountd unmount callback cannot
697 	 * be done correctly anyway...
698 	 */
699 
700 	mntfs *mf = mp->am_mnt;
701 	fserver *fs;
702 	char *colon, *path;
703 
704 	if (mf->mf_error || mf->mf_refc > 1)
705 		return;
706 
707 	fs = mf->mf_server;
708 
709 	/*
710 	 * Call the mount daemon on the server to
711 	 * announce that we are not using the fs any more.
712 	 *
713 	 * This is *wrong*.  The mountd should be called
714 	 * when the fhandle is flushed from the cache, and
715 	 * a reference held to the cached entry while the
716 	 * fs is mounted...
717 	 */
718 	colon = path = strchr(mf->mf_info, ':');
719 	if (fs && colon) {
720 		fh_cache f;
721 #ifdef DEBUG
722 		dlog("calling mountd for %s", mf->mf_info);
723 #endif /* DEBUG */
724 		*path++ = '\0';
725 		f.fh_path = path;
726 		f.fh_sin = *fs->fs_ip;
727 		f.fh_sin.sin_port = (u_short) 0;
728 		f.fh_fs = fs;
729 		f.fh_id = 0;
730 		f.fh_error = 0;
731 		(void) prime_nfs_fhandle_cache(colon+1, mf->mf_server, (struct fhstatus *) 0, (voidp) mf);
732 		(void) call_mountd(&f, MOUNTPROC_UMNT, (fwd_fun) 0, (voidp) 0);
733 		*colon = ':';
734 	}
735 #endif /* INFORM_MOUNTD */
736 
737 #ifdef KICK_KERNEL
738 	/* This should go into the mainline code, not in nfs_ops... */
739 
740 	/*
741 	 * Run lstat over the underlying directory in
742 	 * case this was a direct mount.  This will
743 	 * get the kernel back in sync with reality.
744 	 */
745 	if (mp->am_parent && mp->am_parent->am_path &&
746 	    STREQ(mp->am_parent->am_mnt->mf_ops->fs_type, "direct")) {
747 		struct stat stb;
748 		int pid;
749 		if ((pid = background()) == 0) {
750 			if (lstat(mp->am_parent->am_path, &stb) < 0) {
751 				plog(XLOG_ERROR, "lstat(%s) after unmount: %m", mp->am_parent->am_path);
752 #ifdef DEBUG
753 			} else {
754 				dlog("hack lstat(%s): ok", mp->am_parent->am_path);
755 #endif /* DEBUG */
756 			}
757 			_exit(0);
758 		}
759 	}
760 #endif /* KICK_KERNEL */
761 }
762 
763 /*
764  * Network file system
765  */
766 am_ops nfs_ops = {
767 	"nfs",
768 	nfs_match,
769 	nfs_init,
770 	auto_fmount,
771 	nfs_fmount,
772 	auto_fumount,
773 	nfs_fumount,
774 	efs_lookuppn,
775 	efs_readdir,
776 	0, /* nfs_readlink */
777 	0, /* nfs_mounted */
778 	nfs_umounted,
779 	find_nfs_srvr,
780 	FS_MKMNT|FS_BACKGROUND|FS_AMQINFO
781 };
782 
783 #endif /* HAS_NFS */
784