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