2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
23 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
25 * Copyright (c) 1989, 1993, 1995
26 * The Regents of the University of California. All rights reserved.
28 * This code is derived from software contributed to Berkeley by
29 * Rick Macklem at The University of Guelph.
31 * Redistribution and use in source and binary forms, with or without
32 * modification, are permitted provided that the following conditions
34 * 1. Redistributions of source code must retain the above copyright
35 * notice, this list of conditions and the following disclaimer.
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in the
38 * documentation and/or other materials provided with the distribution.
39 * 3. All advertising materials mentioning features or use of this software
40 * must display the following acknowledgement:
41 * This product includes software developed by the University of
42 * California, Berkeley and its contributors.
43 * 4. Neither the name of the University nor the names of its contributors
44 * may be used to endorse or promote products derived from this software
45 * without specific prior written permission.
47 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59 * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95
60 * FreeBSD-Id: nfs_vfsops.c,v 1.52 1997/11/12 05:42:21 julian Exp $
63 #include <sys/param.h>
64 #include <sys/systm.h>
66 #include <sys/ioctl.h>
67 #include <sys/signal.h>
68 #include <sys/proc_internal.h> /* for fs rooting to update rootdir in fdp */
69 #include <sys/kauth.h>
70 #include <sys/vnode_internal.h>
71 #include <sys/malloc.h>
72 #include <sys/kernel.h>
73 #include <sys/sysctl.h>
74 #include <sys/mount_internal.h>
75 #include <sys/kpi_mbuf.h>
76 #include <sys/socket.h>
77 #include <sys/socketvar.h>
78 #include <sys/fcntl.h>
79 #include <libkern/OSAtomic.h>
82 #include <sys/vmparam.h>
84 #if !defined(NO_MOUNT_PRIVATE)
85 #include <sys/filedesc.h>
86 #endif /* NO_MOUNT_PRIVATE */
89 #include <net/route.h>
90 #include <netinet/in.h>
92 #include <nfs/rpcv2.h>
93 #include <nfs/nfsproto.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/nfs_lock.h>
102 extern int nfs_mountroot(void);
104 extern int nfs_ticks
;
105 extern int nfs_mount_type
;
106 extern int nfs_resv_mounts
;
108 struct nfsstats nfsstats
;
109 static int nfs_sysctl(int *, u_int
, user_addr_t
, size_t *, user_addr_t
, size_t, vfs_context_t
);
110 /* XXX CSM 11/25/97 Upgrade sysctl.h someday */
112 SYSCTL_NODE(_vfs
, MOUNT_NFS
, nfs
, CTLFLAG_RW
, 0, "NFS filesystem");
113 SYSCTL_STRUCT(_vfs_nfs
, NFS_NFSSTATS
, nfsstats
, CTLFLAG_RD
,
114 &nfsstats
, nfsstats
, "");
117 SYSCTL_DECL(_vfs_generic_nfs
);
118 SYSCTL_NODE(_vfs_generic_nfs
, OID_AUTO
, client
, CTLFLAG_RW
, 0,
120 /* how long NFS will wait before signalling vfs that it's down. */
121 static int nfs_tprintf_initial_delay
= NFS_TPRINTF_INITIAL_DELAY
;
122 SYSCTL_INT(_vfs_generic_nfs_client
, NFS_TPRINTF_INITIAL_DELAY
,
123 initialdowndelay
, CTLFLAG_RW
, &nfs_tprintf_initial_delay
, 0, "");
124 /* how long between console messages "nfs server foo not responding" */
125 static int nfs_tprintf_delay
= NFS_TPRINTF_DELAY
;
126 SYSCTL_INT(_vfs_generic_nfs_client
, NFS_TPRINTF_DELAY
,
127 nextdowndelay
, CTLFLAG_RW
, &nfs_tprintf_delay
, 0, "");
129 static int nfs_iosize(struct nfsmount
*nmp
);
130 static int mountnfs(struct user_nfs_args
*,mount_t
,mbuf_t
,proc_t
,vnode_t
*);
131 static int nfs_mount(mount_t mp
, vnode_t vp
, user_addr_t data
, vfs_context_t context
);
132 static int nfs_start(mount_t mp
, int flags
, vfs_context_t context
);
133 static int nfs_unmount(mount_t mp
, int mntflags
, vfs_context_t context
);
134 static int nfs_root(mount_t mp
, vnode_t
*vpp
, vfs_context_t context
);
135 static int nfs_statfs(mount_t mp
, struct vfsstatfs
*sbp
, vfs_context_t context
);
136 static int nfs_vfs_getattr(mount_t mp
, struct vfs_attr
*fsap
, vfs_context_t context
);
137 static int nfs_sync( mount_t mp
, int waitfor
, vfs_context_t context
);
138 static int nfs_vptofh(vnode_t vp
, int *fhlenp
, unsigned char *fhp
, vfs_context_t context
);
139 static int nfs_fhtovp(mount_t mp
, int fhlen
, unsigned char *fhp
, vnode_t
*vpp
, vfs_context_t context
);
140 static int nfs_vget(mount_t
, ino64_t
, vnode_t
*, vfs_context_t context
);
144 * nfs vfs operations.
146 struct vfsops nfs_vfsops
= {
164 nfs_mount_diskless(struct nfs_dlmount
*, const char *, int, vnode_t
*, mount_t
*);
165 #if !defined(NO_MOUNT_PRIVATE)
167 nfs_mount_diskless_private(struct nfs_dlmount
*, const char *, int, vnode_t
*, mount_t
*);
168 #endif /* NO_MOUNT_PRIVATE */
170 static int nfs_iosize(nmp
)
171 struct nfsmount
* nmp
;
176 * Calculate the size used for io buffers. Use the larger
177 * of the two sizes to minimise nfs requests but make sure
178 * that it is at least one VM page to avoid wasting buffer
179 * space and to allow easy mmapping of I/O buffers.
180 * The read/write rpc calls handle the splitting up of
181 * buffers into multiple requests if the buffer size is
182 * larger than the I/O size.
184 iosize
= max(nmp
->nm_rsize
, nmp
->nm_wsize
);
185 if (iosize
< PAGE_SIZE
)
187 return (trunc_page_32(iosize
));
194 nfs_statfs(mount_t mp
, struct vfsstatfs
*sbp
, vfs_context_t context
)
196 proc_t p
= vfs_context_proc(context
);
198 struct nfs_statfs
*sfp
;
202 caddr_t bpos
, dpos
, cp2
;
203 struct nfsmount
*nmp
= VFSTONFS(mp
);
204 int error
= 0, v3
= (nmp
->nm_flag
& NFSMNT_NFSV3
), retattr
;
205 mbuf_t mreq
, mrep
, md
, mb
, mb2
;
208 struct ucred temp_cred
;
211 sfp
= (struct nfs_statfs
*)0;
214 if ((error
= vnode_get(vp
)))
217 bzero(&temp_cred
, sizeof(temp_cred
));
218 temp_cred
.cr_ngroups
= 1;
219 cred
= kauth_cred_create(&temp_cred
);
221 if (v3
&& (nmp
->nm_state
& NFSSTA_GOTFSINFO
) == 0)
222 nfs_fsinfo(nmp
, vp
, cred
, p
);
223 nfsm_reqhead(NFSX_FH(v3
));
225 kauth_cred_rele(cred
);
229 OSAddAtomic(1, (SInt32
*)&nfsstats
.rpccnt
[NFSPROC_FSSTAT
]);
231 nfsm_request(vp
, NFSPROC_FSSTAT
, p
, cred
, &xid
);
233 nfsm_postop_attr_update(vp
, v3
, retattr
, &xid
);
234 nfsm_dissect(sfp
, struct nfs_statfs
*, NFSX_STATFS(v3
));
236 sbp
->f_flags
= nmp
->nm_flag
;
237 sbp
->f_iosize
= nfs_iosize(nmp
);
240 * Adjust block size to get total block count to fit in a long.
241 * If we can't increase block size enough, clamp to max long.
243 u_quad_t tquad
, tquad2
, bsize
;
244 bsize
= NFS_FABLKSIZE
;
246 fxdr_hyper(&sfp
->sf_tbytes
, &tquad
);
248 while ((tquad
& ~0x7fffffff) && (bsize
< 0x40000000)) {
252 sbp
->f_blocks
= (tquad
& ~0x7fffffff) ? 0x7fffffff : (long)tquad
;
254 fxdr_hyper(&sfp
->sf_fbytes
, &tquad
);
256 sbp
->f_bfree
= (tquad
& ~0x7fffffff) ? 0x7fffffff : (long)tquad
;
258 fxdr_hyper(&sfp
->sf_abytes
, &tquad
);
260 sbp
->f_bavail
= (tquad
& ~0x7fffffff) ? 0x7fffffff : (long)tquad
;
262 sbp
->f_bsize
= (long)bsize
;
264 /* adjust file slots too... */
265 fxdr_hyper(&sfp
->sf_tfiles
, &tquad
);
266 fxdr_hyper(&sfp
->sf_ffiles
, &tquad2
);
267 while (tquad
& ~0x7fffffff) {
271 sbp
->f_files
= tquad
;
272 sbp
->f_ffree
= tquad2
;
274 sbp
->f_bsize
= fxdr_unsigned(long, sfp
->sf_bsize
);
275 sbp
->f_blocks
= fxdr_unsigned(long, sfp
->sf_blocks
);
276 sbp
->f_bfree
= fxdr_unsigned(long, sfp
->sf_bfree
);
277 sbp
->f_bavail
= fxdr_unsigned(long, sfp
->sf_bavail
);
282 kauth_cred_rele(cred
);
288 * The nfs_statfs code is complicated, and used by mountnfs(), so leave it as-is
289 * and handle VFS_GETATTR by calling nfs_statfs and copying fields.
292 nfs_vfs_getattr(mount_t mp
, struct vfs_attr
*fsap
, vfs_context_t context
)
296 if (VFSATTR_IS_ACTIVE(fsap
, f_bsize
) ||
297 VFSATTR_IS_ACTIVE(fsap
, f_iosize
) ||
298 VFSATTR_IS_ACTIVE(fsap
, f_blocks
) ||
299 VFSATTR_IS_ACTIVE(fsap
, f_bfree
) ||
300 VFSATTR_IS_ACTIVE(fsap
, f_bavail
) ||
301 VFSATTR_IS_ACTIVE(fsap
, f_bused
) ||
302 VFSATTR_IS_ACTIVE(fsap
, f_files
) ||
303 VFSATTR_IS_ACTIVE(fsap
, f_ffree
)) {
306 error
= nfs_statfs(mp
, &sb
, context
);
308 VFSATTR_RETURN(fsap
, f_bsize
, sb
.f_bsize
);
309 VFSATTR_RETURN(fsap
, f_iosize
, sb
.f_iosize
);
310 VFSATTR_RETURN(fsap
, f_blocks
, sb
.f_blocks
);
311 VFSATTR_RETURN(fsap
, f_bfree
, sb
.f_bfree
);
312 VFSATTR_RETURN(fsap
, f_bavail
, sb
.f_bavail
);
313 VFSATTR_RETURN(fsap
, f_bused
, sb
.f_blocks
- sb
.f_bfree
);
314 VFSATTR_RETURN(fsap
, f_files
, sb
.f_files
);
315 VFSATTR_RETURN(fsap
, f_ffree
, sb
.f_ffree
);
319 if (VFSATTR_IS_ACTIVE(fsap
, f_capabilities
)) {
320 struct nfsmount
*nmp
;
321 struct nfsv3_pathconf pc
;
322 u_int32_t caps
, valid
;
326 if (!(nmp
= VFSTONFS(mp
)))
329 v3
= (nmp
->nm_flag
& NFSMNT_NFSV3
);
332 * The capabilities[] array defines what this volume supports.
334 * The valid[] array defines which bits this code understands
335 * the meaning of (whether the volume has that capability or not).
336 * Any zero bits here means "I don't know what you're asking about"
337 * and the caller cannot tell whether that capability is
342 /* try to get fsinfo if we haven't already */
343 if (!(nmp
->nm_state
& NFSSTA_GOTFSINFO
)) {
344 nfs_fsinfo(nmp
, vp
, vfs_context_ucred(context
),
345 vfs_context_proc(context
));
346 if (!(nmp
= VFSTONFS(vnode_mount(vp
))))
349 if (nmp
->nm_state
& NFSSTA_GOTFSINFO
) {
350 /* fsinfo indicates (non)support of links and symlinks */
351 valid
|= VOL_CAP_FMT_SYMBOLICLINKS
|
352 VOL_CAP_FMT_HARDLINKS
;
353 if (nmp
->nm_fsinfo
.fsproperties
& NFSV3FSINFO_SYMLINK
)
354 caps
|= VOL_CAP_FMT_SYMBOLICLINKS
;
355 if (nmp
->nm_fsinfo
.fsproperties
& NFSV3FSINFO_LINK
)
356 caps
|= VOL_CAP_FMT_HARDLINKS
;
357 /* if fsinfo indicates all pathconf info is the same, */
358 /* we can use it to report case attributes */
359 if ((nmp
->nm_fsinfo
.fsproperties
& NFSV3FSINFO_HOMOGENEOUS
) &&
360 !(nmp
->nm_state
& NFSSTA_GOTPATHCONF
)) {
361 /* no cached pathconf info, try to get now */
362 error
= nfs_pathconfrpc(vp
, &pc
,
363 vfs_context_ucred(context
),
364 vfs_context_proc(context
));
365 if (!(nmp
= VFSTONFS(vnode_mount(vp
))))
368 /* all files have the same pathconf info, */
369 /* so cache a copy of the results */
370 nfs_pathconf_cache(nmp
, &pc
);
373 if (nmp
->nm_state
& NFSSTA_GOTPATHCONF
) {
374 valid
|= VOL_CAP_FMT_CASE_SENSITIVE
|
375 VOL_CAP_FMT_CASE_PRESERVING
;
376 if (!(nmp
->nm_fsinfo
.pcflags
&
377 NFSPCINFO_CASE_INSENSITIVE
))
378 caps
|= VOL_CAP_FMT_CASE_SENSITIVE
;
379 if (nmp
->nm_fsinfo
.pcflags
&
380 NFSPCINFO_CASE_PRESERVING
)
381 caps
|= VOL_CAP_FMT_CASE_PRESERVING
;
383 /* Is server's max file size at least 2TB? */
384 if (nmp
->nm_fsinfo
.maxfilesize
>= 0x20000000000ULL
)
385 caps
|= VOL_CAP_FMT_2TB_FILESIZE
;
388 * NFSv3 supports 64 bits of file size.
389 * Without FSINFO from the server, we'll
390 * just assume maxfilesize >= 2TB
392 caps
|= VOL_CAP_FMT_2TB_FILESIZE
;
395 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_FORMAT
] =
396 // VOL_CAP_FMT_PERSISTENTOBJECTIDS |
397 // VOL_CAP_FMT_SYMBOLICLINKS |
398 // VOL_CAP_FMT_HARDLINKS |
399 // VOL_CAP_FMT_JOURNAL |
400 // VOL_CAP_FMT_JOURNAL_ACTIVE |
401 // VOL_CAP_FMT_NO_ROOT_TIMES |
402 // VOL_CAP_FMT_SPARSE_FILES |
403 // VOL_CAP_FMT_ZERO_RUNS |
404 // VOL_CAP_FMT_CASE_SENSITIVE |
405 // VOL_CAP_FMT_CASE_PRESERVING |
406 // VOL_CAP_FMT_FAST_STATFS |
407 // VOL_CAP_FMT_2TB_FILESIZE |
409 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_FORMAT
] =
410 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
411 // VOL_CAP_FMT_SYMBOLICLINKS |
412 // VOL_CAP_FMT_HARDLINKS |
413 // VOL_CAP_FMT_JOURNAL |
414 // VOL_CAP_FMT_JOURNAL_ACTIVE |
415 // VOL_CAP_FMT_NO_ROOT_TIMES |
416 // VOL_CAP_FMT_SPARSE_FILES |
417 // VOL_CAP_FMT_ZERO_RUNS |
418 // VOL_CAP_FMT_CASE_SENSITIVE |
419 // VOL_CAP_FMT_CASE_PRESERVING |
420 VOL_CAP_FMT_FAST_STATFS
|
421 VOL_CAP_FMT_2TB_FILESIZE
|
425 * We don't support most of the interfaces.
427 * We MAY support locking, but we don't have any easy way of probing.
428 * We can tell if there's no lockd running or if locks have been
429 * disabled for a mount, so we can definitely answer NO in that case.
430 * Any attempt to send a request to lockd to test for locking support
431 * may cause the lazily-launched locking daemons to be started
432 * unnecessarily. So we avoid that. However, we do record if we ever
433 * successfully perform a lock operation on a mount point, so if it
434 * looks like lock ops have worked, we do report that we support them.
437 if ((!nfslockdvnode
&& !nfslockdwaiting
) ||
438 (nmp
->nm_flag
& NFSMNT_NOLOCKS
)) {
439 /* locks disabled on this mount, so they definitely won't work */
440 valid
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
441 } else if (nmp
->nm_state
& NFSSTA_LOCKSWORK
) {
442 caps
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
443 valid
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
445 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_INTERFACES
] =
446 // VOL_CAP_INT_SEARCHFS |
447 // VOL_CAP_INT_ATTRLIST |
448 // VOL_CAP_INT_NFSEXPORT |
449 // VOL_CAP_INT_READDIRATTR |
450 // VOL_CAP_INT_EXCHANGEDATA |
451 // VOL_CAP_INT_COPYFILE |
452 // VOL_CAP_INT_ALLOCATE |
453 // VOL_CAP_INT_VOL_RENAME |
454 // VOL_CAP_INT_ADVLOCK |
455 // VOL_CAP_INT_FLOCK |
456 // VOL_CAP_INT_EXTENDED_SECURITY |
457 // VOL_CAP_INT_USERACCESS |
459 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_INTERFACES
] =
460 VOL_CAP_INT_SEARCHFS
|
461 VOL_CAP_INT_ATTRLIST
|
462 VOL_CAP_INT_NFSEXPORT
|
463 VOL_CAP_INT_READDIRATTR
|
464 VOL_CAP_INT_EXCHANGEDATA
|
465 VOL_CAP_INT_COPYFILE
|
466 VOL_CAP_INT_ALLOCATE
|
467 VOL_CAP_INT_VOL_RENAME
|
468 // VOL_CAP_INT_ADVLOCK |
469 // VOL_CAP_INT_FLOCK |
470 // VOL_CAP_INT_EXTENDED_SECURITY |
471 // VOL_CAP_INT_USERACCESS |
474 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
475 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
477 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
478 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
480 VFSATTR_SET_SUPPORTED(fsap
, f_capabilities
);
483 if (VFSATTR_IS_ACTIVE(fsap
, f_attributes
)) {
484 fsap
->f_attributes
.validattr
.commonattr
= 0;
485 fsap
->f_attributes
.validattr
.volattr
=
486 ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
487 fsap
->f_attributes
.validattr
.dirattr
= 0;
488 fsap
->f_attributes
.validattr
.fileattr
= 0;
489 fsap
->f_attributes
.validattr
.forkattr
= 0;
491 fsap
->f_attributes
.nativeattr
.commonattr
= 0;
492 fsap
->f_attributes
.nativeattr
.volattr
=
493 ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
494 fsap
->f_attributes
.nativeattr
.dirattr
= 0;
495 fsap
->f_attributes
.nativeattr
.fileattr
= 0;
496 fsap
->f_attributes
.nativeattr
.forkattr
= 0;
498 VFSATTR_SET_SUPPORTED(fsap
, f_attributes
);
505 * nfs version 3 fsinfo rpc call
508 nfs_fsinfo(nmp
, vp
, cred
, p
)
509 struct nfsmount
*nmp
;
514 struct nfsv3_fsinfo
*fsp
;
518 int prefsize
, maxsize
;
519 caddr_t bpos
, dpos
, cp2
;
520 int error
= 0, retattr
;
521 mbuf_t mreq
, mrep
, md
, mb
, mb2
;
524 nfsm_reqhead(NFSX_FH(1));
527 OSAddAtomic(1, (SInt32
*)&nfsstats
.rpccnt
[NFSPROC_FSINFO
]);
529 nfsm_request(vp
, NFSPROC_FSINFO
, p
, cred
, &xid
);
531 nfsm_postop_attr_update(vp
, 1, retattr
, &xid
);
534 nfsm_dissect(fsp
, struct nfsv3_fsinfo
*, NFSX_V3FSINFO
);
535 prefsize
= fxdr_unsigned(u_long
, fsp
->fs_wtpref
);
536 if (prefsize
< nmp
->nm_wsize
)
537 nmp
->nm_wsize
= (prefsize
+ NFS_FABLKSIZE
- 1) &
538 ~(NFS_FABLKSIZE
- 1);
539 maxsize
= fxdr_unsigned(u_long
, fsp
->fs_wtmax
);
540 if (maxsize
< nmp
->nm_wsize
) {
541 nmp
->nm_wsize
= maxsize
& ~(NFS_FABLKSIZE
- 1);
542 if (nmp
->nm_wsize
== 0)
543 nmp
->nm_wsize
= maxsize
;
545 prefsize
= fxdr_unsigned(u_long
, fsp
->fs_rtpref
);
546 if (prefsize
< nmp
->nm_rsize
)
547 nmp
->nm_rsize
= (prefsize
+ NFS_FABLKSIZE
- 1) &
548 ~(NFS_FABLKSIZE
- 1);
549 maxsize
= fxdr_unsigned(u_long
, fsp
->fs_rtmax
);
550 if (maxsize
< nmp
->nm_rsize
) {
551 nmp
->nm_rsize
= maxsize
& ~(NFS_FABLKSIZE
- 1);
552 if (nmp
->nm_rsize
== 0)
553 nmp
->nm_rsize
= maxsize
;
555 prefsize
= fxdr_unsigned(u_long
, fsp
->fs_dtpref
);
556 if (prefsize
< nmp
->nm_readdirsize
)
557 nmp
->nm_readdirsize
= prefsize
;
558 if (maxsize
< nmp
->nm_readdirsize
) {
559 nmp
->nm_readdirsize
= maxsize
;
561 fxdr_hyper(&fsp
->fs_maxfilesize
, &nmp
->nm_fsinfo
.maxfilesize
);
562 nmp
->nm_fsinfo
.fsproperties
= fxdr_unsigned(u_long
, fsp
->fs_properties
);
563 nmp
->nm_state
|= NFSSTA_GOTFSINFO
;
570 * Mount a remote root fs via. nfs. This depends on the info in the
571 * nfs_diskless structure that has been filled in properly by some primary
573 * It goes something like this:
574 * - do enough of "ifconfig" by calling ifioctl() so that the system
575 * can talk to the server
576 * - If nfs_diskless.mygateway is filled in, use that address as
578 * - hand craft the swap nfs vnode hanging off a fake mount point
579 * if swdevt[0].sw_dev == NODEV
580 * - build the rootfs mount point and call mountnfs() to do the rest.
585 struct nfs_diskless nd
;
586 struct nfs_vattr nvattr
;
591 #if !defined(NO_MOUNT_PRIVATE)
594 #endif /* NO_MOUNT_PRIVATE */
597 procp
= current_proc(); /* XXX */
600 * Call nfs_boot_init() to fill in the nfs_diskless struct.
601 * Note: networking must already have been configured before
604 bzero((caddr_t
) &nd
, sizeof(nd
));
605 error
= nfs_boot_init(&nd
, procp
);
607 panic("nfs_boot_init failed with %d\n", error
);
611 * Try NFSv3 first, then fallback to NFSv2.
612 * Likewise, try TCP first, then fall back to UDP.
615 sotype
= SOCK_STREAM
;
618 error
= nfs_boot_getfh(&nd
, procp
, v3
, sotype
);
620 if (error
== EHOSTDOWN
|| error
== EHOSTUNREACH
) {
621 if (nd
.nd_root
.ndm_path
)
622 FREE_ZONE(nd
.nd_root
.ndm_path
,
623 MAXPATHLEN
, M_NAMEI
);
624 if (nd
.nd_private
.ndm_path
)
625 FREE_ZONE(nd
.nd_private
.ndm_path
,
626 MAXPATHLEN
, M_NAMEI
);
630 if (sotype
== SOCK_STREAM
) {
631 printf("nfs_boot_getfh(v3,TCP) failed with %d, trying UDP...\n", error
);
635 printf("nfs_boot_getfh(v3,UDP) failed with %d, trying v2...\n", error
);
637 sotype
= SOCK_STREAM
;
639 } else if (sotype
== SOCK_STREAM
) {
640 printf("nfs_boot_getfh(v2,TCP) failed with %d, trying UDP...\n", error
);
644 panic("nfs_boot_getfh(v2,UDP) failed with %d\n", error
);
648 * Create the root mount point.
650 #if !defined(NO_MOUNT_PRIVATE)
651 if ((error
= nfs_mount_diskless(&nd
.nd_root
, "/", MNT_RDONLY
|MNT_ROOTFS
, &vp
, &mp
)))
653 if ((error
= nfs_mount_diskless(&nd
.nd_root
, "/", MNT_ROOTFS
, &vp
, &mp
)))
654 #endif /* NO_MOUNT_PRIVATE */
657 if (sotype
== SOCK_STREAM
) {
658 printf("nfs_mount_diskless(v3,TCP) failed with %d, trying UDP...\n", error
);
662 printf("nfs_mount_diskless(v3,UDP) failed with %d, trying v2...\n", error
);
664 sotype
= SOCK_STREAM
;
666 } else if (sotype
== SOCK_STREAM
) {
667 printf("nfs_mount_diskless(v2,TCP) failed with %d, trying UDP...\n", error
);
671 panic("nfs_mount_diskless(v2,UDP) root failed with %d\n", error
);
673 printf("root on %s\n", (char *)&nd
.nd_root
.ndm_host
);
679 #if !defined(NO_MOUNT_PRIVATE)
680 if (nd
.nd_private
.ndm_saddr
.sin_addr
.s_addr
) {
681 error
= nfs_mount_diskless_private(&nd
.nd_private
, "/private",
682 0, &vppriv
, &mppriv
);
684 panic("nfs_mount_diskless private failed with %d\n", error
);
686 printf("private on %s\n", (char *)&nd
.nd_private
.ndm_host
);
689 mount_list_add(mppriv
);
692 #endif /* NO_MOUNT_PRIVATE */
694 if (nd
.nd_root
.ndm_path
)
695 FREE_ZONE(nd
.nd_root
.ndm_path
, MAXPATHLEN
, M_NAMEI
);
696 if (nd
.nd_private
.ndm_path
)
697 FREE_ZONE(nd
.nd_private
.ndm_path
, MAXPATHLEN
, M_NAMEI
);
699 /* Get root attributes (for the time). */
700 error
= nfs_getattr(vp
, &nvattr
, kauth_cred_get(), procp
);
701 if (error
) panic("nfs_mountroot: getattr for root");
706 * Internal version of mount system call for diskless setup.
710 struct nfs_dlmount
*ndmntp
,
716 struct user_nfs_args args
;
722 procp
= current_proc(); /* XXX */
724 if ((error
= vfs_rootmountalloc("nfs", ndmntp
->ndm_host
, &mp
))) {
725 printf("nfs_mount_diskless: NFS not configured");
729 mp
->mnt_flag
|= mntflag
;
730 if (!(mntflag
& MNT_RDONLY
))
731 mp
->mnt_flag
&= ~MNT_RDONLY
;
733 /* Initialize mount args. */
734 bzero((caddr_t
) &args
, sizeof(args
));
735 args
.addr
= CAST_USER_ADDR_T(&ndmntp
->ndm_saddr
);
736 args
.addrlen
= ndmntp
->ndm_saddr
.sin_len
;
737 args
.sotype
= ndmntp
->ndm_sotype
;
738 args
.fh
= CAST_USER_ADDR_T(&ndmntp
->ndm_fh
[0]);
739 args
.fhsize
= ndmntp
->ndm_fhlen
;
740 args
.hostname
= CAST_USER_ADDR_T(ndmntp
->ndm_host
);
741 args
.flags
= NFSMNT_RESVPORT
;
742 if (ndmntp
->ndm_nfsv3
)
743 args
.flags
|= NFSMNT_NFSV3
;
745 error
= mbuf_get(MBUF_WAITOK
, MBUF_TYPE_SONAME
, &m
);
747 printf("nfs_mount_diskless: mbuf_get(soname) failed");
750 mbuf_setlen(m
, ndmntp
->ndm_saddr
.sin_len
);
751 bcopy((caddr_t
)args
.addr
, mbuf_data(m
), ndmntp
->ndm_saddr
.sin_len
);
752 if ((error
= mountnfs(&args
, mp
, m
, procp
, vpp
))) {
753 printf("nfs_mountroot: mount %s failed: %d\n", mntname
, error
);
754 // XXX vfs_rootmountfailed(mp);
756 mp
->mnt_vtable
->vfc_refcount
--;
759 mount_lock_destroy(mp
);
760 FREE_ZONE(mp
, sizeof(struct mount
), M_MOUNT
);
767 #if !defined(NO_MOUNT_PRIVATE)
769 * Internal version of mount system call to mount "/private"
770 * separately in diskless setup
773 nfs_mount_diskless_private(
774 struct nfs_dlmount
*ndmntp
,
780 struct user_nfs_args args
;
785 struct vfstable
*vfsp
;
788 struct vfs_context context
;
790 procp
= current_proc(); /* XXX */
791 context
.vc_proc
= procp
;
792 context
.vc_ucred
= kauth_cred_get();
796 * mimic main()!. Temporarily set up rootvnode and other stuff so
797 * that namei works. Need to undo this because main() does it, too
799 struct filedesc
*fdp
; /* pointer to file descriptor state */
801 mountlist
.tqh_first
->mnt_flag
|= MNT_ROOTFS
;
803 /* Get the vnode for '/'. Set fdp->fd_cdir to reference it. */
804 if (VFS_ROOT(mountlist
.tqh_first
, &rootvnode
, NULL
))
805 panic("cannot find root vnode");
806 error
= vnode_ref(rootvnode
);
808 printf("nfs_mountroot: vnode_ref() failed on root vnode!\n");
811 fdp
->fd_cdir
= rootvnode
;
816 * Get vnode to be covered
818 NDINIT(&nd
, LOOKUP
, FOLLOW
| LOCKLEAF
, UIO_SYSSPACE32
,
820 if ((error
= namei(&nd
))) {
821 printf("nfs_mountroot: private namei failed!\n");
825 /* undo vnode_ref() in mimic main()! */
826 vnode_rele(rootvnode
);
831 if ((error
= VNOP_FSYNC(vp
, MNT_WAIT
, &context
)) ||
832 (error
= buf_invalidateblks(vp
, BUF_WRITE_DATA
, 0, 0))) {
836 if (vnode_vtype(vp
) != VDIR
) {
840 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
)
841 if (!strcmp(vfsp
->vfc_name
, "nfs"))
844 printf("nfs_mountroot: private NFS not configured\n");
848 if (vnode_mountedhere(vp
) != NULL
) {
854 * Allocate and initialize the filesystem.
856 mp
= _MALLOC_ZONE((u_long
)sizeof(struct mount
), M_MOUNT
, M_WAITOK
);
858 printf("nfs_mountroot: unable to allocate mount structure\n");
862 bzero((char *)mp
, (u_long
)sizeof(struct mount
));
864 /* Initialize the default IO constraints */
865 mp
->mnt_maxreadcnt
= mp
->mnt_maxwritecnt
= MAXPHYS
;
866 mp
->mnt_segreadcnt
= mp
->mnt_segwritecnt
= 32;
869 TAILQ_INIT(&mp
->mnt_vnodelist
);
870 TAILQ_INIT(&mp
->mnt_workerqueue
);
871 TAILQ_INIT(&mp
->mnt_newvnodes
);
872 (void)vfs_busy(mp
, LK_NOWAIT
);
873 TAILQ_INIT(&mp
->mnt_vnodelist
);
875 vfsp
->vfc_refcount
++;
877 mp
->mnt_vtable
= vfsp
;
878 mp
->mnt_op
= vfsp
->vfc_vfsops
;
879 // mp->mnt_stat.f_type = vfsp->vfc_typenum;
880 mp
->mnt_flag
= mntflag
;
881 mp
->mnt_flag
|= vfsp
->vfc_flags
& MNT_VISFLAGMASK
;
882 strncpy(mp
->mnt_vfsstat
.f_fstypename
, vfsp
->vfc_name
, MFSNAMELEN
-1);
883 vp
->v_mountedhere
= mp
;
884 mp
->mnt_vnodecovered
= vp
;
885 mp
->mnt_vfsstat
.f_owner
= kauth_cred_getuid(kauth_cred_get());
886 (void) copystr(mntname
, mp
->mnt_vfsstat
.f_mntonname
, MNAMELEN
- 1, 0);
887 (void) copystr(ndmntp
->ndm_host
, mp
->mnt_vfsstat
.f_mntfromname
, MNAMELEN
- 1, 0);
889 /* Initialize mount args. */
890 bzero((caddr_t
) &args
, sizeof(args
));
891 args
.addr
= CAST_USER_ADDR_T(&ndmntp
->ndm_saddr
);
892 args
.addrlen
= ndmntp
->ndm_saddr
.sin_len
;
893 args
.sotype
= ndmntp
->ndm_sotype
;
894 args
.fh
= CAST_USER_ADDR_T(ndmntp
->ndm_fh
);
895 args
.fhsize
= ndmntp
->ndm_fhlen
;
896 args
.hostname
= CAST_USER_ADDR_T(ndmntp
->ndm_host
);
897 args
.flags
= NFSMNT_RESVPORT
;
898 if (ndmntp
->ndm_nfsv3
)
899 args
.flags
|= NFSMNT_NFSV3
;
901 error
= mbuf_get(MBUF_WAITOK
, MBUF_TYPE_SONAME
, &m
);
903 printf("nfs_mount_diskless_private: mbuf_get(soname) failed");
906 mbuf_setlen(m
, ndmntp
->ndm_saddr
.sin_len
);
907 bcopy((caddr_t
)args
.addr
, mbuf_data(m
), ndmntp
->ndm_saddr
.sin_len
);
908 if ((error
= mountnfs(&args
, mp
, m
, procp
, &vp
))) {
909 printf("nfs_mountroot: mount %s failed: %d\n", mntname
, error
);
911 vfsp
->vfc_refcount
--;
914 mount_lock_destroy(mp
);
915 FREE_ZONE(mp
, sizeof (struct mount
), M_MOUNT
);
923 #endif /* NO_MOUNT_PRIVATE */
931 nfs_mount(mount_t mp
, vnode_t vp
, user_addr_t data
, vfs_context_t context
)
933 proc_t p
= vfs_context_proc(context
);
935 struct user_nfs_args args
;
936 struct nfs_args tempargs
;
939 u_char nfh
[NFSX_V3FHMAX
];
942 error
= copyin(data
, (caddr_t
)&argsvers
, sizeof (argsvers
));
948 if (vfs_context_is64bit(context
))
949 error
= copyin(data
, (caddr_t
)&args
, sizeof (struct user_nfs_args3
));
951 error
= copyin(data
, (caddr_t
)&tempargs
, sizeof (struct nfs_args3
));
954 if (vfs_context_is64bit(context
))
955 error
= copyin(data
, (caddr_t
)&args
, sizeof (args
));
957 error
= copyin(data
, (caddr_t
)&tempargs
, sizeof (tempargs
));
960 return (EPROGMISMATCH
);
965 if (!vfs_context_is64bit(context
)) {
966 args
.version
= tempargs
.version
;
967 args
.addrlen
= tempargs
.addrlen
;
968 args
.sotype
= tempargs
.sotype
;
969 args
.proto
= tempargs
.proto
;
970 args
.fhsize
= tempargs
.fhsize
;
971 args
.flags
= tempargs
.flags
;
972 args
.wsize
= tempargs
.wsize
;
973 args
.rsize
= tempargs
.rsize
;
974 args
.readdirsize
= tempargs
.readdirsize
;
975 args
.timeo
= tempargs
.timeo
;
976 args
.retrans
= tempargs
.retrans
;
977 args
.maxgrouplist
= tempargs
.maxgrouplist
;
978 args
.readahead
= tempargs
.readahead
;
979 args
.leaseterm
= tempargs
.leaseterm
;
980 args
.deadthresh
= tempargs
.deadthresh
;
981 args
.addr
= CAST_USER_ADDR_T(tempargs
.addr
);
982 args
.fh
= CAST_USER_ADDR_T(tempargs
.fh
);
983 args
.hostname
= CAST_USER_ADDR_T(tempargs
.hostname
);
985 args
.acregmin
= tempargs
.acregmin
;
986 args
.acregmax
= tempargs
.acregmax
;
987 args
.acdirmin
= tempargs
.acdirmin
;
988 args
.acdirmax
= tempargs
.acdirmax
;
992 if (args
.fhsize
< 0 || args
.fhsize
> NFSX_V3FHMAX
)
994 error
= copyin(args
.fh
, (caddr_t
)nfh
, args
.fhsize
);
998 mntfrom
= &vfs_statfs(mp
)->f_mntfromname
[0];
999 error
= copyinstr(args
.hostname
, mntfrom
, MAXPATHLEN
-1, &len
);
1002 bzero(&mntfrom
[len
], MAXPATHLEN
- len
);
1004 /* sockargs() call must be after above copyin() calls */
1005 error
= sockargs(&nam
, args
.addr
, args
.addrlen
, MBUF_TYPE_SONAME
);
1009 args
.fh
= CAST_USER_ADDR_T(&nfh
[0]);
1010 error
= mountnfs(&args
, mp
, nam
, p
, &vp
);
1015 * Common code for mount and mountroot
1019 struct user_nfs_args
*argp
,
1025 struct nfsmount
*nmp
;
1028 struct nfs_vattr nvattrs
;
1029 struct vfs_context context
; /* XXX get from caller? */
1033 * Silently clear NFSMNT_NOCONN if it's a TCP mount, it makes
1034 * no sense in that context.
1036 if (argp
->sotype
== SOCK_STREAM
)
1037 argp
->flags
&= ~NFSMNT_NOCONN
;
1039 if (vfs_flags(mp
) & MNT_UPDATE
) {
1041 /* update paths, file handles, etc, here XXX */
1045 MALLOC_ZONE(nmp
, struct nfsmount
*,
1046 sizeof (struct nfsmount
), M_NFSMNT
, M_WAITOK
);
1051 bzero((caddr_t
)nmp
, sizeof (struct nfsmount
));
1052 TAILQ_INIT(&nmp
->nm_uidlruhead
);
1053 TAILQ_INIT(&nmp
->nm_bufq
);
1054 vfs_setfsprivate(mp
, nmp
);
1057 /* setup defaults */
1058 nmp
->nm_timeo
= NFS_TIMEO
;
1059 nmp
->nm_retry
= NFS_RETRANS
;
1060 if (argp
->sotype
== SOCK_DGRAM
) {
1061 nmp
->nm_wsize
= NFS_DGRAM_WSIZE
;
1062 nmp
->nm_rsize
= NFS_DGRAM_RSIZE
;
1064 nmp
->nm_wsize
= NFS_WSIZE
;
1065 nmp
->nm_rsize
= NFS_RSIZE
;
1067 nmp
->nm_readdirsize
= NFS_READDIRSIZE
;
1068 nmp
->nm_numgrps
= NFS_MAXGRPS
;
1069 nmp
->nm_readahead
= NFS_DEFRAHEAD
;
1070 nmp
->nm_tprintf_delay
= nfs_tprintf_delay
;
1071 if (nmp
->nm_tprintf_delay
< 0)
1072 nmp
->nm_tprintf_delay
= 0;
1073 nmp
->nm_tprintf_initial_delay
= nfs_tprintf_initial_delay
;
1074 if (nmp
->nm_tprintf_initial_delay
< 0)
1075 nmp
->nm_tprintf_initial_delay
= 0;
1076 nmp
->nm_acregmin
= NFS_MINATTRTIMO
;
1077 nmp
->nm_acregmax
= NFS_MAXATTRTIMO
;
1078 nmp
->nm_acdirmin
= NFS_MINDIRATTRTIMO
;
1079 nmp
->nm_acdirmax
= NFS_MAXDIRATTRTIMO
;
1082 nmp
->nm_mountp
= mp
;
1083 vfs_setauthopaque(mp
);
1084 nmp
->nm_flag
= argp
->flags
;
1087 if ((argp
->flags
& NFSMNT_TIMEO
) && argp
->timeo
> 0) {
1088 nmp
->nm_timeo
= (argp
->timeo
* NFS_HZ
+ 5) / 10;
1089 if (nmp
->nm_timeo
< NFS_MINTIMEO
)
1090 nmp
->nm_timeo
= NFS_MINTIMEO
;
1091 else if (nmp
->nm_timeo
> NFS_MAXTIMEO
)
1092 nmp
->nm_timeo
= NFS_MAXTIMEO
;
1095 if ((argp
->flags
& NFSMNT_RETRANS
) && argp
->retrans
> 1) {
1096 nmp
->nm_retry
= argp
->retrans
;
1097 if (nmp
->nm_retry
> NFS_MAXREXMIT
)
1098 nmp
->nm_retry
= NFS_MAXREXMIT
;
1101 if (argp
->flags
& NFSMNT_NFSV3
) {
1102 if (argp
->sotype
== SOCK_DGRAM
)
1103 maxio
= NFS_MAXDGRAMDATA
;
1105 maxio
= NFS_MAXDATA
;
1107 maxio
= NFS_V2MAXDATA
;
1109 if ((argp
->flags
& NFSMNT_WSIZE
) && argp
->wsize
> 0) {
1110 nmp
->nm_wsize
= argp
->wsize
;
1111 /* Round down to multiple of blocksize */
1112 nmp
->nm_wsize
&= ~(NFS_FABLKSIZE
- 1);
1113 if (nmp
->nm_wsize
<= 0)
1114 nmp
->nm_wsize
= NFS_FABLKSIZE
;
1116 if (nmp
->nm_wsize
> maxio
)
1117 nmp
->nm_wsize
= maxio
;
1118 if (nmp
->nm_wsize
> MAXBSIZE
)
1119 nmp
->nm_wsize
= MAXBSIZE
;
1121 if ((argp
->flags
& NFSMNT_RSIZE
) && argp
->rsize
> 0) {
1122 nmp
->nm_rsize
= argp
->rsize
;
1123 /* Round down to multiple of blocksize */
1124 nmp
->nm_rsize
&= ~(NFS_FABLKSIZE
- 1);
1125 if (nmp
->nm_rsize
<= 0)
1126 nmp
->nm_rsize
= NFS_FABLKSIZE
;
1128 if (nmp
->nm_rsize
> maxio
)
1129 nmp
->nm_rsize
= maxio
;
1130 if (nmp
->nm_rsize
> MAXBSIZE
)
1131 nmp
->nm_rsize
= MAXBSIZE
;
1133 if ((argp
->flags
& NFSMNT_READDIRSIZE
) && argp
->readdirsize
> 0) {
1134 nmp
->nm_readdirsize
= argp
->readdirsize
;
1136 if (nmp
->nm_readdirsize
> maxio
)
1137 nmp
->nm_readdirsize
= maxio
;
1138 if (nmp
->nm_readdirsize
> nmp
->nm_rsize
)
1139 nmp
->nm_readdirsize
= nmp
->nm_rsize
;
1141 if ((argp
->flags
& NFSMNT_MAXGRPS
) && argp
->maxgrouplist
>= 0 &&
1142 argp
->maxgrouplist
<= NFS_MAXGRPS
)
1143 nmp
->nm_numgrps
= argp
->maxgrouplist
;
1144 if ((argp
->flags
& NFSMNT_READAHEAD
) && argp
->readahead
>= 0 &&
1145 argp
->readahead
<= NFS_MAXRAHEAD
)
1146 nmp
->nm_readahead
= argp
->readahead
;
1148 if (argp
->version
>= 4) {
1149 if ((argp
->flags
& NFSMNT_ACREGMIN
) && argp
->acregmin
>= 0)
1150 nmp
->nm_acregmin
= argp
->acregmin
;
1151 if ((argp
->flags
& NFSMNT_ACREGMAX
) && argp
->acregmax
>= 0)
1152 nmp
->nm_acregmax
= argp
->acregmax
;
1153 if ((argp
->flags
& NFSMNT_ACDIRMIN
) && argp
->acdirmin
>= 0)
1154 nmp
->nm_acdirmin
= argp
->acdirmin
;
1155 if ((argp
->flags
& NFSMNT_ACDIRMAX
) && argp
->acdirmax
>= 0)
1156 nmp
->nm_acdirmax
= argp
->acdirmax
;
1157 if (nmp
->nm_acregmin
> nmp
->nm_acregmax
)
1158 nmp
->nm_acregmin
= nmp
->nm_acregmax
;
1159 if (nmp
->nm_acdirmin
> nmp
->nm_acdirmax
)
1160 nmp
->nm_acdirmin
= nmp
->nm_acdirmax
;
1163 /* Set up the sockets and per-host congestion */
1164 nmp
->nm_sotype
= argp
->sotype
;
1165 nmp
->nm_soproto
= argp
->proto
;
1167 /* make sure mbuf constants are set up */
1172 * For Connection based sockets (TCP,...) defer the connect until
1173 * the first request, in case the server is not responding.
1175 if (nmp
->nm_sotype
== SOCK_DGRAM
&&
1176 (error
= nfs_connect(nmp
, (struct nfsreq
*)0)))
1180 * Get file attributes for the mountpoint. These are needed
1181 * in order to properly create the root vnode.
1183 // LP64todo - fix CAST_DOWN of argp->fh
1184 error
= nfs_getattr_no_vnode(mp
, CAST_DOWN(caddr_t
, argp
->fh
), argp
->fhsize
,
1185 proc_ucred(p
), p
, &nvattrs
, &xid
);
1188 * we got problems... we couldn't get the attributes
1189 * from the NFS server... so the mount fails.
1195 * A reference count is needed on the nfsnode representing the
1196 * remote root. If this object is not persistent, then backward
1197 * traversals of the mount point (i.e. "..") will not work if
1198 * the nfsnode gets flushed out of the cache. UFS does not have
1199 * this problem, because one can identify root inodes by their
1200 * number == ROOTINO (2).
1202 error
= nfs_nget(mp
, NULL
, NULL
, CAST_DOWN(caddr_t
, argp
->fh
), argp
->fhsize
,
1203 &nvattrs
, &xid
, NG_MARKROOT
, &np
);
1208 * save this vnode pointer. That way nfs_unmount()
1209 * does not need to call nfs_nget() just get it to drop
1210 * this vnode reference.
1212 nmp
->nm_dvp
= *vpp
= NFSTOV(np
);
1213 /* get usecount and drop iocount */
1214 error
= vnode_ref(*vpp
);
1222 * Set the mount point's block I/O size.
1223 * We really need to do this after we get info back from
1224 * the server about what its preferred I/O sizes are.
1226 if (nmp
->nm_flag
& NFSMNT_NFSV3
)
1227 nfs_fsinfo(nmp
, *vpp
, proc_ucred(p
), p
);
1228 vfs_statfs(mp
)->f_iosize
= nfs_iosize(nmp
);
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;