]> git.saurik.com Git - apple/xnu.git/blob - bsd/nfs/nfs_vfsops.c
xnu-517.3.15.tar.gz
[apple/xnu.git] / bsd / nfs / nfs_vfsops.c
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
26 /*
27 * Copyright (c) 1989, 1993, 1995
28 * The Regents of the University of California. All rights reserved.
29 *
30 * This code is derived from software contributed to Berkeley by
31 * Rick Macklem at The University of Guelph.
32 *
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
35 * are met:
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by the University of
44 * California, Berkeley and its contributors.
45 * 4. Neither the name of the University nor the names of its contributors
46 * may be used to endorse or promote products derived from this software
47 * without specific prior written permission.
48 *
49 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * SUCH DAMAGE.
60 *
61 * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95
62 * FreeBSD-Id: nfs_vfsops.c,v 1.52 1997/11/12 05:42:21 julian Exp $
63 */
64
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/conf.h>
68 #include <sys/ioctl.h>
69 #include <sys/signal.h>
70 #include <sys/proc.h>
71 #include <sys/namei.h>
72 #include <sys/vnode.h>
73 #include <sys/malloc.h>
74 #include <sys/kernel.h>
75 #include <sys/sysctl.h>
76 #include <sys/mount.h>
77 #include <sys/mbuf.h>
78 #include <sys/socket.h>
79 #include <sys/socketvar.h>
80
81 #include <sys/vm.h>
82 #include <sys/vmparam.h>
83
84 #if !defined(NO_MOUNT_PRIVATE)
85 #include <sys/filedesc.h>
86 #endif /* NO_MOUNT_PRIVATE */
87
88 #include <net/if.h>
89 #include <net/route.h>
90 #include <netinet/in.h>
91
92 #include <nfs/rpcv2.h>
93 #include <nfs/nfsproto.h>
94 #include <nfs/nfs.h>
95 #include <nfs/nfsnode.h>
96 #include <nfs/nfsmount.h>
97 #include <nfs/xdr_subs.h>
98 #include <nfs/nfsm_subs.h>
99 #include <nfs/nfsdiskless.h>
100 #include <nfs/nqnfs.h>
101
102 extern int nfs_mountroot __P((void));
103
104 extern int nfs_ticks;
105 extern int nfs_mount_type;
106 extern int nfs_resv_mounts;
107
108 struct nfsstats nfsstats;
109 static int nfs_sysctl(int *, u_int, void *, size_t *, void *, size_t,
110 struct proc *);
111 /* XXX CSM 11/25/97 Upgrade sysctl.h someday */
112 #ifdef notyet
113 SYSCTL_NODE(_vfs, MOUNT_NFS, nfs, CTLFLAG_RW, 0, "NFS filesystem");
114 SYSCTL_STRUCT(_vfs_nfs, NFS_NFSSTATS, nfsstats, CTLFLAG_RD,
115 &nfsstats, nfsstats, "");
116 #endif
117 #if NFSDIAG
118 int nfs_debug;
119 /* XXX CSM 11/25/97 Upgrade sysctl.h someday */
120 #ifdef notyet
121 SYSCTL_INT(_vfs_nfs, OID_AUTO, debug, CTLFLAG_RW, &nfs_debug, 0, "");
122 #endif
123 #endif
124
125 SYSCTL_DECL(_vfs_generic_nfs);
126 SYSCTL_NODE(_vfs_generic_nfs, OID_AUTO, client, CTLFLAG_RW, 0,
127 "nfs client hinge");
128 /* how long NFS will wait before signalling vfs that it's down. */
129 static int nfs_tprintf_initial_delay = NFS_TPRINTF_INITIAL_DELAY;
130 SYSCTL_INT(_vfs_generic_nfs_client, NFS_TPRINTF_INITIAL_DELAY,
131 initialdowndelay, CTLFLAG_RW, &nfs_tprintf_initial_delay, 0, "");
132 /* how long between console messages "nfs server foo not responding" */
133 static int nfs_tprintf_delay = NFS_TPRINTF_DELAY;
134 SYSCTL_INT(_vfs_generic_nfs_client, NFS_TPRINTF_DELAY,
135 nextdowndelay, CTLFLAG_RW, &nfs_tprintf_delay, 0, "");
136
137 static int nfs_iosize __P((struct nfsmount *nmp));
138 static int mountnfs __P((struct nfs_args *,struct mount *,
139 struct mbuf *,char *,char *,struct vnode **));
140 static int nfs_mount __P(( struct mount *mp, char *path, caddr_t data,
141 struct nameidata *ndp, struct proc *p));
142 static int nfs_start __P(( struct mount *mp, int flags,
143 struct proc *p));
144 static int nfs_unmount __P(( struct mount *mp, int mntflags,
145 struct proc *p));
146 static int nfs_root __P(( struct mount *mp, struct vnode **vpp));
147 static int nfs_quotactl __P(( struct mount *mp, int cmds, uid_t uid,
148 caddr_t arg, struct proc *p));
149 static int nfs_statfs __P(( struct mount *mp, struct statfs *sbp,
150 struct proc *p));
151 static int nfs_sync __P(( struct mount *mp, int waitfor,
152 struct ucred *cred, struct proc *p));
153 static int nfs_vptofh __P(( struct vnode *vp, struct fid *fhp));
154 static int nfs_fhtovp __P((struct mount *mp, struct fid *fhp,
155 struct mbuf *nam, struct vnode **vpp,
156 int *exflagsp, struct ucred **credanonp));
157 static int nfs_vget __P((struct mount *, void *, struct vnode **));
158
159
160 /*
161 * nfs vfs operations.
162 */
163 struct vfsops nfs_vfsops = {
164 nfs_mount,
165 nfs_start,
166 nfs_unmount,
167 nfs_root,
168 nfs_quotactl,
169 nfs_statfs,
170 nfs_sync,
171 nfs_vget,
172 nfs_fhtovp,
173 nfs_vptofh,
174 nfs_init,
175 nfs_sysctl
176 };
177 /* XXX CSM 11/25/97 Mysterious kernel.h ld crud */
178 #ifdef notyet
179 VFS_SET(nfs_vfsops, nfs, MOUNT_NFS, VFCF_NETWORK);
180 #endif
181
182
183 void nfsargs_ntoh __P((struct nfs_args *));
184 static int
185 nfs_mount_diskless __P((struct nfs_dlmount *, char *, int, struct vnode **,
186 struct mount **));
187 #if !defined(NO_MOUNT_PRIVATE)
188 static int
189 nfs_mount_diskless_private __P((struct nfs_dlmount *, char *, int,
190 struct vnode **, struct mount **));
191 #endif /* NO_MOUNT_PRIVATE */
192 static void nfs_convert_oargs __P((struct nfs_args *args,
193 struct onfs_args *oargs));
194 #if NFSDIAG
195 int nfsreqqusers = 0;
196 extern int nfsbtlen, nfsbtcpu, nfsbtthread, nfsbt[32];
197 #endif
198
199 static int nfs_iosize(nmp)
200 struct nfsmount* nmp;
201 {
202 int iosize;
203
204 /*
205 * Calculate the size used for io buffers. Use the larger
206 * of the two sizes to minimise nfs requests but make sure
207 * that it is at least one VM page to avoid wasting buffer
208 * space and to allow easy mmapping of I/O buffers.
209 * The read/write rpc calls handle the splitting up of
210 * buffers into multiple requests if the buffer size is
211 * larger than the I/O size.
212 */
213 iosize = max(nmp->nm_rsize, nmp->nm_wsize);
214 if (iosize < PAGE_SIZE)
215 iosize = PAGE_SIZE;
216 return (trunc_page_32(iosize));
217 }
218
219 static void nfs_convert_oargs(args,oargs)
220 struct nfs_args *args;
221 struct onfs_args *oargs;
222 {
223 args->version = NFS_ARGSVERSION;
224 args->addr = oargs->addr;
225 args->addrlen = oargs->addrlen;
226 args->sotype = oargs->sotype;
227 args->proto = oargs->proto;
228 args->fh = oargs->fh;
229 args->fhsize = oargs->fhsize;
230 args->flags = oargs->flags;
231 args->wsize = oargs->wsize;
232 args->rsize = oargs->rsize;
233 args->readdirsize = oargs->readdirsize;
234 args->timeo = oargs->timeo;
235 args->retrans = oargs->retrans;
236 args->maxgrouplist = oargs->maxgrouplist;
237 args->readahead = oargs->readahead;
238 args->leaseterm = oargs->leaseterm;
239 args->deadthresh = oargs->deadthresh;
240 args->hostname = oargs->hostname;
241 }
242
243 /*
244 * nfs statfs call
245 */
246 int
247 nfs_statfs(mp, sbp, p)
248 struct mount *mp;
249 register struct statfs *sbp;
250 struct proc *p;
251 {
252 register struct vnode *vp;
253 register struct nfs_statfs *sfp;
254 register caddr_t cp;
255 register u_long *tl;
256 register long t1, t2;
257 caddr_t bpos, dpos, cp2;
258 struct nfsmount *nmp = VFSTONFS(mp);
259 int error = 0, v3 = (nmp->nm_flag & NFSMNT_NFSV3), retattr;
260 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
261 struct ucred *cred;
262 u_quad_t tquad;
263 extern int nfs_mount_type;
264 u_int64_t xid;
265
266 #ifndef nolint
267 sfp = (struct nfs_statfs *)0;
268 #endif
269 vp = nmp->nm_dvp;
270 if (error = vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, p))
271 return(error);
272 cred = crget();
273 cred->cr_ngroups = 1;
274 if (v3 && (nmp->nm_state & NFSSTA_GOTFSINFO) == 0)
275 (void)nfs_fsinfo(nmp, vp, cred, p);
276 nfsstats.rpccnt[NFSPROC_FSSTAT]++;
277 nfsm_reqhead(vp, NFSPROC_FSSTAT, NFSX_FH(v3));
278 nfsm_fhtom(vp, v3);
279 nfsm_request(vp, NFSPROC_FSSTAT, p, cred, &xid);
280 if (v3)
281 nfsm_postop_attr(vp, retattr, &xid);
282 nfsm_dissect(sfp, struct nfs_statfs *, NFSX_STATFS(v3));
283
284 /* XXX CSM 12/2/97 Cleanup when/if we integrate FreeBSD mount.h */
285 #ifdef notyet
286 sbp->f_type = MOUNT_NFS;
287 #else
288 sbp->f_type = nfs_mount_type;
289 #endif
290 sbp->f_flags = nmp->nm_flag;
291 sbp->f_iosize = nfs_iosize(nmp);
292 if (v3) {
293 sbp->f_bsize = NFS_FABLKSIZE;
294 fxdr_hyper(&sfp->sf_tbytes, &tquad);
295 sbp->f_blocks = (long)(tquad / ((u_quad_t)NFS_FABLKSIZE));
296 fxdr_hyper(&sfp->sf_fbytes, &tquad);
297 sbp->f_bfree = (long)(tquad / ((u_quad_t)NFS_FABLKSIZE));
298 fxdr_hyper(&sfp->sf_abytes, &tquad);
299 sbp->f_bavail = (long)(tquad / ((u_quad_t)NFS_FABLKSIZE));
300 sbp->f_files = (fxdr_unsigned(long, sfp->sf_tfiles.nfsuquad[1])
301 & 0x7fffffff);
302 sbp->f_ffree = (fxdr_unsigned(long, sfp->sf_ffiles.nfsuquad[1])
303 & 0x7fffffff);
304 } else {
305 sbp->f_bsize = fxdr_unsigned(long, sfp->sf_bsize);
306 sbp->f_blocks = fxdr_unsigned(long, sfp->sf_blocks);
307 sbp->f_bfree = fxdr_unsigned(long, sfp->sf_bfree);
308 sbp->f_bavail = fxdr_unsigned(long, sfp->sf_bavail);
309 sbp->f_files = 0;
310 sbp->f_ffree = 0;
311 }
312 if (sbp != &mp->mnt_stat) {
313 bcopy(mp->mnt_stat.f_mntonname, sbp->f_mntonname, MNAMELEN);
314 bcopy(mp->mnt_stat.f_mntfromname, sbp->f_mntfromname, MNAMELEN);
315 }
316 nfsm_reqdone;
317 VOP_UNLOCK(vp, 0, p);
318 crfree(cred);
319 return (error);
320 }
321
322 /*
323 * nfs version 3 fsinfo rpc call
324 */
325 int
326 nfs_fsinfo(nmp, vp, cred, p)
327 register struct nfsmount *nmp;
328 register struct vnode *vp;
329 struct ucred *cred;
330 struct proc *p;
331 {
332 register struct nfsv3_fsinfo *fsp;
333 register caddr_t cp;
334 register long t1, t2;
335 register u_long *tl, pref, max;
336 caddr_t bpos, dpos, cp2;
337 int error = 0, retattr;
338 struct mbuf *mreq, *mrep, *md, *mb, *mb2;
339 u_int64_t xid;
340
341 nfsstats.rpccnt[NFSPROC_FSINFO]++;
342 nfsm_reqhead(vp, NFSPROC_FSINFO, NFSX_FH(1));
343 nfsm_fhtom(vp, 1);
344 nfsm_request(vp, NFSPROC_FSINFO, p, cred, &xid);
345 nfsm_postop_attr(vp, retattr, &xid);
346 if (!error) {
347 nfsm_dissect(fsp, struct nfsv3_fsinfo *, NFSX_V3FSINFO);
348 pref = fxdr_unsigned(u_long, fsp->fs_wtpref);
349 if (pref < nmp->nm_wsize)
350 nmp->nm_wsize = (pref + NFS_FABLKSIZE - 1) &
351 ~(NFS_FABLKSIZE - 1);
352 max = fxdr_unsigned(u_long, fsp->fs_wtmax);
353 if (max < nmp->nm_wsize) {
354 nmp->nm_wsize = max & ~(NFS_FABLKSIZE - 1);
355 if (nmp->nm_wsize == 0)
356 nmp->nm_wsize = max;
357 }
358 pref = fxdr_unsigned(u_long, fsp->fs_rtpref);
359 if (pref < nmp->nm_rsize)
360 nmp->nm_rsize = (pref + NFS_FABLKSIZE - 1) &
361 ~(NFS_FABLKSIZE - 1);
362 max = fxdr_unsigned(u_long, fsp->fs_rtmax);
363 if (max < nmp->nm_rsize) {
364 nmp->nm_rsize = max & ~(NFS_FABLKSIZE - 1);
365 if (nmp->nm_rsize == 0)
366 nmp->nm_rsize = max;
367 }
368 pref = fxdr_unsigned(u_long, fsp->fs_dtpref);
369 if (pref < nmp->nm_readdirsize)
370 nmp->nm_readdirsize = pref;
371 if (max < nmp->nm_readdirsize) {
372 nmp->nm_readdirsize = max;
373 }
374 nmp->nm_state |= NFSSTA_GOTFSINFO;
375 }
376 nfsm_reqdone;
377 return (error);
378 }
379
380 /*
381 * Mount a remote root fs via. nfs. This depends on the info in the
382 * nfs_diskless structure that has been filled in properly by some primary
383 * bootstrap.
384 * It goes something like this:
385 * - do enough of "ifconfig" by calling ifioctl() so that the system
386 * can talk to the server
387 * - If nfs_diskless.mygateway is filled in, use that address as
388 * a default gateway.
389 * - hand craft the swap nfs vnode hanging off a fake mount point
390 * if swdevt[0].sw_dev == NODEV
391 * - build the rootfs mount point and call mountnfs() to do the rest.
392 */
393 int
394 nfs_mountroot()
395 {
396 struct nfs_diskless nd;
397 struct vattr attr;
398 struct mount *mp;
399 struct vnode *vp;
400 struct proc *procp;
401 long n;
402 int error;
403 #if !defined(NO_MOUNT_PRIVATE)
404 struct mount *mppriv;
405 struct vnode *vppriv;
406 #endif /* NO_MOUNT_PRIVATE */
407 int v3;
408
409 procp = current_proc(); /* XXX */
410
411 /*
412 * Call nfs_boot_init() to fill in the nfs_diskless struct.
413 * Note: networking must already have been configured before
414 * we're called.
415 */
416 bzero((caddr_t) &nd, sizeof(nd));
417 error = nfs_boot_init(&nd, procp);
418 if (error) {
419 panic("nfs_boot_init failed with %d\n", error);
420 }
421
422 /* try NFSv3 first, if that fails then try NFSv2 */
423 v3 = 1;
424
425 tryagain:
426 error = nfs_boot_getfh(&nd, procp, v3);
427 if (error) {
428 if (error == EHOSTDOWN || error == EHOSTUNREACH) {
429 if (nd.nd_root.ndm_path)
430 FREE_ZONE(nd.nd_root.ndm_path,
431 MAXPATHLEN, M_NAMEI);
432 if (nd.nd_private.ndm_path)
433 FREE_ZONE(nd.nd_private.ndm_path,
434 MAXPATHLEN, M_NAMEI);
435 return (error);
436 }
437 if (v3) {
438 printf("nfs_boot_getfh(v3) failed with %d, trying v2...\n", error);
439 v3 = 0;
440 goto tryagain;
441 }
442 panic("nfs_boot_getfh(v2) failed with %d\n", error);
443 }
444
445 /*
446 * Create the root mount point.
447 */
448 #if !defined(NO_MOUNT_PRIVATE)
449 if ((error = nfs_mount_diskless(&nd.nd_root, "/", MNT_RDONLY, &vp, &mp))) {
450 #else
451 if (error = nfs_mount_diskless(&nd.nd_root, "/", NULL, &vp, &mp)) {
452 #endif /* NO_MOUNT_PRIVATE */
453 if (v3) {
454 printf("nfs_mount_diskless(v3) failed with %d, trying v2...\n", error);
455 v3 = 0;
456 goto tryagain;
457 }
458 panic("nfs_mount_diskless root failed with %d\n", error);
459 }
460 printf("root on %s\n", (char *)&nd.nd_root.ndm_host);
461
462 simple_lock(&mountlist_slock);
463 CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
464 simple_unlock(&mountlist_slock);
465 vfs_unbusy(mp, procp);
466 rootvp = vp;
467
468 #if !defined(NO_MOUNT_PRIVATE)
469 if (nd.nd_private.ndm_saddr.sin_addr.s_addr) {
470 error = nfs_mount_diskless_private(&nd.nd_private, "/private",
471 NULL, &vppriv, &mppriv);
472 if (error) {
473 panic("nfs_mount_diskless private failed with %d\n", error);
474 }
475 printf("private on %s\n", (char *)&nd.nd_private.ndm_host);
476
477 simple_lock(&mountlist_slock);
478 CIRCLEQ_INSERT_TAIL(&mountlist, mppriv, mnt_list);
479 simple_unlock(&mountlist_slock);
480 vfs_unbusy(mppriv, procp);
481 }
482
483 #endif /* NO_MOUNT_PRIVATE */
484
485 if (nd.nd_root.ndm_path)
486 FREE_ZONE(nd.nd_root.ndm_path, MAXPATHLEN, M_NAMEI);
487 if (nd.nd_private.ndm_path)
488 FREE_ZONE(nd.nd_private.ndm_path, MAXPATHLEN, M_NAMEI);
489
490 /* Get root attributes (for the time). */
491 error = VOP_GETATTR(vp, &attr, procp->p_ucred, procp);
492 if (error) panic("nfs_mountroot: getattr for root");
493 n = attr.va_mtime.tv_sec;
494 inittodr(n);
495 return (0);
496 }
497
498 /*
499 * Internal version of mount system call for diskless setup.
500 */
501 static int
502 nfs_mount_diskless(ndmntp, mntname, mntflag, vpp, mpp)
503 struct nfs_dlmount *ndmntp;
504 char *mntname;
505 int mntflag;
506 struct vnode **vpp;
507 struct mount **mpp;
508 {
509 struct nfs_args args;
510 struct mount *mp;
511 struct mbuf *m;
512 int error;
513 struct proc *procp;
514
515 procp = current_proc(); /* XXX */
516
517 if ((error = vfs_rootmountalloc("nfs", ndmntp->ndm_host, &mp))) {
518 printf("nfs_mountroot: NFS not configured");
519 return (error);
520 }
521 mp->mnt_flag = mntflag;
522
523 /* Initialize mount args. */
524 bzero((caddr_t) &args, sizeof(args));
525 args.addr = (struct sockaddr *)&ndmntp->ndm_saddr;
526 args.addrlen = args.addr->sa_len;
527 args.sotype = SOCK_DGRAM;
528 args.fh = ndmntp->ndm_fh;
529 args.fhsize = ndmntp->ndm_fhlen;
530 args.hostname = ndmntp->ndm_host;
531 args.flags = NFSMNT_RESVPORT;
532 if (ndmntp->ndm_nfsv3)
533 args.flags |= NFSMNT_NFSV3;
534
535 MGET(m, M_DONTWAIT, MT_SONAME);
536 bcopy((caddr_t)args.addr, mtod(m, caddr_t),
537 (m->m_len = args.addr->sa_len));
538 if ((error = mountnfs(&args, mp, m, mntname, args.hostname, vpp))) {
539 printf("nfs_mountroot: mount %s failed: %d", mntname, error);
540 mp->mnt_vfc->vfc_refcount--;
541
542 if (mp->mnt_kern_flag & MNTK_IO_XINFO)
543 FREE(mp->mnt_xinfo_ptr, M_TEMP);
544 vfs_unbusy(mp, procp);
545
546 FREE_ZONE(mp, sizeof (struct mount), M_MOUNT);
547 return (error);
548 }
549 #if 0 /* Causes incorrect reporting of "mounted on" */
550 (void) copystr(args.hostname, mp->mnt_stat.f_mntonname, MNAMELEN - 1, 0);
551 #endif /* 0 */
552 *mpp = mp;
553 return (0);
554 }
555
556 #if !defined(NO_MOUNT_PRIVATE)
557 /*
558 * Internal version of mount system call to mount "/private"
559 * separately in diskless setup
560 */
561 static int
562 nfs_mount_diskless_private(ndmntp, mntname, mntflag, vpp, mpp)
563 struct nfs_dlmount *ndmntp;
564 char *mntname;
565 int mntflag;
566 struct vnode **vpp;
567 struct mount **mpp;
568 {
569 struct nfs_args args;
570 struct mount *mp;
571 struct mbuf *m;
572 int error;
573 struct proc *procp;
574 struct vfsconf *vfsp;
575 struct nameidata nd;
576 struct vnode *vp;
577
578 procp = current_proc(); /* XXX */
579
580 {
581 /*
582 * mimic main()!. Temporarily set up rootvnode and other stuff so
583 * that namei works. Need to undo this because main() does it, too
584 */
585 struct filedesc *fdp; /* pointer to file descriptor state */
586 fdp = procp->p_fd;
587 mountlist.cqh_first->mnt_flag |= MNT_ROOTFS;
588
589 /* Get the vnode for '/'. Set fdp->fd_cdir to reference it. */
590 if (VFS_ROOT(mountlist.cqh_first, &rootvnode))
591 panic("cannot find root vnode");
592 VREF(rootvnode);
593 fdp->fd_cdir = rootvnode;
594 VOP_UNLOCK(rootvnode, 0, procp);
595 fdp->fd_rdir = NULL;
596 }
597
598 /*
599 * Get vnode to be covered
600 */
601 NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE,
602 mntname, procp);
603 if ((error = namei(&nd))) {
604 printf("nfs_mountroot: private namei failed!");
605 return (error);
606 }
607 {
608 /* undo VREF in mimic main()! */
609 vrele(rootvnode);
610 }
611 vp = nd.ni_vp;
612 if ((error = vinvalbuf(vp, V_SAVE, procp->p_ucred, procp, 0, 0))) {
613 vput(vp);
614 return (error);
615 }
616 if (vp->v_type != VDIR) {
617 vput(vp);
618 return (ENOTDIR);
619 }
620 for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next)
621 if (!strcmp(vfsp->vfc_name, "nfs"))
622 break;
623 if (vfsp == NULL) {
624 printf("nfs_mountroot: private NFS not configured");
625 vput(vp);
626 return (ENODEV);
627 }
628 if (vp->v_mountedhere != NULL) {
629 vput(vp);
630 return (EBUSY);
631 }
632
633 /*
634 * Allocate and initialize the filesystem.
635 */
636 mp = _MALLOC_ZONE((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK);
637 bzero((char *)mp, (u_long)sizeof(struct mount));
638
639 /* Initialize the default IO constraints */
640 mp->mnt_maxreadcnt = mp->mnt_maxwritecnt = MAXPHYS;
641 mp->mnt_segreadcnt = mp->mnt_segwritecnt = 32;
642
643 lockinit(&mp->mnt_lock, PVFS, "vfslock", 0, 0);
644 (void)vfs_busy(mp, LK_NOWAIT, 0, procp);
645 LIST_INIT(&mp->mnt_vnodelist);
646 mp->mnt_op = vfsp->vfc_vfsops;
647 mp->mnt_vfc = vfsp;
648 vfsp->vfc_refcount++;
649 mp->mnt_stat.f_type = vfsp->vfc_typenum;
650 mp->mnt_flag = mntflag;
651 mp->mnt_flag |= vfsp->vfc_flags & MNT_VISFLAGMASK;
652 strncpy(mp->mnt_stat.f_fstypename, vfsp->vfc_name, MFSNAMELEN);
653 vp->v_mountedhere = mp;
654 mp->mnt_vnodecovered = vp;
655 mp->mnt_stat.f_owner = procp->p_ucred->cr_uid;
656 (void) copystr(mntname, mp->mnt_stat.f_mntonname, MNAMELEN - 1, 0);
657 (void) copystr(ndmntp->ndm_host, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, 0);
658
659 /* Initialize mount args. */
660 bzero((caddr_t) &args, sizeof(args));
661 args.addr = (struct sockaddr *)&ndmntp->ndm_saddr;
662 args.addrlen = args.addr->sa_len;
663 args.sotype = SOCK_DGRAM;
664 args.fh = ndmntp->ndm_fh;
665 args.fhsize = ndmntp->ndm_fhlen;
666 args.hostname = ndmntp->ndm_host;
667 args.flags = NFSMNT_RESVPORT;
668 if (ndmntp->ndm_nfsv3)
669 args.flags |= NFSMNT_NFSV3;
670
671 MGET(m, M_DONTWAIT, MT_SONAME);
672 bcopy((caddr_t)args.addr, mtod(m, caddr_t),
673 (m->m_len = args.addr->sa_len));
674 if ((error = mountnfs(&args, mp, m, mntname, args.hostname, &vp))) {
675 printf("nfs_mountroot: mount %s failed: %d", mntname, error);
676 mp->mnt_vfc->vfc_refcount--;
677
678 if (mp->mnt_kern_flag & MNTK_IO_XINFO)
679 FREE(mp->mnt_xinfo_ptr, M_TEMP);
680 vfs_unbusy(mp, procp);
681
682 FREE_ZONE(mp, sizeof (struct mount), M_MOUNT);
683 return (error);
684 }
685
686 *mpp = mp;
687 *vpp = vp;
688 return (0);
689 }
690 #endif /* NO_MOUNT_PRIVATE */
691
692 /*
693 * VFS Operations.
694 *
695 * mount system call
696 * It seems a bit dumb to copyinstr() the host and path here and then
697 * bcopy() them in mountnfs(), but I wanted to detect errors before
698 * doing the sockargs() call because sockargs() allocates an mbuf and
699 * an error after that means that I have to release the mbuf.
700 */
701 /* ARGSUSED */
702 static int
703 nfs_mount(mp, path, data, ndp, p)
704 struct mount *mp;
705 char *path;
706 caddr_t data;
707 struct nameidata *ndp;
708 struct proc *p;
709 {
710 int error;
711 struct nfs_args args;
712 struct mbuf *nam;
713 struct vnode *vp;
714 char pth[MNAMELEN], hst[MNAMELEN];
715 size_t len;
716 u_char nfh[NFSX_V3FHMAX];
717
718 error = copyin(data, (caddr_t)&args, sizeof (struct nfs_args));
719 if (error)
720 return (error);
721 if (args.version != NFS_ARGSVERSION) {
722 #ifndef NO_COMPAT_PRELITE2
723 /*
724 * If the argument version is unknown, then assume the
725 * caller is a pre-lite2 4.4BSD client and convert its
726 * arguments.
727 */
728 struct onfs_args oargs;
729 error = copyin(data, (caddr_t)&oargs, sizeof (struct onfs_args));
730 if (error)
731 return (error);
732 nfs_convert_oargs(&args,&oargs);
733 #else /* NO_COMPAT_PRELITE2 */
734 return (EPROGMISMATCH);
735 #endif /* !NO_COMPAT_PRELITE2 */
736 }
737 if (args.fhsize > NFSX_V3FHMAX)
738 return (EINVAL);
739 error = copyin((caddr_t)args.fh, (caddr_t)nfh, args.fhsize);
740 if (error)
741 return (error);
742 error = copyinstr(path, pth, MNAMELEN-1, &len);
743 if (error)
744 return (error);
745 bzero(&pth[len], MNAMELEN - len);
746 error = copyinstr(args.hostname, hst, MNAMELEN-1, &len);
747 if (error)
748 return (error);
749 bzero(&hst[len], MNAMELEN - len);
750 /* sockargs() call must be after above copyin() calls */
751 error = sockargs(&nam, (caddr_t)args.addr, args.addrlen, MT_SONAME);
752 if (error)
753 return (error);
754 args.fh = nfh;
755 error = mountnfs(&args, mp, nam, pth, hst, &vp);
756 return (error);
757 }
758
759 /*
760 * Common code for mount and mountroot
761 */
762 static int
763 mountnfs(argp, mp, nam, pth, hst, vpp)
764 register struct nfs_args *argp;
765 register struct mount *mp;
766 struct mbuf *nam;
767 char *pth, *hst;
768 struct vnode **vpp;
769 {
770 register struct nfsmount *nmp;
771 struct nfsnode *np;
772 int error, maxio;
773 struct vattr attrs;
774 struct proc *curproc;
775
776 /*
777 * turning off NQNFS until we have further testing
778 * with UBC changes, in particular, nfs_pagein and nfs_pageout.
779 * Those have NQNFS defined out in conjunction with this
780 * returning an error. Remove when fully tested.
781 */
782 if (argp->flags & NFSMNT_NQNFS) {
783 error = NFSERR_NOTSUPP;
784 goto bad2;
785 }
786
787 /*
788 * Silently clear NFSMNT_NOCONN if it's a TCP mount, it makes
789 * no sense in that context.
790 */
791 if (argp->sotype == SOCK_STREAM)
792 argp->flags &= ~NFSMNT_NOCONN;
793
794 if (mp->mnt_flag & MNT_UPDATE) {
795 nmp = VFSTONFS(mp);
796 /* update paths, file handles, etc, here XXX */
797 m_freem(nam);
798 return (0);
799 } else {
800 MALLOC_ZONE(nmp, struct nfsmount *,
801 sizeof (struct nfsmount), M_NFSMNT, M_WAITOK);
802 bzero((caddr_t)nmp, sizeof (struct nfsmount));
803 TAILQ_INIT(&nmp->nm_uidlruhead);
804 TAILQ_INIT(&nmp->nm_bufq);
805 mp->mnt_data = (qaddr_t)nmp;
806 }
807 vfs_getnewfsid(mp);
808 nmp->nm_mountp = mp;
809 nmp->nm_flag = argp->flags;
810 if (nmp->nm_flag & NFSMNT_NQNFS)
811 /*
812 * We have to set mnt_maxsymlink to a non-zero value so
813 * that COMPAT_43 routines will know that we are setting
814 * the d_type field in directories (and can zero it for
815 * unsuspecting binaries).
816 */
817 mp->mnt_maxsymlinklen = 1;
818 nmp->nm_timeo = NFS_TIMEO;
819 nmp->nm_retry = NFS_RETRANS;
820 if (argp->sotype == SOCK_DGRAM) {
821 nmp->nm_wsize = NFS_DGRAM_WSIZE;
822 nmp->nm_rsize = NFS_DGRAM_RSIZE;
823 } else {
824 nmp->nm_wsize = NFS_WSIZE;
825 nmp->nm_rsize = NFS_RSIZE;
826 }
827 nmp->nm_readdirsize = NFS_READDIRSIZE;
828 nmp->nm_numgrps = NFS_MAXGRPS;
829 nmp->nm_readahead = NFS_DEFRAHEAD;
830 nmp->nm_leaseterm = NQ_DEFLEASE;
831 nmp->nm_deadthresh = NQ_DEADTHRESH;
832 nmp->nm_tprintf_delay = nfs_tprintf_delay;
833 if (nmp->nm_tprintf_delay < 0)
834 nmp->nm_tprintf_delay = 0;
835 nmp->nm_tprintf_initial_delay = nfs_tprintf_initial_delay;
836 if (nmp->nm_tprintf_initial_delay < 0)
837 nmp->nm_tprintf_initial_delay = 0;
838 CIRCLEQ_INIT(&nmp->nm_timerhead);
839 nmp->nm_inprog = NULLVP;
840 bcopy(hst, mp->mnt_stat.f_mntfromname, MNAMELEN);
841 bcopy(pth, mp->mnt_stat.f_mntonname, MNAMELEN);
842 nmp->nm_nam = nam;
843
844 if ((argp->flags & NFSMNT_TIMEO) && argp->timeo > 0) {
845 nmp->nm_timeo = (argp->timeo * NFS_HZ + 5) / 10;
846 if (nmp->nm_timeo < NFS_MINTIMEO)
847 nmp->nm_timeo = NFS_MINTIMEO;
848 else if (nmp->nm_timeo > NFS_MAXTIMEO)
849 nmp->nm_timeo = NFS_MAXTIMEO;
850 }
851
852 if ((argp->flags & NFSMNT_RETRANS) && argp->retrans > 1) {
853 nmp->nm_retry = argp->retrans;
854 if (nmp->nm_retry > NFS_MAXREXMIT)
855 nmp->nm_retry = NFS_MAXREXMIT;
856 }
857
858 if (argp->flags & NFSMNT_NFSV3) {
859 if (argp->sotype == SOCK_DGRAM)
860 maxio = NFS_MAXDGRAMDATA;
861 else
862 maxio = NFS_MAXDATA;
863 } else
864 maxio = NFS_V2MAXDATA;
865
866 if ((argp->flags & NFSMNT_WSIZE) && argp->wsize > 0) {
867 nmp->nm_wsize = argp->wsize;
868 /* Round down to multiple of blocksize */
869 nmp->nm_wsize &= ~(NFS_FABLKSIZE - 1);
870 if (nmp->nm_wsize <= 0)
871 nmp->nm_wsize = NFS_FABLKSIZE;
872 }
873 if (nmp->nm_wsize > maxio)
874 nmp->nm_wsize = maxio;
875 if (nmp->nm_wsize > MAXBSIZE)
876 nmp->nm_wsize = MAXBSIZE;
877
878 if ((argp->flags & NFSMNT_RSIZE) && argp->rsize > 0) {
879 nmp->nm_rsize = argp->rsize;
880 /* Round down to multiple of blocksize */
881 nmp->nm_rsize &= ~(NFS_FABLKSIZE - 1);
882 if (nmp->nm_rsize <= 0)
883 nmp->nm_rsize = NFS_FABLKSIZE;
884 }
885 if (nmp->nm_rsize > maxio)
886 nmp->nm_rsize = maxio;
887 if (nmp->nm_rsize > MAXBSIZE)
888 nmp->nm_rsize = MAXBSIZE;
889
890 if ((argp->flags & NFSMNT_READDIRSIZE) && argp->readdirsize > 0) {
891 nmp->nm_readdirsize = argp->readdirsize;
892 }
893 if (nmp->nm_readdirsize > maxio)
894 nmp->nm_readdirsize = maxio;
895 if (nmp->nm_readdirsize > nmp->nm_rsize)
896 nmp->nm_readdirsize = nmp->nm_rsize;
897
898 if ((argp->flags & NFSMNT_MAXGRPS) && argp->maxgrouplist >= 0 &&
899 argp->maxgrouplist <= NFS_MAXGRPS)
900 nmp->nm_numgrps = argp->maxgrouplist;
901 if ((argp->flags & NFSMNT_READAHEAD) && argp->readahead >= 0 &&
902 argp->readahead <= NFS_MAXRAHEAD)
903 nmp->nm_readahead = argp->readahead;
904 if ((argp->flags & NFSMNT_LEASETERM) && argp->leaseterm >= 2 &&
905 argp->leaseterm <= NQ_MAXLEASE)
906 nmp->nm_leaseterm = argp->leaseterm;
907 if ((argp->flags & NFSMNT_DEADTHRESH) && argp->deadthresh >= 1 &&
908 argp->deadthresh <= NQ_NEVERDEAD)
909 nmp->nm_deadthresh = argp->deadthresh;
910 /* Set up the sockets and per-host congestion */
911 nmp->nm_sotype = argp->sotype;
912 nmp->nm_soproto = argp->proto;
913
914 /*
915 * For Connection based sockets (TCP,...) defer the connect until
916 * the first request, in case the server is not responding.
917 */
918 if (nmp->nm_sotype == SOCK_DGRAM &&
919 (error = nfs_connect(nmp, (struct nfsreq *)0)))
920 goto bad;
921
922 /*
923 * A reference count is needed on the nfsnode representing the
924 * remote root. If this object is not persistent, then backward
925 * traversals of the mount point (i.e. "..") will not work if
926 * the nfsnode gets flushed out of the cache. UFS does not have
927 * this problem, because one can identify root inodes by their
928 * number == ROOTINO (2).
929 */
930 error = nfs_nget(mp, (nfsfh_t *)argp->fh, argp->fhsize, &np);
931 if (error)
932 goto bad;
933
934 /*
935 * save this vnode pointer. That way nfs_unmount()
936 * does not need to call nfs_net() just get it to drop
937 * this vnode reference.
938 */
939 nmp->nm_dvp = *vpp = NFSTOV(np);
940
941 /*
942 * Get file attributes for the mountpoint. This has the side
943 * effect of filling in (*vpp)->v_type with the correct value.
944 */
945 curproc = current_proc();
946 error = VOP_GETATTR(*vpp, &attrs, curproc->p_ucred, curproc);
947 if (error) {
948 /*
949 * we got problems... we couldn't get the attributes
950 * from the NFS server... so the mount fails.
951 */
952 vput(*vpp);
953 goto bad;
954 }
955
956 /*
957 * Set the mount point's block I/O size.
958 * We really need to do this after we get info back from
959 * the server about what its preferred I/O sizes are.
960 */
961 if (nmp->nm_flag & NFSMNT_NFSV3)
962 nfs_fsinfo(nmp, *vpp, curproc->p_ucred, curproc);
963 mp->mnt_stat.f_iosize = nfs_iosize(nmp);
964
965 /*
966 * Lose the lock but keep the ref.
967 */
968 VOP_UNLOCK(*vpp, 0, curproc);
969
970 if (nmp->nm_flag & NFSMNT_RESVPORT)
971 nfs_resv_mounts++;
972 nmp->nm_state |= NFSSTA_MOUNTED;
973 return (0);
974 bad:
975 nfs_disconnect(nmp);
976 FREE_ZONE((caddr_t)nmp, sizeof (struct nfsmount), M_NFSMNT);
977 bad2:
978 m_freem(nam);
979 return (error);
980 }
981
982
983 /*
984 * unmount system call
985 */
986 static int
987 nfs_unmount(mp, mntflags, p)
988 struct mount *mp;
989 int mntflags;
990 struct proc *p;
991 {
992 register struct nfsmount *nmp;
993 struct vnode *vp;
994 int error, flags = 0;
995
996 nmp = VFSTONFS(mp);
997 /*
998 * During a force unmount we want to...
999 * Mark that we are doing a force unmount.
1000 * Make the mountpoint soft.
1001 */
1002 if (mntflags & MNT_FORCE) {
1003 flags |= FORCECLOSE;
1004 nmp->nm_state |= NFSSTA_FORCE;
1005 nmp->nm_flag |= NFSMNT_SOFT;
1006 }
1007 /*
1008 * Goes something like this..
1009 * - Call vflush() to clear out vnodes for this file system,
1010 * except for the swap files. Deal with them in 2nd pass.
1011 * It will do vgone making the vnode VBAD at that time.
1012 * - Decrement reference on the vnode representing remote root.
1013 * - Close the socket
1014 * - Free up the data structures
1015 */
1016 vp = nmp->nm_dvp;
1017
1018 /*
1019 * Must handshake with nqnfs_clientd() if it is active.
1020 */
1021 nmp->nm_state |= NFSSTA_DISMINPROG;
1022 while (nmp->nm_inprog != NULLVP)
1023 (void) tsleep((caddr_t)&lbolt, PSOCK, "nfsdism", 0);
1024 /*
1025 * vflush will check for busy vnodes on mountpoint.
1026 * Will do the right thing for MNT_FORCE. That is, we should
1027 * not get EBUSY back.
1028 */
1029 error = vflush(mp, vp, SKIPSWAP | flags);
1030 if (mntflags & MNT_FORCE) {
1031 error = vflush(mp, NULLVP, flags); /* locks vp in the process */
1032 } else {
1033 if (vp->v_usecount > 1) {
1034 nmp->nm_state &= ~NFSSTA_DISMINPROG;
1035 return (EBUSY);
1036 }
1037 error = vflush(mp, vp, flags);
1038 }
1039
1040 if (error) {
1041 nmp->nm_state &= ~NFSSTA_DISMINPROG;
1042 return (error);
1043 }
1044
1045 /*
1046 * We are now committed to the unmount.
1047 * For NQNFS, let the server daemon free the nfsmount structure.
1048 */
1049 if (nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB))
1050 nmp->nm_state |= NFSSTA_DISMNT;
1051 nmp->nm_state &= ~NFSSTA_MOUNTED;
1052 if (nmp->nm_flag & NFSMNT_RESVPORT) {
1053 if (--nfs_resv_mounts == 0)
1054 nfs_bind_resv_thread_wake();
1055 }
1056
1057 /*
1058 * Release the root vnode reference held by mountnfs()
1059 * vflush did the vgone for us when we didn't skip over
1060 * it in the MNT_FORCE case. (Thus vp can't be locked when
1061 * called vflush in non-skip vp case.)
1062 */
1063 vrele(vp);
1064 if (!(mntflags & MNT_FORCE))
1065 vgone(vp);
1066 mp->mnt_data = 0; /* don't want to end up using stale vp */
1067 nfs_disconnect(nmp);
1068 m_freem(nmp->nm_nam);
1069
1070 if ((nmp->nm_flag & (NFSMNT_NQNFS | NFSMNT_KERB)) == 0) {
1071 register struct nfsreq *rp;
1072 /*
1073 * Loop through outstanding request list and remove dangling
1074 * references to defunct nfsmount struct
1075 */
1076 #if NFSDIAG && 0
1077 if (hw_atomic_add(&nfsreqqusers, 1) != 1)
1078 nfsatompanic("unmount add");
1079 nfsbtlen = backtrace(&nfsbt, sizeof(nfsbt));
1080 nfsbtcpu = cpu_number();
1081 nfsbtthread = (int)(current_thread());
1082 #endif
1083
1084 for (rp = nfs_reqq.tqh_first; rp; rp = rp->r_chain.tqe_next)
1085 if (rp->r_nmp == nmp)
1086 rp->r_nmp = (struct nfsmount *)0;
1087 #if NFSDIAG && 0
1088 if (hw_atomic_sub(&nfsreqqusers, 1) != 0)
1089 nfsatompanic("unmount sub");
1090 #endif
1091 FREE_ZONE((caddr_t)nmp, sizeof (struct nfsmount), M_NFSMNT);
1092 }
1093 return (0);
1094 }
1095
1096 /*
1097 * Return root of a filesystem
1098 */
1099 static int
1100 nfs_root(mp, vpp)
1101 struct mount *mp;
1102 struct vnode **vpp;
1103 {
1104 register struct vnode *vp;
1105 struct nfsmount *nmp;
1106 int error, vpid;
1107
1108 nmp = VFSTONFS(mp);
1109 vp = nmp->nm_dvp;
1110 vpid = vp->v_id;
1111 while (error = vget(vp, LK_EXCLUSIVE, current_proc())) {
1112 /* vget may return ENOENT if the dir changes while in vget */
1113 /* If that happens, try vget again, else return the error */
1114 if ((error != ENOENT) || (vp->v_id == vpid))
1115 return (error);
1116 vpid = vp->v_id;
1117 }
1118 if (vp->v_type == VNON)
1119 vp->v_type = VDIR;
1120 vp->v_flag |= VROOT;
1121 *vpp = vp;
1122 return (0);
1123 }
1124
1125 extern int syncprt;
1126
1127 /*
1128 * Flush out the buffer cache
1129 */
1130 /* ARGSUSED */
1131 static int
1132 nfs_sync(mp, waitfor, cred, p)
1133 struct mount *mp;
1134 int waitfor;
1135 struct ucred *cred;
1136 struct proc *p;
1137 {
1138 register struct vnode *vp;
1139 int error, allerror = 0;
1140
1141 /*
1142 * Force stale buffer cache information to be flushed.
1143 */
1144 loop:
1145 LIST_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
1146 int didhold;
1147 /*
1148 * If the vnode that we are about to sync is no longer
1149 * associated with this mount point, start over.
1150 */
1151 if (vp->v_mount != mp)
1152 goto loop;
1153 if (VOP_ISLOCKED(vp) || LIST_FIRST(&VTONFS(vp)->n_dirtyblkhd) == NULL)
1154 continue;
1155 if (vget(vp, LK_EXCLUSIVE, p))
1156 goto loop;
1157 didhold = ubc_hold(vp);
1158 error = VOP_FSYNC(vp, cred, waitfor, p);
1159 if (error)
1160 allerror = error;
1161 VOP_UNLOCK(vp, 0, p);
1162 if (didhold)
1163 ubc_rele(vp);
1164 vrele(vp);
1165 }
1166 return (allerror);
1167 }
1168
1169 /*
1170 * NFS flat namespace lookup.
1171 * Currently unsupported.
1172 */
1173 /* ARGSUSED */
1174 static int
1175 nfs_vget(mp, ino, vpp)
1176 struct mount *mp;
1177 void *ino; /* XXX void* or ino_t? */
1178 struct vnode **vpp;
1179 {
1180
1181 return (EOPNOTSUPP);
1182 }
1183
1184 /*
1185 * At this point, this should never happen
1186 */
1187 /* ARGSUSED */
1188 static int
1189 nfs_fhtovp(mp, fhp, nam, vpp, exflagsp, credanonp)
1190 register struct mount *mp;
1191 struct fid *fhp;
1192 struct mbuf *nam;
1193 struct vnode **vpp;
1194 int *exflagsp;
1195 struct ucred **credanonp;
1196 {
1197
1198 return (EINVAL);
1199 }
1200
1201 /*
1202 * Vnode pointer to File handle, should never happen either
1203 */
1204 /* ARGSUSED */
1205 static int
1206 nfs_vptofh(vp, fhp)
1207 struct vnode *vp;
1208 struct fid *fhp;
1209 {
1210
1211 return (EINVAL);
1212 }
1213
1214 /*
1215 * Vfs start routine, a no-op.
1216 */
1217 /* ARGSUSED */
1218 static int
1219 nfs_start(mp, flags, p)
1220 struct mount *mp;
1221 int flags;
1222 struct proc *p;
1223 {
1224
1225 return (0);
1226 }
1227
1228 /*
1229 * Do operations associated with quotas, not supported
1230 */
1231 /* ARGSUSED */
1232 static int
1233 nfs_quotactl(mp, cmd, uid, arg, p)
1234 struct mount *mp;
1235 int cmd;
1236 uid_t uid;
1237 caddr_t arg;
1238 struct proc *p;
1239 {
1240
1241 return (EOPNOTSUPP);
1242 }
1243
1244 /*
1245 * Do that sysctl thang...
1246 */
1247 static int
1248 nfs_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp,
1249 size_t newlen, struct proc *p)
1250 {
1251 int error;
1252 struct sysctl_req *req;
1253 struct vfsidctl vc;
1254 struct mount *mp;
1255 struct nfsmount *nmp;
1256 struct vfsquery vq;
1257
1258 /*
1259 * All names at this level are terminal.
1260 */
1261 if(namelen > 1)
1262 return ENOTDIR; /* overloaded */
1263
1264 /* common code for "new style" VFS_CTL sysctl, get the mount. */
1265 switch (name[0]) {
1266 case VFS_CTL_TIMEO:
1267 case VFS_CTL_QUERY:
1268 req = oldp;
1269 error = SYSCTL_IN(req, &vc, sizeof(vc));
1270 if (error)
1271 return (error);
1272 mp = vfs_getvfs(&vc.vc_fsid);
1273 if (mp == NULL)
1274 return (ENOENT);
1275 nmp = VFSTONFS(mp);
1276 if (nmp == NULL)
1277 return (ENOENT);
1278 bzero(&vq, sizeof(vq));
1279 VCTLTOREQ(&vc, req);
1280 }
1281
1282 switch(name[0]) {
1283 case NFS_NFSSTATS:
1284 if(!oldp) {
1285 *oldlenp = sizeof nfsstats;
1286 return 0;
1287 }
1288
1289 if(*oldlenp < sizeof nfsstats) {
1290 *oldlenp = sizeof nfsstats;
1291 return ENOMEM;
1292 }
1293
1294 error = copyout(&nfsstats, oldp, sizeof nfsstats);
1295 if (error)
1296 return (error);
1297
1298 if(newp && newlen != sizeof nfsstats)
1299 return EINVAL;
1300
1301 if(newp) {
1302 return copyin(newp, &nfsstats, sizeof nfsstats);
1303 }
1304 return 0;
1305 case VFS_CTL_QUERY:
1306 if ((nmp->nm_state & NFSSTA_TIMEO))
1307 vq.vq_flags |= VQ_NOTRESP;
1308 error = SYSCTL_OUT(req, &vq, sizeof(vq));
1309 break;
1310 case VFS_CTL_TIMEO:
1311 if (req->oldptr != NULL) {
1312 error = SYSCTL_OUT(req, &nmp->nm_tprintf_initial_delay,
1313 sizeof(nmp->nm_tprintf_initial_delay));
1314 if (error)
1315 return (error);
1316 }
1317 if (req->newptr != NULL) {
1318 error = SYSCTL_IN(req, &nmp->nm_tprintf_initial_delay,
1319 sizeof(nmp->nm_tprintf_initial_delay));
1320 if (error)
1321 return (error);
1322 if (nmp->nm_tprintf_initial_delay < 0)
1323 nmp->nm_tprintf_initial_delay = 0;
1324 }
1325 break;
1326 default:
1327 return (ENOTSUP);
1328 }
1329 return (error);
1330 }
1331