Home | History | Annotate | Line # | Download | only in nfs
nfs_vfsops.c revision 1.22
      1 /*
      2  * Copyright (c) 1989, 1993
      3  *	The Regents of the University of California.  All rights reserved.
      4  *
      5  * This code is derived from software contributed to Berkeley by
      6  * Rick Macklem at The University of Guelph.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by the University of
     19  *	California, Berkeley and its contributors.
     20  * 4. Neither the name of the University nor the names of its contributors
     21  *    may be used to endorse or promote products derived from this software
     22  *    without specific prior written permission.
     23  *
     24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34  * SUCH DAMAGE.
     35  *
     36  *	from: @(#)nfs_vfsops.c	8.3 (Berkeley) 1/4/94
     37  *	$Id: nfs_vfsops.c,v 1.22 1994/06/13 15:29:01 gwr Exp $
     38  */
     39 
     40 #include <sys/param.h>
     41 #include <sys/conf.h>
     42 #include <sys/ioctl.h>
     43 #include <sys/signal.h>
     44 #include <sys/proc.h>
     45 #include <sys/namei.h>
     46 #include <sys/vnode.h>
     47 #include <sys/kernel.h>
     48 #include <sys/mount.h>
     49 #include <sys/buf.h>
     50 #include <sys/mbuf.h>
     51 #include <sys/socket.h>
     52 #include <sys/systm.h>
     53 
     54 #include <net/if.h>
     55 #include <net/route.h>
     56 #include <netinet/in.h>
     57 
     58 #include <nfs/rpcv2.h>
     59 #include <nfs/nfsv2.h>
     60 #include <nfs/nfsnode.h>
     61 #include <nfs/nfsmount.h>
     62 #include <nfs/nfs.h>
     63 #include <nfs/xdr_subs.h>
     64 #include <nfs/nfsm_subs.h>
     65 #include <nfs/nfsdiskless.h>
     66 #include <nfs/nqnfs.h>
     67 
     68 /*
     69  * nfs vfs operations.
     70  */
     71 struct vfsops nfs_vfsops = {
     72 	MOUNT_NFS,
     73 	nfs_mount,
     74 	nfs_start,
     75 	nfs_unmount,
     76 	nfs_root,
     77 	nfs_quotactl,
     78 	nfs_statfs,
     79 	nfs_sync,
     80 	nfs_vget,
     81 	nfs_fhtovp,
     82 	nfs_vptofh,
     83 	nfs_init,
     84 };
     85 
     86 extern u_long nfs_procids[NFS_NPROCS];
     87 extern u_long nfs_prog, nfs_vers;
     88 void nfs_disconnect __P((struct nfsmount *));
     89 
     90 static struct mount *
     91 nfs_mount_diskless __P((struct nfs_dlmount *, char *, int, struct vnode **));
     92 
     93 #define TRUE	1
     94 #define	FALSE	0
     95 
     96 /*
     97  * nfs statfs call
     98  */
     99 int
    100 nfs_statfs(mp, sbp, p)
    101 	struct mount *mp;
    102 	register struct statfs *sbp;
    103 	struct proc *p;
    104 {
    105 	register struct vnode *vp;
    106 	register struct nfsv2_statfs *sfp;
    107 	register caddr_t cp;
    108 	register long t1;
    109 	caddr_t bpos, dpos, cp2;
    110 	int error = 0, isnq;
    111 	struct mbuf *mreq, *mrep, *md, *mb, *mb2;
    112 	struct nfsmount *nmp;
    113 	struct ucred *cred;
    114 	struct nfsnode *np;
    115 
    116 	nmp = VFSTONFS(mp);
    117 	isnq = (nmp->nm_flag & NFSMNT_NQNFS);
    118 	if (error = nfs_nget(mp, &nmp->nm_fh, &np))
    119 		return (error);
    120 	vp = NFSTOV(np);
    121 	nfsstats.rpccnt[NFSPROC_STATFS]++;
    122 	cred = crget();
    123 	cred->cr_ngroups = 1;
    124 	nfsm_reqhead(vp, NFSPROC_STATFS, NFSX_FH);
    125 	nfsm_fhtom(vp);
    126 	nfsm_request(vp, NFSPROC_STATFS, p, cred);
    127 	nfsm_dissect(sfp, struct nfsv2_statfs *, NFSX_STATFS(isnq));
    128 #ifdef COMPAT_09
    129 	sbp->f_type = 2;
    130 #else
    131 	sbp->f_type = 0;
    132 #endif
    133 	sbp->f_flags = nmp->nm_flag;
    134 	sbp->f_iosize = NFS_MAXDGRAMDATA;
    135 	sbp->f_bsize = fxdr_unsigned(long, sfp->sf_bsize);
    136 	sbp->f_blocks = fxdr_unsigned(long, sfp->sf_blocks);
    137 	sbp->f_bfree = fxdr_unsigned(long, sfp->sf_bfree);
    138 	sbp->f_bavail = fxdr_unsigned(long, sfp->sf_bavail);
    139 	if (isnq) {
    140 		sbp->f_files = fxdr_unsigned(long, sfp->sf_files);
    141 		sbp->f_ffree = fxdr_unsigned(long, sfp->sf_ffree);
    142 	} else {
    143 		sbp->f_files = 0;
    144 		sbp->f_ffree = 0;
    145 	}
    146 	if (sbp != &mp->mnt_stat) {
    147 		bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
    148 		bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
    149 	}
    150 	strncpy(&sbp->f_fstypename[0], mp->mnt_op->vfs_name, MFSNAMELEN);
    151 	sbp->f_fstypename[MFSNAMELEN] = '\0';
    152 	nfsm_reqdone;
    153 	vrele(vp);
    154 	crfree(cred);
    155 	return (error);
    156 }
    157 
    158 /*
    159  * Mount a remote root fs via. NFS.  It goes like this:
    160  * - Call nfs_boot_init() to fill in the nfs_diskless struct
    161  *   (using RARP, bootparam RPC, mountd RPC)
    162  * - hand craft the swap nfs vnode hanging off a fake mount point
    163  *	if swdevt[0].sw_dev == NODEV
    164  * - build the rootfs mount point and call mountnfs() to do the rest.
    165  */
    166 int
    167 nfs_mountroot()
    168 {
    169 	struct nfs_diskless nd;
    170 	struct vattr attr;
    171 	struct mount *mp;
    172 	struct vnode *vp;
    173 	struct proc *procp;
    174 	struct ucred *cred;
    175 	long n;
    176 	int error;
    177 
    178 	procp = curproc; /* XXX */
    179 
    180 	/*
    181 	 * Call nfs_boot_init() to fill in the nfs_diskless struct.
    182 	 * Side effect:  Finds and configures a network interface.
    183 	 */
    184 	bzero((caddr_t) &nd, sizeof(nd));
    185 	nfs_boot_init(&nd, procp);
    186 
    187 	/*
    188 	 * Create the root mount point.
    189 	 */
    190 	mp = nfs_mount_diskless(&nd.nd_root, "/", MNT_RDONLY, &vp);
    191 
    192 	/*
    193 	 * Link it into the mount list.
    194 	 */
    195 	if (vfs_lock(mp))
    196 		panic("nfs_mountroot: vfs_lock");
    197 	TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    198 	mp->mnt_flag |= MNT_ROOTFS;
    199 	mp->mnt_vnodecovered = NULLVP;
    200 	vfs_unlock(mp);
    201 	rootvp = vp;
    202 
    203 
    204 	/* Get root attributes (for the time). */
    205 	error = VOP_GETATTR(vp, &attr, procp->p_cred->pc_ucred, procp);
    206 	if (error) panic("nfs_mountroot: getattr for root");
    207 	n = attr.va_mtime.ts_sec;	/* XXX - Always zero.  Why? -gwr */
    208 	printf(" root time: 0x%x\n", n);
    209 	inittodr(n);
    210 
    211 #ifdef notyet
    212 	/* Set up swap credentials. */
    213 	proc0.p_ucred->cr_uid = ntohl(nd.swap_ucred.cr_uid);
    214 	proc0.p_ucred->cr_gid = ntohl(nd.swap_ucred.cr_gid);
    215 	if ((proc0.p_ucred->cr_ngroups = ntohs(nd.swap_ucred.cr_ngroups)) >
    216 		NGROUPS)
    217 		proc0.p_ucred->cr_ngroups = NGROUPS;
    218 	for (i = 0; i < proc0.p_ucred->cr_ngroups; i++)
    219 	    proc0.p_ucred->cr_groups[i] = ntohl(nd.swap_ucred.cr_groups[i]);
    220 #endif
    221 
    222 	/*
    223 	 * "Mount" the swap device.
    224 	 *
    225 	 * On a "dataless" configuration (swap on disk) we will have:
    226 	 *	(swdevt[0].sw_dev != NODEV) identifying the swap device.
    227 	 */
    228 	if (swdevt[0].sw_dev != NODEV) {
    229 		if (bdevvp(swapdev, &swapdev_vp))
    230 			panic("nfs_mountroot: can't get swap vp for dev %d,%d",
    231 				  major(swdevt[0].sw_dev), minor(swdevt[0].sw_dev));
    232 		return (0);
    233 	}
    234 
    235 	/*
    236 	 * If swapping to an nfs node:  (swdevt[0].sw_dev == NODEV)
    237 	 * Create a fake mount point just for the swap vnode so that the
    238 	 * swap file can be on a different server from the rootfs.
    239 	 */
    240 	mp = nfs_mount_diskless(&nd.nd_swap, "/swap", 0, &vp);
    241 
    242 	/*
    243 	 * Since the swap file is not the root dir of a file system,
    244 	 * hack it to a regular file.
    245 	 */
    246 	vp->v_type = VREG;
    247 	vp->v_flag = 0;
    248 	swapdev_vp = vp;
    249 	VREF(vp);
    250 	swdevt[0].sw_vp = vp;
    251 
    252 	/*
    253 	 * Find out how large the swap file is.
    254 	 */
    255 	error = VOP_GETATTR(vp, &attr, procp->p_cred->pc_ucred, procp);
    256 	if (error) panic("nfs_mountroot: getattr for swap");
    257 	n = (long) (attr.va_size / DEV_BSIZE);
    258 	printf(" swap size: 0x%x (blocks)\n", n);	/* XXX */
    259 	swdevt[0].sw_nblks = n;
    260 
    261 	return (0);
    262 }
    263 
    264 /*
    265  * Internal version of mount system call for diskless setup.
    266  */
    267 static struct mount *
    268 nfs_mount_diskless(ndmntp, mntname, mntflag, vpp)
    269 	struct nfs_dlmount *ndmntp;
    270 	char *mntname;
    271 	int mntflag;
    272 	struct vnode **vpp;
    273 {
    274 	struct nfs_args args;
    275 	struct mount *mp;
    276 	struct mbuf *m;
    277 	int error;
    278 
    279 	/* Create the mount point. */
    280 	mp = (struct mount *)malloc((u_long)sizeof(struct mount),
    281 	    M_MOUNT, M_NOWAIT);
    282 	if (mp == NULL)
    283 		panic("nfs_mountroot: malloc mount for %s", mntname);
    284 	bzero((char *)mp, (u_long)sizeof(struct mount));
    285 	mp->mnt_op = &nfs_vfsops;
    286 	mp->mnt_flag = mntflag;
    287 
    288 	/* Initialize mount args. */
    289 	bzero((caddr_t) &args, sizeof(args));
    290 	args.addr     = (struct sockaddr *)&ndmntp->ndm_saddr;
    291 	args.addrlen  = args.addr->sa_len;
    292 	args.sotype   = SOCK_DGRAM;
    293 	args.fh       = (nfsv2fh_t *)ndmntp->ndm_fh;
    294 	args.hostname = ndmntp->ndm_host;
    295 
    296 	/* Get mbuf for server sockaddr. */
    297 	MGET(m, MT_SONAME, M_DONTWAIT);
    298 	if (m == NULL)
    299 		panic("nfs_mountroot: mget soname for %s", mntname);
    300 	bcopy((caddr_t)args.addr, mtod(m, caddr_t),
    301 	      (m->m_len = args.addr->sa_len));
    302 
    303 	if (error = mountnfs(&args, mp, m, mntname, args.hostname, vpp))
    304 		panic("nfs_mountroot: mount %s failed: %d", mntname);
    305 
    306 	return (mp);
    307 }
    308 
    309 void
    310 nfs_decode_args(nmp, argp)
    311 	struct nfsmount *nmp;
    312 	struct nfs_args *argp;
    313 {
    314 	int s;
    315 
    316 	s = splnet();
    317 	/* Update flags atomically.  Don't change the lock bits. */
    318 	nmp->nm_flag =
    319 	    (argp->flags & ~NFSMNT_INTERNAL) | (nmp->nm_flag & NFSMNT_INTERNAL);
    320 	splx(s);
    321 
    322 	if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) {
    323 		nmp->nm_timeo = (argp->timeo * NFS_HZ + 5) / 10;
    324 		if (nmp->nm_timeo < NFS_MINTIMEO)
    325 			nmp->nm_timeo = NFS_MINTIMEO;
    326 		else if (nmp->nm_timeo > NFS_MAXTIMEO)
    327 			nmp->nm_timeo = NFS_MAXTIMEO;
    328 	}
    329 
    330 	if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) {
    331 		nmp->nm_retry = argp->retrans;
    332 		if (nmp->nm_retry > NFS_MAXREXMIT)
    333 			nmp->nm_retry = NFS_MAXREXMIT;
    334 	}
    335 
    336 	if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) {
    337 		nmp->nm_wsize = argp->wsize;
    338 		/* Round down to multiple of blocksize */
    339 		nmp->nm_wsize &= ~0x1ff;
    340 		if (nmp->nm_wsize <= 0)
    341 			nmp->nm_wsize = 512;
    342 		else if (nmp->nm_wsize > NFS_MAXDATA)
    343 			nmp->nm_wsize = NFS_MAXDATA;
    344 	}
    345 	if (nmp->nm_wsize > MAXBSIZE)
    346 		nmp->nm_wsize = MAXBSIZE;
    347 
    348 	if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) {
    349 		nmp->nm_rsize = argp->rsize;
    350 		/* Round down to multiple of blocksize */
    351 		nmp->nm_rsize &= ~0x1ff;
    352 		if (nmp->nm_rsize <= 0)
    353 			nmp->nm_rsize = 512;
    354 		else if (nmp->nm_rsize > NFS_MAXDATA)
    355 			nmp->nm_rsize = NFS_MAXDATA;
    356 	}
    357 	if (nmp->nm_rsize > MAXBSIZE)
    358 		nmp->nm_rsize = MAXBSIZE;
    359 
    360 	if ((argp->flags & NFSMNT_MAXGRPS) && argp->maxgrouplist >= 0 &&
    361 		argp->maxgrouplist <= NFS_MAXGRPS)
    362 		nmp->nm_numgrps = argp->maxgrouplist;
    363 	if ((argp->flags & NFSMNT_READAHEAD) && argp->readahead >= 0 &&
    364 		argp->readahead <= NFS_MAXRAHEAD)
    365 		nmp->nm_readahead = argp->readahead;
    366 	if ((argp->flags & NFSMNT_LEASETERM) && argp->leaseterm >= 2 &&
    367 		argp->leaseterm <= NQ_MAXLEASE)
    368 		nmp->nm_leaseterm = argp->leaseterm;
    369 	if ((argp->flags & NFSMNT_DEADTHRESH) && argp->deadthresh >= 1 &&
    370 		argp->deadthresh <= NQ_NEVERDEAD)
    371 		nmp->nm_deadthresh = argp->deadthresh;
    372 }
    373 
    374 /*
    375  * VFS Operations.
    376  *
    377  * mount system call
    378  * It seems a bit dumb to copyinstr() the host and path here and then
    379  * bcopy() them in mountnfs(), but I wanted to detect errors before
    380  * doing the sockargs() call because sockargs() allocates an mbuf and
    381  * an error after that means that I have to release the mbuf.
    382  */
    383 /* ARGSUSED */
    384 int
    385 nfs_mount(mp, path, data, ndp, p)
    386 	struct mount *mp;
    387 	char *path;
    388 	caddr_t data;
    389 	struct nameidata *ndp;
    390 	struct proc *p;
    391 {
    392 	int error;
    393 	struct nfs_args args;
    394 	struct mbuf *nam;
    395 	struct vnode *vp;
    396 	char pth[MNAMELEN], hst[MNAMELEN];
    397 	u_int len;
    398 	nfsv2fh_t nfh;
    399 
    400 	if (error = copyin(data, (caddr_t)&args, sizeof (struct nfs_args)))
    401 		return (error);
    402 	if (mp->mnt_flag & MNT_UPDATE) {
    403 		register struct nfsmount *nmp = VFSTONFS(mp);
    404 
    405 		if (nmp == NULL)
    406 			return (EIO);
    407 		nfs_decode_args(nmp, &args);
    408 		return (0);
    409 	}
    410 	if (error = copyin((caddr_t)args.fh, (caddr_t)&nfh, sizeof (nfsv2fh_t)))
    411 		return (error);
    412 	if (error = copyinstr(path, pth, MNAMELEN-1, &len))
    413 		return (error);
    414 	bzero(&pth[len], MNAMELEN - len);
    415 	if (error = copyinstr(args.hostname, hst, MNAMELEN-1, &len))
    416 		return (error);
    417 	bzero(&hst[len], MNAMELEN - len);
    418 	/* sockargs() call must be after above copyin() calls */
    419 	if (error = sockargs(&nam, (caddr_t)args.addr,
    420 		args.addrlen, MT_SONAME))
    421 		return (error);
    422 	args.fh = &nfh;
    423 	error = mountnfs(&args, mp, nam, pth, hst, &vp);
    424 	return (error);
    425 }
    426 
    427 /*
    428  * Common code for mount and mountroot
    429  */
    430 int
    431 mountnfs(argp, mp, nam, pth, hst, vpp)
    432 	register struct nfs_args *argp;
    433 	register struct mount *mp;
    434 	struct mbuf *nam;
    435 	char *pth, *hst;
    436 	struct vnode **vpp;
    437 {
    438 	register struct nfsmount *nmp;
    439 	struct nfsnode *np;
    440 	int error;
    441 
    442 	if (mp->mnt_flag & MNT_UPDATE) {
    443 		nmp = VFSTONFS(mp);
    444 		/* update paths, file handles, etc, here	XXX */
    445 		m_freem(nam);
    446 		return (0);
    447 	} else {
    448 		MALLOC(nmp, struct nfsmount *, sizeof (struct nfsmount),
    449 		    M_NFSMNT, M_WAITOK);
    450 		bzero((caddr_t)nmp, sizeof (struct nfsmount));
    451 		mp->mnt_data = (qaddr_t)nmp;
    452 	}
    453 	getnewfsid(mp, makefstype(MOUNT_NFS));
    454 	nmp->nm_mountp = mp;
    455 	if ((argp->flags & (NFSMNT_NQNFS | NFSMNT_MYWRITE)) ==
    456 		(NFSMNT_NQNFS | NFSMNT_MYWRITE)) {
    457 		error = EPERM;
    458 		goto bad;
    459 	}
    460 	if (argp->flags & NFSMNT_NQNFS)
    461 		/*
    462 		 * We have to set mnt_maxsymlink to a non-zero value so
    463 		 * that COMPAT_43 routines will know that we are setting
    464 		 * the d_type field in directories (and can zero it for
    465 		 * unsuspecting binaries).
    466 		 */
    467 		mp->mnt_maxsymlinklen = 1;
    468 	nmp->nm_timeo = NFS_TIMEO;
    469 	nmp->nm_retry = NFS_RETRANS;
    470 	nmp->nm_wsize = NFS_WSIZE;
    471 	nmp->nm_rsize = NFS_RSIZE;
    472 	nmp->nm_numgrps = NFS_MAXGRPS;
    473 	nmp->nm_readahead = NFS_DEFRAHEAD;
    474 	nmp->nm_leaseterm = NQ_DEFLEASE;
    475 	nmp->nm_deadthresh = NQ_DEADTHRESH;
    476 	nmp->nm_tnext = (struct nfsnode *)nmp;
    477 	nmp->nm_tprev = (struct nfsnode *)nmp;
    478 	nmp->nm_inprog = NULLVP;
    479 	bcopy((caddr_t)argp->fh, (caddr_t)&nmp->nm_fh, sizeof(nfsv2fh_t));
    480 #ifdef COMPAT_09
    481 	mp->mnt_stat.f_type = 2;
    482 #else
    483 	mp->mnt_stat.f_type = 0;
    484 #endif
    485 	bcopy(hst, mp->mnt_stat.f_mntfromname, MNAMELEN);
    486 	bcopy(pth, mp->mnt_stat.f_mntonname, MNAMELEN);
    487 	nmp->nm_nam = nam;
    488 	nfs_decode_args(nmp, argp);
    489 
    490 	/* Set up the sockets and per-host congestion */
    491 	nmp->nm_sotype = argp->sotype;
    492 	nmp->nm_soproto = argp->proto;
    493 
    494 	/*
    495 	 * For Connection based sockets (TCP,...) defer the connect until
    496 	 * the first request, in case the server is not responding.
    497 	 */
    498 	if (nmp->nm_sotype == SOCK_DGRAM &&
    499 		(error = nfs_connect(nmp, (struct nfsreq *)0)))
    500 		goto bad;
    501 
    502 	/*
    503 	 * This is silly, but it has to be set so that vinifod() works.
    504 	 * We do not want to do an nfs_statfs() here since we can get
    505 	 * stuck on a dead server and we are holding a lock on the mount
    506 	 * point.
    507 	 */
    508 	mp->mnt_stat.f_iosize = NFS_MAXDGRAMDATA;
    509 	/*
    510 	 * A reference count is needed on the nfsnode representing the
    511 	 * remote root.  If this object is not persistent, then backward
    512 	 * traversals of the mount point (i.e. "..") will not work if
    513 	 * the nfsnode gets flushed out of the cache. Ufs does not have
    514 	 * this problem, because one can identify root inodes by their
    515 	 * number == ROOTINO (2).
    516 	 */
    517 	if (error = nfs_nget(mp, &nmp->nm_fh, &np))
    518 		goto bad;
    519 	*vpp = NFSTOV(np);
    520 
    521 	return (0);
    522 bad:
    523 	nfs_disconnect(nmp);
    524 	free((caddr_t)nmp, M_NFSMNT);
    525 	m_freem(nam);
    526 	return (error);
    527 }
    528 
    529 /*
    530  * unmount system call
    531  */
    532 int
    533 nfs_unmount(mp, mntflags, p)
    534 	struct mount *mp;
    535 	int mntflags;
    536 	struct proc *p;
    537 {
    538 	register struct nfsmount *nmp;
    539 	struct nfsnode *np;
    540 	struct vnode *vp;
    541 	int error, flags = 0;
    542 	extern int doforce;
    543 
    544 	if (mntflags & MNT_FORCE) {
    545 		if (!doforce || (mp->mnt_flag & MNT_ROOTFS))
    546 			return (EINVAL);
    547 		flags |= FORCECLOSE;
    548 	}
    549 	nmp = VFSTONFS(mp);
    550 	/*
    551 	 * Goes something like this..
    552 	 * - Check for activity on the root vnode (other than ourselves).
    553 	 * - Call vflush() to clear out vnodes for this file system,
    554 	 *   except for the root vnode.
    555 	 * - Decrement reference on the vnode representing remote root.
    556 	 * - Close the socket
    557 	 * - Free up the data structures
    558 	 */
    559 	/*
    560 	 * We need to decrement the ref. count on the nfsnode representing
    561 	 * the remote root.  See comment in mountnfs().  The VFS unmount()
    562 	 * has done vput on this vnode, otherwise we would get deadlock!
    563 	 */
    564 	if (error = nfs_nget(mp, &nmp->nm_fh, &np))
    565 		return(error);
    566 	vp = NFSTOV(np);
    567 	if (vp->v_usecount > 2) {
    568 		vput(vp);
    569 		return (EBUSY);
    570 	}
    571 
    572 	/*
    573 	 * Must handshake with nqnfs_clientd() if it is active.
    574 	 */
    575 	nmp->nm_flag |= NFSMNT_DISMINPROG;
    576 	while (nmp->nm_inprog != NULLVP)
    577 		(void) tsleep((caddr_t)&lbolt, PSOCK, "nfsdism", 0);
    578 	if (error = vflush(mp, vp, flags)) {
    579 		vput(vp);
    580 		nmp->nm_flag &= ~NFSMNT_DISMINPROG;
    581 		return (error);
    582 	}
    583 
    584 	/*
    585 	 * We are now committed to the unmount.
    586 	 * For NQNFS, let the server daemon free the nfsmount structure.
    587 	 */
    588 	if (nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB))
    589 		nmp->nm_flag |= NFSMNT_DISMNT;
    590 
    591 	/*
    592 	 * There are two reference counts to get rid of here.
    593 	 */
    594 	vrele(vp);
    595 	vrele(vp);
    596 	vgone(vp);
    597 	nfs_disconnect(nmp);
    598 	m_freem(nmp->nm_nam);
    599 
    600 	if ((nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB)) == 0)
    601 		free((caddr_t)nmp, M_NFSMNT);
    602 	return (0);
    603 }
    604 
    605 /*
    606  * Return root of a filesystem
    607  */
    608 int
    609 nfs_root(mp, vpp)
    610 	struct mount *mp;
    611 	struct vnode **vpp;
    612 {
    613 	register struct vnode *vp;
    614 	struct nfsmount *nmp;
    615 	struct nfsnode *np;
    616 	int error;
    617 
    618 	nmp = VFSTONFS(mp);
    619 	if (error = nfs_nget(mp, &nmp->nm_fh, &np))
    620 		return (error);
    621 	vp = NFSTOV(np);
    622 	vp->v_type = VDIR;
    623 	vp->v_flag = VROOT;
    624 	*vpp = vp;
    625 	return (0);
    626 }
    627 
    628 extern int syncprt;
    629 
    630 /*
    631  * Flush out the buffer cache
    632  */
    633 /* ARGSUSED */
    634 int
    635 nfs_sync(mp, waitfor, cred, p)
    636 	struct mount *mp;
    637 	int waitfor;
    638 	struct ucred *cred;
    639 	struct proc *p;
    640 {
    641 	register struct vnode *vp;
    642 	int error, allerror = 0;
    643 
    644 	/*
    645 	 * Force stale buffer cache information to be flushed.
    646 	 */
    647 loop:
    648 	for (vp = mp->mnt_vnodelist.lh_first;
    649 	     vp != NULL;
    650 	     vp = vp->v_mntvnodes.le_next) {
    651 		/*
    652 		 * If the vnode that we are about to sync is no longer
    653 		 * associated with this mount point, start over.
    654 		 */
    655 		if (vp->v_mount != mp)
    656 			goto loop;
    657 		if (VOP_ISLOCKED(vp) || vp->v_dirtyblkhd.lh_first == NULL)
    658 			continue;
    659 		if (vget(vp, 1))
    660 			goto loop;
    661 		if (error = VOP_FSYNC(vp, cred, waitfor, p))
    662 			allerror = error;
    663 		vput(vp);
    664 	}
    665 	return (allerror);
    666 }
    667 
    668 /*
    669  * NFS flat namespace lookup.
    670  * Currently unsupported.
    671  */
    672 /* ARGSUSED */
    673 int
    674 nfs_vget(mp, ino, vpp)
    675 	struct mount *mp;
    676 	ino_t ino;
    677 	struct vnode **vpp;
    678 {
    679 
    680 	return (EOPNOTSUPP);
    681 }
    682 
    683 /*
    684  * At this point, this should never happen
    685  */
    686 /* ARGSUSED */
    687 int
    688 nfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp)
    689 	register struct mount *mp;
    690 	struct fid *fhp;
    691 	struct mbuf *nam;
    692 	struct vnode **vpp;
    693 	int *exflagsp;
    694 	struct ucred **credanonp;
    695 {
    696 
    697 	return (EINVAL);
    698 }
    699 
    700 /*
    701  * Vnode pointer to File handle, should never happen either
    702  */
    703 /* ARGSUSED */
    704 int
    705 nfs_vptofh(vp, fhp)
    706 	struct vnode *vp;
    707 	struct fid *fhp;
    708 {
    709 
    710 	return (EINVAL);
    711 }
    712 
    713 /*
    714  * Vfs start routine, a no-op.
    715  */
    716 /* ARGSUSED */
    717 int
    718 nfs_start(mp, flags, p)
    719 	struct mount *mp;
    720 	int flags;
    721 	struct proc *p;
    722 {
    723 
    724 	return (0);
    725 }
    726 
    727 /*
    728  * Do operations associated with quotas, not supported
    729  */
    730 /* ARGSUSED */
    731 int
    732 nfs_quotactl(mp, cmd, uid, arg, p)
    733 	struct mount *mp;
    734 	int cmd;
    735 	uid_t uid;
    736 	caddr_t arg;
    737 	struct proc *p;
    738 {
    739 
    740 	return (EOPNOTSUPP);
    741 }
    742