2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1989, 1993, 1995
25 * The Regents of the University of California. All rights reserved.
27 * This code is derived from software contributed to Berkeley by
28 * Rick Macklem at The University of Guelph.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95
59 * FreeBSD-Id: nfs_vfsops.c,v 1.52 1997/11/12 05:42:21 julian Exp $
62 #include <sys/param.h>
63 #include <sys/systm.h>
65 #include <sys/ioctl.h>
66 #include <sys/signal.h>
67 #include <sys/proc_internal.h> /* for fs rooting to update rootdir in fdp */
68 #include <sys/kauth.h>
69 #include <sys/vnode_internal.h>
70 #include <sys/malloc.h>
71 #include <sys/kernel.h>
72 #include <sys/sysctl.h>
73 #include <sys/mount_internal.h>
74 #include <sys/kpi_mbuf.h>
75 #include <sys/socket.h>
76 #include <sys/socketvar.h>
77 #include <sys/fcntl.h>
78 #include <libkern/OSAtomic.h>
81 #include <sys/vmparam.h>
83 #if !defined(NO_MOUNT_PRIVATE)
84 #include <sys/filedesc.h>
85 #endif /* NO_MOUNT_PRIVATE */
88 #include <net/route.h>
89 #include <netinet/in.h>
91 #include <nfs/rpcv2.h>
92 #include <nfs/nfsproto.h>
94 #include <nfs/nfsnode.h>
95 #include <nfs/nfsmount.h>
96 #include <nfs/xdr_subs.h>
97 #include <nfs/nfsm_subs.h>
98 #include <nfs/nfsdiskless.h>
99 #include <nfs/nfs_lock.h>
101 extern int nfs_mountroot(void);
103 extern int nfs_ticks
;
104 extern int nfs_mount_type
;
105 extern int nfs_resv_mounts
;
107 struct nfsstats nfsstats
;
108 static int nfs_sysctl(int *, u_int
, user_addr_t
, size_t *, user_addr_t
, size_t, vfs_context_t
);
109 /* XXX CSM 11/25/97 Upgrade sysctl.h someday */
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
, "");
116 SYSCTL_DECL(_vfs_generic_nfs
);
117 SYSCTL_NODE(_vfs_generic_nfs
, OID_AUTO
, client
, CTLFLAG_RW
, 0,
119 /* how long NFS will wait before signalling vfs that it's down. */
120 static int nfs_tprintf_initial_delay
= NFS_TPRINTF_INITIAL_DELAY
;
121 SYSCTL_INT(_vfs_generic_nfs_client
, NFS_TPRINTF_INITIAL_DELAY
,
122 initialdowndelay
, CTLFLAG_RW
, &nfs_tprintf_initial_delay
, 0, "");
123 /* how long between console messages "nfs server foo not responding" */
124 static int nfs_tprintf_delay
= NFS_TPRINTF_DELAY
;
125 SYSCTL_INT(_vfs_generic_nfs_client
, NFS_TPRINTF_DELAY
,
126 nextdowndelay
, CTLFLAG_RW
, &nfs_tprintf_delay
, 0, "");
128 static int nfs_biosize(struct nfsmount
*);
129 static int mountnfs(struct user_nfs_args
*,mount_t
,mbuf_t
,proc_t
,vnode_t
*);
130 static int nfs_mount(mount_t mp
, vnode_t vp
, user_addr_t data
, vfs_context_t context
);
131 static int nfs_start(mount_t mp
, int flags
, vfs_context_t context
);
132 static int nfs_unmount(mount_t mp
, int mntflags
, vfs_context_t context
);
133 static int nfs_root(mount_t mp
, vnode_t
*vpp
, vfs_context_t context
);
134 static int nfs_statfs(mount_t mp
, struct vfsstatfs
*sbp
, vfs_context_t context
);
135 static int nfs_vfs_getattr(mount_t mp
, struct vfs_attr
*fsap
, vfs_context_t context
);
136 static int nfs_sync( mount_t mp
, int waitfor
, vfs_context_t context
);
137 static int nfs_vptofh(vnode_t vp
, int *fhlenp
, unsigned char *fhp
, vfs_context_t context
);
138 static int nfs_fhtovp(mount_t mp
, int fhlen
, unsigned char *fhp
, vnode_t
*vpp
, vfs_context_t context
);
139 static int nfs_vget(mount_t
, ino64_t
, vnode_t
*, vfs_context_t context
);
143 * nfs vfs operations.
145 struct vfsops nfs_vfsops
= {
163 nfs_mount_diskless(struct nfs_dlmount
*, const char *, int, vnode_t
*, mount_t
*);
164 #if !defined(NO_MOUNT_PRIVATE)
166 nfs_mount_diskless_private(struct nfs_dlmount
*, const char *, int, vnode_t
*, mount_t
*);
167 #endif /* NO_MOUNT_PRIVATE */
170 nfs_biosize(struct nfsmount
*nmp
)
175 * Calculate the size used for io buffers. Use the larger
176 * of the two sizes to minimise nfs requests but make sure
177 * that it is at least one VM page to avoid wasting buffer
178 * space and to allow easy mmapping of I/O buffers.
179 * The read/write rpc calls handle the splitting up of
180 * buffers into multiple requests if the buffer size is
181 * larger than the I/O size.
183 iosize
= max(nmp
->nm_rsize
, nmp
->nm_wsize
);
184 if (iosize
< PAGE_SIZE
)
186 return (trunc_page_32(iosize
));
193 nfs_statfs(mount_t mp
, struct vfsstatfs
*sbp
, vfs_context_t context
)
195 proc_t p
= vfs_context_proc(context
);
197 struct nfs_statfs
*sfp
;
201 caddr_t bpos
, dpos
, cp2
;
202 struct nfsmount
*nmp
= VFSTONFS(mp
);
203 int error
= 0, v3
= (nmp
->nm_flag
& NFSMNT_NFSV3
), retattr
;
204 mbuf_t mreq
, mrep
, md
, mb
, mb2
;
207 struct ucred temp_cred
;
210 sfp
= (struct nfs_statfs
*)0;
213 if ((error
= vnode_get(vp
)))
216 bzero(&temp_cred
, sizeof(temp_cred
));
217 temp_cred
.cr_ngroups
= 1;
218 cred
= kauth_cred_create(&temp_cred
);
220 if (v3
&& (nmp
->nm_state
& NFSSTA_GOTFSINFO
) == 0)
221 nfs_fsinfo(nmp
, vp
, cred
, p
);
222 nfsm_reqhead(NFSX_FH(v3
));
224 kauth_cred_rele(cred
);
228 OSAddAtomic(1, (SInt32
*)&nfsstats
.rpccnt
[NFSPROC_FSSTAT
]);
230 nfsm_request(vp
, NFSPROC_FSSTAT
, p
, cred
, &xid
);
232 nfsm_postop_attr_update(vp
, v3
, retattr
, &xid
);
233 nfsm_dissect(sfp
, struct nfs_statfs
*, NFSX_STATFS(v3
));
235 sbp
->f_flags
= nmp
->nm_flag
;
236 sbp
->f_iosize
= NFS_IOSIZE
;
239 * Adjust block size to get total block count to fit in a long.
240 * If we can't increase block size enough, clamp to max long.
242 u_quad_t tquad
, tquad2
, bsize
;
243 bsize
= NFS_FABLKSIZE
;
245 fxdr_hyper(&sfp
->sf_tbytes
, &tquad
);
247 while ((tquad
& ~0x7fffffff) && (bsize
< 0x40000000)) {
251 sbp
->f_blocks
= (tquad
& ~0x7fffffff) ? 0x7fffffff : (long)tquad
;
253 fxdr_hyper(&sfp
->sf_fbytes
, &tquad
);
255 sbp
->f_bfree
= (tquad
& ~0x7fffffff) ? 0x7fffffff : (long)tquad
;
257 fxdr_hyper(&sfp
->sf_abytes
, &tquad
);
259 sbp
->f_bavail
= (tquad
& ~0x7fffffff) ? 0x7fffffff : (long)tquad
;
261 sbp
->f_bsize
= (long)bsize
;
263 /* adjust file slots too... */
264 fxdr_hyper(&sfp
->sf_tfiles
, &tquad
);
265 fxdr_hyper(&sfp
->sf_ffiles
, &tquad2
);
266 while (tquad
& ~0x7fffffff) {
270 sbp
->f_files
= tquad
;
271 sbp
->f_ffree
= tquad2
;
273 sbp
->f_bsize
= fxdr_unsigned(long, sfp
->sf_bsize
);
274 sbp
->f_blocks
= fxdr_unsigned(long, sfp
->sf_blocks
);
275 sbp
->f_bfree
= fxdr_unsigned(long, sfp
->sf_bfree
);
276 sbp
->f_bavail
= fxdr_unsigned(long, sfp
->sf_bavail
);
281 kauth_cred_rele(cred
);
287 * The nfs_statfs code is complicated, and used by mountnfs(), so leave it as-is
288 * and handle VFS_GETATTR by calling nfs_statfs and copying fields.
291 nfs_vfs_getattr(mount_t mp
, struct vfs_attr
*fsap
, vfs_context_t context
)
295 if (VFSATTR_IS_ACTIVE(fsap
, f_bsize
) ||
296 VFSATTR_IS_ACTIVE(fsap
, f_iosize
) ||
297 VFSATTR_IS_ACTIVE(fsap
, f_blocks
) ||
298 VFSATTR_IS_ACTIVE(fsap
, f_bfree
) ||
299 VFSATTR_IS_ACTIVE(fsap
, f_bavail
) ||
300 VFSATTR_IS_ACTIVE(fsap
, f_bused
) ||
301 VFSATTR_IS_ACTIVE(fsap
, f_files
) ||
302 VFSATTR_IS_ACTIVE(fsap
, f_ffree
)) {
305 error
= nfs_statfs(mp
, &sb
, context
);
307 VFSATTR_RETURN(fsap
, f_bsize
, sb
.f_bsize
);
308 VFSATTR_RETURN(fsap
, f_iosize
, sb
.f_iosize
);
309 VFSATTR_RETURN(fsap
, f_blocks
, sb
.f_blocks
);
310 VFSATTR_RETURN(fsap
, f_bfree
, sb
.f_bfree
);
311 VFSATTR_RETURN(fsap
, f_bavail
, sb
.f_bavail
);
312 VFSATTR_RETURN(fsap
, f_bused
, sb
.f_blocks
- sb
.f_bfree
);
313 VFSATTR_RETURN(fsap
, f_files
, sb
.f_files
);
314 VFSATTR_RETURN(fsap
, f_ffree
, sb
.f_ffree
);
318 if (VFSATTR_IS_ACTIVE(fsap
, f_capabilities
)) {
319 struct nfsmount
*nmp
;
320 struct nfsv3_pathconf pc
;
321 u_int32_t caps
, valid
;
325 if (!(nmp
= VFSTONFS(mp
)))
328 v3
= (nmp
->nm_flag
& NFSMNT_NFSV3
);
331 * The capabilities[] array defines what this volume supports.
333 * The valid[] array defines which bits this code understands
334 * the meaning of (whether the volume has that capability or not).
335 * Any zero bits here means "I don't know what you're asking about"
336 * and the caller cannot tell whether that capability is
341 /* try to get fsinfo if we haven't already */
342 if (!(nmp
->nm_state
& NFSSTA_GOTFSINFO
)) {
343 nfs_fsinfo(nmp
, vp
, vfs_context_ucred(context
),
344 vfs_context_proc(context
));
345 if (!(nmp
= VFSTONFS(vnode_mount(vp
))))
348 if (nmp
->nm_state
& NFSSTA_GOTFSINFO
) {
349 /* fsinfo indicates (non)support of links and symlinks */
350 valid
|= VOL_CAP_FMT_SYMBOLICLINKS
|
351 VOL_CAP_FMT_HARDLINKS
;
352 if (nmp
->nm_fsinfo
.fsproperties
& NFSV3FSINFO_SYMLINK
)
353 caps
|= VOL_CAP_FMT_SYMBOLICLINKS
;
354 if (nmp
->nm_fsinfo
.fsproperties
& NFSV3FSINFO_LINK
)
355 caps
|= VOL_CAP_FMT_HARDLINKS
;
356 /* if fsinfo indicates all pathconf info is the same, */
357 /* we can use it to report case attributes */
358 if ((nmp
->nm_fsinfo
.fsproperties
& NFSV3FSINFO_HOMOGENEOUS
) &&
359 !(nmp
->nm_state
& NFSSTA_GOTPATHCONF
)) {
360 /* no cached pathconf info, try to get now */
361 error
= nfs_pathconfrpc(vp
, &pc
,
362 vfs_context_ucred(context
),
363 vfs_context_proc(context
));
364 if (!(nmp
= VFSTONFS(vnode_mount(vp
))))
367 /* all files have the same pathconf info, */
368 /* so cache a copy of the results */
369 nfs_pathconf_cache(nmp
, &pc
);
372 if (nmp
->nm_state
& NFSSTA_GOTPATHCONF
) {
373 valid
|= VOL_CAP_FMT_CASE_SENSITIVE
|
374 VOL_CAP_FMT_CASE_PRESERVING
;
375 if (!(nmp
->nm_fsinfo
.pcflags
&
376 NFSPCINFO_CASE_INSENSITIVE
))
377 caps
|= VOL_CAP_FMT_CASE_SENSITIVE
;
378 if (nmp
->nm_fsinfo
.pcflags
&
379 NFSPCINFO_CASE_PRESERVING
)
380 caps
|= VOL_CAP_FMT_CASE_PRESERVING
;
382 /* Is server's max file size at least 2TB? */
383 if (nmp
->nm_fsinfo
.maxfilesize
>= 0x20000000000ULL
)
384 caps
|= VOL_CAP_FMT_2TB_FILESIZE
;
387 * NFSv3 supports 64 bits of file size.
388 * Without FSINFO from the server, we'll
389 * just assume maxfilesize >= 2TB
391 caps
|= VOL_CAP_FMT_2TB_FILESIZE
;
394 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_FORMAT
] =
395 // VOL_CAP_FMT_PERSISTENTOBJECTIDS |
396 // VOL_CAP_FMT_SYMBOLICLINKS |
397 // VOL_CAP_FMT_HARDLINKS |
398 // VOL_CAP_FMT_JOURNAL |
399 // VOL_CAP_FMT_JOURNAL_ACTIVE |
400 // VOL_CAP_FMT_NO_ROOT_TIMES |
401 // VOL_CAP_FMT_SPARSE_FILES |
402 // VOL_CAP_FMT_ZERO_RUNS |
403 // VOL_CAP_FMT_CASE_SENSITIVE |
404 // VOL_CAP_FMT_CASE_PRESERVING |
405 // VOL_CAP_FMT_FAST_STATFS |
406 // VOL_CAP_FMT_2TB_FILESIZE |
408 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_FORMAT
] =
409 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
410 // VOL_CAP_FMT_SYMBOLICLINKS |
411 // VOL_CAP_FMT_HARDLINKS |
412 // VOL_CAP_FMT_JOURNAL |
413 // VOL_CAP_FMT_JOURNAL_ACTIVE |
414 // VOL_CAP_FMT_NO_ROOT_TIMES |
415 // VOL_CAP_FMT_SPARSE_FILES |
416 // VOL_CAP_FMT_ZERO_RUNS |
417 // VOL_CAP_FMT_CASE_SENSITIVE |
418 // VOL_CAP_FMT_CASE_PRESERVING |
419 VOL_CAP_FMT_FAST_STATFS
|
420 VOL_CAP_FMT_2TB_FILESIZE
|
424 * We don't support most of the interfaces.
426 * We MAY support locking, but we don't have any easy way of probing.
427 * We can tell if there's no lockd running or if locks have been
428 * disabled for a mount, so we can definitely answer NO in that case.
429 * Any attempt to send a request to lockd to test for locking support
430 * may cause the lazily-launched locking daemons to be started
431 * unnecessarily. So we avoid that. However, we do record if we ever
432 * successfully perform a lock operation on a mount point, so if it
433 * looks like lock ops have worked, we do report that we support them.
436 if ((!nfslockdvnode
&& !nfslockdwaiting
) ||
437 (nmp
->nm_flag
& NFSMNT_NOLOCKS
)) {
438 /* locks disabled on this mount, so they definitely won't work */
439 valid
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
440 } else if (nmp
->nm_state
& NFSSTA_LOCKSWORK
) {
441 caps
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
442 valid
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
444 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_INTERFACES
] =
445 // VOL_CAP_INT_SEARCHFS |
446 // VOL_CAP_INT_ATTRLIST |
447 // VOL_CAP_INT_NFSEXPORT |
448 // VOL_CAP_INT_READDIRATTR |
449 // VOL_CAP_INT_EXCHANGEDATA |
450 // VOL_CAP_INT_COPYFILE |
451 // VOL_CAP_INT_ALLOCATE |
452 // VOL_CAP_INT_VOL_RENAME |
453 // VOL_CAP_INT_ADVLOCK |
454 // VOL_CAP_INT_FLOCK |
455 // VOL_CAP_INT_EXTENDED_SECURITY |
456 // VOL_CAP_INT_USERACCESS |
458 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_INTERFACES
] =
459 VOL_CAP_INT_SEARCHFS
|
460 VOL_CAP_INT_ATTRLIST
|
461 VOL_CAP_INT_NFSEXPORT
|
462 VOL_CAP_INT_READDIRATTR
|
463 VOL_CAP_INT_EXCHANGEDATA
|
464 VOL_CAP_INT_COPYFILE
|
465 VOL_CAP_INT_ALLOCATE
|
466 VOL_CAP_INT_VOL_RENAME
|
467 // VOL_CAP_INT_ADVLOCK |
468 // VOL_CAP_INT_FLOCK |
469 // VOL_CAP_INT_EXTENDED_SECURITY |
470 // VOL_CAP_INT_USERACCESS |
473 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
474 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
476 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
477 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
479 VFSATTR_SET_SUPPORTED(fsap
, f_capabilities
);
482 if (VFSATTR_IS_ACTIVE(fsap
, f_attributes
)) {
483 fsap
->f_attributes
.validattr
.commonattr
= 0;
484 fsap
->f_attributes
.validattr
.volattr
=
485 ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
486 fsap
->f_attributes
.validattr
.dirattr
= 0;
487 fsap
->f_attributes
.validattr
.fileattr
= 0;
488 fsap
->f_attributes
.validattr
.forkattr
= 0;
490 fsap
->f_attributes
.nativeattr
.commonattr
= 0;
491 fsap
->f_attributes
.nativeattr
.volattr
=
492 ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
493 fsap
->f_attributes
.nativeattr
.dirattr
= 0;
494 fsap
->f_attributes
.nativeattr
.fileattr
= 0;
495 fsap
->f_attributes
.nativeattr
.forkattr
= 0;
497 VFSATTR_SET_SUPPORTED(fsap
, f_attributes
);
504 * nfs version 3 fsinfo rpc call
507 nfs_fsinfo(nmp
, vp
, cred
, p
)
508 struct nfsmount
*nmp
;
513 struct nfsv3_fsinfo
*fsp
;
517 int prefsize
, maxsize
;
518 caddr_t bpos
, dpos
, cp2
;
519 int error
= 0, retattr
;
520 mbuf_t mreq
, mrep
, md
, mb
, mb2
;
523 nfsm_reqhead(NFSX_FH(1));
526 OSAddAtomic(1, (SInt32
*)&nfsstats
.rpccnt
[NFSPROC_FSINFO
]);
528 nfsm_request(vp
, NFSPROC_FSINFO
, p
, cred
, &xid
);
530 nfsm_postop_attr_update(vp
, 1, retattr
, &xid
);
533 nfsm_dissect(fsp
, struct nfsv3_fsinfo
*, NFSX_V3FSINFO
);
534 prefsize
= fxdr_unsigned(u_long
, fsp
->fs_wtpref
);
535 if (prefsize
< nmp
->nm_wsize
)
536 nmp
->nm_wsize
= (prefsize
+ NFS_FABLKSIZE
- 1) &
537 ~(NFS_FABLKSIZE
- 1);
538 maxsize
= fxdr_unsigned(u_long
, fsp
->fs_wtmax
);
539 if (maxsize
< nmp
->nm_wsize
) {
540 nmp
->nm_wsize
= maxsize
& ~(NFS_FABLKSIZE
- 1);
541 if (nmp
->nm_wsize
== 0)
542 nmp
->nm_wsize
= maxsize
;
544 prefsize
= fxdr_unsigned(u_long
, fsp
->fs_rtpref
);
545 if (prefsize
< nmp
->nm_rsize
)
546 nmp
->nm_rsize
= (prefsize
+ NFS_FABLKSIZE
- 1) &
547 ~(NFS_FABLKSIZE
- 1);
548 maxsize
= fxdr_unsigned(u_long
, fsp
->fs_rtmax
);
549 if (maxsize
< nmp
->nm_rsize
) {
550 nmp
->nm_rsize
= maxsize
& ~(NFS_FABLKSIZE
- 1);
551 if (nmp
->nm_rsize
== 0)
552 nmp
->nm_rsize
= maxsize
;
554 prefsize
= fxdr_unsigned(u_long
, fsp
->fs_dtpref
);
555 if (prefsize
< nmp
->nm_readdirsize
)
556 nmp
->nm_readdirsize
= prefsize
;
557 if (maxsize
< nmp
->nm_readdirsize
) {
558 nmp
->nm_readdirsize
= maxsize
;
560 fxdr_hyper(&fsp
->fs_maxfilesize
, &nmp
->nm_fsinfo
.maxfilesize
);
561 nmp
->nm_fsinfo
.fsproperties
= fxdr_unsigned(u_long
, fsp
->fs_properties
);
562 nmp
->nm_state
|= NFSSTA_GOTFSINFO
;
569 * Mount a remote root fs via. nfs. This depends on the info in the
570 * nfs_diskless structure that has been filled in properly by some primary
572 * It goes something like this:
573 * - do enough of "ifconfig" by calling ifioctl() so that the system
574 * can talk to the server
575 * - If nfs_diskless.mygateway is filled in, use that address as
577 * - hand craft the swap nfs vnode hanging off a fake mount point
578 * if swdevt[0].sw_dev == NODEV
579 * - build the rootfs mount point and call mountnfs() to do the rest.
584 struct nfs_diskless nd
;
585 struct nfs_vattr nvattr
;
590 #if !defined(NO_MOUNT_PRIVATE)
593 #endif /* NO_MOUNT_PRIVATE */
596 procp
= current_proc(); /* XXX */
599 * Call nfs_boot_init() to fill in the nfs_diskless struct.
600 * Note: networking must already have been configured before
603 bzero((caddr_t
) &nd
, sizeof(nd
));
604 error
= nfs_boot_init(&nd
, procp
);
606 panic("nfs_boot_init failed with %d\n", error
);
610 * Try NFSv3 first, then fallback to NFSv2.
611 * Likewise, try TCP first, then fall back to UDP.
614 sotype
= SOCK_STREAM
;
617 error
= nfs_boot_getfh(&nd
, procp
, v3
, sotype
);
619 if (error
== EHOSTDOWN
|| error
== EHOSTUNREACH
) {
620 if (nd
.nd_root
.ndm_path
)
621 FREE_ZONE(nd
.nd_root
.ndm_path
,
622 MAXPATHLEN
, M_NAMEI
);
623 if (nd
.nd_private
.ndm_path
)
624 FREE_ZONE(nd
.nd_private
.ndm_path
,
625 MAXPATHLEN
, M_NAMEI
);
629 if (sotype
== SOCK_STREAM
) {
630 printf("nfs_boot_getfh(v3,TCP) failed with %d, trying UDP...\n", error
);
634 printf("nfs_boot_getfh(v3,UDP) failed with %d, trying v2...\n", error
);
636 sotype
= SOCK_STREAM
;
638 } else if (sotype
== SOCK_STREAM
) {
639 printf("nfs_boot_getfh(v2,TCP) failed with %d, trying UDP...\n", error
);
643 panic("nfs_boot_getfh(v2,UDP) failed with %d\n", error
);
647 * Create the root mount point.
649 #if !defined(NO_MOUNT_PRIVATE)
650 if ((error
= nfs_mount_diskless(&nd
.nd_root
, "/", MNT_RDONLY
|MNT_ROOTFS
, &vp
, &mp
)))
652 if ((error
= nfs_mount_diskless(&nd
.nd_root
, "/", MNT_ROOTFS
, &vp
, &mp
)))
653 #endif /* NO_MOUNT_PRIVATE */
656 if (sotype
== SOCK_STREAM
) {
657 printf("nfs_mount_diskless(v3,TCP) failed with %d, trying UDP...\n", error
);
661 printf("nfs_mount_diskless(v3,UDP) failed with %d, trying v2...\n", error
);
663 sotype
= SOCK_STREAM
;
665 } else if (sotype
== SOCK_STREAM
) {
666 printf("nfs_mount_diskless(v2,TCP) failed with %d, trying UDP...\n", error
);
670 panic("nfs_mount_diskless(v2,UDP) root failed with %d\n", error
);
672 printf("root on %s\n", (char *)&nd
.nd_root
.ndm_host
);
678 #if !defined(NO_MOUNT_PRIVATE)
679 if (nd
.nd_private
.ndm_saddr
.sin_addr
.s_addr
) {
680 error
= nfs_mount_diskless_private(&nd
.nd_private
, "/private",
681 0, &vppriv
, &mppriv
);
683 panic("nfs_mount_diskless private failed with %d\n", error
);
685 printf("private on %s\n", (char *)&nd
.nd_private
.ndm_host
);
688 mount_list_add(mppriv
);
691 #endif /* NO_MOUNT_PRIVATE */
693 if (nd
.nd_root
.ndm_path
)
694 FREE_ZONE(nd
.nd_root
.ndm_path
, MAXPATHLEN
, M_NAMEI
);
695 if (nd
.nd_private
.ndm_path
)
696 FREE_ZONE(nd
.nd_private
.ndm_path
, MAXPATHLEN
, M_NAMEI
);
698 /* Get root attributes (for the time). */
699 error
= nfs_getattr(vp
, &nvattr
, kauth_cred_get(), procp
);
700 if (error
) panic("nfs_mountroot: getattr for root");
705 * Internal version of mount system call for diskless setup.
709 struct nfs_dlmount
*ndmntp
,
715 struct user_nfs_args args
;
721 procp
= current_proc(); /* XXX */
723 if ((error
= vfs_rootmountalloc("nfs", ndmntp
->ndm_host
, &mp
))) {
724 printf("nfs_mount_diskless: NFS not configured");
728 mp
->mnt_flag
|= mntflag
;
729 if (!(mntflag
& MNT_RDONLY
))
730 mp
->mnt_flag
&= ~MNT_RDONLY
;
732 /* Initialize mount args. */
733 bzero((caddr_t
) &args
, sizeof(args
));
734 args
.addr
= CAST_USER_ADDR_T(&ndmntp
->ndm_saddr
);
735 args
.addrlen
= ndmntp
->ndm_saddr
.sin_len
;
736 args
.sotype
= ndmntp
->ndm_sotype
;
737 args
.fh
= CAST_USER_ADDR_T(&ndmntp
->ndm_fh
[0]);
738 args
.fhsize
= ndmntp
->ndm_fhlen
;
739 args
.hostname
= CAST_USER_ADDR_T(ndmntp
->ndm_host
);
740 args
.flags
= NFSMNT_RESVPORT
;
741 if (ndmntp
->ndm_nfsv3
)
742 args
.flags
|= NFSMNT_NFSV3
;
744 error
= mbuf_get(MBUF_WAITOK
, MBUF_TYPE_SONAME
, &m
);
746 printf("nfs_mount_diskless: mbuf_get(soname) failed");
749 mbuf_setlen(m
, ndmntp
->ndm_saddr
.sin_len
);
750 bcopy((caddr_t
)args
.addr
, mbuf_data(m
), ndmntp
->ndm_saddr
.sin_len
);
751 if ((error
= mountnfs(&args
, mp
, m
, procp
, vpp
))) {
752 printf("nfs_mountroot: mount %s failed: %d\n", mntname
, error
);
753 // XXX vfs_rootmountfailed(mp);
755 mp
->mnt_vtable
->vfc_refcount
--;
758 mount_lock_destroy(mp
);
759 FREE_ZONE(mp
, sizeof(struct mount
), M_MOUNT
);
766 #if !defined(NO_MOUNT_PRIVATE)
768 * Internal version of mount system call to mount "/private"
769 * separately in diskless setup
772 nfs_mount_diskless_private(
773 struct nfs_dlmount
*ndmntp
,
779 struct user_nfs_args args
;
784 struct vfstable
*vfsp
;
787 struct vfs_context context
;
789 procp
= current_proc(); /* XXX */
790 context
.vc_proc
= procp
;
791 context
.vc_ucred
= kauth_cred_get();
795 * mimic main()!. Temporarily set up rootvnode and other stuff so
796 * that namei works. Need to undo this because main() does it, too
798 struct filedesc
*fdp
; /* pointer to file descriptor state */
800 mountlist
.tqh_first
->mnt_flag
|= MNT_ROOTFS
;
802 /* Get the vnode for '/'. Set fdp->fd_cdir to reference it. */
803 if (VFS_ROOT(mountlist
.tqh_first
, &rootvnode
, NULL
))
804 panic("cannot find root vnode");
805 error
= vnode_ref(rootvnode
);
807 printf("nfs_mountroot: vnode_ref() failed on root vnode!\n");
810 fdp
->fd_cdir
= rootvnode
;
815 * Get vnode to be covered
817 NDINIT(&nd
, LOOKUP
, FOLLOW
| LOCKLEAF
, UIO_SYSSPACE32
,
819 if ((error
= namei(&nd
))) {
820 printf("nfs_mountroot: private namei failed!\n");
824 /* undo vnode_ref() in mimic main()! */
825 vnode_rele(rootvnode
);
830 if ((error
= VNOP_FSYNC(vp
, MNT_WAIT
, &context
)) ||
831 (error
= buf_invalidateblks(vp
, BUF_WRITE_DATA
, 0, 0))) {
835 if (vnode_vtype(vp
) != VDIR
) {
839 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
)
840 if (!strcmp(vfsp
->vfc_name
, "nfs"))
843 printf("nfs_mountroot: private NFS not configured\n");
847 if (vnode_mountedhere(vp
) != NULL
) {
853 * Allocate and initialize the filesystem.
855 mp
= _MALLOC_ZONE((u_long
)sizeof(struct mount
), M_MOUNT
, M_WAITOK
);
857 printf("nfs_mountroot: unable to allocate mount structure\n");
861 bzero((char *)mp
, (u_long
)sizeof(struct mount
));
863 /* Initialize the default IO constraints */
864 mp
->mnt_maxreadcnt
= mp
->mnt_maxwritecnt
= MAXPHYS
;
865 mp
->mnt_segreadcnt
= mp
->mnt_segwritecnt
= 32;
868 TAILQ_INIT(&mp
->mnt_vnodelist
);
869 TAILQ_INIT(&mp
->mnt_workerqueue
);
870 TAILQ_INIT(&mp
->mnt_newvnodes
);
871 (void)vfs_busy(mp
, LK_NOWAIT
);
872 TAILQ_INIT(&mp
->mnt_vnodelist
);
874 vfsp
->vfc_refcount
++;
876 mp
->mnt_vtable
= vfsp
;
877 mp
->mnt_op
= vfsp
->vfc_vfsops
;
878 // mp->mnt_stat.f_type = vfsp->vfc_typenum;
879 mp
->mnt_flag
= mntflag
;
880 mp
->mnt_flag
|= vfsp
->vfc_flags
& MNT_VISFLAGMASK
;
881 strncpy(mp
->mnt_vfsstat
.f_fstypename
, vfsp
->vfc_name
, MFSNAMELEN
-1);
882 vp
->v_mountedhere
= mp
;
883 mp
->mnt_vnodecovered
= vp
;
884 mp
->mnt_vfsstat
.f_owner
= kauth_cred_getuid(kauth_cred_get());
885 (void) copystr(mntname
, mp
->mnt_vfsstat
.f_mntonname
, MNAMELEN
- 1, 0);
886 (void) copystr(ndmntp
->ndm_host
, mp
->mnt_vfsstat
.f_mntfromname
, MNAMELEN
- 1, 0);
888 /* Initialize mount args. */
889 bzero((caddr_t
) &args
, sizeof(args
));
890 args
.addr
= CAST_USER_ADDR_T(&ndmntp
->ndm_saddr
);
891 args
.addrlen
= ndmntp
->ndm_saddr
.sin_len
;
892 args
.sotype
= ndmntp
->ndm_sotype
;
893 args
.fh
= CAST_USER_ADDR_T(ndmntp
->ndm_fh
);
894 args
.fhsize
= ndmntp
->ndm_fhlen
;
895 args
.hostname
= CAST_USER_ADDR_T(ndmntp
->ndm_host
);
896 args
.flags
= NFSMNT_RESVPORT
;
897 if (ndmntp
->ndm_nfsv3
)
898 args
.flags
|= NFSMNT_NFSV3
;
900 error
= mbuf_get(MBUF_WAITOK
, MBUF_TYPE_SONAME
, &m
);
902 printf("nfs_mount_diskless_private: mbuf_get(soname) failed");
905 mbuf_setlen(m
, ndmntp
->ndm_saddr
.sin_len
);
906 bcopy((caddr_t
)args
.addr
, mbuf_data(m
), ndmntp
->ndm_saddr
.sin_len
);
907 if ((error
= mountnfs(&args
, mp
, m
, procp
, &vp
))) {
908 printf("nfs_mountroot: mount %s failed: %d\n", mntname
, error
);
910 vfsp
->vfc_refcount
--;
913 mount_lock_destroy(mp
);
914 FREE_ZONE(mp
, sizeof (struct mount
), M_MOUNT
);
922 #endif /* NO_MOUNT_PRIVATE */
930 nfs_mount(mount_t mp
, vnode_t vp
, user_addr_t data
, vfs_context_t context
)
932 proc_t p
= vfs_context_proc(context
);
934 struct user_nfs_args args
;
935 struct nfs_args tempargs
;
938 u_char nfh
[NFSX_V3FHMAX
];
941 error
= copyin(data
, (caddr_t
)&argsvers
, sizeof (argsvers
));
947 if (vfs_context_is64bit(context
))
948 error
= copyin(data
, (caddr_t
)&args
, sizeof (struct user_nfs_args3
));
950 error
= copyin(data
, (caddr_t
)&tempargs
, sizeof (struct nfs_args3
));
953 if (vfs_context_is64bit(context
))
954 error
= copyin(data
, (caddr_t
)&args
, sizeof (args
));
956 error
= copyin(data
, (caddr_t
)&tempargs
, sizeof (tempargs
));
959 return (EPROGMISMATCH
);
964 if (!vfs_context_is64bit(context
)) {
965 args
.version
= tempargs
.version
;
966 args
.addrlen
= tempargs
.addrlen
;
967 args
.sotype
= tempargs
.sotype
;
968 args
.proto
= tempargs
.proto
;
969 args
.fhsize
= tempargs
.fhsize
;
970 args
.flags
= tempargs
.flags
;
971 args
.wsize
= tempargs
.wsize
;
972 args
.rsize
= tempargs
.rsize
;
973 args
.readdirsize
= tempargs
.readdirsize
;
974 args
.timeo
= tempargs
.timeo
;
975 args
.retrans
= tempargs
.retrans
;
976 args
.maxgrouplist
= tempargs
.maxgrouplist
;
977 args
.readahead
= tempargs
.readahead
;
978 args
.leaseterm
= tempargs
.leaseterm
;
979 args
.deadthresh
= tempargs
.deadthresh
;
980 args
.addr
= CAST_USER_ADDR_T(tempargs
.addr
);
981 args
.fh
= CAST_USER_ADDR_T(tempargs
.fh
);
982 args
.hostname
= CAST_USER_ADDR_T(tempargs
.hostname
);
984 args
.acregmin
= tempargs
.acregmin
;
985 args
.acregmax
= tempargs
.acregmax
;
986 args
.acdirmin
= tempargs
.acdirmin
;
987 args
.acdirmax
= tempargs
.acdirmax
;
991 if (args
.fhsize
< 0 || args
.fhsize
> NFSX_V3FHMAX
)
993 error
= copyin(args
.fh
, (caddr_t
)nfh
, args
.fhsize
);
997 mntfrom
= &vfs_statfs(mp
)->f_mntfromname
[0];
998 error
= copyinstr(args
.hostname
, mntfrom
, MAXPATHLEN
-1, &len
);
1001 bzero(&mntfrom
[len
], MAXPATHLEN
- len
);
1003 /* sockargs() call must be after above copyin() calls */
1004 error
= sockargs(&nam
, args
.addr
, args
.addrlen
, MBUF_TYPE_SONAME
);
1008 args
.fh
= CAST_USER_ADDR_T(&nfh
[0]);
1009 error
= mountnfs(&args
, mp
, nam
, p
, &vp
);
1014 * Common code for mount and mountroot
1018 struct user_nfs_args
*argp
,
1024 struct nfsmount
*nmp
;
1027 struct nfs_vattr nvattrs
;
1028 struct vfs_context context
; /* XXX get from caller? */
1032 * Silently clear NFSMNT_NOCONN if it's a TCP mount, it makes
1033 * no sense in that context.
1035 if (argp
->sotype
== SOCK_STREAM
)
1036 argp
->flags
&= ~NFSMNT_NOCONN
;
1038 if (vfs_flags(mp
) & MNT_UPDATE
) {
1040 /* update paths, file handles, etc, here XXX */
1044 MALLOC_ZONE(nmp
, struct nfsmount
*,
1045 sizeof (struct nfsmount
), M_NFSMNT
, M_WAITOK
);
1050 bzero((caddr_t
)nmp
, sizeof (struct nfsmount
));
1051 TAILQ_INIT(&nmp
->nm_uidlruhead
);
1052 TAILQ_INIT(&nmp
->nm_bufq
);
1053 vfs_setfsprivate(mp
, nmp
);
1056 /* setup defaults */
1057 nmp
->nm_timeo
= NFS_TIMEO
;
1058 nmp
->nm_retry
= NFS_RETRANS
;
1059 if (argp
->sotype
== SOCK_DGRAM
) {
1060 nmp
->nm_wsize
= NFS_DGRAM_WSIZE
;
1061 nmp
->nm_rsize
= NFS_DGRAM_RSIZE
;
1063 nmp
->nm_wsize
= NFS_WSIZE
;
1064 nmp
->nm_rsize
= NFS_RSIZE
;
1066 nmp
->nm_readdirsize
= NFS_READDIRSIZE
;
1067 nmp
->nm_numgrps
= NFS_MAXGRPS
;
1068 nmp
->nm_readahead
= NFS_DEFRAHEAD
;
1069 nmp
->nm_tprintf_delay
= nfs_tprintf_delay
;
1070 if (nmp
->nm_tprintf_delay
< 0)
1071 nmp
->nm_tprintf_delay
= 0;
1072 nmp
->nm_tprintf_initial_delay
= nfs_tprintf_initial_delay
;
1073 if (nmp
->nm_tprintf_initial_delay
< 0)
1074 nmp
->nm_tprintf_initial_delay
= 0;
1075 nmp
->nm_acregmin
= NFS_MINATTRTIMO
;
1076 nmp
->nm_acregmax
= NFS_MAXATTRTIMO
;
1077 nmp
->nm_acdirmin
= NFS_MINDIRATTRTIMO
;
1078 nmp
->nm_acdirmax
= NFS_MAXDIRATTRTIMO
;
1081 nmp
->nm_mountp
= mp
;
1082 vfs_setauthopaque(mp
);
1083 nmp
->nm_flag
= argp
->flags
;
1086 if ((argp
->flags
& NFSMNT_TIMEO
) && argp
->timeo
> 0) {
1087 nmp
->nm_timeo
= (argp
->timeo
* NFS_HZ
+ 5) / 10;
1088 if (nmp
->nm_timeo
< NFS_MINTIMEO
)
1089 nmp
->nm_timeo
= NFS_MINTIMEO
;
1090 else if (nmp
->nm_timeo
> NFS_MAXTIMEO
)
1091 nmp
->nm_timeo
= NFS_MAXTIMEO
;
1094 if ((argp
->flags
& NFSMNT_RETRANS
) && argp
->retrans
> 1) {
1095 nmp
->nm_retry
= argp
->retrans
;
1096 if (nmp
->nm_retry
> NFS_MAXREXMIT
)
1097 nmp
->nm_retry
= NFS_MAXREXMIT
;
1100 if (argp
->flags
& NFSMNT_NFSV3
) {
1101 if (argp
->sotype
== SOCK_DGRAM
)
1102 maxio
= NFS_MAXDGRAMDATA
;
1104 maxio
= NFS_MAXDATA
;
1106 maxio
= NFS_V2MAXDATA
;
1108 if ((argp
->flags
& NFSMNT_WSIZE
) && argp
->wsize
> 0) {
1109 nmp
->nm_wsize
= argp
->wsize
;
1110 /* Round down to multiple of blocksize */
1111 nmp
->nm_wsize
&= ~(NFS_FABLKSIZE
- 1);
1112 if (nmp
->nm_wsize
<= 0)
1113 nmp
->nm_wsize
= NFS_FABLKSIZE
;
1115 if (nmp
->nm_wsize
> maxio
)
1116 nmp
->nm_wsize
= maxio
;
1117 if (nmp
->nm_wsize
> NFS_MAXBSIZE
)
1118 nmp
->nm_wsize
= NFS_MAXBSIZE
;
1120 if ((argp
->flags
& NFSMNT_RSIZE
) && argp
->rsize
> 0) {
1121 nmp
->nm_rsize
= argp
->rsize
;
1122 /* Round down to multiple of blocksize */
1123 nmp
->nm_rsize
&= ~(NFS_FABLKSIZE
- 1);
1124 if (nmp
->nm_rsize
<= 0)
1125 nmp
->nm_rsize
= NFS_FABLKSIZE
;
1127 if (nmp
->nm_rsize
> maxio
)
1128 nmp
->nm_rsize
= maxio
;
1129 if (nmp
->nm_rsize
> NFS_MAXBSIZE
)
1130 nmp
->nm_rsize
= NFS_MAXBSIZE
;
1132 if ((argp
->flags
& NFSMNT_READDIRSIZE
) && argp
->readdirsize
> 0) {
1133 nmp
->nm_readdirsize
= argp
->readdirsize
;
1135 if (nmp
->nm_readdirsize
> maxio
)
1136 nmp
->nm_readdirsize
= maxio
;
1137 if (nmp
->nm_readdirsize
> nmp
->nm_rsize
)
1138 nmp
->nm_readdirsize
= nmp
->nm_rsize
;
1140 if ((argp
->flags
& NFSMNT_MAXGRPS
) && argp
->maxgrouplist
>= 0 &&
1141 argp
->maxgrouplist
<= NFS_MAXGRPS
)
1142 nmp
->nm_numgrps
= argp
->maxgrouplist
;
1143 if ((argp
->flags
& NFSMNT_READAHEAD
) && argp
->readahead
>= 0 &&
1144 argp
->readahead
<= NFS_MAXRAHEAD
)
1145 nmp
->nm_readahead
= argp
->readahead
;
1147 if (argp
->version
>= 4) {
1148 if ((argp
->flags
& NFSMNT_ACREGMIN
) && argp
->acregmin
>= 0)
1149 nmp
->nm_acregmin
= argp
->acregmin
;
1150 if ((argp
->flags
& NFSMNT_ACREGMAX
) && argp
->acregmax
>= 0)
1151 nmp
->nm_acregmax
= argp
->acregmax
;
1152 if ((argp
->flags
& NFSMNT_ACDIRMIN
) && argp
->acdirmin
>= 0)
1153 nmp
->nm_acdirmin
= argp
->acdirmin
;
1154 if ((argp
->flags
& NFSMNT_ACDIRMAX
) && argp
->acdirmax
>= 0)
1155 nmp
->nm_acdirmax
= argp
->acdirmax
;
1156 if (nmp
->nm_acregmin
> nmp
->nm_acregmax
)
1157 nmp
->nm_acregmin
= nmp
->nm_acregmax
;
1158 if (nmp
->nm_acdirmin
> nmp
->nm_acdirmax
)
1159 nmp
->nm_acdirmin
= nmp
->nm_acdirmax
;
1162 /* Set up the sockets and per-host congestion */
1163 nmp
->nm_sotype
= argp
->sotype
;
1164 nmp
->nm_soproto
= argp
->proto
;
1166 /* make sure mbuf constants are set up */
1171 * For Connection based sockets (TCP,...) defer the connect until
1172 * the first request, in case the server is not responding.
1174 if (nmp
->nm_sotype
== SOCK_DGRAM
&&
1175 (error
= nfs_connect(nmp
, (struct nfsreq
*)0)))
1179 * Get file attributes for the mountpoint. These are needed
1180 * in order to properly create the root vnode.
1182 // LP64todo - fix CAST_DOWN of argp->fh
1183 error
= nfs_getattr_no_vnode(mp
, CAST_DOWN(caddr_t
, argp
->fh
), argp
->fhsize
,
1184 proc_ucred(p
), p
, &nvattrs
, &xid
);
1187 * we got problems... we couldn't get the attributes
1188 * from the NFS server... so the mount fails.
1194 * A reference count is needed on the nfsnode representing the
1195 * remote root. If this object is not persistent, then backward
1196 * traversals of the mount point (i.e. "..") will not work if
1197 * the nfsnode gets flushed out of the cache. UFS does not have
1198 * this problem, because one can identify root inodes by their
1199 * number == ROOTINO (2).
1201 error
= nfs_nget(mp
, NULL
, NULL
, CAST_DOWN(caddr_t
, argp
->fh
), argp
->fhsize
,
1202 &nvattrs
, &xid
, NG_MARKROOT
, &np
);
1207 * save this vnode pointer. That way nfs_unmount()
1208 * does not need to call nfs_nget() just get it to drop
1209 * this vnode reference.
1211 nmp
->nm_dvp
= *vpp
= NFSTOV(np
);
1212 /* get usecount and drop iocount */
1213 error
= vnode_ref(*vpp
);
1221 * Set the mount point's block I/O size.
1222 * We really need to do this after we get info back from
1223 * the server about what its preferred I/O sizes are.
1225 if (nmp
->nm_flag
& NFSMNT_NFSV3
)
1226 nfs_fsinfo(nmp
, *vpp
, proc_ucred(p
), p
);
1227 nmp
->nm_biosize
= nfs_biosize(nmp
);
1228 vfs_statfs(mp
)->f_iosize
= NFS_IOSIZE
;
1231 * V3 mounts give us a (relatively) reliable remote access(2)
1232 * call, so advertise the fact.
1234 * XXX this may not be the best way to go, as the granularity
1235 * offered isn't a good match to our needs.
1237 if (nmp
->nm_flag
& NFSMNT_NFSV3
)
1238 vfs_setauthopaqueaccess(mp
);
1241 * Do statfs to ensure static info gets set to reasonable values.
1243 context
.vc_proc
= p
;
1244 context
.vc_ucred
= proc_ucred(p
);
1245 nfs_statfs(mp
, vfs_statfs(mp
), &context
);
1247 if (nmp
->nm_flag
& NFSMNT_RESVPORT
)
1249 nmp
->nm_state
|= NFSSTA_MOUNTED
;
1252 nfs_disconnect(nmp
);
1253 FREE_ZONE((caddr_t
)nmp
, sizeof (struct nfsmount
), M_NFSMNT
);
1260 * unmount system call
1266 __unused vfs_context_t context
)
1268 register struct nfsmount
*nmp
;
1270 int error
, flags
= 0;
1274 * During a force unmount we want to...
1275 * Mark that we are doing a force unmount.
1276 * Make the mountpoint soft.
1278 if (mntflags
& MNT_FORCE
) {
1279 flags
|= FORCECLOSE
;
1280 nmp
->nm_state
|= NFSSTA_FORCE
;
1281 nmp
->nm_flag
|= NFSMNT_SOFT
;
1284 * Goes something like this..
1285 * - Call vflush() to clear out vnodes for this file system,
1286 * except for the swap files. Deal with them in 2nd pass.
1287 * - Decrement reference on the vnode representing remote root.
1288 * - Close the socket
1289 * - Free up the data structures
1294 * vflush will check for busy vnodes on mountpoint.
1295 * Will do the right thing for MNT_FORCE. That is, we should
1296 * not get EBUSY back.
1298 error
= vflush(mp
, vp
, SKIPSWAP
| flags
);
1299 if (mntflags
& MNT_FORCE
) {
1300 error
= vflush(mp
, NULLVP
, flags
); /* locks vp in the process */
1302 if (vnode_isinuse(vp
, 1))
1304 error
= vflush(mp
, vp
, flags
);
1309 nmp
->nm_state
&= ~NFSSTA_MOUNTED
;
1310 if (nmp
->nm_flag
& NFSMNT_RESVPORT
) {
1311 if (--nfs_resv_mounts
== 0)
1312 nfs_bind_resv_thread_wake();
1316 * Release the root vnode reference held by mountnfs()
1320 (void)vflush(mp
, NULLVP
, FORCECLOSE
);
1321 vfs_setfsprivate(mp
, 0); /* don't want to end up using stale vp */
1323 nfs_disconnect(nmp
);
1324 mbuf_freem(nmp
->nm_nam
);
1326 if ((nmp
->nm_flag
& NFSMNT_KERB
) == 0) {
1329 * Loop through outstanding request list and remove dangling
1330 * references to defunct nfsmount struct
1332 for (rp
= nfs_reqq
.tqh_first
; rp
; rp
= rp
->r_chain
.tqe_next
)
1333 if (rp
->r_nmp
== nmp
)
1334 rp
->r_nmp
= (struct nfsmount
*)0;
1335 /* Need to wake up any rcvlock waiters so they notice the unmount. */
1336 if (nmp
->nm_state
& NFSSTA_WANTRCV
) {
1337 nmp
->nm_state
&= ~NFSSTA_WANTRCV
;
1338 wakeup(&nmp
->nm_state
);
1340 FREE_ZONE((caddr_t
)nmp
, sizeof (struct nfsmount
), M_NFSMNT
);
1346 * Return root of a filesystem
1349 nfs_root(mount_t mp
, vnode_t
*vpp
, __unused vfs_context_t context
)
1352 struct nfsmount
*nmp
;
1358 vpid
= vnode_vid(vp
);
1359 while ((error
= vnode_getwithvid(vp
, vpid
))) {
1360 /* vnode_get() may return ENOENT if the dir changes. */
1361 /* If that happens, just try it again, else return the error. */
1362 if ((error
!= ENOENT
) || (vnode_vid(vp
) == vpid
))
1364 vpid
= vnode_vid(vp
);
1371 * Flush out the buffer cache
1374 struct nfs_sync_cargs
{
1375 vfs_context_t context
;
1381 nfs_sync_callout(vnode_t vp
, void *arg
)
1383 struct nfs_sync_cargs
*cargs
= (struct nfs_sync_cargs
*)arg
;
1386 if (LIST_EMPTY(&VTONFS(vp
)->n_dirtyblkhd
))
1387 return (VNODE_RETURNED
);
1388 if (VTONFS(vp
)->n_flag
& NWRBUSY
)
1389 return (VNODE_RETURNED
);
1391 error
= nfs_flush(vp
, cargs
->waitfor
,
1392 vfs_context_ucred(cargs
->context
),
1393 vfs_context_proc(cargs
->context
), 0);
1395 cargs
->error
= error
;
1397 return (VNODE_RETURNED
);
1401 nfs_sync(mount_t mp
, int waitfor
, vfs_context_t context
)
1403 struct nfs_sync_cargs cargs
;
1405 cargs
.waitfor
= waitfor
;
1406 cargs
.context
= context
;
1409 vnode_iterate(mp
, 0, nfs_sync_callout
, &cargs
);
1411 return (cargs
.error
);
1415 * NFS flat namespace lookup.
1416 * Currently unsupported.
1421 __unused mount_t mp
,
1422 __unused ino64_t ino
,
1423 __unused vnode_t
*vpp
,
1424 __unused vfs_context_t context
)
1431 * At this point, this should never happen
1436 __unused mount_t mp
,
1438 __unused
unsigned char *fhp
,
1439 __unused vnode_t
*vpp
,
1440 __unused vfs_context_t context
)
1447 * Vnode pointer to File handle, should never happen either
1452 __unused vnode_t vp
,
1453 __unused
int *fhlenp
,
1454 __unused
unsigned char *fhp
,
1455 __unused vfs_context_t context
)
1462 * Vfs start routine, a no-op.
1467 __unused mount_t mp
,
1469 __unused vfs_context_t context
)
1476 * Do that sysctl thang...
1479 nfs_sysctl(int *name
, u_int namelen
, user_addr_t oldp
, size_t *oldlenp
,
1480 user_addr_t newp
, size_t newlen
, vfs_context_t context
)
1483 struct sysctl_req
*req
= NULL
;
1485 struct user_vfsidctl user_vc
;
1487 struct nfsmount
*nmp
= NULL
;
1489 boolean_t is_64_bit
;
1492 * All names at this level are terminal.
1495 return ENOTDIR
; /* overloaded */
1497 is_64_bit
= vfs_context_is64bit(context
);
1499 /* common code for "new style" VFS_CTL sysctl, get the mount. */
1503 case VFS_CTL_NOLOCKS
:
1504 req
= CAST_DOWN(struct sysctl_req
*, oldp
);
1506 error
= SYSCTL_IN(req
, &user_vc
, sizeof(user_vc
));
1509 mp
= vfs_getvfs(&user_vc
.vc_fsid
);
1512 error
= SYSCTL_IN(req
, &vc
, sizeof(vc
));
1515 mp
= vfs_getvfs(&vc
.vc_fsid
);
1522 bzero(&vq
, sizeof(vq
));
1525 req
->newptr
= user_vc
.vc_ptr
;
1526 req
->newlen
= (size_t)user_vc
.vc_len
;
1529 req
->newptr
= CAST_USER_ADDR_T(vc
.vc_ptr
);
1530 req
->newlen
= vc
.vc_len
;
1537 *oldlenp
= sizeof nfsstats
;
1541 if(*oldlenp
< sizeof nfsstats
) {
1542 *oldlenp
= sizeof nfsstats
;
1546 error
= copyout(&nfsstats
, oldp
, sizeof nfsstats
);
1550 if(newp
&& newlen
!= sizeof nfsstats
)
1554 return copyin(newp
, &nfsstats
, sizeof nfsstats
);
1557 case VFS_CTL_NOLOCKS
:
1558 val
= (nmp
->nm_flag
& NFSMNT_NOLOCKS
) ? 1 : 0;
1559 if (req
->oldptr
!= USER_ADDR_NULL
) {
1560 error
= SYSCTL_OUT(req
, &val
, sizeof(val
));
1564 if (req
->newptr
!= USER_ADDR_NULL
) {
1565 error
= SYSCTL_IN(req
, &val
, sizeof(val
));
1569 nmp
->nm_flag
|= NFSMNT_NOLOCKS
;
1571 nmp
->nm_flag
&= ~NFSMNT_NOLOCKS
;
1575 if (nmp
->nm_state
& NFSSTA_TIMEO
)
1576 vq
.vq_flags
|= VQ_NOTRESP
;
1577 if (!(nmp
->nm_flag
& NFSMNT_NOLOCKS
) &&
1578 (nmp
->nm_state
& NFSSTA_LOCKTIMEO
))
1579 vq
.vq_flags
|= VQ_NOTRESPLOCK
;
1580 error
= SYSCTL_OUT(req
, &vq
, sizeof(vq
));
1583 if (req
->oldptr
!= USER_ADDR_NULL
) {
1584 error
= SYSCTL_OUT(req
, &nmp
->nm_tprintf_initial_delay
,
1585 sizeof(nmp
->nm_tprintf_initial_delay
));
1589 if (req
->newptr
!= USER_ADDR_NULL
) {
1590 error
= SYSCTL_IN(req
, &nmp
->nm_tprintf_initial_delay
,
1591 sizeof(nmp
->nm_tprintf_initial_delay
));
1594 if (nmp
->nm_tprintf_initial_delay
< 0)
1595 nmp
->nm_tprintf_initial_delay
= 0;