Home | History | Annotate | Line # | Download | only in nfs
nfs_vfsops.c revision 1.164
      1 /*	$NetBSD: nfs_vfsops.c,v 1.164 2006/09/02 13:37:52 yamt Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1989, 1993, 1995
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * Rick Macklem at The University of Guelph.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. Neither the name of the University nor the names of its contributors
     19  *    may be used to endorse or promote products derived from this software
     20  *    without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  * SUCH DAMAGE.
     33  *
     34  *	@(#)nfs_vfsops.c	8.12 (Berkeley) 5/20/95
     35  */
     36 
     37 #include <sys/cdefs.h>
     38 __KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.164 2006/09/02 13:37:52 yamt Exp $");
     39 
     40 #if defined(_KERNEL_OPT)
     41 #include "opt_compat_netbsd.h"
     42 #include "opt_nfs.h"
     43 #endif
     44 
     45 #include <sys/param.h>
     46 #include <sys/ioctl.h>
     47 #include <sys/signal.h>
     48 #include <sys/proc.h>
     49 #include <sys/namei.h>
     50 #include <sys/device.h>
     51 #include <sys/vnode.h>
     52 #include <sys/kernel.h>
     53 #include <sys/mount.h>
     54 #include <sys/buf.h>
     55 #include <sys/mbuf.h>
     56 #include <sys/dirent.h>
     57 #include <sys/socket.h>
     58 #include <sys/socketvar.h>
     59 #include <sys/sysctl.h>
     60 #include <sys/systm.h>
     61 #include <sys/timetc.h>
     62 #include <sys/kauth.h>
     63 
     64 #include <net/if.h>
     65 #include <net/route.h>
     66 #include <netinet/in.h>
     67 
     68 #include <nfs/rpcv2.h>
     69 #include <nfs/nfsproto.h>
     70 #include <nfs/nfsnode.h>
     71 #include <nfs/nfs.h>
     72 #include <nfs/nfsmount.h>
     73 #include <nfs/xdr_subs.h>
     74 #include <nfs/nfsm_subs.h>
     75 #include <nfs/nfsdiskless.h>
     76 #include <nfs/nqnfs.h>
     77 #include <nfs/nfs_var.h>
     78 
     79 extern struct nfsstats nfsstats;
     80 extern int nfs_ticks;
     81 
     82 /*
     83  * keep a count of the nfs mounts to generate ficticious drive names
     84  * for the per drive stats.
     85  */
     86 unsigned int nfs_mount_count = 0;
     87 
     88 MALLOC_DEFINE(M_NFSMNT, "NFS mount", "NFS mount structure");
     89 
     90 /*
     91  * nfs vfs operations.
     92  */
     93 
     94 extern const struct vnodeopv_desc nfsv2_vnodeop_opv_desc;
     95 extern const struct vnodeopv_desc spec_nfsv2nodeop_opv_desc;
     96 extern const struct vnodeopv_desc fifo_nfsv2nodeop_opv_desc;
     97 
     98 const struct vnodeopv_desc * const nfs_vnodeopv_descs[] = {
     99 	&nfsv2_vnodeop_opv_desc,
    100 	&spec_nfsv2nodeop_opv_desc,
    101 	&fifo_nfsv2nodeop_opv_desc,
    102 	NULL,
    103 };
    104 
    105 struct vfsops nfs_vfsops = {
    106 	MOUNT_NFS,
    107 	nfs_mount,
    108 	nfs_start,
    109 	nfs_unmount,
    110 	nfs_root,
    111 	nfs_quotactl,
    112 	nfs_statvfs,
    113 	nfs_sync,
    114 	nfs_vget,
    115 	nfs_fhtovp,
    116 	nfs_vptofh,
    117 	nfs_vfs_init,
    118 	nfs_vfs_reinit,
    119 	nfs_vfs_done,
    120 	nfs_mountroot,
    121 	(int (*)(struct mount *, struct vnode *, struct timespec *)) eopnotsupp,
    122 	vfs_stdextattrctl,
    123 	nfs_vnodeopv_descs,
    124 	0,
    125 	{ NULL, NULL },
    126 };
    127 VFS_ATTACH(nfs_vfsops);
    128 
    129 extern u_int32_t nfs_procids[NFS_NPROCS];
    130 extern u_int32_t nfs_prog, nfs_vers;
    131 
    132 static int nfs_mount_diskless __P((struct nfs_dlmount *, const char *,
    133     struct mount **, struct vnode **, struct lwp *));
    134 
    135 /*
    136  * nfs statvfs call
    137  */
    138 int
    139 nfs_statvfs(mp, sbp, l)
    140 	struct mount *mp;
    141 	struct statvfs *sbp;
    142 	struct lwp *l;
    143 {
    144 	struct vnode *vp;
    145 	struct nfs_statfs *sfp;
    146 	caddr_t cp;
    147 	u_int32_t *tl;
    148 	int32_t t1, t2;
    149 	caddr_t bpos, dpos, cp2;
    150 	struct nfsmount *nmp = VFSTONFS(mp);
    151 	int error = 0, retattr;
    152 #ifdef NFS_V2_ONLY
    153 	const int v3 = 0;
    154 #else
    155 	int v3 = (nmp->nm_flag & NFSMNT_NFSV3);
    156 #endif
    157 	struct mbuf *mreq, *mrep = NULL, *md, *mb;
    158 	kauth_cred_t cred;
    159 	u_quad_t tquad;
    160 	struct nfsnode *np;
    161 
    162 #ifndef nolint
    163 	sfp = (struct nfs_statfs *)0;
    164 #endif
    165 	vp = nmp->nm_vnode;
    166 	np = VTONFS(vp);
    167 	cred = kauth_cred_alloc();
    168 #ifndef NFS_V2_ONLY
    169 	if (v3 && (nmp->nm_iflag & NFSMNT_GOTFSINFO) == 0)
    170 		(void)nfs_fsinfo(nmp, vp, cred, l);
    171 #endif
    172 	nfsstats.rpccnt[NFSPROC_FSSTAT]++;
    173 	nfsm_reqhead(np, NFSPROC_FSSTAT, NFSX_FH(v3));
    174 	nfsm_fhtom(np, v3);
    175 	nfsm_request(np, NFSPROC_FSSTAT, l, cred);
    176 	if (v3)
    177 		nfsm_postop_attr(vp, retattr, 0);
    178 	if (error) {
    179 		if (mrep != NULL) {
    180 			if (mrep->m_next != NULL)
    181 				printf("nfs_vfsops: nfs_statvfs would lose buffers\n");
    182 			m_freem(mrep);
    183 		}
    184 		goto nfsmout;
    185 	}
    186 	nfsm_dissect(sfp, struct nfs_statfs *, NFSX_STATFS(v3));
    187 	sbp->f_flag = nmp->nm_flag;
    188 	sbp->f_iosize = min(nmp->nm_rsize, nmp->nm_wsize);
    189 	if (v3) {
    190 		sbp->f_frsize = sbp->f_bsize = NFS_FABLKSIZE;
    191 		tquad = fxdr_hyper(&sfp->sf_tbytes);
    192 		sbp->f_blocks = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE);
    193 		tquad = fxdr_hyper(&sfp->sf_fbytes);
    194 		sbp->f_bfree = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE);
    195 		tquad = fxdr_hyper(&sfp->sf_abytes);
    196 		tquad = ((quad_t)tquad / (quad_t)NFS_FABLKSIZE);
    197 		sbp->f_bresvd = sbp->f_bfree - tquad;
    198 		sbp->f_bavail = tquad;
    199 #ifdef COMPAT_20
    200 		/* Handle older NFS servers returning negative values */
    201 		if ((quad_t)sbp->f_bavail < 0)
    202 			sbp->f_bavail = 0;
    203 #endif
    204 		tquad = fxdr_hyper(&sfp->sf_tfiles);
    205 		sbp->f_files = tquad;
    206 		tquad = fxdr_hyper(&sfp->sf_ffiles);
    207 		sbp->f_ffree = tquad;
    208 		sbp->f_favail = tquad;
    209 		sbp->f_fresvd = 0;
    210 		sbp->f_namemax = MAXNAMLEN;
    211 	} else {
    212 		sbp->f_bsize = NFS_FABLKSIZE;
    213 		sbp->f_frsize = fxdr_unsigned(int32_t, sfp->sf_bsize);
    214 		sbp->f_blocks = fxdr_unsigned(int32_t, sfp->sf_blocks);
    215 		sbp->f_bfree = fxdr_unsigned(int32_t, sfp->sf_bfree);
    216 		sbp->f_bavail = fxdr_unsigned(int32_t, sfp->sf_bavail);
    217 		sbp->f_fresvd = 0;
    218 		sbp->f_files = 0;
    219 		sbp->f_ffree = 0;
    220 		sbp->f_favail = 0;
    221 		sbp->f_fresvd = 0;
    222 		sbp->f_namemax = MAXNAMLEN;
    223 	}
    224 	copy_statvfs_info(sbp, mp);
    225 	nfsm_reqdone;
    226 	kauth_cred_free(cred);
    227 	return (error);
    228 }
    229 
    230 #ifndef NFS_V2_ONLY
    231 /*
    232  * nfs version 3 fsinfo rpc call
    233  */
    234 int
    235 nfs_fsinfo(nmp, vp, cred, l)
    236 	struct nfsmount *nmp;
    237 	struct vnode *vp;
    238 	kauth_cred_t cred;
    239 	struct lwp *l;
    240 {
    241 	struct nfsv3_fsinfo *fsp;
    242 	caddr_t cp;
    243 	int32_t t1, t2;
    244 	u_int32_t *tl, pref, xmax;
    245 	caddr_t bpos, dpos, cp2;
    246 	int error = 0, retattr;
    247 	struct mbuf *mreq, *mrep, *md, *mb;
    248 	u_int64_t maxfsize;
    249 	struct nfsnode *np = VTONFS(vp);
    250 
    251 	nfsstats.rpccnt[NFSPROC_FSINFO]++;
    252 	nfsm_reqhead(np, NFSPROC_FSINFO, NFSX_FH(1));
    253 	nfsm_fhtom(np, 1);
    254 	nfsm_request(np, NFSPROC_FSINFO, l, cred);
    255 	nfsm_postop_attr(vp, retattr, 0);
    256 	if (!error) {
    257 		nfsm_dissect(fsp, struct nfsv3_fsinfo *, NFSX_V3FSINFO);
    258 		pref = fxdr_unsigned(u_int32_t, fsp->fs_wtpref);
    259 		if ((nmp->nm_flag & NFSMNT_WSIZE) == 0 &&
    260 		    pref < nmp->nm_wsize && pref >= NFS_FABLKSIZE)
    261 			nmp->nm_wsize = (pref + NFS_FABLKSIZE - 1) &
    262 				~(NFS_FABLKSIZE - 1);
    263 		xmax = fxdr_unsigned(u_int32_t, fsp->fs_wtmax);
    264 		if (xmax < nmp->nm_wsize && xmax > 0) {
    265 			nmp->nm_wsize = xmax & ~(NFS_FABLKSIZE - 1);
    266 			if (nmp->nm_wsize == 0)
    267 				nmp->nm_wsize = xmax;
    268 		}
    269 		pref = fxdr_unsigned(u_int32_t, fsp->fs_rtpref);
    270 		if ((nmp->nm_flag & NFSMNT_RSIZE) == 0 &&
    271 		    pref < nmp->nm_rsize && pref >= NFS_FABLKSIZE)
    272 			nmp->nm_rsize = (pref + NFS_FABLKSIZE - 1) &
    273 				~(NFS_FABLKSIZE - 1);
    274 		xmax = fxdr_unsigned(u_int32_t, fsp->fs_rtmax);
    275 		if (xmax < nmp->nm_rsize && xmax > 0) {
    276 			nmp->nm_rsize = xmax & ~(NFS_FABLKSIZE - 1);
    277 			if (nmp->nm_rsize == 0)
    278 				nmp->nm_rsize = xmax;
    279 		}
    280 		pref = fxdr_unsigned(u_int32_t, fsp->fs_dtpref);
    281 		if (pref < nmp->nm_readdirsize && pref >= NFS_DIRFRAGSIZ)
    282 			nmp->nm_readdirsize = (pref + NFS_DIRFRAGSIZ - 1) &
    283 				~(NFS_DIRFRAGSIZ - 1);
    284 		if (xmax < nmp->nm_readdirsize && xmax > 0) {
    285 			nmp->nm_readdirsize = xmax & ~(NFS_DIRFRAGSIZ - 1);
    286 			if (nmp->nm_readdirsize == 0)
    287 				nmp->nm_readdirsize = xmax;
    288 		}
    289 		/* XXX */
    290 		nmp->nm_maxfilesize = (u_int64_t)0x80000000 * DEV_BSIZE - 1;
    291 		maxfsize = fxdr_hyper(&fsp->fs_maxfilesize);
    292 		if (maxfsize > 0 && maxfsize < nmp->nm_maxfilesize)
    293 			nmp->nm_maxfilesize = maxfsize;
    294 		nmp->nm_mountp->mnt_fs_bshift =
    295 		    ffs(MIN(nmp->nm_rsize, nmp->nm_wsize)) - 1;
    296 		nmp->nm_iflag |= NFSMNT_GOTFSINFO;
    297 	}
    298 	nfsm_reqdone;
    299 	return (error);
    300 }
    301 #endif
    302 
    303 /*
    304  * Mount a remote root fs via. NFS.  It goes like this:
    305  * - Call nfs_boot_init() to fill in the nfs_diskless struct
    306  * - build the rootfs mount point and call mountnfs() to do the rest.
    307  */
    308 int
    309 nfs_mountroot()
    310 {
    311 #ifdef __HAVE_TIMECOUNTER
    312 	struct timespec ts;
    313 #endif
    314 	struct nfs_diskless *nd;
    315 	struct vattr attr;
    316 	struct mount *mp;
    317 	struct vnode *vp;
    318 	struct lwp *l;
    319 	long n;
    320 	int error;
    321 
    322 	l = curlwp; /* XXX */
    323 
    324 	if (device_class(root_device) != DV_IFNET)
    325 		return (ENODEV);
    326 
    327 	/*
    328 	 * XXX time must be non-zero when we init the interface or else
    329 	 * the arp code will wedge.  [Fixed now in if_ether.c]
    330 	 * However, the NFS attribute cache gives false "hits" when the
    331 	 * current time < NFS_ATTRTIMEO(nmp, np) so keep this in for now.
    332 	 */
    333 	if (time_second < NFS_MAXATTRTIMO) {
    334 #ifdef __HAVE_TIMECOUNTER
    335 		ts.tv_sec = NFS_MAXATTRTIMO;
    336 		ts.tv_nsec = 0;
    337 		tc_setclock(&ts);
    338 #else /* !__HAVE_TIMECOUNTER */
    339 		time.tv_sec = NFS_MAXATTRTIMO;
    340 #endif /* !__HAVE_TIMECOUNTER */
    341 	}
    342 
    343 	/*
    344 	 * Call nfs_boot_init() to fill in the nfs_diskless struct.
    345 	 * Side effect:  Finds and configures a network interface.
    346 	 */
    347 	nd = malloc(sizeof(*nd), M_NFSMNT, M_WAITOK);
    348 	memset((caddr_t)nd, 0, sizeof(*nd));
    349 	error = nfs_boot_init(nd, l);
    350 	if (error) {
    351 		free(nd, M_NFSMNT);
    352 		return (error);
    353 	}
    354 
    355 	/*
    356 	 * Create the root mount point.
    357 	 */
    358 	error = nfs_mount_diskless(&nd->nd_root, "/", &mp, &vp, l);
    359 	if (error)
    360 		goto out;
    361 	printf("root on %s\n", nd->nd_root.ndm_host);
    362 
    363 	/*
    364 	 * Link it into the mount list.
    365 	 */
    366 	simple_lock(&mountlist_slock);
    367 	CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
    368 	simple_unlock(&mountlist_slock);
    369 	rootvp = vp;
    370 	mp->mnt_vnodecovered = NULLVP;
    371 	vfs_unbusy(mp);
    372 
    373 	/* Get root attributes (for the time). */
    374 	error = VOP_GETATTR(vp, &attr, l->l_cred, l);
    375 	if (error)
    376 		panic("nfs_mountroot: getattr for root");
    377 	n = attr.va_atime.tv_sec;
    378 #ifdef	DEBUG
    379 	printf("root time: 0x%lx\n", n);
    380 #endif
    381 	setrootfstime(n);
    382 
    383 out:
    384 	if (error)
    385 		nfs_boot_cleanup(nd, l);
    386 	free(nd, M_NFSMNT);
    387 	return (error);
    388 }
    389 
    390 /*
    391  * Internal version of mount system call for diskless setup.
    392  * Separate function because we used to call it twice.
    393  * (once for root and once for swap)
    394  */
    395 static int
    396 nfs_mount_diskless(ndmntp, mntname, mpp, vpp, l)
    397 	struct nfs_dlmount *ndmntp;
    398 	const char *mntname;	/* mount point name */
    399 	struct mount **mpp;
    400 	struct vnode **vpp;
    401 	struct lwp *l;
    402 {
    403 	struct mount *mp;
    404 	struct mbuf *m;
    405 	int error;
    406 
    407 	vfs_rootmountalloc(MOUNT_NFS, mntname, &mp);
    408 
    409 	mp->mnt_op = &nfs_vfsops;
    410 
    411 	/*
    412 	 * Historical practice expects NFS root file systems to
    413 	 * be initially mounted r/w.
    414 	 */
    415 	mp->mnt_flag &= ~MNT_RDONLY;
    416 
    417 	/* Get mbuf for server sockaddr. */
    418 	m = m_get(M_WAIT, MT_SONAME);
    419 	if (m == NULL)
    420 		panic("nfs_mountroot: mget soname for %s", mntname);
    421 	MCLAIM(m, &nfs_mowner);
    422 	memcpy(mtod(m, caddr_t), (caddr_t)ndmntp->ndm_args.addr,
    423 	      (m->m_len = ndmntp->ndm_args.addr->sa_len));
    424 
    425 	error = mountnfs(&ndmntp->ndm_args, mp, m, mntname,
    426 			 ndmntp->ndm_args.hostname, vpp, l);
    427 	if (error) {
    428 		mp->mnt_op->vfs_refcount--;
    429 		vfs_unbusy(mp);
    430 		printf("nfs_mountroot: mount %s failed: %d\n",
    431 		       mntname, error);
    432 		free(mp, M_MOUNT);
    433 	} else
    434 		*mpp = mp;
    435 
    436 	return (error);
    437 }
    438 
    439 void
    440 nfs_decode_args(nmp, argp, l)
    441 	struct nfsmount *nmp;
    442 	struct nfs_args *argp;
    443 	struct lwp *l;
    444 {
    445 	int s;
    446 	int adjsock;
    447 	int maxio;
    448 
    449 	s = splsoftnet();
    450 
    451 	/*
    452 	 * Silently clear NFSMNT_NOCONN if it's a TCP mount, it makes
    453 	 * no sense in that context.
    454 	 */
    455 	if (argp->sotype == SOCK_STREAM)
    456 		argp->flags &= ~NFSMNT_NOCONN;
    457 
    458 	/*
    459 	 * Cookie translation is not needed for v2, silently ignore it.
    460 	 */
    461 	if ((argp->flags & (NFSMNT_XLATECOOKIE|NFSMNT_NFSV3)) ==
    462 	    NFSMNT_XLATECOOKIE)
    463 		argp->flags &= ~NFSMNT_XLATECOOKIE;
    464 
    465 	/* Re-bind if rsrvd port requested and wasn't on one */
    466 	adjsock = !(nmp->nm_flag & NFSMNT_RESVPORT)
    467 		  && (argp->flags & NFSMNT_RESVPORT);
    468 	/* Also re-bind if we're switching to/from a connected UDP socket */
    469 	adjsock |= ((nmp->nm_flag & NFSMNT_NOCONN) !=
    470 		    (argp->flags & NFSMNT_NOCONN));
    471 
    472 	/* Update flags. */
    473 	nmp->nm_flag = argp->flags;
    474 	splx(s);
    475 
    476 	if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) {
    477 		nmp->nm_timeo = (argp->timeo * NFS_HZ + 5) / 10;
    478 		if (nmp->nm_timeo < NFS_MINTIMEO)
    479 			nmp->nm_timeo = NFS_MINTIMEO;
    480 		else if (nmp->nm_timeo > NFS_MAXTIMEO)
    481 			nmp->nm_timeo = NFS_MAXTIMEO;
    482 	}
    483 
    484 	if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) {
    485 		nmp->nm_retry = argp->retrans;
    486 		if (nmp->nm_retry > NFS_MAXREXMIT)
    487 			nmp->nm_retry = NFS_MAXREXMIT;
    488 	}
    489 
    490 #ifndef NFS_V2_ONLY
    491 	if (argp->flags & NFSMNT_NFSV3) {
    492 		if (argp->sotype == SOCK_DGRAM)
    493 			maxio = NFS_MAXDGRAMDATA;
    494 		else
    495 			maxio = NFS_MAXDATA;
    496 	} else
    497 #endif
    498 		maxio = NFS_V2MAXDATA;
    499 
    500 	if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) {
    501 		int osize = nmp->nm_wsize;
    502 		nmp->nm_wsize = argp->wsize;
    503 		/* Round down to multiple of blocksize */
    504 		nmp->nm_wsize &= ~(NFS_FABLKSIZE - 1);
    505 		if (nmp->nm_wsize <= 0)
    506 			nmp->nm_wsize = NFS_FABLKSIZE;
    507 		adjsock |= (nmp->nm_wsize != osize);
    508 	}
    509 	if (nmp->nm_wsize > maxio)
    510 		nmp->nm_wsize = maxio;
    511 	if (nmp->nm_wsize > MAXBSIZE)
    512 		nmp->nm_wsize = MAXBSIZE;
    513 
    514 	if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) {
    515 		int osize = nmp->nm_rsize;
    516 		nmp->nm_rsize = argp->rsize;
    517 		/* Round down to multiple of blocksize */
    518 		nmp->nm_rsize &= ~(NFS_FABLKSIZE - 1);
    519 		if (nmp->nm_rsize <= 0)
    520 			nmp->nm_rsize = NFS_FABLKSIZE;
    521 		adjsock |= (nmp->nm_rsize != osize);
    522 	}
    523 	if (nmp->nm_rsize > maxio)
    524 		nmp->nm_rsize = maxio;
    525 	if (nmp->nm_rsize > MAXBSIZE)
    526 		nmp->nm_rsize = MAXBSIZE;
    527 
    528 	if ((argp->flags & NFSMNT_READDIRSIZE) && argp->readdirsize > 0) {
    529 		nmp->nm_readdirsize = argp->readdirsize;
    530 		/* Round down to multiple of minimum blocksize */
    531 		nmp->nm_readdirsize &= ~(NFS_DIRFRAGSIZ - 1);
    532 		if (nmp->nm_readdirsize < NFS_DIRFRAGSIZ)
    533 			nmp->nm_readdirsize = NFS_DIRFRAGSIZ;
    534 		/* Bigger than buffer size makes no sense */
    535 		if (nmp->nm_readdirsize > NFS_DIRBLKSIZ)
    536 			nmp->nm_readdirsize = NFS_DIRBLKSIZ;
    537 	} else if (argp->flags & NFSMNT_RSIZE)
    538 		nmp->nm_readdirsize = nmp->nm_rsize;
    539 
    540 	if (nmp->nm_readdirsize > maxio)
    541 		nmp->nm_readdirsize = maxio;
    542 
    543 	if ((argp->flags & NFSMNT_MAXGRPS) && argp->maxgrouplist >= 0 &&
    544 		argp->maxgrouplist <= NFS_MAXGRPS)
    545 		nmp->nm_numgrps = argp->maxgrouplist;
    546 	if ((argp->flags & NFSMNT_READAHEAD) && argp->readahead >= 0 &&
    547 		argp->readahead <= NFS_MAXRAHEAD)
    548 		nmp->nm_readahead = argp->readahead;
    549 	if ((argp->flags & NFSMNT_LEASETERM) && argp->leaseterm >= 2 &&
    550 		argp->leaseterm <= NQ_MAXLEASE)
    551 		nmp->nm_leaseterm = argp->leaseterm;
    552 	if ((argp->flags & NFSMNT_DEADTHRESH) && argp->deadthresh >= 1 &&
    553 		argp->deadthresh <= NQ_NEVERDEAD)
    554 		nmp->nm_deadthresh = argp->deadthresh;
    555 
    556 	adjsock |= ((nmp->nm_sotype != argp->sotype) ||
    557 		    (nmp->nm_soproto != argp->proto));
    558 	nmp->nm_sotype = argp->sotype;
    559 	nmp->nm_soproto = argp->proto;
    560 
    561 	if (nmp->nm_so && adjsock) {
    562 		nfs_safedisconnect(nmp);
    563 		if (nmp->nm_sotype == SOCK_DGRAM)
    564 			while (nfs_connect(nmp, (struct nfsreq *)0, l)) {
    565 				printf("nfs_args: retrying connect\n");
    566 				(void) tsleep((caddr_t)&lbolt,
    567 					      PSOCK, "nfscn3", 0);
    568 			}
    569 	}
    570 }
    571 
    572 /*
    573  * VFS Operations.
    574  *
    575  * mount system call
    576  * It seems a bit dumb to copyinstr() the host and path here and then
    577  * memcpy() them in mountnfs(), but I wanted to detect errors before
    578  * doing the sockargs() call because sockargs() allocates an mbuf and
    579  * an error after that means that I have to release the mbuf.
    580  */
    581 /* ARGSUSED */
    582 int
    583 nfs_mount(mp, path, data, ndp, l)
    584 	struct mount *mp;
    585 	const char *path;
    586 	void *data;
    587 	struct nameidata *ndp;
    588 	struct lwp *l;
    589 {
    590 	int error;
    591 	struct nfs_args args;
    592 	struct mbuf *nam;
    593 	struct nfsmount *nmp = VFSTONFS(mp);
    594 	struct sockaddr *sa;
    595 	struct vnode *vp;
    596 	char *pth, *hst;
    597 	struct proc *p;
    598 	size_t len;
    599 	u_char *nfh;
    600 
    601 	error = copyin(data, (caddr_t)&args, sizeof (struct nfs_args));
    602 	if (error)
    603 		return (error);
    604 
    605 	p = l->l_proc;
    606 	if (mp->mnt_flag & MNT_GETARGS) {
    607 
    608 		if (nmp == NULL)
    609 			return (EIO);
    610 		if (args.addr != NULL) {
    611 			sa = mtod(nmp->nm_nam, struct sockaddr *);
    612 			error = copyout(sa, args.addr, sa->sa_len);
    613 			if (error)
    614 				return (error);
    615 			args.addrlen = sa->sa_len;
    616 		} else
    617 			args.addrlen = 0;
    618 
    619 		args.version = NFS_ARGSVERSION;
    620 		args.sotype = nmp->nm_sotype;
    621 		args.proto = nmp->nm_soproto;
    622 		args.fh = NULL;
    623 		args.fhsize = 0;
    624 		args.flags = nmp->nm_flag;
    625 		args.wsize = nmp->nm_wsize;
    626 		args.rsize = nmp->nm_rsize;
    627 		args.readdirsize = nmp->nm_readdirsize;
    628 		args.timeo = nmp->nm_timeo;
    629 		args.retrans = nmp->nm_retry;
    630 		args.maxgrouplist = nmp->nm_numgrps;
    631 		args.readahead = nmp->nm_readahead;
    632 		args.leaseterm = nmp->nm_leaseterm;
    633 		args.deadthresh = nmp->nm_deadthresh;
    634 		args.hostname = NULL;
    635 		return (copyout(&args, data, sizeof(args)));
    636 	}
    637 
    638 	if (args.version != NFS_ARGSVERSION)
    639 		return (EPROGMISMATCH);
    640 #ifdef NFS_V2_ONLY
    641 	if (args.flags & NFSMNT_NQNFS)
    642 		return (EPROGUNAVAIL);
    643 	if (args.flags & NFSMNT_NFSV3)
    644 		return (EPROGMISMATCH);
    645 #endif
    646 	if (mp->mnt_flag & MNT_UPDATE) {
    647 		if (nmp == NULL)
    648 			return (EIO);
    649 		/*
    650 		 * When doing an update, we can't change from or to
    651 		 * v3 and/or nqnfs, or change cookie translation
    652 		 */
    653 		args.flags = (args.flags &
    654 		    ~(NFSMNT_NFSV3|NFSMNT_NQNFS|NFSMNT_XLATECOOKIE)) |
    655 		    (nmp->nm_flag &
    656 			(NFSMNT_NFSV3|NFSMNT_NQNFS|NFSMNT_XLATECOOKIE));
    657 		nfs_decode_args(nmp, &args, l);
    658 		return (0);
    659 	}
    660 	if (args.fhsize < 0 || args.fhsize > NFSX_V3FHMAX)
    661 		return (EINVAL);
    662 	MALLOC(nfh, u_char *, NFSX_V3FHMAX, M_TEMP, M_WAITOK);
    663 	error = copyin((caddr_t)args.fh, (caddr_t)nfh, args.fhsize);
    664 	if (error)
    665 		return (error);
    666 	MALLOC(pth, char *, MNAMELEN, M_TEMP, M_WAITOK);
    667 	error = copyinstr(path, pth, MNAMELEN - 1, &len);
    668 	if (error)
    669 		goto free_nfh;
    670 	memset(&pth[len], 0, MNAMELEN - len);
    671 	MALLOC(hst, char *, MNAMELEN, M_TEMP, M_WAITOK);
    672 	error = copyinstr(args.hostname, hst, MNAMELEN - 1, &len);
    673 	if (error)
    674 		goto free_pth;
    675 	memset(&hst[len], 0, MNAMELEN - len);
    676 	/* sockargs() call must be after above copyin() calls */
    677 	error = sockargs(&nam, (caddr_t)args.addr, args.addrlen, MT_SONAME);
    678 	if (error)
    679 		goto free_hst;
    680 	MCLAIM(nam, &nfs_mowner);
    681 	args.fh = nfh;
    682 	error = mountnfs(&args, mp, nam, pth, hst, &vp, l);
    683 
    684 free_hst:
    685 	FREE(hst, M_TEMP);
    686 free_pth:
    687 	FREE(pth, M_TEMP);
    688 free_nfh:
    689 	FREE(nfh, M_TEMP);
    690 
    691 	return (error);
    692 }
    693 
    694 /*
    695  * Common code for mount and mountroot
    696  */
    697 int
    698 mountnfs(argp, mp, nam, pth, hst, vpp, l)
    699 	struct nfs_args *argp;
    700 	struct mount *mp;
    701 	struct mbuf *nam;
    702 	const char *pth, *hst;
    703 	struct vnode **vpp;
    704 	struct lwp *l;
    705 {
    706 	struct nfsmount *nmp;
    707 	struct nfsnode *np;
    708 	int error;
    709 	struct vattr *attrs;
    710 	kauth_cred_t cr;
    711 	char iosname[IOSTATNAMELEN];
    712 
    713 	/*
    714 	 * If the number of nfs iothreads to use has never
    715 	 * been set, create a reasonable number of them.
    716 	 */
    717 
    718 	if (nfs_niothreads < 0) {
    719 		nfs_niothreads = NFS_DEFAULT_NIOTHREADS;
    720 		nfs_getset_niothreads(TRUE);
    721 	}
    722 
    723 	if (mp->mnt_flag & MNT_UPDATE) {
    724 		nmp = VFSTONFS(mp);
    725 		/* update paths, file handles, etc, here	XXX */
    726 		m_freem(nam);
    727 		return (0);
    728 	} else {
    729 		MALLOC(nmp, struct nfsmount *, sizeof (struct nfsmount),
    730 		    M_NFSMNT, M_WAITOK);
    731 		memset((caddr_t)nmp, 0, sizeof (struct nfsmount));
    732 		mp->mnt_data = nmp;
    733 		TAILQ_INIT(&nmp->nm_uidlruhead);
    734 		TAILQ_INIT(&nmp->nm_bufq);
    735 		lockinit(&nmp->nm_writeverflock, PRIBIO, "nfswverf", 0, 0);
    736 		simple_lock_init(&nmp->nm_slock);
    737 	}
    738 	vfs_getnewfsid(mp);
    739 	nmp->nm_mountp = mp;
    740 
    741 #ifndef NFS_V2_ONLY
    742 	if (argp->flags & NFSMNT_NQNFS)
    743 		mp->mnt_iflag |= IMNT_DTYPE;
    744 #endif
    745 
    746 #ifndef NFS_V2_ONLY
    747 	if ((argp->flags & NFSMNT_NFSV3) == 0)
    748 #endif
    749 	{
    750 		/*
    751 		 * V2 can only handle 32 bit filesizes. For v3, nfs_fsinfo
    752 		 * will fill this in.
    753 		 */
    754 		nmp->nm_maxfilesize = 0xffffffffLL;
    755 		if (argp->fhsize != NFSX_V2FH) {
    756 			return EINVAL;
    757 		}
    758 	}
    759 
    760 	nmp->nm_timeo = NFS_TIMEO;
    761 	nmp->nm_retry = NFS_RETRANS;
    762 	nmp->nm_wsize = NFS_WSIZE;
    763 	nmp->nm_rsize = NFS_RSIZE;
    764 	nmp->nm_readdirsize = NFS_READDIRSIZE;
    765 	nmp->nm_numgrps = NFS_MAXGRPS;
    766 	nmp->nm_readahead = NFS_DEFRAHEAD;
    767 	nmp->nm_leaseterm = NQ_DEFLEASE;
    768 	nmp->nm_deadthresh = NQ_DEADTHRESH;
    769 	CIRCLEQ_INIT(&nmp->nm_timerhead);
    770 	nmp->nm_inprog = NULLVP;
    771 	error = set_statvfs_info(pth, UIO_SYSSPACE, hst, UIO_SYSSPACE, mp, l);
    772 	if (error)
    773 		goto bad;
    774 	nmp->nm_nam = nam;
    775 
    776 	/* Set up the sockets and per-host congestion */
    777 	nmp->nm_sotype = argp->sotype;
    778 	nmp->nm_soproto = argp->proto;
    779 
    780 	nfs_decode_args(nmp, argp, l);
    781 
    782 	mp->mnt_fs_bshift = ffs(MIN(nmp->nm_rsize, nmp->nm_wsize)) - 1;
    783 	mp->mnt_dev_bshift = DEV_BSHIFT;
    784 
    785 	/*
    786 	 * For Connection based sockets (TCP,...) defer the connect until
    787 	 * the first request, in case the server is not responding.
    788 	 */
    789 	if (nmp->nm_sotype == SOCK_DGRAM &&
    790 		(error = nfs_connect(nmp, (struct nfsreq *)0, l)))
    791 		goto bad;
    792 
    793 	/*
    794 	 * This is silly, but it has to be set so that vinifod() works.
    795 	 * We do not want to do an nfs_statvfs() here since we can get
    796 	 * stuck on a dead server and we are holding a lock on the mount
    797 	 * point.
    798 	 */
    799 	mp->mnt_stat.f_iosize = NFS_MAXDGRAMDATA;
    800 	error = nfs_nget(mp, (nfsfh_t *)argp->fh, argp->fhsize, &np);
    801 	if (error)
    802 		goto bad;
    803 	*vpp = NFSTOV(np);
    804 	MALLOC(attrs, struct vattr *, sizeof(struct vattr), M_TEMP, M_WAITOK);
    805 	VOP_GETATTR(*vpp, attrs, l->l_cred, l);
    806 	if ((nmp->nm_flag & NFSMNT_NFSV3) && ((*vpp)->v_type == VDIR)) {
    807 		cr = kauth_cred_alloc();
    808 		kauth_cred_setuid(cr, attrs->va_uid);
    809 		kauth_cred_seteuid(cr, attrs->va_uid);
    810 		kauth_cred_setsvuid(cr, attrs->va_uid);
    811 		kauth_cred_setgid(cr, attrs->va_gid);
    812 		kauth_cred_setegid(cr, attrs->va_gid);
    813 		kauth_cred_setsvgid(cr, attrs->va_gid);
    814 		nfs_cookieheuristic(*vpp, &nmp->nm_iflag, l, cr);
    815 		kauth_cred_free(cr);
    816 	}
    817 	FREE(attrs, M_TEMP);
    818 
    819 	/*
    820 	 * A reference count is needed on the nfsnode representing the
    821 	 * remote root.  If this object is not persistent, then backward
    822 	 * traversals of the mount point (i.e. "..") will not work if
    823 	 * the nfsnode gets flushed out of the cache. Ufs does not have
    824 	 * this problem, because one can identify root inodes by their
    825 	 * number == ROOTINO (2). So, just unlock, but no rele.
    826 	 */
    827 
    828 	nmp->nm_vnode = *vpp;
    829 	VOP_UNLOCK(*vpp, 0);
    830 
    831 	snprintf(iosname, sizeof(iosname), "nfs%u", nfs_mount_count++);
    832 	nmp->nm_stats = iostat_alloc(IOSTAT_NFS, nmp, iosname);
    833 
    834 	return (0);
    835 bad:
    836 	nfs_disconnect(nmp);
    837 	free((caddr_t)nmp, M_NFSMNT);
    838 	m_freem(nam);
    839 	return (error);
    840 }
    841 
    842 /*
    843  * unmount system call
    844  */
    845 int
    846 nfs_unmount(mp, mntflags, l)
    847 	struct mount *mp;
    848 	int mntflags;
    849 	struct lwp *l;
    850 {
    851 	struct nfsmount *nmp;
    852 	struct vnode *vp;
    853 	int error, flags = 0;
    854 
    855 	if (mntflags & MNT_FORCE)
    856 		flags |= FORCECLOSE;
    857 	nmp = VFSTONFS(mp);
    858 	/*
    859 	 * Goes something like this..
    860 	 * - Check for activity on the root vnode (other than ourselves).
    861 	 * - Call vflush() to clear out vnodes for this file system,
    862 	 *   except for the root vnode.
    863 	 * - Decrement reference on the vnode representing remote root.
    864 	 * - Close the socket
    865 	 * - Free up the data structures
    866 	 */
    867 	/*
    868 	 * We need to decrement the ref. count on the nfsnode representing
    869 	 * the remote root.  See comment in mountnfs().  The VFS unmount()
    870 	 * has done vput on this vnode, otherwise we would get deadlock!
    871 	 */
    872 	vp = nmp->nm_vnode;
    873 	error = vget(vp, LK_EXCLUSIVE | LK_RETRY);
    874 	if (error != 0)
    875 		return error;
    876 
    877 	if ((mntflags & MNT_FORCE) == 0 && vp->v_usecount > 2) {
    878 		vput(vp);
    879 		return (EBUSY);
    880 	}
    881 
    882 	/*
    883 	 * Must handshake with nqnfs_clientd() if it is active.
    884 	 */
    885 	nmp->nm_iflag |= NFSMNT_DISMINPROG;
    886 	while (nmp->nm_inprog != NULLVP)
    887 		(void) tsleep((caddr_t)&lbolt, PSOCK, "nfsdism", 0);
    888 	error = vflush(mp, vp, flags);
    889 	if (error) {
    890 		vput(vp);
    891 		nmp->nm_iflag &= ~NFSMNT_DISMINPROG;
    892 		return (error);
    893 	}
    894 
    895 	/*
    896 	 * We are now committed to the unmount; mark the mount structure
    897 	 * as doomed so that any sleepers kicked awake by nfs_disconnect
    898 	 * will go away cleanly.
    899 	 */
    900 	nmp->nm_iflag |= NFSMNT_DISMNT;
    901 
    902 	/*
    903 	 * Clean up the stats... note that we carefully avoid decrementing
    904 	 * nfs_mount_count here for good reason - we may not be unmounting
    905 	 * the last thing mounted.
    906 	 */
    907 	iostat_free(nmp->nm_stats);
    908 
    909 	/*
    910 	 * There are two reference counts to get rid of here
    911 	 * (see comment in mountnfs()).
    912 	 */
    913 	vrele(vp);
    914 	vput(vp);
    915 	vgone(vp);
    916 	nfs_disconnect(nmp);
    917 	m_freem(nmp->nm_nam);
    918 
    919 	/*
    920 	 * For NQNFS, let the server daemon free the nfsmount structure.
    921 	 */
    922 	if ((nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB)) == 0)
    923 		free((caddr_t)nmp, M_NFSMNT);
    924 	return (0);
    925 }
    926 
    927 /*
    928  * Return root of a filesystem
    929  */
    930 int
    931 nfs_root(mp, vpp)
    932 	struct mount *mp;
    933 	struct vnode **vpp;
    934 {
    935 	struct vnode *vp;
    936 	struct nfsmount *nmp;
    937 	int error;
    938 
    939 	nmp = VFSTONFS(mp);
    940 	vp = nmp->nm_vnode;
    941 	error = vget(vp, LK_EXCLUSIVE | LK_RETRY);
    942 	if (error != 0)
    943 		return error;
    944 	if (vp->v_type == VNON)
    945 		vp->v_type = VDIR;
    946 	vp->v_flag = VROOT;
    947 	*vpp = vp;
    948 	return (0);
    949 }
    950 
    951 extern int syncprt;
    952 
    953 /*
    954  * Flush out the buffer cache
    955  */
    956 /* ARGSUSED */
    957 int
    958 nfs_sync(mp, waitfor, cred, l)
    959 	struct mount *mp;
    960 	int waitfor;
    961 	kauth_cred_t cred;
    962 	struct lwp *l;
    963 {
    964 	struct vnode *vp;
    965 	int error, allerror = 0;
    966 
    967 	/*
    968 	 * Force stale buffer cache information to be flushed.
    969 	 */
    970 loop:
    971 	LIST_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
    972 		/*
    973 		 * If the vnode that we are about to sync is no longer
    974 		 * associated with this mount point, start over.
    975 		 */
    976 		if (vp->v_mount != mp)
    977 			goto loop;
    978 		if (waitfor == MNT_LAZY || VOP_ISLOCKED(vp) ||
    979 		    (LIST_EMPTY(&vp->v_dirtyblkhd) &&
    980 		     vp->v_uobj.uo_npages == 0))
    981 			continue;
    982 		if (vget(vp, LK_EXCLUSIVE))
    983 			goto loop;
    984 		error = VOP_FSYNC(vp, cred,
    985 		    waitfor == MNT_WAIT ? FSYNC_WAIT : 0, 0, 0, l);
    986 		if (error)
    987 			allerror = error;
    988 		vput(vp);
    989 	}
    990 	return (allerror);
    991 }
    992 
    993 /*
    994  * NFS flat namespace lookup.
    995  * Currently unsupported.
    996  */
    997 /* ARGSUSED */
    998 int
    999 nfs_vget(mp, ino, vpp)
   1000 	struct mount *mp;
   1001 	ino_t ino;
   1002 	struct vnode **vpp;
   1003 {
   1004 
   1005 	return (EOPNOTSUPP);
   1006 }
   1007 
   1008 /*
   1009  * Do that sysctl thang...
   1010  */
   1011 static int
   1012 sysctl_vfs_nfs_iothreads(SYSCTLFN_ARGS)
   1013 {
   1014 	int error;
   1015 
   1016 	nfs_getset_niothreads(0);
   1017         error = sysctl_lookup(SYSCTLFN_CALL(rnode));
   1018 	if (error || newp == NULL)
   1019 		return (error);
   1020 	nfs_getset_niothreads(1);
   1021 
   1022 	return (0);
   1023 }
   1024 
   1025 SYSCTL_SETUP(sysctl_vfs_nfs_setup, "sysctl vfs.nfs subtree setup")
   1026 {
   1027 
   1028 	sysctl_createv(clog, 0, NULL, NULL,
   1029 		       CTLFLAG_PERMANENT,
   1030 		       CTLTYPE_NODE, "vfs", NULL,
   1031 		       NULL, 0, NULL, 0,
   1032 		       CTL_VFS, CTL_EOL);
   1033 	sysctl_createv(clog, 0, NULL, NULL,
   1034 		       CTLFLAG_PERMANENT,
   1035 		       CTLTYPE_NODE, "nfs",
   1036 		       SYSCTL_DESCR("NFS vfs options"),
   1037 		       NULL, 0, NULL, 0,
   1038 		       CTL_VFS, 2, CTL_EOL);
   1039 	/*
   1040 	 * XXX the "2" above could be dynamic, thereby eliminating one
   1041 	 * more instance of the "number to vfs" mapping problem, but
   1042 	 * "2" is the order as taken from sys/mount.h
   1043 	 */
   1044 
   1045 	sysctl_createv(clog, 0, NULL, NULL,
   1046 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1047 		       CTLTYPE_STRUCT, "nfsstats",
   1048 		       SYSCTL_DESCR("NFS operation statistics"),
   1049 		       NULL, 0, &nfsstats, sizeof(nfsstats),
   1050 		       CTL_VFS, 2, NFS_NFSSTATS, CTL_EOL);
   1051 	sysctl_createv(clog, 0, NULL, NULL,
   1052 		       CTLFLAG_PERMANENT|CTLFLAG_READWRITE,
   1053 		       CTLTYPE_INT, "iothreads",
   1054 		       SYSCTL_DESCR("Number of NFS client processes desired"),
   1055 		       sysctl_vfs_nfs_iothreads, 0, &nfs_niothreads, 0,
   1056 		       CTL_VFS, 2, NFS_IOTHREADS, CTL_EOL);
   1057 }
   1058 
   1059 /* ARGSUSED */
   1060 int
   1061 nfs_fhtovp(struct mount *mp, struct fid *fid, struct vnode **vpp)
   1062 {
   1063 	size_t fidsize;
   1064 	size_t fhsize;
   1065 	struct nfsnode *np;
   1066 	int error;
   1067 	struct vattr va;
   1068 
   1069 	fidsize = fid->fid_len;
   1070 	if (fidsize < sizeof(*fid)) {
   1071 		return EINVAL;
   1072 	}
   1073 	fhsize = fidsize - sizeof(*fid);
   1074 	if ((fhsize % NFSX_UNSIGNED) != 0) {
   1075 		return EINVAL;
   1076 	}
   1077 	if ((VFSTONFS(mp)->nm_flag & NFSMNT_NFSV3) != 0) {
   1078 		if (fhsize > NFSX_V3FHMAX || fhsize == 0) {
   1079 			return EINVAL;
   1080 		}
   1081 	} else {
   1082 		if (fhsize != NFSX_V2FH) {
   1083 			return EINVAL;
   1084 		}
   1085 	}
   1086 	error = nfs_nget(mp, (void *)fid->fid_data, fhsize, &np);
   1087 	if (error) {
   1088 		return error;
   1089 	}
   1090 	*vpp = NFSTOV(np);
   1091 	error = VOP_GETATTR(*vpp, &va, kauth_cred_get(), curlwp);
   1092 	if (error != 0) {
   1093 		vput(*vpp);
   1094 	}
   1095 	return error;
   1096 }
   1097 
   1098 /* ARGSUSED */
   1099 int
   1100 nfs_vptofh(struct vnode *vp, struct fid *buf, size_t *bufsize)
   1101 {
   1102 	struct nfsnode *np;
   1103 	struct fid *fid;
   1104 	size_t fidsize;
   1105 	int error = 0;
   1106 
   1107 	np = VTONFS(vp);
   1108 	fidsize = sizeof(*fid) + np->n_fhsize;
   1109 	if (*bufsize < fidsize) {
   1110 		error = E2BIG;
   1111 	}
   1112 	*bufsize = fidsize;
   1113 	if (error == 0) {
   1114 		struct fid fid_store;
   1115 
   1116 		fid = &fid_store;
   1117 		memset(fid, 0, sizeof(*fid));
   1118 		fid->fid_len = fidsize;
   1119 		memcpy(buf, fid, sizeof(*fid));
   1120 		memcpy(buf->fid_data, np->n_fhp, np->n_fhsize);
   1121 	}
   1122 	return error;
   1123 }
   1124 
   1125 /*
   1126  * Vfs start routine, a no-op.
   1127  */
   1128 /* ARGSUSED */
   1129 int
   1130 nfs_start(mp, flags, l)
   1131 	struct mount *mp;
   1132 	int flags;
   1133 	struct lwp *l;
   1134 {
   1135 
   1136 	return (0);
   1137 }
   1138 
   1139 /*
   1140  * Do operations associated with quotas, not supported
   1141  */
   1142 /* ARGSUSED */
   1143 int
   1144 nfs_quotactl(mp, cmd, uid, arg, l)
   1145 	struct mount *mp;
   1146 	int cmd;
   1147 	uid_t uid;
   1148 	void *arg;
   1149 	struct lwp *l;
   1150 {
   1151 
   1152 	return (EOPNOTSUPP);
   1153 }
   1154