2 * Copyright (c) 2000-2019 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
30 * Copyright (c) 1989, 1993, 1995
31 * The Regents of the University of California. All rights reserved.
33 * This code is derived from software contributed to Berkeley by
34 * Rick Macklem at The University of Guelph.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
44 * 3. All advertising materials mentioning features or use of this software
45 * must display the following acknowledgement:
46 * This product includes software developed by the University of
47 * California, Berkeley and its contributors.
48 * 4. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * @(#)nfs_vfsops.c 8.12 (Berkeley) 5/20/95
65 * FreeBSD-Id: nfs_vfsops.c,v 1.52 1997/11/12 05:42:21 julian Exp $
68 #include <nfs/nfs_conf.h>
72 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
73 * support for mandatory and extensible security protections. This notice
74 * is included in support of clause 2.2 (b) of the Apple Public License,
78 #include <sys/param.h>
79 #include <sys/systm.h>
81 #include <sys/ioctl.h>
82 #include <sys/signal.h>
83 #include <sys/proc_internal.h> /* for fs rooting to update rootdir in fdp */
84 #include <sys/kauth.h>
85 #include <sys/vnode_internal.h>
86 #include <sys/malloc.h>
87 #include <sys/kernel.h>
88 #include <sys/sysctl.h>
89 #include <sys/mount_internal.h>
90 #include <sys/kpi_mbuf.h>
91 #include <sys/socket.h>
93 #include <sys/socketvar.h>
94 #include <sys/fcntl.h>
95 #include <sys/quota.h>
97 #include <libkern/OSAtomic.h>
100 #include <sys/vmparam.h>
102 #if !defined(NO_MOUNT_PRIVATE)
103 #include <sys/filedesc.h>
104 #endif /* NO_MOUNT_PRIVATE */
107 #include <net/route.h>
108 #include <netinet/in.h>
110 #include <nfs/rpcv2.h>
111 #include <nfs/krpc.h>
112 #include <nfs/nfsproto.h>
114 #include <nfs/nfsnode.h>
115 #include <nfs/nfs_gss.h>
116 #include <nfs/nfsmount.h>
117 #include <nfs/xdr_subs.h>
118 #include <nfs/nfsm_subs.h>
119 #include <nfs/nfsdiskless.h>
120 #include <nfs/nfs_lock.h>
122 #include <security/mac_framework.h>
125 #include <pexpert/pexpert.h>
127 #define NFS_VFS_DBG(...) NFS_DBG(NFS_FAC_VFS, 7, ## __VA_ARGS__)
134 static lck_grp_t
*nfs_global_grp
, *nfs_mount_grp
;
135 lck_mtx_t
*nfs_global_mutex
;
136 uint32_t nfs_fs_attr_bitmap
[NFS_ATTR_BITMAP_LEN
];
137 uint32_t nfs_object_attr_bitmap
[NFS_ATTR_BITMAP_LEN
];
138 uint32_t nfs_getattr_bitmap
[NFS_ATTR_BITMAP_LEN
];
139 struct nfsclientidlist nfsclientids
;
142 struct nfs_reqqhead nfs_reqq
;
143 lck_grp_t
*nfs_request_grp
;
144 lck_mtx_t
*nfs_request_mutex
;
145 thread_call_t nfs_request_timer_call
;
146 int nfs_request_timer_on
;
147 u_int32_t nfs_xid
= 0;
148 u_int32_t nfs_xidwrap
= 0; /* to build a (non-wrapping) 64 bit xid */
150 thread_call_t nfs_buf_timer_call
;
153 lck_grp_t
*nfs_open_grp
;
154 uint32_t nfs_open_owner_seqnum
= 0;
155 uint32_t nfs_lock_owner_seqnum
= 0;
156 thread_call_t nfs4_callback_timer_call
;
157 int nfs4_callback_timer_on
= 0;
158 char nfs4_default_domain
[MAXPATHLEN
];
161 lck_grp_t
*nfsiod_lck_grp
;
162 lck_mtx_t
*nfsiod_mutex
;
163 struct nfsiodlist nfsiodfree
, nfsiodwork
;
164 struct nfsiodmountlist nfsiodmounts
;
165 int nfsiod_thread_count
= 0;
166 int nfsiod_thread_max
= NFS_DEFASYNCTHREAD
;
167 int nfs_max_async_writes
= NFS_DEFMAXASYNCWRITES
;
169 int nfs_iosize
= NFS_IOSIZE
;
170 int nfs_access_cache_timeout
= NFS_MAXATTRTIMO
;
171 int nfs_access_delete
= 1; /* too many servers get this wrong - workaround on by default */
172 int nfs_access_dotzfs
= 1;
173 int nfs_access_for_getattr
= 0;
174 int nfs_allow_async
= 0;
175 int nfs_statfs_rate_limit
= NFS_DEFSTATFSRATELIMIT
;
176 int nfs_lockd_mounts
= 0;
177 int nfs_lockd_request_sent
= 0;
178 int nfs_idmap_ctrl
= NFS_IDMAP_CTRL_USE_IDMAP_SERVICE
;
179 int nfs_callback_port
= 0;
181 int nfs_tprintf_initial_delay
= NFS_TPRINTF_INITIAL_DELAY
;
182 int nfs_tprintf_delay
= NFS_TPRINTF_DELAY
;
185 int mountnfs(char *, mount_t
, vfs_context_t
, vnode_t
*);
187 static int nfs_mount_diskless(struct nfs_dlmount
*, const char *, int, vnode_t
*, mount_t
*, vfs_context_t
);
188 #if !defined(NO_MOUNT_PRIVATE)
189 static int nfs_mount_diskless_private(struct nfs_dlmount
*, const char *, int, vnode_t
*, mount_t
*, vfs_context_t
);
190 #endif /* NO_MOUNT_PRIVATE */
192 int nfs_mount_connect(struct nfsmount
*);
193 void nfs_mount_drain_and_cleanup(struct nfsmount
*);
194 void nfs_mount_cleanup(struct nfsmount
*);
195 int nfs_mountinfo_assemble(struct nfsmount
*, struct xdrbuf
*);
196 int nfs4_mount_update_path_with_symlink(struct nfsmount
*, struct nfs_fs_path
*, uint32_t, fhandle_t
*, int *, fhandle_t
*, vfs_context_t
);
199 * NFS VFS operations.
201 int nfs_vfs_mount(mount_t
, vnode_t
, user_addr_t
, vfs_context_t
);
202 int nfs_vfs_start(mount_t
, int, vfs_context_t
);
203 int nfs_vfs_unmount(mount_t
, int, vfs_context_t
);
204 int nfs_vfs_root(mount_t
, vnode_t
*, vfs_context_t
);
205 int nfs_vfs_quotactl(mount_t
, int, uid_t
, caddr_t
, vfs_context_t
);
206 int nfs_vfs_getattr(mount_t
, struct vfs_attr
*, vfs_context_t
);
207 int nfs_vfs_sync(mount_t
, int, vfs_context_t
);
208 int nfs_vfs_vget(mount_t
, ino64_t
, vnode_t
*, vfs_context_t
);
209 int nfs_vfs_vptofh(vnode_t
, int *, unsigned char *, vfs_context_t
);
210 int nfs_vfs_fhtovp(mount_t
, int, unsigned char *, vnode_t
*, vfs_context_t
);
211 int nfs_vfs_init(struct vfsconf
*);
212 int nfs_vfs_sysctl(int *, u_int
, user_addr_t
, size_t *, user_addr_t
, size_t, vfs_context_t
);
214 const struct vfsops nfs_vfsops
= {
215 .vfs_mount
= nfs_vfs_mount
,
216 .vfs_start
= nfs_vfs_start
,
217 .vfs_unmount
= nfs_vfs_unmount
,
218 .vfs_root
= nfs_vfs_root
,
219 .vfs_quotactl
= nfs_vfs_quotactl
,
220 .vfs_getattr
= nfs_vfs_getattr
,
221 .vfs_sync
= nfs_vfs_sync
,
222 .vfs_vget
= nfs_vfs_vget
,
223 .vfs_fhtovp
= nfs_vfs_fhtovp
,
224 .vfs_vptofh
= nfs_vfs_vptofh
,
225 .vfs_init
= nfs_vfs_init
,
226 .vfs_sysctl
= nfs_vfs_sysctl
,
227 // We do not support the remaining VFS ops
232 * version-specific NFS functions
234 int nfs3_mount(struct nfsmount
*, vfs_context_t
, nfsnode_t
*);
235 int nfs4_mount(struct nfsmount
*, vfs_context_t
, nfsnode_t
*);
236 int nfs3_fsinfo(struct nfsmount
*, nfsnode_t
, vfs_context_t
);
237 int nfs3_update_statfs(struct nfsmount
*, vfs_context_t
);
238 int nfs4_update_statfs(struct nfsmount
*, vfs_context_t
);
240 #define nfs3_getquota NULL
241 #define nfs4_getquota NULL
243 int nfs3_getquota(struct nfsmount
*, vfs_context_t
, uid_t
, int, struct dqblk
*);
244 int nfs4_getquota(struct nfsmount
*, vfs_context_t
, uid_t
, int, struct dqblk
*);
247 const struct nfs_funcs nfs3_funcs
= {
248 .nf_mount
= nfs3_mount
,
249 .nf_update_statfs
= nfs3_update_statfs
,
250 .nf_getquota
= nfs3_getquota
,
251 .nf_access_rpc
= nfs3_access_rpc
,
252 .nf_getattr_rpc
= nfs3_getattr_rpc
,
253 .nf_setattr_rpc
= nfs3_setattr_rpc
,
254 .nf_read_rpc_async
= nfs3_read_rpc_async
,
255 .nf_read_rpc_async_finish
= nfs3_read_rpc_async_finish
,
256 .nf_readlink_rpc
= nfs3_readlink_rpc
,
257 .nf_write_rpc_async
= nfs3_write_rpc_async
,
258 .nf_write_rpc_async_finish
= nfs3_write_rpc_async_finish
,
259 .nf_commit_rpc
= nfs3_commit_rpc
,
260 .nf_lookup_rpc_async
= nfs3_lookup_rpc_async
,
261 .nf_lookup_rpc_async_finish
= nfs3_lookup_rpc_async_finish
,
262 .nf_remove_rpc
= nfs3_remove_rpc
,
263 .nf_rename_rpc
= nfs3_rename_rpc
,
264 .nf_setlock_rpc
= nfs3_setlock_rpc
,
265 .nf_unlock_rpc
= nfs3_unlock_rpc
,
266 .nf_getlock_rpc
= nfs3_getlock_rpc
269 const struct nfs_funcs nfs4_funcs
= {
270 .nf_mount
= nfs4_mount
,
271 .nf_update_statfs
= nfs4_update_statfs
,
272 .nf_getquota
= nfs4_getquota
,
273 .nf_access_rpc
= nfs4_access_rpc
,
274 .nf_getattr_rpc
= nfs4_getattr_rpc
,
275 .nf_setattr_rpc
= nfs4_setattr_rpc
,
276 .nf_read_rpc_async
= nfs4_read_rpc_async
,
277 .nf_read_rpc_async_finish
= nfs4_read_rpc_async_finish
,
278 .nf_readlink_rpc
= nfs4_readlink_rpc
,
279 .nf_write_rpc_async
= nfs4_write_rpc_async
,
280 .nf_write_rpc_async_finish
= nfs4_write_rpc_async_finish
,
281 .nf_commit_rpc
= nfs4_commit_rpc
,
282 .nf_lookup_rpc_async
= nfs4_lookup_rpc_async
,
283 .nf_lookup_rpc_async_finish
= nfs4_lookup_rpc_async_finish
,
284 .nf_remove_rpc
= nfs4_remove_rpc
,
285 .nf_rename_rpc
= nfs4_rename_rpc
,
286 .nf_setlock_rpc
= nfs4_setlock_rpc
,
287 .nf_unlock_rpc
= nfs4_unlock_rpc
,
288 .nf_getlock_rpc
= nfs4_getlock_rpc
293 * Called once to initialize data structures...
296 nfs_vfs_init(__unused
struct vfsconf
*vfsp
)
302 * Check to see if major data structures haven't bloated.
304 if (sizeof(struct nfsnode
) > NFS_NODEALLOC
) {
305 printf("struct nfsnode bloated (> %dbytes)\n", NFS_NODEALLOC
);
306 printf("Try reducing NFS_SMALLFH\n");
308 if (sizeof(struct nfsmount
) > NFS_MNTALLOC
) {
309 printf("struct nfsmount bloated (> %dbytes)\n", NFS_MNTALLOC
);
312 nfs_ticks
= (hz
* NFS_TICKINTVL
+ 500) / 1000;
317 /* init async I/O thread pool state */
318 TAILQ_INIT(&nfsiodfree
);
319 TAILQ_INIT(&nfsiodwork
);
320 TAILQ_INIT(&nfsiodmounts
);
321 nfsiod_lck_grp
= lck_grp_alloc_init("nfsiod", LCK_GRP_ATTR_NULL
);
322 nfsiod_mutex
= lck_mtx_alloc_init(nfsiod_lck_grp
, LCK_ATTR_NULL
);
324 /* init lock groups, etc. */
325 nfs_mount_grp
= lck_grp_alloc_init("nfs_mount", LCK_GRP_ATTR_NULL
);
326 nfs_open_grp
= lck_grp_alloc_init("nfs_open", LCK_GRP_ATTR_NULL
);
327 nfs_global_grp
= lck_grp_alloc_init("nfs_global", LCK_GRP_ATTR_NULL
);
329 nfs_global_mutex
= lck_mtx_alloc_init(nfs_global_grp
, LCK_ATTR_NULL
);
331 /* init request list mutex */
332 nfs_request_grp
= lck_grp_alloc_init("nfs_request", LCK_GRP_ATTR_NULL
);
333 nfs_request_mutex
= lck_mtx_alloc_init(nfs_request_grp
, LCK_ATTR_NULL
);
335 /* initialize NFS request list */
336 TAILQ_INIT(&nfs_reqq
);
338 nfs_nbinit(); /* Init the nfsbuf table */
339 nfs_nhinit(); /* Init the nfsnode table */
340 nfs_lockinit(); /* Init the nfs lock state */
342 nfs_gss_init(); /* Init RPCSEC_GSS security */
347 NFS4_PER_FS_ATTRIBUTES(nfs_fs_attr_bitmap
);
348 NFS4_PER_OBJECT_ATTRIBUTES(nfs_object_attr_bitmap
);
349 NFS4_DEFAULT_ATTRIBUTES(nfs_getattr_bitmap
);
350 for (i
= 0; i
< NFS_ATTR_BITMAP_LEN
; i
++) {
351 nfs_getattr_bitmap
[i
] &= nfs_object_attr_bitmap
[i
];
353 TAILQ_INIT(&nfsclientids
);
356 /* initialize NFS timer callouts */
357 nfs_request_timer_call
= thread_call_allocate(nfs_request_timer
, NULL
);
358 nfs_buf_timer_call
= thread_call_allocate(nfs_buf_timer
, NULL
);
360 nfs4_callback_timer_call
= thread_call_allocate(nfs4_callback_timer
, NULL
);
370 nfs3_update_statfs(struct nfsmount
*nmp
, vfs_context_t ctx
)
373 int error
= 0, lockerror
, status
, nfsvers
;
375 struct nfsm_chain nmreq
, nmrep
;
378 nfsvers
= nmp
->nm_vers
;
383 if ((error
= vnode_get(NFSTOV(np
)))) {
387 nfsm_chain_null(&nmreq
);
388 nfsm_chain_null(&nmrep
);
390 nfsm_chain_build_alloc_init(error
, &nmreq
, NFSX_FH(nfsvers
));
391 nfsm_chain_add_fh(error
, &nmreq
, nfsvers
, np
->n_fhp
, np
->n_fhsize
);
392 nfsm_chain_build_done(error
, &nmreq
);
394 error
= nfs_request2(np
, NULL
, &nmreq
, NFSPROC_FSSTAT
, vfs_context_thread(ctx
),
395 vfs_context_ucred(ctx
), NULL
, R_SOFT
, &nmrep
, &xid
, &status
);
396 if (error
== ETIMEDOUT
) {
399 if ((lockerror
= nfs_node_lock(np
))) {
402 if (nfsvers
== NFS_VER3
) {
403 nfsm_chain_postop_attr_update(error
, &nmrep
, np
, &xid
);
411 nfsm_assert(error
, NFSTONMP(np
), ENXIO
);
413 lck_mtx_lock(&nmp
->nm_lock
);
414 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SPACE_TOTAL
);
415 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SPACE_FREE
);
416 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SPACE_AVAIL
);
417 if (nfsvers
== NFS_VER3
) {
418 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_FILES_AVAIL
);
419 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_FILES_TOTAL
);
420 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_FILES_FREE
);
421 nmp
->nm_fsattr
.nfsa_bsize
= NFS_FABLKSIZE
;
422 nfsm_chain_get_64(error
, &nmrep
, nmp
->nm_fsattr
.nfsa_space_total
);
423 nfsm_chain_get_64(error
, &nmrep
, nmp
->nm_fsattr
.nfsa_space_free
);
424 nfsm_chain_get_64(error
, &nmrep
, nmp
->nm_fsattr
.nfsa_space_avail
);
425 nfsm_chain_get_64(error
, &nmrep
, nmp
->nm_fsattr
.nfsa_files_total
);
426 nfsm_chain_get_64(error
, &nmrep
, nmp
->nm_fsattr
.nfsa_files_free
);
427 nfsm_chain_get_64(error
, &nmrep
, nmp
->nm_fsattr
.nfsa_files_avail
);
430 nfsm_chain_adv(error
, &nmrep
, NFSX_UNSIGNED
); // skip tsize?
431 nfsm_chain_get_32(error
, &nmrep
, nmp
->nm_fsattr
.nfsa_bsize
);
432 nfsm_chain_get_32(error
, &nmrep
, val
);
434 if (nmp
->nm_fsattr
.nfsa_bsize
<= 0) {
435 nmp
->nm_fsattr
.nfsa_bsize
= NFS_FABLKSIZE
;
437 nmp
->nm_fsattr
.nfsa_space_total
= (uint64_t)val
* nmp
->nm_fsattr
.nfsa_bsize
;
438 nfsm_chain_get_32(error
, &nmrep
, val
);
440 nmp
->nm_fsattr
.nfsa_space_free
= (uint64_t)val
* nmp
->nm_fsattr
.nfsa_bsize
;
441 nfsm_chain_get_32(error
, &nmrep
, val
);
443 nmp
->nm_fsattr
.nfsa_space_avail
= (uint64_t)val
* nmp
->nm_fsattr
.nfsa_bsize
;
445 lck_mtx_unlock(&nmp
->nm_lock
);
447 nfsm_chain_cleanup(&nmreq
);
448 nfsm_chain_cleanup(&nmrep
);
449 vnode_put(NFSTOV(np
));
455 nfs4_update_statfs(struct nfsmount
*nmp
, vfs_context_t ctx
)
458 int error
= 0, lockerror
, status
, nfsvers
, numops
;
460 struct nfsm_chain nmreq
, nmrep
;
461 uint32_t bitmap
[NFS_ATTR_BITMAP_LEN
];
462 struct nfs_vattr nvattr
;
463 struct nfsreq_secinfo_args si
;
465 nfsvers
= nmp
->nm_vers
;
470 if ((error
= vnode_get(NFSTOV(np
)))) {
474 NFSREQ_SECINFO_SET(&si
, np
, NULL
, 0, NULL
, 0);
475 NVATTR_INIT(&nvattr
);
476 nfsm_chain_null(&nmreq
);
477 nfsm_chain_null(&nmrep
);
481 nfsm_chain_build_alloc_init(error
, &nmreq
, 15 * NFSX_UNSIGNED
);
482 nfsm_chain_add_compound_header(error
, &nmreq
, "statfs", nmp
->nm_minor_vers
, numops
);
484 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_PUTFH
);
485 nfsm_chain_add_fh(error
, &nmreq
, nfsvers
, np
->n_fhp
, np
->n_fhsize
);
487 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_GETATTR
);
488 NFS_COPY_ATTRIBUTES(nfs_getattr_bitmap
, bitmap
);
489 NFS4_STATFS_ATTRIBUTES(bitmap
);
490 nfsm_chain_add_bitmap_supported(error
, &nmreq
, bitmap
, nmp
, np
);
491 nfsm_chain_build_done(error
, &nmreq
);
492 nfsm_assert(error
, (numops
== 0), EPROTO
);
494 error
= nfs_request2(np
, NULL
, &nmreq
, NFSPROC4_COMPOUND
,
495 vfs_context_thread(ctx
), vfs_context_ucred(ctx
),
496 NULL
, R_SOFT
, &nmrep
, &xid
, &status
);
497 nfsm_chain_skip_tag(error
, &nmrep
);
498 nfsm_chain_get_32(error
, &nmrep
, numops
);
499 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_PUTFH
);
500 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_GETATTR
);
501 nfsm_assert(error
, NFSTONMP(np
), ENXIO
);
503 lck_mtx_lock(&nmp
->nm_lock
);
504 error
= nfs4_parsefattr(&nmrep
, &nmp
->nm_fsattr
, &nvattr
, NULL
, NULL
, NULL
);
505 lck_mtx_unlock(&nmp
->nm_lock
);
507 if ((lockerror
= nfs_node_lock(np
))) {
511 nfs_loadattrcache(np
, &nvattr
, &xid
, 0);
516 nfsm_assert(error
, NFSTONMP(np
), ENXIO
);
518 nmp
->nm_fsattr
.nfsa_bsize
= NFS_FABLKSIZE
;
520 NVATTR_CLEANUP(&nvattr
);
521 nfsm_chain_cleanup(&nmreq
);
522 nfsm_chain_cleanup(&nmrep
);
523 vnode_put(NFSTOV(np
));
526 #endif /* CONFIG_NFS4 */
530 * Return an NFS volume name from the mntfrom name.
533 nfs_get_volname(struct mount
*mp
, char *volname
, size_t len
, __unused vfs_context_t ctx
)
535 const char *ptr
, *cptr
;
536 const char *mntfrom
= mp
->mnt_vfsstat
.f_mntfromname
;
540 mflen
= strnlen(mntfrom
, MAXPATHLEN
+ 1);
542 if (mflen
> MAXPATHLEN
|| mflen
== 0) {
543 strlcpy(volname
, "Bad volname", len
);
547 /* Move back over trailing slashes */
548 for (ptr
= &mntfrom
[mflen
- 1]; ptr
!= mntfrom
&& *ptr
== '/'; ptr
--) {
552 /* Find first character after the last slash */
554 for (size_t i
= 0; i
< mflen
; i
++) {
555 if (mntfrom
[i
] == '/') {
556 ptr
= &mntfrom
[i
+ 1];
558 /* And the first character after the first colon */
559 else if (cptr
== NULL
&& mntfrom
[i
] == ':') {
560 cptr
= &mntfrom
[i
+ 1];
565 * No slash or nothing after the last slash
566 * use everything past the first colon
568 if (ptr
== NULL
|| *ptr
== '\0') {
571 /* Otherwise use the mntfrom name */
576 mflen
= &mntfrom
[mflen
] - ptr
;
577 len
= mflen
+ 1 < len
? mflen
+ 1 : len
;
579 strlcpy(volname
, ptr
, len
);
584 * The NFS VFS_GETATTR function: "statfs"-type information is retrieved
585 * using the nf_update_statfs() function, and other attributes are cobbled
586 * together from whatever sources we can (getattr, fsinfo, pathconf).
589 nfs_vfs_getattr(mount_t mp
, struct vfs_attr
*fsap
, vfs_context_t ctx
)
591 struct nfsmount
*nmp
;
593 int error
= 0, nfsvers
;
596 if (nfs_mount_gone(nmp
)) {
599 nfsvers
= nmp
->nm_vers
;
601 if (VFSATTR_IS_ACTIVE(fsap
, f_bsize
) ||
602 VFSATTR_IS_ACTIVE(fsap
, f_iosize
) ||
603 VFSATTR_IS_ACTIVE(fsap
, f_blocks
) ||
604 VFSATTR_IS_ACTIVE(fsap
, f_bfree
) ||
605 VFSATTR_IS_ACTIVE(fsap
, f_bavail
) ||
606 VFSATTR_IS_ACTIVE(fsap
, f_bused
) ||
607 VFSATTR_IS_ACTIVE(fsap
, f_files
) ||
608 VFSATTR_IS_ACTIVE(fsap
, f_ffree
)) {
609 int statfsrate
= nfs_statfs_rate_limit
;
613 * Are we rate-limiting statfs RPCs?
614 * (Treat values less than 1 or greater than 1,000,000 as no limit.)
616 if ((statfsrate
> 0) && (statfsrate
< 1000000)) {
621 lck_mtx_lock(&nmp
->nm_lock
);
622 stamp
= (now
.tv_sec
* statfsrate
) + (now
.tv_usec
/ (1000000 / statfsrate
));
623 if (stamp
!= nmp
->nm_fsattrstamp
) {
625 nmp
->nm_fsattrstamp
= stamp
;
629 lck_mtx_unlock(&nmp
->nm_lock
);
632 if (refresh
&& !nfs_use_cache(nmp
)) {
633 error
= nmp
->nm_funcs
->nf_update_statfs(nmp
, ctx
);
635 if ((error
== ESTALE
) || (error
== ETIMEDOUT
)) {
642 lck_mtx_lock(&nmp
->nm_lock
);
643 VFSATTR_RETURN(fsap
, f_iosize
, nfs_iosize
);
644 VFSATTR_RETURN(fsap
, f_bsize
, nmp
->nm_fsattr
.nfsa_bsize
);
645 bsize
= nmp
->nm_fsattr
.nfsa_bsize
;
646 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SPACE_TOTAL
)) {
647 VFSATTR_RETURN(fsap
, f_blocks
, nmp
->nm_fsattr
.nfsa_space_total
/ bsize
);
649 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SPACE_FREE
)) {
650 VFSATTR_RETURN(fsap
, f_bfree
, nmp
->nm_fsattr
.nfsa_space_free
/ bsize
);
652 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SPACE_AVAIL
)) {
653 VFSATTR_RETURN(fsap
, f_bavail
, nmp
->nm_fsattr
.nfsa_space_avail
/ bsize
);
655 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SPACE_TOTAL
) &&
656 NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SPACE_FREE
)) {
657 VFSATTR_RETURN(fsap
, f_bused
,
658 (nmp
->nm_fsattr
.nfsa_space_total
/ bsize
) -
659 (nmp
->nm_fsattr
.nfsa_space_free
/ bsize
));
661 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_FILES_TOTAL
)) {
662 VFSATTR_RETURN(fsap
, f_files
, nmp
->nm_fsattr
.nfsa_files_total
);
664 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_FILES_FREE
)) {
665 VFSATTR_RETURN(fsap
, f_ffree
, nmp
->nm_fsattr
.nfsa_files_free
);
667 lck_mtx_unlock(&nmp
->nm_lock
);
670 if (VFSATTR_IS_ACTIVE(fsap
, f_vol_name
)) {
671 /*%%% IF fail over support is implemented we may need to take nm_lock */
672 nfs_get_volname(mp
, fsap
->f_vol_name
, MAXPATHLEN
, ctx
);
673 VFSATTR_SET_SUPPORTED(fsap
, f_vol_name
);
675 if (VFSATTR_IS_ACTIVE(fsap
, f_capabilities
)
677 u_int32_t caps
, valid
;
678 nfsnode_t np
= nmp
->nm_dnp
;
680 nfsm_assert(error
, VFSTONFS(mp
) && np
, ENXIO
);
684 lck_mtx_lock(&nmp
->nm_lock
);
687 * The capabilities[] array defines what this volume supports.
689 * The valid[] array defines which bits this code understands
690 * the meaning of (whether the volume has that capability or
691 * not). Any zero bits here means "I don't know what you're
692 * asking about" and the caller cannot tell whether that
693 * capability is present or not.
696 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SYMLINK_SUPPORT
)) {
697 valid
|= VOL_CAP_FMT_SYMBOLICLINKS
;
698 if (nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_SYMLINK
) {
699 caps
|= VOL_CAP_FMT_SYMBOLICLINKS
;
702 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_LINK_SUPPORT
)) {
703 valid
|= VOL_CAP_FMT_HARDLINKS
;
704 if (nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_LINK
) {
705 caps
|= VOL_CAP_FMT_HARDLINKS
;
708 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_CASE_INSENSITIVE
)) {
709 valid
|= VOL_CAP_FMT_CASE_SENSITIVE
;
710 if (!(nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_CASE_INSENSITIVE
)) {
711 caps
|= VOL_CAP_FMT_CASE_SENSITIVE
;
714 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_CASE_PRESERVING
)) {
715 valid
|= VOL_CAP_FMT_CASE_PRESERVING
;
716 if (nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_CASE_PRESERVING
) {
717 caps
|= VOL_CAP_FMT_CASE_PRESERVING
;
720 /* Note: VOL_CAP_FMT_2TB_FILESIZE is actually used to test for "large file support" */
721 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_MAXFILESIZE
)) {
722 /* Is server's max file size at least 4GB? */
723 if (nmp
->nm_fsattr
.nfsa_maxfilesize
>= 0x100000000ULL
) {
724 caps
|= VOL_CAP_FMT_2TB_FILESIZE
;
726 } else if (nfsvers
>= NFS_VER3
) {
728 * NFSv3 and up supports 64 bits of file size.
729 * So, we'll just assume maxfilesize >= 4GB
731 caps
|= VOL_CAP_FMT_2TB_FILESIZE
;
734 if (nfsvers
>= NFS_VER4
) {
735 caps
|= VOL_CAP_FMT_HIDDEN_FILES
;
736 valid
|= VOL_CAP_FMT_HIDDEN_FILES
;
737 // VOL_CAP_FMT_OPENDENYMODES
738 // caps |= VOL_CAP_FMT_OPENDENYMODES;
739 // valid |= VOL_CAP_FMT_OPENDENYMODES;
742 // no version of nfs supports immutable files
743 caps
|= VOL_CAP_FMT_NO_IMMUTABLE_FILES
;
744 valid
|= VOL_CAP_FMT_NO_IMMUTABLE_FILES
;
746 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_FORMAT
] =
747 // VOL_CAP_FMT_PERSISTENTOBJECTIDS |
748 // VOL_CAP_FMT_SYMBOLICLINKS |
749 // VOL_CAP_FMT_HARDLINKS |
750 // VOL_CAP_FMT_JOURNAL |
751 // VOL_CAP_FMT_JOURNAL_ACTIVE |
752 // VOL_CAP_FMT_NO_ROOT_TIMES |
753 // VOL_CAP_FMT_SPARSE_FILES |
754 // VOL_CAP_FMT_ZERO_RUNS |
755 // VOL_CAP_FMT_CASE_SENSITIVE |
756 // VOL_CAP_FMT_CASE_PRESERVING |
757 // VOL_CAP_FMT_FAST_STATFS |
758 // VOL_CAP_FMT_2TB_FILESIZE |
759 // VOL_CAP_FMT_OPENDENYMODES |
760 // VOL_CAP_FMT_HIDDEN_FILES |
762 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_FORMAT
] =
763 VOL_CAP_FMT_PERSISTENTOBJECTIDS
|
764 // VOL_CAP_FMT_SYMBOLICLINKS |
765 // VOL_CAP_FMT_HARDLINKS |
766 // VOL_CAP_FMT_JOURNAL |
767 // VOL_CAP_FMT_JOURNAL_ACTIVE |
768 // VOL_CAP_FMT_NO_ROOT_TIMES |
769 // VOL_CAP_FMT_SPARSE_FILES |
770 // VOL_CAP_FMT_ZERO_RUNS |
771 // VOL_CAP_FMT_CASE_SENSITIVE |
772 // VOL_CAP_FMT_CASE_PRESERVING |
773 VOL_CAP_FMT_FAST_STATFS
|
774 VOL_CAP_FMT_2TB_FILESIZE
|
775 // VOL_CAP_FMT_OPENDENYMODES |
776 // VOL_CAP_FMT_HIDDEN_FILES |
780 * We don't support most of the interfaces.
782 * We MAY support locking, but we don't have any easy way of
783 * probing. We can tell if there's no lockd running or if
784 * locks have been disabled for a mount, so we can definitely
785 * answer NO in that case. Any attempt to send a request to
786 * lockd to test for locking support may cause the lazily-
787 * launched locking daemons to be started unnecessarily. So
788 * we avoid that. However, we do record if we ever successfully
789 * perform a lock operation on a mount point, so if it looks
790 * like lock ops have worked, we do report that we support them.
794 if (nfsvers
>= NFS_VER4
) {
795 caps
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
796 valid
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
797 if (nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_ACL
) {
798 caps
|= VOL_CAP_INT_EXTENDED_SECURITY
;
800 valid
|= VOL_CAP_INT_EXTENDED_SECURITY
;
801 if (nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_NAMED_ATTR
) {
802 caps
|= VOL_CAP_INT_EXTENDED_ATTR
;
804 valid
|= VOL_CAP_INT_EXTENDED_ATTR
;
806 if (nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_NAMED_ATTR
) {
807 caps
|= VOL_CAP_INT_NAMEDSTREAMS
;
809 valid
|= VOL_CAP_INT_NAMEDSTREAMS
;
813 if (nmp
->nm_lockmode
== NFS_LOCK_MODE_DISABLED
) {
814 /* locks disabled on this mount, so they definitely won't work */
815 valid
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
816 } else if (nmp
->nm_state
& NFSSTA_LOCKSWORK
) {
817 caps
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
818 valid
= VOL_CAP_INT_ADVLOCK
| VOL_CAP_INT_FLOCK
;
820 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_INTERFACES
] =
821 // VOL_CAP_INT_SEARCHFS |
822 // VOL_CAP_INT_ATTRLIST |
823 // VOL_CAP_INT_NFSEXPORT |
824 // VOL_CAP_INT_READDIRATTR |
825 // VOL_CAP_INT_EXCHANGEDATA |
826 // VOL_CAP_INT_COPYFILE |
827 // VOL_CAP_INT_ALLOCATE |
828 // VOL_CAP_INT_VOL_RENAME |
829 // VOL_CAP_INT_ADVLOCK |
830 // VOL_CAP_INT_FLOCK |
831 // VOL_CAP_INT_EXTENDED_SECURITY |
832 // VOL_CAP_INT_USERACCESS |
833 // VOL_CAP_INT_MANLOCK |
834 // VOL_CAP_INT_NAMEDSTREAMS |
835 // VOL_CAP_INT_EXTENDED_ATTR |
836 VOL_CAP_INT_REMOTE_EVENT
|
838 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_INTERFACES
] =
839 VOL_CAP_INT_SEARCHFS
|
840 VOL_CAP_INT_ATTRLIST
|
841 VOL_CAP_INT_NFSEXPORT
|
842 VOL_CAP_INT_READDIRATTR
|
843 VOL_CAP_INT_EXCHANGEDATA
|
844 VOL_CAP_INT_COPYFILE
|
845 VOL_CAP_INT_ALLOCATE
|
846 VOL_CAP_INT_VOL_RENAME
|
847 // VOL_CAP_INT_ADVLOCK |
848 // VOL_CAP_INT_FLOCK |
849 // VOL_CAP_INT_EXTENDED_SECURITY |
850 // VOL_CAP_INT_USERACCESS |
851 // VOL_CAP_INT_MANLOCK |
852 // VOL_CAP_INT_NAMEDSTREAMS |
853 // VOL_CAP_INT_EXTENDED_ATTR |
854 VOL_CAP_INT_REMOTE_EVENT
|
857 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED1
] = 0;
858 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED1
] = 0;
860 fsap
->f_capabilities
.capabilities
[VOL_CAPABILITIES_RESERVED2
] = 0;
861 fsap
->f_capabilities
.valid
[VOL_CAPABILITIES_RESERVED2
] = 0;
863 VFSATTR_SET_SUPPORTED(fsap
, f_capabilities
);
864 lck_mtx_unlock(&nmp
->nm_lock
);
867 if (VFSATTR_IS_ACTIVE(fsap
, f_attributes
)) {
868 fsap
->f_attributes
.validattr
.commonattr
= 0;
869 fsap
->f_attributes
.validattr
.volattr
=
870 ATTR_VOL_NAME
| ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
871 fsap
->f_attributes
.validattr
.dirattr
= 0;
872 fsap
->f_attributes
.validattr
.fileattr
= 0;
873 fsap
->f_attributes
.validattr
.forkattr
= 0;
875 fsap
->f_attributes
.nativeattr
.commonattr
= 0;
876 fsap
->f_attributes
.nativeattr
.volattr
=
877 ATTR_VOL_NAME
| ATTR_VOL_CAPABILITIES
| ATTR_VOL_ATTRIBUTES
;
878 fsap
->f_attributes
.nativeattr
.dirattr
= 0;
879 fsap
->f_attributes
.nativeattr
.fileattr
= 0;
880 fsap
->f_attributes
.nativeattr
.forkattr
= 0;
882 VFSATTR_SET_SUPPORTED(fsap
, f_attributes
);
889 * nfs version 3 fsinfo rpc call
892 nfs3_fsinfo(struct nfsmount
*nmp
, nfsnode_t np
, vfs_context_t ctx
)
894 int error
= 0, lockerror
, status
, nmlocked
= 0;
896 uint32_t val
, prefsize
, maxsize
;
897 struct nfsm_chain nmreq
, nmrep
;
899 nfsm_chain_null(&nmreq
);
900 nfsm_chain_null(&nmrep
);
902 nfsm_chain_build_alloc_init(error
, &nmreq
, NFSX_FH(nmp
->nm_vers
));
903 nfsm_chain_add_fh(error
, &nmreq
, nmp
->nm_vers
, np
->n_fhp
, np
->n_fhsize
);
904 nfsm_chain_build_done(error
, &nmreq
);
906 error
= nfs_request(np
, NULL
, &nmreq
, NFSPROC_FSINFO
, ctx
, NULL
, &nmrep
, &xid
, &status
);
907 if ((lockerror
= nfs_node_lock(np
))) {
910 nfsm_chain_postop_attr_update(error
, &nmrep
, np
, &xid
);
919 lck_mtx_lock(&nmp
->nm_lock
);
922 nfsm_chain_get_32(error
, &nmrep
, maxsize
);
923 nfsm_chain_get_32(error
, &nmrep
, prefsize
);
925 nmp
->nm_fsattr
.nfsa_maxread
= maxsize
;
926 if (prefsize
< nmp
->nm_rsize
) {
927 nmp
->nm_rsize
= (prefsize
+ NFS_FABLKSIZE
- 1) &
928 ~(NFS_FABLKSIZE
- 1);
930 if ((maxsize
> 0) && (maxsize
< nmp
->nm_rsize
)) {
931 nmp
->nm_rsize
= maxsize
& ~(NFS_FABLKSIZE
- 1);
932 if (nmp
->nm_rsize
== 0) {
933 nmp
->nm_rsize
= maxsize
;
936 nfsm_chain_adv(error
, &nmrep
, NFSX_UNSIGNED
); // skip rtmult
938 nfsm_chain_get_32(error
, &nmrep
, maxsize
);
939 nfsm_chain_get_32(error
, &nmrep
, prefsize
);
941 nmp
->nm_fsattr
.nfsa_maxwrite
= maxsize
;
942 if (prefsize
< nmp
->nm_wsize
) {
943 nmp
->nm_wsize
= (prefsize
+ NFS_FABLKSIZE
- 1) &
944 ~(NFS_FABLKSIZE
- 1);
946 if ((maxsize
> 0) && (maxsize
< nmp
->nm_wsize
)) {
947 nmp
->nm_wsize
= maxsize
& ~(NFS_FABLKSIZE
- 1);
948 if (nmp
->nm_wsize
== 0) {
949 nmp
->nm_wsize
= maxsize
;
952 nfsm_chain_adv(error
, &nmrep
, NFSX_UNSIGNED
); // skip wtmult
954 nfsm_chain_get_32(error
, &nmrep
, prefsize
);
956 if ((prefsize
> 0) && (prefsize
< nmp
->nm_readdirsize
)) {
957 nmp
->nm_readdirsize
= prefsize
;
959 if ((nmp
->nm_fsattr
.nfsa_maxread
> 0) &&
960 (nmp
->nm_fsattr
.nfsa_maxread
< nmp
->nm_readdirsize
)) {
961 nmp
->nm_readdirsize
= nmp
->nm_fsattr
.nfsa_maxread
;
964 nfsm_chain_get_64(error
, &nmrep
, nmp
->nm_fsattr
.nfsa_maxfilesize
);
966 nfsm_chain_adv(error
, &nmrep
, 2 * NFSX_UNSIGNED
); // skip time_delta
968 /* convert FS properties to our own flags */
969 nfsm_chain_get_32(error
, &nmrep
, val
);
971 if (val
& NFSV3FSINFO_LINK
) {
972 nmp
->nm_fsattr
.nfsa_flags
|= NFS_FSFLAG_LINK
;
974 if (val
& NFSV3FSINFO_SYMLINK
) {
975 nmp
->nm_fsattr
.nfsa_flags
|= NFS_FSFLAG_SYMLINK
;
977 if (val
& NFSV3FSINFO_HOMOGENEOUS
) {
978 nmp
->nm_fsattr
.nfsa_flags
|= NFS_FSFLAG_HOMOGENEOUS
;
980 if (val
& NFSV3FSINFO_CANSETTIME
) {
981 nmp
->nm_fsattr
.nfsa_flags
|= NFS_FSFLAG_SET_TIME
;
983 nmp
->nm_state
|= NFSSTA_GOTFSINFO
;
984 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_MAXREAD
);
985 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_MAXWRITE
);
986 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_MAXFILESIZE
);
987 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_LINK_SUPPORT
);
988 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_SYMLINK_SUPPORT
);
989 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_HOMOGENEOUS
);
990 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_CANSETTIME
);
993 lck_mtx_unlock(&nmp
->nm_lock
);
995 nfsm_chain_cleanup(&nmreq
);
996 nfsm_chain_cleanup(&nmrep
);
1001 * Mount a remote root fs via. nfs. This depends on the info in the
1002 * nfs_diskless structure that has been filled in properly by some primary
1004 * It goes something like this:
1005 * - do enough of "ifconfig" by calling ifioctl() so that the system
1006 * can talk to the server
1007 * - If nfs_diskless.mygateway is filled in, use that address as
1008 * a default gateway.
1009 * - hand craft the swap nfs vnode hanging off a fake mount point
1010 * if swdevt[0].sw_dev == NODEV
1011 * - build the rootfs mount point and call mountnfs() to do the rest.
1017 struct nfs_diskless nd
;
1022 #if !defined(NO_MOUNT_PRIVATE)
1023 mount_t mppriv
= NULL
;
1024 vnode_t vppriv
= NULL
;
1025 #endif /* NO_MOUNT_PRIVATE */
1029 * Call nfs_boot_init() to fill in the nfs_diskless struct.
1030 * Note: networking must already have been configured before
1033 bzero((caddr_t
) &nd
, sizeof(nd
));
1034 error
= nfs_boot_init(&nd
);
1036 panic("nfs_boot_init: unable to initialize NFS root system information, "
1037 "error %d, check configuration: %s\n", error
, PE_boot_args());
1041 * Try NFSv3 first, then fallback to NFSv2.
1042 * Likewise, try TCP first, then fall back to UDP.
1045 sotype
= SOCK_STREAM
;
1048 error
= nfs_boot_getfh(&nd
, v3
, sotype
);
1050 if (error
== EHOSTDOWN
|| error
== EHOSTUNREACH
) {
1051 if (nd
.nd_root
.ndm_mntfrom
) {
1052 FREE_ZONE(nd
.nd_root
.ndm_mntfrom
,
1053 MAXPATHLEN
, M_NAMEI
);
1055 if (nd
.nd_root
.ndm_path
) {
1056 FREE_ZONE(nd
.nd_root
.ndm_path
,
1057 MAXPATHLEN
, M_NAMEI
);
1059 if (nd
.nd_private
.ndm_mntfrom
) {
1060 FREE_ZONE(nd
.nd_private
.ndm_mntfrom
,
1061 MAXPATHLEN
, M_NAMEI
);
1063 if (nd
.nd_private
.ndm_path
) {
1064 FREE_ZONE(nd
.nd_private
.ndm_path
,
1065 MAXPATHLEN
, M_NAMEI
);
1070 if (sotype
== SOCK_STREAM
) {
1071 printf("NFS mount (v3,TCP) failed with error %d, trying UDP...\n", error
);
1072 sotype
= SOCK_DGRAM
;
1075 printf("NFS mount (v3,UDP) failed with error %d, trying v2...\n", error
);
1077 sotype
= SOCK_STREAM
;
1079 } else if (sotype
== SOCK_STREAM
) {
1080 printf("NFS mount (v2,TCP) failed with error %d, trying UDP...\n", error
);
1081 sotype
= SOCK_DGRAM
;
1084 printf("NFS mount (v2,UDP) failed with error %d, giving up...\n", error
);
1088 panic("NFS mount failed: NFS server mountd not responding, check server configuration: %s", PE_boot_args());
1091 panic("NFS mount failed: NFS server refused mount, check server configuration: %s", PE_boot_args());
1093 panic("NFS mount failed with error %d, check configuration: %s", error
, PE_boot_args());
1097 ctx
= vfs_context_kernel();
1100 * Create the root mount point.
1102 #if !defined(NO_MOUNT_PRIVATE)
1104 //PWC hack until we have a real "mount" tool to remount root rw
1106 int flags
= MNT_ROOTFS
| MNT_RDONLY
;
1107 PE_parse_boot_argn("-rwroot_hack", &rw_root
, sizeof(rw_root
));
1110 kprintf("-rwroot_hack in effect: mounting root fs read/write\n");
1113 if ((error
= nfs_mount_diskless(&nd
.nd_root
, "/", flags
, &vp
, &mp
, ctx
)))
1115 if ((error
= nfs_mount_diskless(&nd
.nd_root
, "/", MNT_ROOTFS
, &vp
, &mp
, ctx
)))
1116 #endif /* NO_MOUNT_PRIVATE */
1119 if (sotype
== SOCK_STREAM
) {
1120 printf("NFS root mount (v3,TCP) failed with %d, trying UDP...\n", error
);
1121 sotype
= SOCK_DGRAM
;
1124 printf("NFS root mount (v3,UDP) failed with %d, trying v2...\n", error
);
1126 sotype
= SOCK_STREAM
;
1128 } else if (sotype
== SOCK_STREAM
) {
1129 printf("NFS root mount (v2,TCP) failed with %d, trying UDP...\n", error
);
1130 sotype
= SOCK_DGRAM
;
1133 printf("NFS root mount (v2,UDP) failed with error %d, giving up...\n", error
);
1135 panic("NFS root mount failed with error %d, check configuration: %s\n", error
, PE_boot_args());
1138 printf("root on %s\n", nd
.nd_root
.ndm_mntfrom
);
1144 #if !defined(NO_MOUNT_PRIVATE)
1145 if (nd
.nd_private
.ndm_saddr
.sin_addr
.s_addr
) {
1146 error
= nfs_mount_diskless_private(&nd
.nd_private
, "/private",
1147 0, &vppriv
, &mppriv
, ctx
);
1149 panic("NFS /private mount failed with error %d, check configuration: %s\n", error
, PE_boot_args());
1151 printf("private on %s\n", nd
.nd_private
.ndm_mntfrom
);
1154 mount_list_add(mppriv
);
1157 #endif /* NO_MOUNT_PRIVATE */
1159 if (nd
.nd_root
.ndm_mntfrom
) {
1160 FREE_ZONE(nd
.nd_root
.ndm_mntfrom
, MAXPATHLEN
, M_NAMEI
);
1162 if (nd
.nd_root
.ndm_path
) {
1163 FREE_ZONE(nd
.nd_root
.ndm_path
, MAXPATHLEN
, M_NAMEI
);
1165 if (nd
.nd_private
.ndm_mntfrom
) {
1166 FREE_ZONE(nd
.nd_private
.ndm_mntfrom
, MAXPATHLEN
, M_NAMEI
);
1168 if (nd
.nd_private
.ndm_path
) {
1169 FREE_ZONE(nd
.nd_private
.ndm_path
, MAXPATHLEN
, M_NAMEI
);
1172 /* Get root attributes (for the time). */
1173 error
= nfs_getattr(VTONFS(vp
), NULL
, ctx
, NGA_UNCACHED
);
1175 panic("NFS mount: failed to get attributes for root directory, error %d, check server", error
);
1181 * Internal version of mount system call for diskless setup.
1185 struct nfs_dlmount
*ndmntp
,
1186 const char *mntname
,
1193 int error
, numcomps
;
1194 char *xdrbuf
, *p
, *cp
, *frompath
, *endserverp
;
1195 char uaddr
[MAX_IPv4_STR_LEN
];
1197 uint32_t mattrs
[NFS_MATTR_BITMAP_LEN
];
1198 uint32_t mflags_mask
[NFS_MFLAG_BITMAP_LEN
];
1199 uint32_t mflags
[NFS_MFLAG_BITMAP_LEN
];
1200 uint32_t argslength_offset
, attrslength_offset
, end_offset
;
1202 if ((error
= vfs_rootmountalloc("nfs", ndmntp
->ndm_mntfrom
, &mp
))) {
1203 printf("nfs_mount_diskless: NFS not configured\n");
1207 mp
->mnt_flag
|= mntflag
;
1208 if (!(mntflag
& MNT_RDONLY
)) {
1209 mp
->mnt_flag
&= ~MNT_RDONLY
;
1212 /* find the server-side path being mounted */
1213 frompath
= ndmntp
->ndm_mntfrom
;
1214 if (*frompath
== '[') { /* skip IPv6 literal address */
1215 while (*frompath
&& (*frompath
!= ']')) {
1218 if (*frompath
== ']') {
1222 while (*frompath
&& (*frompath
!= ':')) {
1225 endserverp
= frompath
;
1226 while (*frompath
&& (*frompath
== ':')) {
1229 /* count fs location path components */
1231 while (*p
&& (*p
== '/')) {
1237 while (*p
&& (*p
!= '/')) {
1240 while (*p
&& (*p
== '/')) {
1245 /* convert address to universal address string */
1246 if (inet_ntop(AF_INET
, &ndmntp
->ndm_saddr
.sin_addr
, uaddr
, sizeof(uaddr
)) != uaddr
) {
1247 printf("nfs_mount_diskless: bad address\n");
1251 /* prepare mount attributes */
1252 NFS_BITMAP_ZERO(mattrs
, NFS_MATTR_BITMAP_LEN
);
1253 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_VERSION
);
1254 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SOCKET_TYPE
);
1255 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_PORT
);
1256 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FH
);
1257 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FS_LOCATIONS
);
1258 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MNTFLAGS
);
1260 /* prepare mount flags */
1261 NFS_BITMAP_ZERO(mflags_mask
, NFS_MFLAG_BITMAP_LEN
);
1262 NFS_BITMAP_ZERO(mflags
, NFS_MFLAG_BITMAP_LEN
);
1263 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_RESVPORT
);
1264 NFS_BITMAP_SET(mflags
, NFS_MFLAG_RESVPORT
);
1266 /* build xdr buffer */
1267 xb_init_buffer(&xb
, NULL
, 0);
1268 xb_add_32(error
, &xb
, NFS_ARGSVERSION_XDR
);
1269 argslength_offset
= xb_offset(&xb
);
1270 xb_add_32(error
, &xb
, 0); // args length
1271 xb_add_32(error
, &xb
, NFS_XDRARGS_VERSION_0
);
1272 xb_add_bitmap(error
, &xb
, mattrs
, NFS_MATTR_BITMAP_LEN
);
1273 attrslength_offset
= xb_offset(&xb
);
1274 xb_add_32(error
, &xb
, 0); // attrs length
1275 xb_add_32(error
, &xb
, ndmntp
->ndm_nfsv3
? 3 : 2); // NFS version
1276 xb_add_string(error
, &xb
, ((ndmntp
->ndm_sotype
== SOCK_DGRAM
) ? "udp" : "tcp"), 3);
1277 xb_add_32(error
, &xb
, ntohs(ndmntp
->ndm_saddr
.sin_port
)); // NFS port
1278 xb_add_fh(error
, &xb
, &ndmntp
->ndm_fh
[0], ndmntp
->ndm_fhlen
);
1280 xb_add_32(error
, &xb
, 1); /* fs location count */
1281 xb_add_32(error
, &xb
, 1); /* server count */
1282 xb_add_string(error
, &xb
, ndmntp
->ndm_mntfrom
, (endserverp
- ndmntp
->ndm_mntfrom
)); /* server name */
1283 xb_add_32(error
, &xb
, 1); /* address count */
1284 xb_add_string(error
, &xb
, uaddr
, strlen(uaddr
)); /* address */
1285 xb_add_32(error
, &xb
, 0); /* empty server info */
1286 xb_add_32(error
, &xb
, numcomps
); /* pathname component count */
1288 while (*p
&& (*p
== '/')) {
1293 while (*p
&& (*p
!= '/')) {
1296 xb_add_string(error
, &xb
, cp
, (p
- cp
)); /* component */
1300 while (*p
&& (*p
== '/')) {
1304 xb_add_32(error
, &xb
, 0); /* empty fsl info */
1305 xb_add_32(error
, &xb
, mntflag
); /* MNT flags */
1306 xb_build_done(error
, &xb
);
1308 /* update opaque counts */
1309 end_offset
= xb_offset(&xb
);
1311 error
= xb_seek(&xb
, argslength_offset
);
1312 xb_add_32(error
, &xb
, end_offset
- argslength_offset
+ XDRWORD
/*version*/);
1315 error
= xb_seek(&xb
, attrslength_offset
);
1316 xb_add_32(error
, &xb
, end_offset
- attrslength_offset
- XDRWORD
/*don't include length field*/);
1319 printf("nfs_mount_diskless: error %d assembling mount args\n", error
);
1323 /* grab the assembled buffer */
1324 xdrbuf
= xb_buffer_base(&xb
);
1325 xb
.xb_flags
&= ~XB_CLEANUP
;
1328 if ((error
= mountnfs(xdrbuf
, mp
, ctx
, vpp
))) {
1329 printf("nfs_mountroot: mount %s failed: %d\n", mntname
, error
);
1330 // XXX vfs_rootmountfailed(mp);
1332 mp
->mnt_vtable
->vfc_refcount
--;
1333 mount_list_unlock();
1335 mount_lock_destroy(mp
);
1337 mac_mount_label_destroy(mp
);
1339 FREE_ZONE(mp
, sizeof(struct mount
), M_MOUNT
);
1347 #if !defined(NO_MOUNT_PRIVATE)
1349 * Internal version of mount system call to mount "/private"
1350 * separately in diskless setup
1353 nfs_mount_diskless_private(
1354 struct nfs_dlmount
*ndmntp
,
1355 const char *mntname
,
1362 int error
, numcomps
;
1364 struct vfstable
*vfsp
;
1365 struct nameidata nd
;
1367 char *xdrbuf
= NULL
, *p
, *cp
, *frompath
, *endserverp
;
1368 char uaddr
[MAX_IPv4_STR_LEN
];
1370 uint32_t mattrs
[NFS_MATTR_BITMAP_LEN
];
1371 uint32_t mflags_mask
[NFS_MFLAG_BITMAP_LEN
], mflags
[NFS_MFLAG_BITMAP_LEN
];
1372 uint32_t argslength_offset
, attrslength_offset
, end_offset
;
1374 procp
= current_proc(); /* XXX */
1375 xb_init(&xb
, XDRBUF_NONE
);
1379 * mimic main()!. Temporarily set up rootvnode and other stuff so
1380 * that namei works. Need to undo this because main() does it, too
1382 struct filedesc
*fdp
; /* pointer to file descriptor state */
1384 mountlist
.tqh_first
->mnt_flag
|= MNT_ROOTFS
;
1386 /* Get the vnode for '/'. Set fdp->fd_cdir to reference it. */
1387 if (VFS_ROOT(mountlist
.tqh_first
, &rootvnode
, NULL
)) {
1388 panic("cannot find root vnode");
1390 error
= vnode_ref(rootvnode
);
1392 printf("nfs_mountroot: vnode_ref() failed on root vnode!\n");
1395 fdp
->fd_cdir
= rootvnode
;
1396 fdp
->fd_rdir
= NULL
;
1400 * Get vnode to be covered
1402 NDINIT(&nd
, LOOKUP
, OP_LOOKUP
, FOLLOW
| LOCKLEAF
, UIO_SYSSPACE
,
1403 CAST_USER_ADDR_T(mntname
), ctx
);
1404 if ((error
= namei(&nd
))) {
1405 printf("nfs_mountroot: private namei failed!\n");
1409 /* undo vnode_ref() in mimic main()! */
1410 vnode_rele(rootvnode
);
1415 if ((error
= VNOP_FSYNC(vp
, MNT_WAIT
, ctx
)) ||
1416 (error
= buf_invalidateblks(vp
, BUF_WRITE_DATA
, 0, 0))) {
1420 if (vnode_vtype(vp
) != VDIR
) {
1425 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
) {
1426 if (!strncmp(vfsp
->vfc_name
, "nfs", sizeof(vfsp
->vfc_name
))) {
1431 printf("nfs_mountroot: private NFS not configured\n");
1436 if (vnode_mountedhere(vp
) != NULL
) {
1443 * Allocate and initialize the filesystem.
1445 mp
= _MALLOC_ZONE((u_int32_t
)sizeof(struct mount
), M_MOUNT
, M_WAITOK
);
1447 printf("nfs_mountroot: unable to allocate mount structure\n");
1452 bzero((char *)mp
, sizeof(struct mount
));
1454 /* Initialize the default IO constraints */
1455 mp
->mnt_maxreadcnt
= mp
->mnt_maxwritecnt
= MAXPHYS
;
1456 mp
->mnt_segreadcnt
= mp
->mnt_segwritecnt
= 32;
1457 mp
->mnt_ioflags
= 0;
1458 mp
->mnt_realrootvp
= NULLVP
;
1459 mp
->mnt_authcache_ttl
= 0; /* Allways go to our lookup */
1461 mount_lock_init(mp
);
1462 TAILQ_INIT(&mp
->mnt_vnodelist
);
1463 TAILQ_INIT(&mp
->mnt_workerqueue
);
1464 TAILQ_INIT(&mp
->mnt_newvnodes
);
1465 (void)vfs_busy(mp
, LK_NOWAIT
);
1466 TAILQ_INIT(&mp
->mnt_vnodelist
);
1468 vfsp
->vfc_refcount
++;
1469 mount_list_unlock();
1470 mp
->mnt_vtable
= vfsp
;
1471 mp
->mnt_op
= vfsp
->vfc_vfsops
;
1472 // mp->mnt_stat.f_type = vfsp->vfc_typenum;
1473 mp
->mnt_flag
= mntflag
;
1474 mp
->mnt_flag
|= vfsp
->vfc_flags
& MNT_VISFLAGMASK
;
1475 strncpy(mp
->mnt_vfsstat
.f_fstypename
, vfsp
->vfc_name
, MFSNAMELEN
- 1);
1476 vp
->v_mountedhere
= mp
;
1477 mp
->mnt_vnodecovered
= vp
;
1479 mp
->mnt_vfsstat
.f_owner
= kauth_cred_getuid(kauth_cred_get());
1480 (void) copystr(mntname
, mp
->mnt_vfsstat
.f_mntonname
, MAXPATHLEN
- 1, 0);
1481 (void) copystr(ndmntp
->ndm_mntfrom
, mp
->mnt_vfsstat
.f_mntfromname
, MAXPATHLEN
- 1, 0);
1483 mac_mount_label_init(mp
);
1484 mac_mount_label_associate(ctx
, mp
);
1487 /* find the server-side path being mounted */
1488 frompath
= ndmntp
->ndm_mntfrom
;
1489 if (*frompath
== '[') { /* skip IPv6 literal address */
1490 while (*frompath
&& (*frompath
!= ']')) {
1493 if (*frompath
== ']') {
1497 while (*frompath
&& (*frompath
!= ':')) {
1500 endserverp
= frompath
;
1501 while (*frompath
&& (*frompath
== ':')) {
1504 /* count fs location path components */
1506 while (*p
&& (*p
== '/')) {
1512 while (*p
&& (*p
!= '/')) {
1515 while (*p
&& (*p
== '/')) {
1520 /* convert address to universal address string */
1521 if (inet_ntop(AF_INET
, &ndmntp
->ndm_saddr
.sin_addr
, uaddr
, sizeof(uaddr
)) != uaddr
) {
1522 printf("nfs_mountroot: bad address\n");
1527 /* prepare mount attributes */
1528 NFS_BITMAP_ZERO(mattrs
, NFS_MATTR_BITMAP_LEN
);
1529 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_VERSION
);
1530 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SOCKET_TYPE
);
1531 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_PORT
);
1532 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FH
);
1533 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FS_LOCATIONS
);
1534 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MNTFLAGS
);
1536 /* prepare mount flags */
1537 NFS_BITMAP_ZERO(mflags_mask
, NFS_MFLAG_BITMAP_LEN
);
1538 NFS_BITMAP_ZERO(mflags
, NFS_MFLAG_BITMAP_LEN
);
1539 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_RESVPORT
);
1540 NFS_BITMAP_SET(mflags
, NFS_MFLAG_RESVPORT
);
1542 /* build xdr buffer */
1543 xb_init_buffer(&xb
, NULL
, 0);
1544 xb_add_32(error
, &xb
, NFS_ARGSVERSION_XDR
);
1545 argslength_offset
= xb_offset(&xb
);
1546 xb_add_32(error
, &xb
, 0); // args length
1547 xb_add_32(error
, &xb
, NFS_XDRARGS_VERSION_0
);
1548 xb_add_bitmap(error
, &xb
, mattrs
, NFS_MATTR_BITMAP_LEN
);
1549 attrslength_offset
= xb_offset(&xb
);
1550 xb_add_32(error
, &xb
, 0); // attrs length
1551 xb_add_32(error
, &xb
, ndmntp
->ndm_nfsv3
? 3 : 2); // NFS version
1552 xb_add_string(error
, &xb
, ((ndmntp
->ndm_sotype
== SOCK_DGRAM
) ? "udp" : "tcp"), 3);
1553 xb_add_32(error
, &xb
, ntohs(ndmntp
->ndm_saddr
.sin_port
)); // NFS port
1554 xb_add_fh(error
, &xb
, &ndmntp
->ndm_fh
[0], ndmntp
->ndm_fhlen
);
1556 xb_add_32(error
, &xb
, 1); /* fs location count */
1557 xb_add_32(error
, &xb
, 1); /* server count */
1558 xb_add_string(error
, &xb
, ndmntp
->ndm_mntfrom
, (endserverp
- ndmntp
->ndm_mntfrom
)); /* server name */
1559 xb_add_32(error
, &xb
, 1); /* address count */
1560 xb_add_string(error
, &xb
, uaddr
, strlen(uaddr
)); /* address */
1561 xb_add_32(error
, &xb
, 0); /* empty server info */
1562 xb_add_32(error
, &xb
, numcomps
); /* pathname component count */
1564 while (*p
&& (*p
== '/')) {
1569 while (*p
&& (*p
!= '/')) {
1572 xb_add_string(error
, &xb
, cp
, (p
- cp
)); /* component */
1576 while (*p
&& (*p
== '/')) {
1580 xb_add_32(error
, &xb
, 0); /* empty fsl info */
1581 xb_add_32(error
, &xb
, mntflag
); /* MNT flags */
1582 xb_build_done(error
, &xb
);
1584 /* update opaque counts */
1585 end_offset
= xb_offset(&xb
);
1587 error
= xb_seek(&xb
, argslength_offset
);
1588 xb_add_32(error
, &xb
, end_offset
- argslength_offset
+ XDRWORD
/*version*/);
1591 error
= xb_seek(&xb
, attrslength_offset
);
1592 xb_add_32(error
, &xb
, end_offset
- attrslength_offset
- XDRWORD
/*don't include length field*/);
1595 printf("nfs_mountroot: error %d assembling mount args\n", error
);
1598 /* grab the assembled buffer */
1599 xdrbuf
= xb_buffer_base(&xb
);
1600 xb
.xb_flags
&= ~XB_CLEANUP
;
1603 if ((error
= mountnfs(xdrbuf
, mp
, ctx
, &vp
))) {
1604 printf("nfs_mountroot: mount %s failed: %d\n", mntname
, error
);
1605 vnode_put(mp
->mnt_vnodecovered
);
1607 vfsp
->vfc_refcount
--;
1608 mount_list_unlock();
1610 mount_lock_destroy(mp
);
1612 mac_mount_label_destroy(mp
);
1614 FREE_ZONE(mp
, sizeof(struct mount
), M_MOUNT
);
1624 #endif /* NO_MOUNT_PRIVATE */
1629 * Convert old style NFS mount args to XDR.
1632 nfs_convert_old_nfs_args(mount_t mp
, user_addr_t data
, vfs_context_t ctx
, int argsversion
, int inkernel
, char **xdrbufp
)
1634 int error
= 0, args64bit
, argsize
, numcomps
;
1635 struct user_nfs_args args
;
1636 struct nfs_args tempargs
;
1639 u_char nfh
[NFS4_FHSIZE
];
1640 char *mntfrom
, *endserverp
, *frompath
, *p
, *cp
;
1641 struct sockaddr_storage ss
;
1643 char uaddr
[MAX_IPv6_STR_LEN
];
1644 uint32_t mattrs
[NFS_MATTR_BITMAP_LEN
];
1645 uint32_t mflags_mask
[NFS_MFLAG_BITMAP_LEN
], mflags
[NFS_MFLAG_BITMAP_LEN
];
1646 uint32_t nfsvers
, nfslockmode
= 0, argslength_offset
, attrslength_offset
, end_offset
;
1651 /* allocate a temporary buffer for mntfrom */
1652 MALLOC_ZONE(mntfrom
, char*, MAXPATHLEN
, M_NAMEI
, M_WAITOK
);
1657 args64bit
= (inkernel
|| vfs_context_is64bit(ctx
));
1658 argsp
= args64bit
? (void*)&args
: (void*)&tempargs
;
1660 argsize
= args64bit
? sizeof(args
) : sizeof(tempargs
);
1661 switch (argsversion
) {
1663 argsize
-= NFS_ARGSVERSION4_INCSIZE
;
1665 argsize
-= NFS_ARGSVERSION5_INCSIZE
;
1667 argsize
-= NFS_ARGSVERSION6_INCSIZE
;
1671 error
= EPROGMISMATCH
;
1675 /* read in the structure */
1677 bcopy(CAST_DOWN(void *, data
), argsp
, argsize
);
1679 error
= copyin(data
, argsp
, argsize
);
1684 args
.addrlen
= tempargs
.addrlen
;
1685 args
.sotype
= tempargs
.sotype
;
1686 args
.proto
= tempargs
.proto
;
1687 args
.fhsize
= tempargs
.fhsize
;
1688 args
.flags
= tempargs
.flags
;
1689 args
.wsize
= tempargs
.wsize
;
1690 args
.rsize
= tempargs
.rsize
;
1691 args
.readdirsize
= tempargs
.readdirsize
;
1692 args
.timeo
= tempargs
.timeo
;
1693 args
.retrans
= tempargs
.retrans
;
1694 args
.maxgrouplist
= tempargs
.maxgrouplist
;
1695 args
.readahead
= tempargs
.readahead
;
1696 args
.leaseterm
= tempargs
.leaseterm
;
1697 args
.deadthresh
= tempargs
.deadthresh
;
1698 args
.addr
= CAST_USER_ADDR_T(tempargs
.addr
);
1699 args
.fh
= CAST_USER_ADDR_T(tempargs
.fh
);
1700 args
.hostname
= CAST_USER_ADDR_T(tempargs
.hostname
);
1701 if (args
.version
>= 4) {
1702 args
.acregmin
= tempargs
.acregmin
;
1703 args
.acregmax
= tempargs
.acregmax
;
1704 args
.acdirmin
= tempargs
.acdirmin
;
1705 args
.acdirmax
= tempargs
.acdirmax
;
1707 if (args
.version
>= 5) {
1708 args
.auth
= tempargs
.auth
;
1710 if (args
.version
>= 6) {
1711 args
.deadtimeout
= tempargs
.deadtimeout
;
1715 if ((args
.fhsize
< 0) || (args
.fhsize
> NFS4_FHSIZE
)) {
1719 if (args
.fhsize
> 0) {
1721 bcopy(CAST_DOWN(void *, args
.fh
), (caddr_t
)nfh
, args
.fhsize
);
1723 error
= copyin(args
.fh
, (caddr_t
)nfh
, args
.fhsize
);
1729 error
= copystr(CAST_DOWN(void *, args
.hostname
), mntfrom
, MAXPATHLEN
- 1, &len
);
1731 error
= copyinstr(args
.hostname
, mntfrom
, MAXPATHLEN
- 1, &len
);
1734 bzero(&mntfrom
[len
], MAXPATHLEN
- len
);
1736 /* find the server-side path being mounted */
1738 if (*frompath
== '[') { /* skip IPv6 literal address */
1739 while (*frompath
&& (*frompath
!= ']')) {
1742 if (*frompath
== ']') {
1746 while (*frompath
&& (*frompath
!= ':')) {
1749 endserverp
= frompath
;
1750 while (*frompath
&& (*frompath
== ':')) {
1753 /* count fs location path components */
1755 while (*p
&& (*p
== '/')) {
1761 while (*p
&& (*p
!= '/')) {
1764 while (*p
&& (*p
== '/')) {
1769 /* copy socket address */
1771 bcopy(CAST_DOWN(void *, args
.addr
), &ss
, args
.addrlen
);
1773 if ((size_t)args
.addrlen
> sizeof(struct sockaddr_storage
)) {
1776 error
= copyin(args
.addr
, &ss
, args
.addrlen
);
1780 ss
.ss_len
= args
.addrlen
;
1782 /* convert address to universal address string */
1783 if (ss
.ss_family
== AF_INET
) {
1784 sinaddr
= &((struct sockaddr_in
*)&ss
)->sin_addr
;
1785 } else if (ss
.ss_family
== AF_INET6
) {
1786 sinaddr
= &((struct sockaddr_in6
*)&ss
)->sin6_addr
;
1790 if (!sinaddr
|| (inet_ntop(ss
.ss_family
, sinaddr
, uaddr
, sizeof(uaddr
)) != uaddr
)) {
1795 /* prepare mount flags */
1796 NFS_BITMAP_ZERO(mflags_mask
, NFS_MFLAG_BITMAP_LEN
);
1797 NFS_BITMAP_ZERO(mflags
, NFS_MFLAG_BITMAP_LEN
);
1798 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_SOFT
);
1799 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_INTR
);
1800 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_RESVPORT
);
1801 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NOCONNECT
);
1802 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_DUMBTIMER
);
1803 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_CALLUMNT
);
1804 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_RDIRPLUS
);
1805 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NONEGNAMECACHE
);
1806 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_MUTEJUKEBOX
);
1807 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NOQUOTA
);
1808 if (args
.flags
& NFSMNT_SOFT
) {
1809 NFS_BITMAP_SET(mflags
, NFS_MFLAG_SOFT
);
1811 if (args
.flags
& NFSMNT_INT
) {
1812 NFS_BITMAP_SET(mflags
, NFS_MFLAG_INTR
);
1814 if (args
.flags
& NFSMNT_RESVPORT
) {
1815 NFS_BITMAP_SET(mflags
, NFS_MFLAG_RESVPORT
);
1817 if (args
.flags
& NFSMNT_NOCONN
) {
1818 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NOCONNECT
);
1820 if (args
.flags
& NFSMNT_DUMBTIMR
) {
1821 NFS_BITMAP_SET(mflags
, NFS_MFLAG_DUMBTIMER
);
1823 if (args
.flags
& NFSMNT_CALLUMNT
) {
1824 NFS_BITMAP_SET(mflags
, NFS_MFLAG_CALLUMNT
);
1826 if (args
.flags
& NFSMNT_RDIRPLUS
) {
1827 NFS_BITMAP_SET(mflags
, NFS_MFLAG_RDIRPLUS
);
1829 if (args
.flags
& NFSMNT_NONEGNAMECACHE
) {
1830 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NONEGNAMECACHE
);
1832 if (args
.flags
& NFSMNT_MUTEJUKEBOX
) {
1833 NFS_BITMAP_SET(mflags
, NFS_MFLAG_MUTEJUKEBOX
);
1835 if (args
.flags
& NFSMNT_NOQUOTA
) {
1836 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NOQUOTA
);
1839 /* prepare mount attributes */
1840 NFS_BITMAP_ZERO(mattrs
, NFS_MATTR_BITMAP_LEN
);
1841 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FLAGS
);
1842 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_VERSION
);
1843 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SOCKET_TYPE
);
1844 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_PORT
);
1845 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FH
);
1846 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FS_LOCATIONS
);
1847 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MNTFLAGS
);
1848 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MNTFROM
);
1849 if (args
.flags
& NFSMNT_NFSV4
) {
1851 } else if (args
.flags
& NFSMNT_NFSV3
) {
1856 if ((args
.flags
& NFSMNT_RSIZE
) && (args
.rsize
> 0)) {
1857 NFS_BITMAP_SET(mattrs
, NFS_MATTR_READ_SIZE
);
1859 if ((args
.flags
& NFSMNT_WSIZE
) && (args
.wsize
> 0)) {
1860 NFS_BITMAP_SET(mattrs
, NFS_MATTR_WRITE_SIZE
);
1862 if ((args
.flags
& NFSMNT_TIMEO
) && (args
.timeo
> 0)) {
1863 NFS_BITMAP_SET(mattrs
, NFS_MATTR_REQUEST_TIMEOUT
);
1865 if ((args
.flags
& NFSMNT_RETRANS
) && (args
.retrans
> 0)) {
1866 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SOFT_RETRY_COUNT
);
1868 if ((args
.flags
& NFSMNT_MAXGRPS
) && (args
.maxgrouplist
> 0)) {
1869 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MAX_GROUP_LIST
);
1871 if ((args
.flags
& NFSMNT_READAHEAD
) && (args
.readahead
> 0)) {
1872 NFS_BITMAP_SET(mattrs
, NFS_MATTR_READAHEAD
);
1874 if ((args
.flags
& NFSMNT_READDIRSIZE
) && (args
.readdirsize
> 0)) {
1875 NFS_BITMAP_SET(mattrs
, NFS_MATTR_READDIR_SIZE
);
1877 if ((args
.flags
& NFSMNT_NOLOCKS
) ||
1878 (args
.flags
& NFSMNT_LOCALLOCKS
)) {
1879 NFS_BITMAP_SET(mattrs
, NFS_MATTR_LOCK_MODE
);
1880 if (args
.flags
& NFSMNT_NOLOCKS
) {
1881 nfslockmode
= NFS_LOCK_MODE_DISABLED
;
1882 } else if (args
.flags
& NFSMNT_LOCALLOCKS
) {
1883 nfslockmode
= NFS_LOCK_MODE_LOCAL
;
1885 nfslockmode
= NFS_LOCK_MODE_ENABLED
;
1888 if (args
.version
>= 4) {
1889 if ((args
.flags
& NFSMNT_ACREGMIN
) && (args
.acregmin
> 0)) {
1890 NFS_BITMAP_SET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MIN
);
1892 if ((args
.flags
& NFSMNT_ACREGMAX
) && (args
.acregmax
> 0)) {
1893 NFS_BITMAP_SET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MAX
);
1895 if ((args
.flags
& NFSMNT_ACDIRMIN
) && (args
.acdirmin
> 0)) {
1896 NFS_BITMAP_SET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MIN
);
1898 if ((args
.flags
& NFSMNT_ACDIRMAX
) && (args
.acdirmax
> 0)) {
1899 NFS_BITMAP_SET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MAX
);
1902 if (args
.version
>= 5) {
1903 if ((args
.flags
& NFSMNT_SECFLAVOR
) || (args
.flags
& NFSMNT_SECSYSOK
)) {
1904 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SECURITY
);
1907 if (args
.version
>= 6) {
1908 if ((args
.flags
& NFSMNT_DEADTIMEOUT
) && (args
.deadtimeout
> 0)) {
1909 NFS_BITMAP_SET(mattrs
, NFS_MATTR_DEAD_TIMEOUT
);
1913 /* build xdr buffer */
1914 xb_init_buffer(&xb
, NULL
, 0);
1915 xb_add_32(error
, &xb
, args
.version
);
1916 argslength_offset
= xb_offset(&xb
);
1917 xb_add_32(error
, &xb
, 0); // args length
1918 xb_add_32(error
, &xb
, NFS_XDRARGS_VERSION_0
);
1919 xb_add_bitmap(error
, &xb
, mattrs
, NFS_MATTR_BITMAP_LEN
);
1920 attrslength_offset
= xb_offset(&xb
);
1921 xb_add_32(error
, &xb
, 0); // attrs length
1922 xb_add_bitmap(error
, &xb
, mflags_mask
, NFS_MFLAG_BITMAP_LEN
); /* mask */
1923 xb_add_bitmap(error
, &xb
, mflags
, NFS_MFLAG_BITMAP_LEN
); /* value */
1924 xb_add_32(error
, &xb
, nfsvers
);
1925 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READ_SIZE
)) {
1926 xb_add_32(error
, &xb
, args
.rsize
);
1928 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_WRITE_SIZE
)) {
1929 xb_add_32(error
, &xb
, args
.wsize
);
1931 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READDIR_SIZE
)) {
1932 xb_add_32(error
, &xb
, args
.readdirsize
);
1934 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READAHEAD
)) {
1935 xb_add_32(error
, &xb
, args
.readahead
);
1937 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MIN
)) {
1938 xb_add_32(error
, &xb
, args
.acregmin
);
1939 xb_add_32(error
, &xb
, 0);
1941 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MAX
)) {
1942 xb_add_32(error
, &xb
, args
.acregmax
);
1943 xb_add_32(error
, &xb
, 0);
1945 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MIN
)) {
1946 xb_add_32(error
, &xb
, args
.acdirmin
);
1947 xb_add_32(error
, &xb
, 0);
1949 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MAX
)) {
1950 xb_add_32(error
, &xb
, args
.acdirmax
);
1951 xb_add_32(error
, &xb
, 0);
1953 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCK_MODE
)) {
1954 xb_add_32(error
, &xb
, nfslockmode
);
1956 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SECURITY
)) {
1957 uint32_t flavors
[2], i
= 0;
1958 if (args
.flags
& NFSMNT_SECFLAVOR
) {
1959 flavors
[i
++] = args
.auth
;
1961 if ((args
.flags
& NFSMNT_SECSYSOK
) && ((i
== 0) || (flavors
[0] != RPCAUTH_SYS
))) {
1962 flavors
[i
++] = RPCAUTH_SYS
;
1964 xb_add_word_array(error
, &xb
, flavors
, i
);
1966 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MAX_GROUP_LIST
)) {
1967 xb_add_32(error
, &xb
, args
.maxgrouplist
);
1969 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SOCKET_TYPE
)) {
1970 xb_add_string(error
, &xb
, ((args
.sotype
== SOCK_DGRAM
) ? "udp" : "tcp"), 3);
1972 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_PORT
)) {
1973 xb_add_32(error
, &xb
, ((ss
.ss_family
== AF_INET
) ?
1974 ntohs(((struct sockaddr_in
*)&ss
)->sin_port
) :
1975 ntohs(((struct sockaddr_in6
*)&ss
)->sin6_port
)));
1977 /* NFS_MATTR_MOUNT_PORT (not available in old args) */
1978 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_REQUEST_TIMEOUT
)) {
1979 /* convert from .1s increments to time */
1980 xb_add_32(error
, &xb
, args
.timeo
/ 10);
1981 xb_add_32(error
, &xb
, (args
.timeo
% 10) * 100000000);
1983 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SOFT_RETRY_COUNT
)) {
1984 xb_add_32(error
, &xb
, args
.retrans
);
1986 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_DEAD_TIMEOUT
)) {
1987 xb_add_32(error
, &xb
, args
.deadtimeout
);
1988 xb_add_32(error
, &xb
, 0);
1990 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_FH
)) {
1991 xb_add_fh(error
, &xb
, &nfh
[0], args
.fhsize
);
1993 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_FS_LOCATIONS
)) {
1994 xb_add_32(error
, &xb
, 1); /* fs location count */
1995 xb_add_32(error
, &xb
, 1); /* server count */
1996 xb_add_string(error
, &xb
, mntfrom
, (endserverp
- mntfrom
)); /* server name */
1997 xb_add_32(error
, &xb
, 1); /* address count */
1998 xb_add_string(error
, &xb
, uaddr
, strlen(uaddr
)); /* address */
1999 xb_add_32(error
, &xb
, 0); /* empty server info */
2000 xb_add_32(error
, &xb
, numcomps
); /* pathname component count */
2003 while (*p
&& (*p
== '/')) {
2008 while (*p
&& (*p
!= '/')) {
2011 xb_add_string(error
, &xb
, cp
, (p
- cp
)); /* component */
2013 while (*p
&& (*p
== '/')) {
2017 xb_add_32(error
, &xb
, 0); /* empty fsl info */
2019 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MNTFLAGS
)) {
2020 xb_add_32(error
, &xb
, (vfs_flags(mp
) & MNT_VISFLAGMASK
)); /* VFS MNT_* flags */
2022 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MNTFROM
)) {
2023 xb_add_string(error
, &xb
, mntfrom
, strlen(mntfrom
)); /* fixed f_mntfromname */
2025 xb_build_done(error
, &xb
);
2027 /* update opaque counts */
2028 end_offset
= xb_offset(&xb
);
2029 error
= xb_seek(&xb
, argslength_offset
);
2030 xb_add_32(error
, &xb
, end_offset
- argslength_offset
+ XDRWORD
/*version*/);
2032 error
= xb_seek(&xb
, attrslength_offset
);
2033 xb_add_32(error
, &xb
, end_offset
- attrslength_offset
- XDRWORD
/*don't include length field*/);
2036 /* grab the assembled buffer */
2037 *xdrbufp
= xb_buffer_base(&xb
);
2038 xb
.xb_flags
&= ~XB_CLEANUP
;
2042 FREE_ZONE(mntfrom
, MAXPATHLEN
, M_NAMEI
);
2052 nfs_vfs_mount(mount_t mp
, vnode_t vp
, user_addr_t data
, vfs_context_t ctx
)
2054 int error
= 0, inkernel
= vfs_iskernelmount(mp
);
2055 uint32_t argsversion
, argslength
;
2056 char *xdrbuf
= NULL
;
2058 /* read in version */
2060 bcopy(CAST_DOWN(void *, data
), &argsversion
, sizeof(argsversion
));
2061 } else if ((error
= copyin(data
, &argsversion
, sizeof(argsversion
)))) {
2065 /* If we have XDR args, then all values in the buffer are in network order */
2066 if (argsversion
== htonl(NFS_ARGSVERSION_XDR
)) {
2067 argsversion
= NFS_ARGSVERSION_XDR
;
2070 switch (argsversion
) {
2075 /* convert old-style args to xdr */
2076 error
= nfs_convert_old_nfs_args(mp
, data
, ctx
, argsversion
, inkernel
, &xdrbuf
);
2078 case NFS_ARGSVERSION_XDR
:
2079 /* copy in xdr buffer */
2081 bcopy(CAST_DOWN(void *, (data
+ XDRWORD
)), &argslength
, XDRWORD
);
2083 error
= copyin((data
+ XDRWORD
), &argslength
, XDRWORD
);
2088 argslength
= ntohl(argslength
);
2089 /* put a reasonable limit on the size of the XDR args */
2090 if (argslength
> 16 * 1024) {
2094 /* allocate xdr buffer */
2095 xdrbuf
= xb_malloc(xdr_rndup(argslength
));
2101 bcopy(CAST_DOWN(void *, data
), xdrbuf
, argslength
);
2103 error
= copyin(data
, xdrbuf
, argslength
);
2107 error
= EPROGMISMATCH
;
2116 error
= mountnfs(xdrbuf
, mp
, ctx
, &vp
);
2121 * Common code for mount and mountroot
2124 /* Set up an NFSv2/v3 mount */
2127 struct nfsmount
*nmp
,
2132 struct nfs_vattr nvattr
;
2142 * Get file attributes for the mountpoint. These are needed
2143 * in order to properly create the root vnode.
2145 error
= nfs3_getattr_rpc(NULL
, nmp
->nm_mountp
, nmp
->nm_fh
->fh_data
, nmp
->nm_fh
->fh_len
, 0,
2146 ctx
, &nvattr
, &xid
);
2151 error
= nfs_nget(nmp
->nm_mountp
, NULL
, NULL
, nmp
->nm_fh
->fh_data
, nmp
->nm_fh
->fh_len
,
2152 &nvattr
, &xid
, RPCAUTH_UNKNOWN
, NG_MARKROOT
, npp
);
2154 nfs_node_unlock(*npp
);
2161 * Try to make sure we have all the general info from the server.
2163 if (nmp
->nm_vers
== NFS_VER2
) {
2164 NFS_BITMAP_SET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_MAXNAME
);
2165 nmp
->nm_fsattr
.nfsa_maxname
= NFS_MAXNAMLEN
;
2166 } else if (nmp
->nm_vers
== NFS_VER3
) {
2167 /* get the NFSv3 FSINFO */
2168 error
= nfs3_fsinfo(nmp
, *npp
, ctx
);
2172 /* If the server indicates all pathconf info is */
2173 /* the same, grab a copy of that info now */
2174 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_HOMOGENEOUS
) &&
2175 (nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_HOMOGENEOUS
)) {
2176 struct nfs_fsattr nfsa
;
2177 if (!nfs3_pathconf_rpc(*npp
, &nfsa
, ctx
)) {
2178 /* cache a copy of the results */
2179 lck_mtx_lock(&nmp
->nm_lock
);
2180 nfs3_pathconf_cache(nmp
, &nfsa
);
2181 lck_mtx_unlock(&nmp
->nm_lock
);
2186 if (*npp
&& error
) {
2187 vnode_put(NFSTOV(*npp
));
2188 vnode_recycle(NFSTOV(*npp
));
2196 * Update an NFSv4 mount path with the contents of the symlink.
2198 * Read the link for the given file handle.
2199 * Insert the link's components into the path.
2202 nfs4_mount_update_path_with_symlink(struct nfsmount
*nmp
, struct nfs_fs_path
*nfsp
, uint32_t curcomp
, fhandle_t
*dirfhp
, int *depthp
, fhandle_t
*fhp
, vfs_context_t ctx
)
2204 int error
= 0, status
, numops
;
2205 uint32_t len
= 0, comp
, newcomp
, linkcompcount
;
2207 struct nfsm_chain nmreq
, nmrep
;
2208 struct nfsreq rq
, *req
= &rq
;
2209 struct nfsreq_secinfo_args si
;
2210 char *link
= NULL
, *p
, *q
, ch
;
2211 struct nfs_fs_path nfsp2
;
2213 bzero(&nfsp2
, sizeof(nfsp2
));
2214 if (dirfhp
->fh_len
) {
2215 NFSREQ_SECINFO_SET(&si
, NULL
, dirfhp
->fh_data
, dirfhp
->fh_len
, nfsp
->np_components
[curcomp
], 0);
2217 NFSREQ_SECINFO_SET(&si
, NULL
, NULL
, 0, nfsp
->np_components
[curcomp
], 0);
2219 nfsm_chain_null(&nmreq
);
2220 nfsm_chain_null(&nmrep
);
2222 MALLOC_ZONE(link
, char *, MAXPATHLEN
, M_NAMEI
, M_WAITOK
);
2229 nfsm_chain_build_alloc_init(error
, &nmreq
, 12 * NFSX_UNSIGNED
);
2230 nfsm_chain_add_compound_header(error
, &nmreq
, "readlink", nmp
->nm_minor_vers
, numops
);
2232 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_PUTFH
);
2233 nfsm_chain_add_fh(error
, &nmreq
, NFS_VER4
, fhp
->fh_data
, fhp
->fh_len
);
2235 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_READLINK
);
2236 nfsm_chain_build_done(error
, &nmreq
);
2237 nfsm_assert(error
, (numops
== 0), EPROTO
);
2240 error
= nfs_request_async(NULL
, nmp
->nm_mountp
, &nmreq
, NFSPROC4_COMPOUND
,
2241 vfs_context_thread(ctx
), vfs_context_ucred(ctx
), &si
, 0, NULL
, &req
);
2243 error
= nfs_request_async_finish(req
, &nmrep
, &xid
, &status
);
2246 nfsm_chain_skip_tag(error
, &nmrep
);
2247 nfsm_chain_get_32(error
, &nmrep
, numops
);
2248 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_PUTFH
);
2249 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_READLINK
);
2250 nfsm_chain_get_32(error
, &nmrep
, len
);
2254 } else if (len
>= MAXPATHLEN
) {
2255 len
= MAXPATHLEN
- 1;
2257 nfsm_chain_get_opaque(error
, &nmrep
, len
, link
);
2259 /* make sure link string is terminated properly */
2262 /* count the number of components in link */
2264 while (*p
&& (*p
== '/')) {
2270 while (*p
&& (*p
!= '/')) {
2273 while (*p
&& (*p
== '/')) {
2278 /* free up used components */
2279 for (comp
= 0; comp
<= curcomp
; comp
++) {
2280 if (nfsp
->np_components
[comp
]) {
2281 FREE(nfsp
->np_components
[comp
], M_TEMP
);
2282 nfsp
->np_components
[comp
] = NULL
;
2286 /* set up new path */
2287 nfsp2
.np_compcount
= nfsp
->np_compcount
- curcomp
- 1 + linkcompcount
;
2288 MALLOC(nfsp2
.np_components
, char **, nfsp2
.np_compcount
* sizeof(char*), M_TEMP
, M_WAITOK
| M_ZERO
);
2289 if (!nfsp2
.np_components
) {
2294 /* add link components */
2296 while (*p
&& (*p
== '/')) {
2299 for (newcomp
= 0; newcomp
< linkcompcount
; newcomp
++) {
2300 /* find end of component */
2302 while (*q
&& (*q
!= '/')) {
2305 MALLOC(nfsp2
.np_components
[newcomp
], char *, q
- p
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
2306 if (!nfsp2
.np_components
[newcomp
]) {
2312 strlcpy(nfsp2
.np_components
[newcomp
], p
, q
- p
+ 1);
2315 while (*p
&& (*p
== '/')) {
2321 /* add remaining components */
2322 for (comp
= curcomp
+ 1; comp
< nfsp
->np_compcount
; comp
++, newcomp
++) {
2323 nfsp2
.np_components
[newcomp
] = nfsp
->np_components
[comp
];
2324 nfsp
->np_components
[comp
] = NULL
;
2327 /* move new path into place */
2328 FREE(nfsp
->np_components
, M_TEMP
);
2329 nfsp
->np_components
= nfsp2
.np_components
;
2330 nfsp
->np_compcount
= nfsp2
.np_compcount
;
2331 nfsp2
.np_components
= NULL
;
2333 /* for absolute link, let the caller now that the next dirfh is root */
2334 if (link
[0] == '/') {
2340 FREE_ZONE(link
, MAXPATHLEN
, M_NAMEI
);
2342 if (nfsp2
.np_components
) {
2343 for (comp
= 0; comp
< nfsp2
.np_compcount
; comp
++) {
2344 if (nfsp2
.np_components
[comp
]) {
2345 FREE(nfsp2
.np_components
[comp
], M_TEMP
);
2348 FREE(nfsp2
.np_components
, M_TEMP
);
2350 nfsm_chain_cleanup(&nmreq
);
2351 nfsm_chain_cleanup(&nmrep
);
2355 /* Set up an NFSv4 mount */
2358 struct nfsmount
*nmp
,
2362 struct nfsm_chain nmreq
, nmrep
;
2363 int error
= 0, numops
, status
, interval
, isdotdot
, loopcnt
= 0, depth
= 0;
2364 struct nfs_fs_path fspath
, *nfsp
, fspath2
;
2365 uint32_t bitmap
[NFS_ATTR_BITMAP_LEN
], comp
, comp2
;
2366 fhandle_t fh
, dirfh
;
2367 struct nfs_vattr nvattr
;
2369 struct nfsreq rq
, *req
= &rq
;
2370 struct nfsreq_secinfo_args si
;
2372 struct nfs_fs_locations nfsls
;
2375 fh
.fh_len
= dirfh
.fh_len
= 0;
2376 TAILQ_INIT(&nmp
->nm_open_owners
);
2377 TAILQ_INIT(&nmp
->nm_delegations
);
2378 TAILQ_INIT(&nmp
->nm_dreturnq
);
2379 nmp
->nm_stategenid
= 1;
2380 NVATTR_INIT(&nvattr
);
2381 bzero(&nfsls
, sizeof(nfsls
));
2382 nfsm_chain_null(&nmreq
);
2383 nfsm_chain_null(&nmrep
);
2386 * If no security flavors were specified we'll want to default to the server's
2387 * preferred flavor. For NFSv4.0 we need a file handle and name to get that via
2388 * SECINFO, so we'll do that on the last component of the server path we are
2389 * mounting. If we are mounting the server's root, we'll need to defer the
2390 * SECINFO call to the first successful LOOKUP request.
2392 if (!nmp
->nm_sec
.count
) {
2393 nmp
->nm_state
|= NFSSTA_NEEDSECINFO
;
2396 /* make a copy of the current location's path */
2397 nfsp
= &nmp
->nm_locations
.nl_locations
[nmp
->nm_locations
.nl_current
.nli_loc
]->nl_path
;
2398 bzero(&fspath
, sizeof(fspath
));
2399 fspath
.np_compcount
= nfsp
->np_compcount
;
2400 if (fspath
.np_compcount
> 0) {
2401 MALLOC(fspath
.np_components
, char **, fspath
.np_compcount
* sizeof(char*), M_TEMP
, M_WAITOK
| M_ZERO
);
2402 if (!fspath
.np_components
) {
2406 for (comp
= 0; comp
< nfsp
->np_compcount
; comp
++) {
2407 int slen
= strlen(nfsp
->np_components
[comp
]);
2408 MALLOC(fspath
.np_components
[comp
], char *, slen
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
2409 if (!fspath
.np_components
[comp
]) {
2413 strlcpy(fspath
.np_components
[comp
], nfsp
->np_components
[comp
], slen
+ 1);
2420 /* for mirror mounts, we can just use the file handle passed in */
2422 dirfh
.fh_len
= nmp
->nm_fh
->fh_len
;
2423 bcopy(nmp
->nm_fh
->fh_data
, dirfh
.fh_data
, dirfh
.fh_len
);
2424 NFSREQ_SECINFO_SET(&si
, NULL
, dirfh
.fh_data
, dirfh
.fh_len
, NULL
, 0);
2428 /* otherwise, we need to get the fh for the directory we are mounting */
2430 /* if no components, just get root */
2431 if (fspath
.np_compcount
== 0) {
2433 // PUTROOTFH + GETATTR(FH)
2434 NFSREQ_SECINFO_SET(&si
, NULL
, NULL
, 0, NULL
, 0);
2436 nfsm_chain_build_alloc_init(error
, &nmreq
, 9 * NFSX_UNSIGNED
);
2437 nfsm_chain_add_compound_header(error
, &nmreq
, "mount", nmp
->nm_minor_vers
, numops
);
2439 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_PUTROOTFH
);
2441 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_GETATTR
);
2442 NFS_CLEAR_ATTRIBUTES(bitmap
);
2443 NFS4_DEFAULT_ATTRIBUTES(bitmap
);
2444 NFS_BITMAP_SET(bitmap
, NFS_FATTR_FILEHANDLE
);
2445 nfsm_chain_add_bitmap(error
, &nmreq
, bitmap
, NFS_ATTR_BITMAP_LEN
);
2446 nfsm_chain_build_done(error
, &nmreq
);
2447 nfsm_assert(error
, (numops
== 0), EPROTO
);
2449 error
= nfs_request_async(NULL
, nmp
->nm_mountp
, &nmreq
, NFSPROC4_COMPOUND
,
2450 vfs_context_thread(ctx
), vfs_context_ucred(ctx
), &si
, 0, NULL
, &req
);
2452 error
= nfs_request_async_finish(req
, &nmrep
, &xid
, &status
);
2454 nfsm_chain_skip_tag(error
, &nmrep
);
2455 nfsm_chain_get_32(error
, &nmrep
, numops
);
2456 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_PUTROOTFH
);
2457 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_GETATTR
);
2459 NFS_CLEAR_ATTRIBUTES(nmp
->nm_fsattr
.nfsa_bitmap
);
2460 error
= nfs4_parsefattr(&nmrep
, &nmp
->nm_fsattr
, &nvattr
, &dirfh
, NULL
, NULL
);
2461 if (!error
&& !NFS_BITMAP_ISSET(&nvattr
.nva_bitmap
, NFS_FATTR_FILEHANDLE
)) {
2462 printf("nfs: mount didn't return filehandle?\n");
2466 nfsm_chain_cleanup(&nmrep
);
2467 nfsm_chain_null(&nmreq
);
2468 NVATTR_CLEANUP(&nvattr
);
2472 /* look up each path component */
2473 for (comp
= 0; comp
< fspath
.np_compcount
;) {
2475 if (fspath
.np_components
[comp
][0] == '.') {
2476 if (fspath
.np_components
[comp
][1] == '\0') {
2481 /* treat ".." specially */
2482 if ((fspath
.np_components
[comp
][1] == '.') &&
2483 (fspath
.np_components
[comp
][2] == '\0')) {
2486 if (isdotdot
&& (dirfh
.fh_len
== 0)) {
2487 /* ".." in root directory is same as "." */
2492 // PUT(ROOT)FH + LOOKUP(P) + GETFH + GETATTR
2493 if (dirfh
.fh_len
== 0) {
2494 NFSREQ_SECINFO_SET(&si
, NULL
, NULL
, 0, isdotdot
? NULL
: fspath
.np_components
[comp
], 0);
2496 NFSREQ_SECINFO_SET(&si
, NULL
, dirfh
.fh_data
, dirfh
.fh_len
, isdotdot
? NULL
: fspath
.np_components
[comp
], 0);
2499 nfsm_chain_build_alloc_init(error
, &nmreq
, 18 * NFSX_UNSIGNED
);
2500 nfsm_chain_add_compound_header(error
, &nmreq
, "mount", nmp
->nm_minor_vers
, numops
);
2503 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_PUTFH
);
2504 nfsm_chain_add_fh(error
, &nmreq
, NFS_VER4
, dirfh
.fh_data
, dirfh
.fh_len
);
2506 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_PUTROOTFH
);
2510 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_LOOKUPP
);
2512 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_LOOKUP
);
2513 nfsm_chain_add_name(error
, &nmreq
,
2514 fspath
.np_components
[comp
], strlen(fspath
.np_components
[comp
]), nmp
);
2517 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_GETFH
);
2519 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_GETATTR
);
2520 NFS_CLEAR_ATTRIBUTES(bitmap
);
2521 NFS4_DEFAULT_ATTRIBUTES(bitmap
);
2522 /* if no namedattr support or component is ".zfs", clear NFS_FATTR_NAMED_ATTR */
2523 if (!NMFLAG(nmp
, NAMEDATTR
) || !strcmp(fspath
.np_components
[comp
], ".zfs")) {
2524 NFS_BITMAP_CLR(bitmap
, NFS_FATTR_NAMED_ATTR
);
2526 nfsm_chain_add_bitmap(error
, &nmreq
, bitmap
, NFS_ATTR_BITMAP_LEN
);
2527 nfsm_chain_build_done(error
, &nmreq
);
2528 nfsm_assert(error
, (numops
== 0), EPROTO
);
2530 error
= nfs_request_async(NULL
, nmp
->nm_mountp
, &nmreq
, NFSPROC4_COMPOUND
,
2531 vfs_context_thread(ctx
), vfs_context_ucred(ctx
), &si
, 0, NULL
, &req
);
2533 error
= nfs_request_async_finish(req
, &nmrep
, &xid
, &status
);
2535 nfsm_chain_skip_tag(error
, &nmrep
);
2536 nfsm_chain_get_32(error
, &nmrep
, numops
);
2537 nfsm_chain_op_check(error
, &nmrep
, dirfh
.fh_len
? NFS_OP_PUTFH
: NFS_OP_PUTROOTFH
);
2538 nfsm_chain_op_check(error
, &nmrep
, isdotdot
? NFS_OP_LOOKUPP
: NFS_OP_LOOKUP
);
2540 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_GETFH
);
2541 nfsm_chain_get_32(error
, &nmrep
, fh
.fh_len
);
2542 if (fh
.fh_len
> sizeof(fh
.fh_data
)) {
2546 nfsm_chain_get_opaque(error
, &nmrep
, fh
.fh_len
, fh
.fh_data
);
2547 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_GETATTR
);
2549 NFS_CLEAR_ATTRIBUTES(nmp
->nm_fsattr
.nfsa_bitmap
);
2550 error
= nfs4_parsefattr(&nmrep
, &nmp
->nm_fsattr
, &nvattr
, NULL
, NULL
, &nfsls
);
2552 nfsm_chain_cleanup(&nmrep
);
2553 nfsm_chain_null(&nmreq
);
2555 /* LOOKUP succeeded but GETATTR failed? This could be a referral. */
2556 /* Try the lookup again with a getattr for fs_locations. */
2557 nfs_fs_locations_cleanup(&nfsls
);
2558 error
= nfs4_get_fs_locations(nmp
, NULL
, dirfh
.fh_data
, dirfh
.fh_len
, fspath
.np_components
[comp
], ctx
, &nfsls
);
2559 if (!error
&& (nfsls
.nl_numlocs
< 1)) {
2563 if (++loopcnt
> MAXSYMLINKS
) {
2564 /* too many symlink/referral redirections */
2568 /* tear down the current connection */
2569 nfs_disconnect(nmp
);
2570 /* replace fs locations */
2571 nfs_fs_locations_cleanup(&nmp
->nm_locations
);
2572 nmp
->nm_locations
= nfsls
;
2573 bzero(&nfsls
, sizeof(nfsls
));
2574 /* initiate a connection using the new fs locations */
2575 error
= nfs_mount_connect(nmp
);
2576 if (!error
&& !(nmp
->nm_locations
.nl_current
.nli_flags
& NLI_VALID
)) {
2580 /* add new server's remote path to beginning of our path and continue */
2581 nfsp
= &nmp
->nm_locations
.nl_locations
[nmp
->nm_locations
.nl_current
.nli_loc
]->nl_path
;
2582 bzero(&fspath2
, sizeof(fspath2
));
2583 fspath2
.np_compcount
= (fspath
.np_compcount
- comp
- 1) + nfsp
->np_compcount
;
2584 if (fspath2
.np_compcount
> 0) {
2585 MALLOC(fspath2
.np_components
, char **, fspath2
.np_compcount
* sizeof(char*), M_TEMP
, M_WAITOK
| M_ZERO
);
2586 if (!fspath2
.np_components
) {
2590 for (comp2
= 0; comp2
< nfsp
->np_compcount
; comp2
++) {
2591 int slen
= strlen(nfsp
->np_components
[comp2
]);
2592 MALLOC(fspath2
.np_components
[comp2
], char *, slen
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
2593 if (!fspath2
.np_components
[comp2
]) {
2594 /* clean up fspath2, then error out */
2597 FREE(fspath2
.np_components
[comp2
], M_TEMP
);
2599 FREE(fspath2
.np_components
, M_TEMP
);
2603 strlcpy(fspath2
.np_components
[comp2
], nfsp
->np_components
[comp2
], slen
+ 1);
2605 if ((fspath
.np_compcount
- comp
- 1) > 0) {
2606 bcopy(&fspath
.np_components
[comp
+ 1], &fspath2
.np_components
[nfsp
->np_compcount
], (fspath
.np_compcount
- comp
- 1) * sizeof(char*));
2608 /* free up unused parts of old path (prior components and component array) */
2610 FREE(fspath
.np_components
[comp
], M_TEMP
);
2611 } while (comp
-- > 0);
2612 FREE(fspath
.np_components
, M_TEMP
);
2613 /* put new path in place */
2616 /* reset dirfh and component index */
2619 NVATTR_CLEANUP(&nvattr
);
2620 if (fspath
.np_compcount
== 0) {
2626 /* if file handle is for a symlink, then update the path with the symlink contents */
2627 if (NFS_BITMAP_ISSET(&nvattr
.nva_bitmap
, NFS_FATTR_TYPE
) && (nvattr
.nva_type
== VLNK
)) {
2628 if (++loopcnt
> MAXSYMLINKS
) {
2631 error
= nfs4_mount_update_path_with_symlink(nmp
, &fspath
, comp
, &dirfh
, &depth
, &fh
, ctx
);
2634 /* directory file handle is either left the same or reset to root (if link was absolute) */
2635 /* path traversal starts at beginning of the path again */
2637 NVATTR_CLEANUP(&nvattr
);
2638 nfs_fs_locations_cleanup(&nfsls
);
2641 NVATTR_CLEANUP(&nvattr
);
2642 nfs_fs_locations_cleanup(&nfsls
);
2643 /* not a symlink... */
2644 if ((nmp
->nm_state
& NFSSTA_NEEDSECINFO
) && (comp
== (fspath
.np_compcount
- 1)) && !isdotdot
) {
2645 /* need to get SECINFO for the directory being mounted */
2646 if (dirfh
.fh_len
== 0) {
2647 NFSREQ_SECINFO_SET(&si
, NULL
, NULL
, 0, isdotdot
? NULL
: fspath
.np_components
[comp
], 0);
2649 NFSREQ_SECINFO_SET(&si
, NULL
, dirfh
.fh_data
, dirfh
.fh_len
, isdotdot
? NULL
: fspath
.np_components
[comp
], 0);
2651 sec
.count
= NX_MAX_SEC_FLAVORS
;
2652 error
= nfs4_secinfo_rpc(nmp
, &si
, vfs_context_ucred(ctx
), sec
.flavors
, &sec
.count
);
2653 /* [sigh] some implementations return "illegal" error for unsupported ops */
2654 if (error
== NFSERR_OP_ILLEGAL
) {
2658 /* set our default security flavor to the first in the list */
2660 nmp
->nm_auth
= sec
.flavors
[0];
2662 nmp
->nm_state
&= ~NFSSTA_NEEDSECINFO
;
2664 /* advance directory file handle, component index, & update depth */
2667 if (!isdotdot
) { /* going down the hierarchy */
2669 } else if (--depth
<= 0) { /* going up the hierarchy */
2670 dirfh
.fh_len
= 0; /* clear dirfh when we hit root */
2675 /* get attrs for mount point root */
2676 numops
= NMFLAG(nmp
, NAMEDATTR
) ? 3 : 2; // PUTFH + GETATTR + OPENATTR
2677 nfsm_chain_build_alloc_init(error
, &nmreq
, 25 * NFSX_UNSIGNED
);
2678 nfsm_chain_add_compound_header(error
, &nmreq
, "mount", nmp
->nm_minor_vers
, numops
);
2680 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_PUTFH
);
2681 nfsm_chain_add_fh(error
, &nmreq
, NFS_VER4
, dirfh
.fh_data
, dirfh
.fh_len
);
2683 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_GETATTR
);
2684 NFS_CLEAR_ATTRIBUTES(bitmap
);
2685 NFS4_DEFAULT_ATTRIBUTES(bitmap
);
2686 /* if no namedattr support or last component is ".zfs", clear NFS_FATTR_NAMED_ATTR */
2687 if (!NMFLAG(nmp
, NAMEDATTR
) || ((fspath
.np_compcount
> 0) && !strcmp(fspath
.np_components
[fspath
.np_compcount
- 1], ".zfs"))) {
2688 NFS_BITMAP_CLR(bitmap
, NFS_FATTR_NAMED_ATTR
);
2690 nfsm_chain_add_bitmap(error
, &nmreq
, bitmap
, NFS_ATTR_BITMAP_LEN
);
2691 if (NMFLAG(nmp
, NAMEDATTR
)) {
2693 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_OPENATTR
);
2694 nfsm_chain_add_32(error
, &nmreq
, 0);
2696 nfsm_chain_build_done(error
, &nmreq
);
2697 nfsm_assert(error
, (numops
== 0), EPROTO
);
2699 error
= nfs_request_async(NULL
, nmp
->nm_mountp
, &nmreq
, NFSPROC4_COMPOUND
,
2700 vfs_context_thread(ctx
), vfs_context_ucred(ctx
), &si
, 0, NULL
, &req
);
2702 error
= nfs_request_async_finish(req
, &nmrep
, &xid
, &status
);
2704 nfsm_chain_skip_tag(error
, &nmrep
);
2705 nfsm_chain_get_32(error
, &nmrep
, numops
);
2706 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_PUTFH
);
2707 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_GETATTR
);
2709 NFS_CLEAR_ATTRIBUTES(nmp
->nm_fsattr
.nfsa_bitmap
);
2710 error
= nfs4_parsefattr(&nmrep
, &nmp
->nm_fsattr
, &nvattr
, NULL
, NULL
, NULL
);
2712 if (NMFLAG(nmp
, NAMEDATTR
)) {
2713 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_OPENATTR
);
2714 if (error
== ENOENT
) {
2717 /* [sigh] some implementations return "illegal" error for unsupported ops */
2718 if (error
|| !NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_supp_attr
, NFS_FATTR_NAMED_ATTR
)) {
2719 nmp
->nm_fsattr
.nfsa_flags
&= ~NFS_FSFLAG_NAMED_ATTR
;
2721 nmp
->nm_fsattr
.nfsa_flags
|= NFS_FSFLAG_NAMED_ATTR
;
2724 nmp
->nm_fsattr
.nfsa_flags
&= ~NFS_FSFLAG_NAMED_ATTR
;
2726 if (NMFLAG(nmp
, NOACL
)) { /* make sure ACL support is turned off */
2727 nmp
->nm_fsattr
.nfsa_flags
&= ~NFS_FSFLAG_ACL
;
2729 if (NMFLAG(nmp
, ACLONLY
) && !(nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_ACL
)) {
2730 NFS_BITMAP_CLR(nmp
->nm_flags
, NFS_MFLAG_ACLONLY
);
2732 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_supp_attr
, NFS_FATTR_FH_EXPIRE_TYPE
)) {
2733 uint32_t fhtype
= ((nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_FHTYPE_MASK
) >> NFS_FSFLAG_FHTYPE_SHIFT
);
2734 if (fhtype
!= NFS_FH_PERSISTENT
) {
2735 printf("nfs: warning: non-persistent file handles! for %s\n", vfs_statfs(nmp
->nm_mountp
)->f_mntfromname
);
2739 /* make sure it's a directory */
2740 if (!NFS_BITMAP_ISSET(&nvattr
.nva_bitmap
, NFS_FATTR_TYPE
) || (nvattr
.nva_type
!= VDIR
)) {
2745 /* save the NFS fsid */
2746 nmp
->nm_fsid
= nvattr
.nva_fsid
;
2748 /* create the root node */
2749 error
= nfs_nget(nmp
->nm_mountp
, NULL
, NULL
, dirfh
.fh_data
, dirfh
.fh_len
, &nvattr
, &xid
, rq
.r_auth
, NG_MARKROOT
, npp
);
2752 if (nmp
->nm_fsattr
.nfsa_flags
& NFS_FSFLAG_ACL
) {
2753 vfs_setextendedsecurity(nmp
->nm_mountp
);
2756 /* adjust I/O sizes to server limits */
2757 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_MAXREAD
) && (nmp
->nm_fsattr
.nfsa_maxread
> 0)) {
2758 if (nmp
->nm_fsattr
.nfsa_maxread
< (uint64_t)nmp
->nm_rsize
) {
2759 nmp
->nm_rsize
= nmp
->nm_fsattr
.nfsa_maxread
& ~(NFS_FABLKSIZE
- 1);
2760 if (nmp
->nm_rsize
== 0) {
2761 nmp
->nm_rsize
= nmp
->nm_fsattr
.nfsa_maxread
;
2765 if (NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_bitmap
, NFS_FATTR_MAXWRITE
) && (nmp
->nm_fsattr
.nfsa_maxwrite
> 0)) {
2766 if (nmp
->nm_fsattr
.nfsa_maxwrite
< (uint64_t)nmp
->nm_wsize
) {
2767 nmp
->nm_wsize
= nmp
->nm_fsattr
.nfsa_maxwrite
& ~(NFS_FABLKSIZE
- 1);
2768 if (nmp
->nm_wsize
== 0) {
2769 nmp
->nm_wsize
= nmp
->nm_fsattr
.nfsa_maxwrite
;
2774 /* set up lease renew timer */
2775 nmp
->nm_renew_timer
= thread_call_allocate(nfs4_renew_timer
, nmp
);
2776 interval
= nmp
->nm_fsattr
.nfsa_lease
/ 2;
2780 nfs_interval_timer_start(nmp
->nm_renew_timer
, interval
* 1000);
2783 if (fspath
.np_components
) {
2784 for (comp
= 0; comp
< fspath
.np_compcount
; comp
++) {
2785 if (fspath
.np_components
[comp
]) {
2786 FREE(fspath
.np_components
[comp
], M_TEMP
);
2789 FREE(fspath
.np_components
, M_TEMP
);
2791 NVATTR_CLEANUP(&nvattr
);
2792 nfs_fs_locations_cleanup(&nfsls
);
2794 nfs_node_unlock(*npp
);
2796 nfsm_chain_cleanup(&nmreq
);
2797 nfsm_chain_cleanup(&nmrep
);
2800 #endif /* CONFIG_NFS4 */
2803 * Thread to handle initial NFS mount connection.
2806 nfs_mount_connect_thread(void *arg
, __unused wait_result_t wr
)
2808 struct nfsmount
*nmp
= arg
;
2809 int error
= 0, savederror
= 0, slpflag
= (NMFLAG(nmp
, INTR
) ? PCATCH
: 0);
2810 int done
= 0, timeo
, tries
, maxtries
;
2812 if (NM_OMFLAG(nmp
, MNTQUICK
)) {
2820 for (tries
= 0; tries
< maxtries
; tries
++) {
2821 error
= nfs_connect(nmp
, 1, timeo
);
2838 /* just keep retrying on any of these errors */
2842 /* looks like we got an answer... */
2847 /* save the best error */
2848 if (nfs_connect_error_class(error
) >= nfs_connect_error_class(savederror
)) {
2856 /* pause before next attempt */
2857 if ((error
= nfs_sigintr(nmp
, NULL
, current_thread(), 0))) {
2860 error
= tsleep(nmp
, PSOCK
| slpflag
, "nfs_mount_connect_retry", 2 * hz
);
2861 if (error
&& (error
!= EWOULDBLOCK
)) {
2867 /* update status of mount connect */
2868 lck_mtx_lock(&nmp
->nm_lock
);
2869 if (!nmp
->nm_mounterror
) {
2870 nmp
->nm_mounterror
= error
;
2872 nmp
->nm_state
&= ~NFSSTA_MOUNT_THREAD
;
2873 lck_mtx_unlock(&nmp
->nm_lock
);
2874 wakeup(&nmp
->nm_nss
);
2878 nfs_mount_connect(struct nfsmount
*nmp
)
2880 int error
= 0, slpflag
;
2882 struct timespec ts
= { .tv_sec
= 2, .tv_nsec
= 0 };
2885 * Set up the socket. Perform initial search for a location/server/address to
2886 * connect to and negotiate any unspecified mount parameters. This work is
2887 * done on a kernel thread to satisfy reserved port usage needs.
2889 slpflag
= NMFLAG(nmp
, INTR
) ? PCATCH
: 0;
2890 lck_mtx_lock(&nmp
->nm_lock
);
2891 /* set flag that the thread is running */
2892 nmp
->nm_state
|= NFSSTA_MOUNT_THREAD
;
2893 if (kernel_thread_start(nfs_mount_connect_thread
, nmp
, &thd
) != KERN_SUCCESS
) {
2894 nmp
->nm_state
&= ~NFSSTA_MOUNT_THREAD
;
2895 nmp
->nm_mounterror
= EIO
;
2896 printf("nfs mount %s start socket connect thread failed\n", vfs_statfs(nmp
->nm_mountp
)->f_mntfromname
);
2898 thread_deallocate(thd
);
2901 /* wait until mount connect thread is finished/gone */
2902 while (nmp
->nm_state
& NFSSTA_MOUNT_THREAD
) {
2903 error
= msleep(&nmp
->nm_nss
, &nmp
->nm_lock
, slpflag
| PSOCK
, "nfsconnectthread", &ts
);
2904 if ((error
&& (error
!= EWOULDBLOCK
)) || ((error
= nfs_sigintr(nmp
, NULL
, current_thread(), 1)))) {
2906 if (!nmp
->nm_mounterror
) {
2907 nmp
->nm_mounterror
= error
;
2909 /* signal the thread that we are aborting */
2910 nmp
->nm_sockflags
|= NMSOCK_UNMOUNT
;
2912 wakeup(nmp
->nm_nss
);
2914 /* and continue waiting on it to finish */
2918 lck_mtx_unlock(&nmp
->nm_lock
);
2920 /* grab mount connect status */
2921 error
= nmp
->nm_mounterror
;
2926 /* Table of maximum minor version for a given version */
2927 uint32_t maxminorverstab
[] = {
2928 0, /* Version 0 (does not exist) */
2929 0, /* Version 1 (does not exist) */
2935 #define NFS_MAX_SUPPORTED_VERSION ((long)(sizeof (maxminorverstab) / sizeof (uint32_t) - 1))
2936 #define NFS_MAX_SUPPORTED_MINOR_VERSION(v) ((long)(maxminorverstab[(v)]))
2938 #define DEFAULT_NFS_MIN_VERS VER2PVER(2, 0)
2939 #define DEFAULT_NFS_MAX_VERS VER2PVER(3, 0)
2942 * Common code to mount an NFS file system.
2951 struct nfsmount
*nmp
;
2954 struct vfsstatfs
*sbp
;
2956 uint32_t i
, val
, maxio
, iosize
, len
;
2958 uint32_t *mflags_mask
;
2960 uint32_t argslength
, attrslength
;
2962 struct nfs_location_index firstloc
= {
2963 .nli_flags
= NLI_VALID
,
2968 static const struct nfs_etype nfs_default_etypes
= {
2969 .count
= NFS_MAX_ETYPES
,
2970 .selected
= NFS_MAX_ETYPES
,
2971 .etypes
= { NFS_AES256_CTS_HMAC_SHA1_96
,
2972 NFS_AES128_CTS_HMAC_SHA1_96
,
2973 NFS_DES3_CBC_SHA1_KD
}
2976 /* make sure mbuf constants are set up */
2977 if (!nfs_mbuf_mhlen
) {
2981 if (vfs_flags(mp
) & MNT_UPDATE
) {
2983 /* update paths, file handles, etc, here XXX */
2987 /* allocate an NFS mount structure for this mount */
2988 MALLOC_ZONE(nmp
, struct nfsmount
*,
2989 sizeof(struct nfsmount
), M_NFSMNT
, M_WAITOK
);
2994 bzero((caddr_t
)nmp
, sizeof(struct nfsmount
));
2995 lck_mtx_init(&nmp
->nm_lock
, nfs_mount_grp
, LCK_ATTR_NULL
);
2996 TAILQ_INIT(&nmp
->nm_resendq
);
2997 TAILQ_INIT(&nmp
->nm_iodq
);
2998 TAILQ_INIT(&nmp
->nm_gsscl
);
2999 LIST_INIT(&nmp
->nm_monlist
);
3000 vfs_setfsprivate(mp
, nmp
);
3002 nmp
->nm_mountp
= mp
;
3003 vfs_setauthopaque(mp
);
3005 * Disable cache_lookup_path for NFS. NFS lookup always needs
3006 * to be called to check if the directory attribute cache is
3007 * valid and possibly purge the directory before calling
3010 vfs_setauthcache_ttl(mp
, 0);
3012 nfs_nhinit_finish();
3014 nmp
->nm_args
= xdrbuf
;
3016 /* set up defaults */
3019 nmp
->nm_min_vers
= DEFAULT_NFS_MIN_VERS
;
3020 nmp
->nm_max_vers
= DEFAULT_NFS_MAX_VERS
;
3021 nmp
->nm_timeo
= NFS_TIMEO
;
3022 nmp
->nm_retry
= NFS_RETRANS
;
3024 nmp
->nm_sofamily
= 0;
3025 nmp
->nm_nfsport
= 0;
3026 nmp
->nm_wsize
= NFS_WSIZE
;
3027 nmp
->nm_rsize
= NFS_RSIZE
;
3028 nmp
->nm_readdirsize
= NFS_READDIRSIZE
;
3029 nmp
->nm_numgrps
= NFS_MAXGRPS
;
3030 nmp
->nm_readahead
= NFS_DEFRAHEAD
;
3031 nmp
->nm_tprintf_delay
= nfs_tprintf_delay
;
3032 if (nmp
->nm_tprintf_delay
< 0) {
3033 nmp
->nm_tprintf_delay
= 0;
3035 nmp
->nm_tprintf_initial_delay
= nfs_tprintf_initial_delay
;
3036 if (nmp
->nm_tprintf_initial_delay
< 0) {
3037 nmp
->nm_tprintf_initial_delay
= 0;
3039 nmp
->nm_acregmin
= NFS_MINATTRTIMO
;
3040 nmp
->nm_acregmax
= NFS_MAXATTRTIMO
;
3041 nmp
->nm_acdirmin
= NFS_MINDIRATTRTIMO
;
3042 nmp
->nm_acdirmax
= NFS_MAXDIRATTRTIMO
;
3043 nmp
->nm_etype
= nfs_default_etypes
;
3044 nmp
->nm_auth
= RPCAUTH_SYS
;
3045 nmp
->nm_iodlink
.tqe_next
= NFSNOLIST
;
3046 nmp
->nm_deadtimeout
= 0;
3047 nmp
->nm_curdeadtimeout
= 0;
3048 NFS_BITMAP_SET(nmp
->nm_flags
, NFS_MFLAG_RDIRPLUS
); /* enable RDIRPLUS by default. It will be reverted later in case NFSv2 is used */
3049 NFS_BITMAP_SET(nmp
->nm_flags
, NFS_MFLAG_NOACL
);
3050 nmp
->nm_realm
= NULL
;
3051 nmp
->nm_principal
= NULL
;
3052 nmp
->nm_sprinc
= NULL
;
3055 mattrs
= nmp
->nm_mattrs
;
3056 mflags
= nmp
->nm_mflags
;
3057 mflags_mask
= nmp
->nm_mflags_mask
;
3059 /* set up NFS mount with args */
3060 xb_init_buffer(&xb
, xdrbuf
, 2 * XDRWORD
);
3061 xb_get_32(error
, &xb
, val
); /* version */
3062 xb_get_32(error
, &xb
, argslength
); /* args length */
3064 xb_init_buffer(&xb
, xdrbuf
, argslength
); /* restart parsing with actual buffer length */
3065 xb_get_32(error
, &xb
, val
); /* version */
3066 xb_get_32(error
, &xb
, argslength
); /* args length */
3067 xb_get_32(error
, &xb
, val
); /* XDR args version */
3068 if (val
!= NFS_XDRARGS_VERSION_0
|| argslength
< ((4 + NFS_MATTR_BITMAP_LEN
+ 1) * XDRWORD
)) {
3071 len
= NFS_MATTR_BITMAP_LEN
;
3072 xb_get_bitmap(error
, &xb
, mattrs
, len
); /* mount attribute bitmap */
3074 xb_get_32(error
, &xb
, attrslength
); /* attrs length */
3075 if (!error
&& (attrslength
> (argslength
- ((4 + NFS_MATTR_BITMAP_LEN
+ 1) * XDRWORD
)))) {
3079 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_FLAGS
)) {
3080 len
= NFS_MFLAG_BITMAP_LEN
;
3081 xb_get_bitmap(error
, &xb
, mflags_mask
, len
); /* mount flag mask */
3082 len
= NFS_MFLAG_BITMAP_LEN
;
3083 xb_get_bitmap(error
, &xb
, mflags
, len
); /* mount flag values */
3085 /* clear all mask bits and OR in all the ones that are set */
3086 nmp
->nm_flags
[0] &= ~mflags_mask
[0];
3087 nmp
->nm_flags
[0] |= (mflags_mask
[0] & mflags
[0]);
3090 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_VERSION
)) {
3091 /* Can't specify a single version and a range */
3092 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_VERSION_RANGE
)) {
3095 xb_get_32(error
, &xb
, nmp
->nm_vers
);
3096 if (nmp
->nm_vers
> NFS_MAX_SUPPORTED_VERSION
||
3097 nmp
->nm_vers
< NFS_VER2
) {
3100 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_MINOR_VERSION
)) {
3101 xb_get_32(error
, &xb
, nmp
->nm_minor_vers
);
3103 nmp
->nm_minor_vers
= maxminorverstab
[nmp
->nm_vers
];
3105 if (nmp
->nm_minor_vers
> maxminorverstab
[nmp
->nm_vers
]) {
3108 nmp
->nm_max_vers
= nmp
->nm_min_vers
=
3109 VER2PVER(nmp
->nm_vers
, nmp
->nm_minor_vers
);
3111 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_MINOR_VERSION
)) {
3112 /* should have also gotten NFS version (and already gotten minor version) */
3113 if (!NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_VERSION
)) {
3117 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_VERSION_RANGE
)) {
3118 xb_get_32(error
, &xb
, nmp
->nm_min_vers
);
3119 xb_get_32(error
, &xb
, nmp
->nm_max_vers
);
3120 if ((nmp
->nm_min_vers
> nmp
->nm_max_vers
) ||
3121 (PVER2MAJOR(nmp
->nm_max_vers
) > NFS_MAX_SUPPORTED_VERSION
) ||
3122 (PVER2MINOR(nmp
->nm_min_vers
) > maxminorverstab
[PVER2MAJOR(nmp
->nm_min_vers
)]) ||
3123 (PVER2MINOR(nmp
->nm_max_vers
) > maxminorverstab
[PVER2MAJOR(nmp
->nm_max_vers
)])) {
3127 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READ_SIZE
)) {
3128 xb_get_32(error
, &xb
, nmp
->nm_rsize
);
3130 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_WRITE_SIZE
)) {
3131 xb_get_32(error
, &xb
, nmp
->nm_wsize
);
3133 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READDIR_SIZE
)) {
3134 xb_get_32(error
, &xb
, nmp
->nm_readdirsize
);
3136 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READAHEAD
)) {
3137 xb_get_32(error
, &xb
, nmp
->nm_readahead
);
3139 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MIN
)) {
3140 xb_get_32(error
, &xb
, nmp
->nm_acregmin
);
3141 xb_skip(error
, &xb
, XDRWORD
);
3143 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MAX
)) {
3144 xb_get_32(error
, &xb
, nmp
->nm_acregmax
);
3145 xb_skip(error
, &xb
, XDRWORD
);
3147 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MIN
)) {
3148 xb_get_32(error
, &xb
, nmp
->nm_acdirmin
);
3149 xb_skip(error
, &xb
, XDRWORD
);
3151 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MAX
)) {
3152 xb_get_32(error
, &xb
, nmp
->nm_acdirmax
);
3153 xb_skip(error
, &xb
, XDRWORD
);
3156 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCK_MODE
)) {
3157 xb_get_32(error
, &xb
, val
);
3159 case NFS_LOCK_MODE_DISABLED
:
3160 case NFS_LOCK_MODE_LOCAL
:
3162 if (nmp
->nm_vers
>= NFS_VER4
) {
3163 /* disabled/local lock mode only allowed on v2/v3 */
3169 case NFS_LOCK_MODE_ENABLED
:
3170 nmp
->nm_lockmode
= val
;
3177 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SECURITY
)) {
3179 xb_get_32(error
, &xb
, seccnt
);
3180 if (!error
&& ((seccnt
< 1) || (seccnt
> NX_MAX_SEC_FLAVORS
))) {
3184 nmp
->nm_sec
.count
= seccnt
;
3185 for (i
= 0; i
< seccnt
; i
++) {
3186 xb_get_32(error
, &xb
, nmp
->nm_sec
.flavors
[i
]);
3187 /* Check for valid security flavor */
3188 switch (nmp
->nm_sec
.flavors
[i
]) {
3199 /* start with the first flavor */
3200 nmp
->nm_auth
= nmp
->nm_sec
.flavors
[0];
3202 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_KERB_ETYPE
)) {
3204 xb_get_32(error
, &xb
, etypecnt
);
3205 if (!error
&& ((etypecnt
< 1) || (etypecnt
> NFS_MAX_ETYPES
))) {
3209 nmp
->nm_etype
.count
= etypecnt
;
3210 xb_get_32(error
, &xb
, nmp
->nm_etype
.selected
);
3213 nmp
->nm_etype
.selected
= etypecnt
; /* Nothing is selected yet, so set selected to count */
3214 for (i
= 0; i
< etypecnt
; i
++) {
3215 xb_get_32(error
, &xb
, nmp
->nm_etype
.etypes
[i
]);
3216 /* Check for valid encryption type */
3217 switch (nmp
->nm_etype
.etypes
[i
]) {
3218 case NFS_DES3_CBC_SHA1_KD
:
3219 case NFS_AES128_CTS_HMAC_SHA1_96
:
3220 case NFS_AES256_CTS_HMAC_SHA1_96
:
3228 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MAX_GROUP_LIST
)) {
3229 xb_get_32(error
, &xb
, nmp
->nm_numgrps
);
3231 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SOCKET_TYPE
)) {
3235 xb_get_32(error
, &xb
, val
);
3236 if (!error
&& ((val
< 3) || (val
> sizeof(sotype
)))) {
3240 error
= xb_get_bytes(&xb
, sotype
, val
, 0);
3243 if (!strcmp(sotype
, "tcp")) {
3244 nmp
->nm_sotype
= SOCK_STREAM
;
3245 } else if (!strcmp(sotype
, "udp")) {
3246 nmp
->nm_sotype
= SOCK_DGRAM
;
3247 } else if (!strcmp(sotype
, "tcp4")) {
3248 nmp
->nm_sotype
= SOCK_STREAM
;
3249 nmp
->nm_sofamily
= AF_INET
;
3250 } else if (!strcmp(sotype
, "udp4")) {
3251 nmp
->nm_sotype
= SOCK_DGRAM
;
3252 nmp
->nm_sofamily
= AF_INET
;
3253 } else if (!strcmp(sotype
, "tcp6")) {
3254 nmp
->nm_sotype
= SOCK_STREAM
;
3255 nmp
->nm_sofamily
= AF_INET6
;
3256 } else if (!strcmp(sotype
, "udp6")) {
3257 nmp
->nm_sotype
= SOCK_DGRAM
;
3258 nmp
->nm_sofamily
= AF_INET6
;
3259 } else if (!strcmp(sotype
, "inet4")) {
3260 nmp
->nm_sofamily
= AF_INET
;
3261 } else if (!strcmp(sotype
, "inet6")) {
3262 nmp
->nm_sofamily
= AF_INET6
;
3263 } else if (!strcmp(sotype
, "inet")) {
3264 nmp
->nm_sofamily
= 0; /* ok */
3265 } else if (!strcmp(sotype
, "ticotsord")) {
3266 nmp
->nm_sofamily
= AF_LOCAL
;
3267 nmp
->nm_sotype
= SOCK_STREAM
;
3268 } else if (!strcmp(sotype
, "ticlts")) {
3269 nmp
->nm_sofamily
= AF_LOCAL
;
3270 nmp
->nm_sotype
= SOCK_DGRAM
;
3275 if (!error
&& (nmp
->nm_vers
>= NFS_VER4
) && nmp
->nm_sotype
&&
3276 (nmp
->nm_sotype
!= SOCK_STREAM
)) {
3277 error
= EINVAL
; /* NFSv4 is only allowed over TCP. */
3281 NFS_VFS_DBG("EINVAL sotype = \"%s\"\n", sotype
);
3285 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_PORT
)) {
3286 xb_get_32(error
, &xb
, nmp
->nm_nfsport
);
3288 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MOUNT_PORT
)) {
3289 xb_get_32(error
, &xb
, nmp
->nm_mountport
);
3291 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_REQUEST_TIMEOUT
)) {
3292 /* convert from time to 0.1s units */
3293 xb_get_32(error
, &xb
, nmp
->nm_timeo
);
3294 xb_get_32(error
, &xb
, val
);
3296 if (val
>= 1000000000) {
3300 nmp
->nm_timeo
*= 10;
3301 nmp
->nm_timeo
+= (val
+ 100000000 - 1) / 100000000;
3302 /* now convert to ticks */
3303 nmp
->nm_timeo
= (nmp
->nm_timeo
* NFS_HZ
+ 5) / 10;
3305 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SOFT_RETRY_COUNT
)) {
3306 xb_get_32(error
, &xb
, val
);
3307 if (!error
&& (val
> 1)) {
3308 nmp
->nm_retry
= val
;
3311 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_DEAD_TIMEOUT
)) {
3312 xb_get_32(error
, &xb
, nmp
->nm_deadtimeout
);
3313 xb_skip(error
, &xb
, XDRWORD
);
3315 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_FH
)) {
3317 MALLOC(nmp
->nm_fh
, fhandle_t
*, sizeof(fhandle_t
), M_TEMP
, M_WAITOK
| M_ZERO
);
3321 xb_get_32(error
, &xb
, nmp
->nm_fh
->fh_len
);
3323 if ((size_t)nmp
->nm_fh
->fh_len
> sizeof(nmp
->nm_fh
->fh_data
)) {
3326 error
= xb_get_bytes(&xb
, (char*)&nmp
->nm_fh
->fh_data
[0], nmp
->nm_fh
->fh_len
, 0);
3330 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_FS_LOCATIONS
)) {
3331 uint32_t loc
, serv
, addr
, comp
;
3332 struct nfs_fs_location
*fsl
;
3333 struct nfs_fs_server
*fss
;
3334 struct nfs_fs_path
*fsp
;
3336 xb_get_32(error
, &xb
, nmp
->nm_locations
.nl_numlocs
); /* fs location count */
3337 /* sanity check location count */
3338 if (!error
&& ((nmp
->nm_locations
.nl_numlocs
< 1) || (nmp
->nm_locations
.nl_numlocs
> 256))) {
3339 NFS_VFS_DBG("Invalid number of fs_locations: %d", nmp
->nm_locations
.nl_numlocs
);
3343 MALLOC(nmp
->nm_locations
.nl_locations
, struct nfs_fs_location
**, nmp
->nm_locations
.nl_numlocs
* sizeof(struct nfs_fs_location
*), M_TEMP
, M_WAITOK
| M_ZERO
);
3344 if (!nmp
->nm_locations
.nl_locations
) {
3347 for (loc
= 0; loc
< nmp
->nm_locations
.nl_numlocs
; loc
++) {
3349 MALLOC(fsl
, struct nfs_fs_location
*, sizeof(struct nfs_fs_location
), M_TEMP
, M_WAITOK
| M_ZERO
);
3353 nmp
->nm_locations
.nl_locations
[loc
] = fsl
;
3354 xb_get_32(error
, &xb
, fsl
->nl_servcount
); /* server count */
3355 /* sanity check server count */
3356 if (!error
&& ((fsl
->nl_servcount
< 1) || (fsl
->nl_servcount
> 256))) {
3357 NFS_VFS_DBG("Invalid server count %d", fsl
->nl_servcount
);
3361 MALLOC(fsl
->nl_servers
, struct nfs_fs_server
**, fsl
->nl_servcount
* sizeof(struct nfs_fs_server
*), M_TEMP
, M_WAITOK
| M_ZERO
);
3362 if (!fsl
->nl_servers
) {
3364 NFS_VFS_DBG("Server count = %d, error = %d\n", fsl
->nl_servcount
, error
);
3366 for (serv
= 0; serv
< fsl
->nl_servcount
; serv
++) {
3368 MALLOC(fss
, struct nfs_fs_server
*, sizeof(struct nfs_fs_server
), M_TEMP
, M_WAITOK
| M_ZERO
);
3372 fsl
->nl_servers
[serv
] = fss
;
3373 xb_get_32(error
, &xb
, val
); /* server name length */
3374 /* sanity check server name length */
3375 if (!error
&& (val
> MAXPATHLEN
)) {
3376 NFS_VFS_DBG("Invalid server name length %d", val
);
3380 MALLOC(fss
->ns_name
, char *, val
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
3381 if (!fss
->ns_name
) {
3385 error
= xb_get_bytes(&xb
, fss
->ns_name
, val
, 0); /* server name */
3386 xb_get_32(error
, &xb
, fss
->ns_addrcount
); /* address count */
3387 /* sanity check address count (OK to be zero) */
3388 if (!error
&& (fss
->ns_addrcount
> 256)) {
3389 NFS_VFS_DBG("Invalid address count %d", fss
->ns_addrcount
);
3393 if (fss
->ns_addrcount
> 0) {
3394 MALLOC(fss
->ns_addresses
, char **, fss
->ns_addrcount
* sizeof(char *), M_TEMP
, M_WAITOK
| M_ZERO
);
3395 if (!fss
->ns_addresses
) {
3398 for (addr
= 0; addr
< fss
->ns_addrcount
; addr
++) {
3399 xb_get_32(error
, &xb
, val
); /* address length */
3400 /* sanity check address length */
3401 if (!error
&& val
> 128) {
3402 NFS_VFS_DBG("Invalid address length %d", val
);
3406 MALLOC(fss
->ns_addresses
[addr
], char *, val
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
3407 if (!fss
->ns_addresses
[addr
]) {
3411 error
= xb_get_bytes(&xb
, fss
->ns_addresses
[addr
], val
, 0); /* address */
3414 xb_get_32(error
, &xb
, val
); /* server info length */
3415 xb_skip(error
, &xb
, val
); /* skip server info */
3418 fsp
= &fsl
->nl_path
;
3419 xb_get_32(error
, &xb
, fsp
->np_compcount
); /* component count */
3420 /* sanity check component count */
3421 if (!error
&& (fsp
->np_compcount
> MAXPATHLEN
)) {
3422 NFS_VFS_DBG("Invalid component count %d", fsp
->np_compcount
);
3426 if (fsp
->np_compcount
) {
3427 MALLOC(fsp
->np_components
, char **, fsp
->np_compcount
* sizeof(char*), M_TEMP
, M_WAITOK
| M_ZERO
);
3428 if (!fsp
->np_components
) {
3432 for (comp
= 0; comp
< fsp
->np_compcount
; comp
++) {
3433 xb_get_32(error
, &xb
, val
); /* component length */
3434 /* sanity check component length */
3435 if (!error
&& (val
== 0)) {
3437 * Apparently some people think a path with zero components should
3438 * be encoded with one zero-length component. So, just ignore any
3439 * zero length components.
3442 fsp
->np_compcount
--;
3443 if (fsp
->np_compcount
== 0) {
3444 FREE(fsp
->np_components
, M_TEMP
);
3445 fsp
->np_components
= NULL
;
3449 if (!error
&& ((val
< 1) || (val
> MAXPATHLEN
))) {
3450 NFS_VFS_DBG("Invalid component path length %d", val
);
3454 MALLOC(fsp
->np_components
[comp
], char *, val
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
3455 if (!fsp
->np_components
[comp
]) {
3459 error
= xb_get_bytes(&xb
, fsp
->np_components
[comp
], val
, 0); /* component */
3461 xb_get_32(error
, &xb
, val
); /* fs location info length */
3462 NFS_VFS_DBG("Skipping fs location info bytes %d", val
);
3463 xb_skip(error
, &xb
, xdr_rndup(val
)); /* skip fs location info */
3466 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MNTFLAGS
)) {
3467 xb_skip(error
, &xb
, XDRWORD
);
3469 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MNTFROM
)) {
3470 xb_get_32(error
, &xb
, len
);
3473 if (val
>= sizeof(vfs_statfs(mp
)->f_mntfromname
)) {
3474 val
= sizeof(vfs_statfs(mp
)->f_mntfromname
) - 1;
3476 error
= xb_get_bytes(&xb
, vfs_statfs(mp
)->f_mntfromname
, val
, 0);
3477 if ((len
- val
) > 0) {
3478 xb_skip(error
, &xb
, len
- val
);
3481 vfs_statfs(mp
)->f_mntfromname
[val
] = '\0';
3485 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_REALM
)) {
3486 xb_get_32(error
, &xb
, len
);
3487 if (!error
&& ((len
< 1) || (len
> MAXPATHLEN
))) {
3491 /* allocate an extra byte for a leading '@' if its not already prepended to the realm */
3492 MALLOC(nmp
->nm_realm
, char *, len
+ 2, M_TEMP
, M_WAITOK
| M_ZERO
);
3493 if (!nmp
->nm_realm
) {
3497 error
= xb_get_bytes(&xb
, nmp
->nm_realm
, len
, 0);
3498 if (error
== 0 && *nmp
->nm_realm
!= '@') {
3499 bcopy(nmp
->nm_realm
, &nmp
->nm_realm
[1], len
);
3500 nmp
->nm_realm
[0] = '@';
3505 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_PRINCIPAL
)) {
3506 xb_get_32(error
, &xb
, len
);
3507 if (!error
&& ((len
< 1) || (len
> MAXPATHLEN
))) {
3511 MALLOC(nmp
->nm_principal
, char *, len
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
3512 if (!nmp
->nm_principal
) {
3516 error
= xb_get_bytes(&xb
, nmp
->nm_principal
, len
, 0);
3520 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SVCPRINCIPAL
)) {
3521 xb_get_32(error
, &xb
, len
);
3522 if (!error
&& ((len
< 1) || (len
> MAXPATHLEN
))) {
3526 MALLOC(nmp
->nm_sprinc
, char *, len
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
3527 if (!nmp
->nm_sprinc
) {
3531 error
= xb_get_bytes(&xb
, nmp
->nm_sprinc
, len
, 0);
3535 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCAL_NFS_PORT
)) {
3536 if (nmp
->nm_nfsport
) {
3538 NFS_VFS_DBG("Can't have ports specified over incompatible socket families");
3541 xb_get_32(error
, &xb
, len
);
3542 if (!error
&& ((len
< 1) || (len
> sizeof(((struct sockaddr_un
*)0)->sun_path
)))) {
3546 MALLOC(nmp
->nm_nfs_localport
, char *, len
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
3547 if (!nmp
->nm_nfs_localport
) {
3551 error
= xb_get_bytes(&xb
, nmp
->nm_nfs_localport
, len
, 0);
3552 nmp
->nm_sofamily
= AF_LOCAL
;
3553 nmp
->nm_nfsport
= 1; /* We use the now deprecated tpcmux port to indcate that we have an AF_LOCAL port */
3554 NFS_VFS_DBG("Setting nfs local port %s (%d)\n", nmp
->nm_nfs_localport
, nmp
->nm_nfsport
);
3556 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCAL_MOUNT_PORT
)) {
3557 if (nmp
->nm_mountport
) {
3559 NFS_VFS_DBG("Can't have ports specified over mulitple socket families");
3562 xb_get_32(error
, &xb
, len
);
3563 if (!error
&& ((len
< 1) || (len
> sizeof(((struct sockaddr_un
*)0)->sun_path
)))) {
3567 MALLOC(nmp
->nm_mount_localport
, char *, len
+ 1, M_TEMP
, M_WAITOK
| M_ZERO
);
3568 if (!nmp
->nm_mount_localport
) {
3572 error
= xb_get_bytes(&xb
, nmp
->nm_mount_localport
, len
, 0);
3573 nmp
->nm_sofamily
= AF_LOCAL
;
3574 nmp
->nm_mountport
= 1; /* We use the now deprecated tpcmux port to indcate that we have an AF_LOCAL port */
3575 NFS_VFS_DBG("Setting mount local port %s (%d)\n", nmp
->nm_mount_localport
, nmp
->nm_mountport
);
3577 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SET_MOUNT_OWNER
)) {
3578 xb_get_32(error
, &xb
, set_owner
);
3580 error
= vfs_context_suser(ctx
);
3582 * root can set owner to whatever, user can set owner to self
3584 if ((error
) && (set_owner
== kauth_cred_getuid(vfs_context_ucred(ctx
)))) {
3585 /* ok for non-root can set owner to self */
3592 * Sanity check/finalize settings.
3595 if (nmp
->nm_timeo
< NFS_MINTIMEO
) {
3596 nmp
->nm_timeo
= NFS_MINTIMEO
;
3597 } else if (nmp
->nm_timeo
> NFS_MAXTIMEO
) {
3598 nmp
->nm_timeo
= NFS_MAXTIMEO
;
3600 if (nmp
->nm_retry
> NFS_MAXREXMIT
) {
3601 nmp
->nm_retry
= NFS_MAXREXMIT
;
3604 if (nmp
->nm_numgrps
> NFS_MAXGRPS
) {
3605 nmp
->nm_numgrps
= NFS_MAXGRPS
;
3607 if (nmp
->nm_readahead
> NFS_MAXRAHEAD
) {
3608 nmp
->nm_readahead
= NFS_MAXRAHEAD
;
3610 if (nmp
->nm_acregmin
> nmp
->nm_acregmax
) {
3611 nmp
->nm_acregmin
= nmp
->nm_acregmax
;
3613 if (nmp
->nm_acdirmin
> nmp
->nm_acdirmax
) {
3614 nmp
->nm_acdirmin
= nmp
->nm_acdirmax
;
3617 /* need at least one fs location */
3618 if (nmp
->nm_locations
.nl_numlocs
< 1) {
3623 if (!NM_OMATTR_GIVEN(nmp
, MNTFROM
)) {
3624 /* init mount's mntfromname to first location */
3625 nfs_location_mntfromname(&nmp
->nm_locations
, firstloc
,
3626 vfs_statfs(mp
)->f_mntfromname
,
3627 sizeof(vfs_statfs(mp
)->f_mntfromname
), 0);
3630 /* Need to save the mounting credential for v4. */
3631 nmp
->nm_mcred
= vfs_context_ucred(ctx
);
3632 if (IS_VALID_CRED(nmp
->nm_mcred
)) {
3633 kauth_cred_ref(nmp
->nm_mcred
);
3637 * If a reserved port is required, check for that privilege.
3638 * (Note that mirror mounts are exempt because the privilege was
3639 * already checked for the original mount.)
3641 if (NMFLAG(nmp
, RESVPORT
) && !vfs_iskernelmount(mp
)) {
3642 error
= priv_check_cred(nmp
->nm_mcred
, PRIV_NETINET_RESERVEDPORT
, 0);
3646 /* set up the version-specific function tables */
3647 if (nmp
->nm_vers
< NFS_VER4
) {
3648 nmp
->nm_funcs
= &nfs3_funcs
;
3651 nmp
->nm_funcs
= &nfs4_funcs
;
3653 /* don't go any further if we don't support NFS4 */
3654 nmp
->nm_funcs
= NULL
;
3660 /* do mount's initial socket connection */
3661 error
= nfs_mount_connect(nmp
);
3664 /* sanity check settings now that version/connection is set */
3665 if (nmp
->nm_vers
== NFS_VER2
) { /* ignore RDIRPLUS on NFSv2 */
3666 NFS_BITMAP_CLR(nmp
->nm_flags
, NFS_MFLAG_RDIRPLUS
);
3669 if (nmp
->nm_vers
>= NFS_VER4
) {
3670 if (NFS_BITMAP_ISSET(nmp
->nm_flags
, NFS_MFLAG_ACLONLY
)) { /* aclonly trumps noacl */
3671 NFS_BITMAP_CLR(nmp
->nm_flags
, NFS_MFLAG_NOACL
);
3673 NFS_BITMAP_CLR(nmp
->nm_flags
, NFS_MFLAG_CALLUMNT
);
3674 if (nmp
->nm_lockmode
!= NFS_LOCK_MODE_ENABLED
) {
3675 error
= EINVAL
; /* disabled/local lock mode only allowed on v2/v3 */
3679 /* ignore these if not v4 */
3680 NFS_BITMAP_CLR(nmp
->nm_flags
, NFS_MFLAG_NOCALLBACK
);
3681 NFS_BITMAP_CLR(nmp
->nm_flags
, NFS_MFLAG_NAMEDATTR
);
3682 NFS_BITMAP_CLR(nmp
->nm_flags
, NFS_MFLAG_NOACL
);
3683 NFS_BITMAP_CLR(nmp
->nm_flags
, NFS_MFLAG_ACLONLY
);
3689 if (nmp
->nm_sotype
== SOCK_DGRAM
) {
3690 /* I/O size defaults for UDP are different */
3691 if (!NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READ_SIZE
)) {
3692 nmp
->nm_rsize
= NFS_DGRAM_RSIZE
;
3694 if (!NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_WRITE_SIZE
)) {
3695 nmp
->nm_wsize
= NFS_DGRAM_WSIZE
;
3699 /* round down I/O sizes to multiple of NFS_FABLKSIZE */
3700 nmp
->nm_rsize
&= ~(NFS_FABLKSIZE
- 1);
3701 if (nmp
->nm_rsize
<= 0) {
3702 nmp
->nm_rsize
= NFS_FABLKSIZE
;
3704 nmp
->nm_wsize
&= ~(NFS_FABLKSIZE
- 1);
3705 if (nmp
->nm_wsize
<= 0) {
3706 nmp
->nm_wsize
= NFS_FABLKSIZE
;
3709 /* and limit I/O sizes to maximum allowed */
3710 maxio
= (nmp
->nm_vers
== NFS_VER2
) ? NFS_V2MAXDATA
:
3711 (nmp
->nm_sotype
== SOCK_DGRAM
) ? NFS_MAXDGRAMDATA
: NFS_MAXDATA
;
3712 if (maxio
> NFS_MAXBSIZE
) {
3713 maxio
= NFS_MAXBSIZE
;
3715 if (nmp
->nm_rsize
> maxio
) {
3716 nmp
->nm_rsize
= maxio
;
3718 if (nmp
->nm_wsize
> maxio
) {
3719 nmp
->nm_wsize
= maxio
;
3722 if (nmp
->nm_readdirsize
> maxio
) {
3723 nmp
->nm_readdirsize
= maxio
;
3725 if (nmp
->nm_readdirsize
> nmp
->nm_rsize
) {
3726 nmp
->nm_readdirsize
= nmp
->nm_rsize
;
3729 /* Set up the sockets and related info */
3730 if (nmp
->nm_sotype
== SOCK_DGRAM
) {
3731 TAILQ_INIT(&nmp
->nm_cwndq
);
3734 if (nmp
->nm_saddr
->sa_family
== AF_LOCAL
) {
3735 struct sockaddr_un
*un
= (struct sockaddr_un
*)nmp
->nm_saddr
;
3737 int n
= snprintf(vfs_statfs(mp
)->f_mntfromname
, sizeof(vfs_statfs(mp
)->f_mntfromname
), "<%s>:", un
->sun_path
);
3739 if (n
> 0 && (size_t)n
< sizeof(vfs_statfs(mp
)->f_mntfromname
)) {
3740 size
= sizeof(vfs_statfs(mp
)->f_mntfromname
) - n
;
3741 nfs_location_mntfromname(&nmp
->nm_locations
, firstloc
,
3742 &vfs_statfs(mp
)->f_mntfromname
[n
], size
, 1);
3748 * Get the root node/attributes from the NFS server and
3749 * do any basic, version-specific setup.
3751 error
= nmp
->nm_funcs
->nf_mount(nmp
, ctx
, &np
);
3755 * A reference count is needed on the node representing the
3756 * remote root. If this object is not persistent, then backward
3757 * traversals of the mount point (i.e. "..") will not work if
3758 * the node gets flushed out of the cache.
3764 /* get usecount and drop iocount */
3765 error
= vnode_ref(*vpp
);
3768 vnode_recycle(*vpp
);
3773 * Do statfs to ensure static info gets set to reasonable values.
3775 if ((error
= nmp
->nm_funcs
->nf_update_statfs(nmp
, ctx
))) {
3776 int error2
= vnode_getwithref(*vpp
);
3781 vnode_recycle(*vpp
);
3784 sbp
= vfs_statfs(mp
);
3785 sbp
->f_bsize
= nmp
->nm_fsattr
.nfsa_bsize
;
3786 sbp
->f_blocks
= nmp
->nm_fsattr
.nfsa_space_total
/ sbp
->f_bsize
;
3787 sbp
->f_bfree
= nmp
->nm_fsattr
.nfsa_space_free
/ sbp
->f_bsize
;
3788 sbp
->f_bavail
= nmp
->nm_fsattr
.nfsa_space_avail
/ sbp
->f_bsize
;
3789 sbp
->f_bused
= (nmp
->nm_fsattr
.nfsa_space_total
/ sbp
->f_bsize
) -
3790 (nmp
->nm_fsattr
.nfsa_space_free
/ sbp
->f_bsize
);
3791 sbp
->f_files
= nmp
->nm_fsattr
.nfsa_files_total
;
3792 sbp
->f_ffree
= nmp
->nm_fsattr
.nfsa_files_free
;
3793 sbp
->f_iosize
= nfs_iosize
;
3795 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SET_MOUNT_OWNER
)) {
3796 sbp
->f_owner
= set_owner
;
3800 * Calculate the size used for I/O buffers. Use the larger
3801 * of the two sizes to minimise NFS requests but make sure
3802 * that it is at least one VM page to avoid wasting buffer
3803 * space and to allow easy mmapping of I/O buffers.
3804 * The read/write RPC calls handle the splitting up of
3805 * buffers into multiple requests if the buffer size is
3806 * larger than the I/O size.
3808 iosize
= max(nmp
->nm_rsize
, nmp
->nm_wsize
);
3809 if (iosize
< PAGE_SIZE
) {
3812 nmp
->nm_biosize
= trunc_page_32(iosize
);
3814 /* For NFSv3 and greater, there is a (relatively) reliable ACCESS call. */
3815 if (nmp
->nm_vers
> NFS_VER2
&& !NMFLAG(nmp
, NOOPAQUE_AUTH
)
3817 vfs_setauthopaqueaccess(mp
);
3820 switch (nmp
->nm_lockmode
) {
3821 case NFS_LOCK_MODE_DISABLED
:
3823 case NFS_LOCK_MODE_LOCAL
:
3824 vfs_setlocklocal(nmp
->nm_mountp
);
3826 case NFS_LOCK_MODE_ENABLED
:
3828 if (nmp
->nm_vers
<= NFS_VER3
) {
3829 nfs_lockd_mount_register(nmp
);
3836 lck_mtx_lock(&nmp
->nm_lock
);
3837 nmp
->nm_state
|= NFSSTA_MOUNTED
;
3838 lck_mtx_unlock(&nmp
->nm_lock
);
3841 nfs_mount_drain_and_cleanup(nmp
);
3848 * We've detected a file system boundary on the server and
3849 * need to mount a new file system so that our file systems
3850 * MIRROR the file systems on the server.
3852 * Build the mount arguments for the new mount and call kernel_mount().
3855 nfs_mirror_mount_domount(vnode_t dvp
, vnode_t vp
, vfs_context_t ctx
)
3857 nfsnode_t np
= VTONFS(vp
);
3859 nfsnode_t dnp
= VTONFS(dvp
);
3861 struct nfsmount
*nmp
= NFSTONMP(np
);
3862 char fstype
[MFSTYPENAMELEN
], *mntfromname
= NULL
, *path
= NULL
, *relpath
, *p
, *cp
;
3863 int error
= 0, pathbuflen
= MAXPATHLEN
, i
, mntflags
= 0, referral
, skipcopy
= 0;
3865 struct xdrbuf xb
, xbnew
;
3866 uint32_t mattrs
[NFS_MATTR_BITMAP_LEN
];
3867 uint32_t newmattrs
[NFS_MATTR_BITMAP_LEN
];
3868 uint32_t newmflags
[NFS_MFLAG_BITMAP_LEN
];
3869 uint32_t newmflags_mask
[NFS_MFLAG_BITMAP_LEN
];
3870 uint32_t argslength
= 0, val
, count
, mlen
, mlen2
, rlen
, relpathcomps
;
3871 uint32_t argslength_offset
, attrslength_offset
, end_offset
;
3872 uint32_t numlocs
, loc
, numserv
, serv
, numaddr
, addr
, numcomp
, comp
;
3874 struct nfs_fs_locations nfsls
;
3876 referral
= (np
->n_vattr
.nva_flags
& NFS_FFLAG_TRIGGER_REFERRAL
);
3878 bzero(&nfsls
, sizeof(nfsls
));
3881 xb_init(&xbnew
, XDRBUF_NONE
);
3883 if (!nmp
|| (nmp
->nm_state
& (NFSSTA_FORCE
| NFSSTA_DEAD
))) {
3887 /* allocate a couple path buffers we need */
3888 MALLOC_ZONE(mntfromname
, char *, pathbuflen
, M_NAMEI
, M_WAITOK
);
3893 MALLOC_ZONE(path
, char *, pathbuflen
, M_NAMEI
, M_WAITOK
);
3899 /* get the path for the directory being mounted on */
3900 error
= vn_getpath(vp
, path
, &pathbuflen
);
3907 * Set up the mntfromname for the new mount based on the
3908 * current mount's mntfromname and the directory's path
3909 * relative to the current mount's mntonname.
3910 * Set up relpath to point at the relative path on the current mount.
3911 * Also, count the number of components in relpath.
3912 * We'll be adding those to each fs location path in the new args.
3914 nlen
= strlcpy(mntfromname
, vfs_statfs(nmp
->nm_mountp
)->f_mntfromname
, MAXPATHLEN
);
3915 if ((nlen
> 0) && (mntfromname
[nlen
- 1] == '/')) { /* avoid double '/' in new name */
3916 mntfromname
[nlen
- 1] = '\0';
3919 relpath
= mntfromname
+ nlen
;
3920 nlen
= strlcat(mntfromname
, path
+ strlen(vfs_statfs(nmp
->nm_mountp
)->f_mntonname
), MAXPATHLEN
);
3921 if (nlen
>= MAXPATHLEN
) {
3922 error
= ENAMETOOLONG
;
3925 /* count the number of components in relpath */
3927 while (*p
&& (*p
== '/')) {
3933 while (*p
&& (*p
!= '/')) {
3936 while (*p
&& (*p
== '/')) {
3941 /* grab a copy of the file system type */
3942 vfs_name(vnode_mount(vp
), fstype
);
3944 /* for referrals, fetch the fs locations */
3946 const char *vname
= vnode_getname(NFSTOV(np
));
3952 error
= nfs4_get_fs_locations(nmp
, dnp
, NULL
, 0, vname
, ctx
, &nfsls
);
3953 vnode_putname(vname
);
3954 if (!error
&& (nfsls
.nl_numlocs
< 1)) {
3962 /* set up NFS mount args based on current mount args */
3964 #define xb_copy_32(E, XBSRC, XBDST, V) \
3967 xb_get_32((E), (XBSRC), (V)); \
3968 if (skipcopy) break; \
3969 xb_add_32((E), (XBDST), (V)); \
3971 #define xb_copy_opaque(E, XBSRC, XBDST) \
3973 uint32_t __count, __val; \
3974 xb_copy_32((E), (XBSRC), (XBDST), __count); \
3976 __count = nfsm_rndup(__count); \
3977 __count /= XDRWORD; \
3978 while (__count-- > 0) \
3979 xb_copy_32((E), (XBSRC), (XBDST), __val); \
3982 xb_init_buffer(&xb
, nmp
->nm_args
, 2 * XDRWORD
);
3983 xb_get_32(error
, &xb
, val
); /* version */
3984 xb_get_32(error
, &xb
, argslength
); /* args length */
3985 xb_init_buffer(&xb
, nmp
->nm_args
, argslength
);
3987 xb_init_buffer(&xbnew
, NULL
, 0);
3988 xb_copy_32(error
, &xb
, &xbnew
, val
); /* version */
3989 argslength_offset
= xb_offset(&xbnew
);
3990 xb_copy_32(error
, &xb
, &xbnew
, val
); /* args length */
3991 xb_copy_32(error
, &xb
, &xbnew
, val
); /* XDR args version */
3992 count
= NFS_MATTR_BITMAP_LEN
;
3993 xb_get_bitmap(error
, &xb
, mattrs
, count
); /* mount attribute bitmap */
3995 for (i
= 0; i
< NFS_MATTR_BITMAP_LEN
; i
++) {
3996 newmattrs
[i
] = mattrs
[i
];
3999 NFS_BITMAP_SET(newmattrs
, NFS_MATTR_FS_LOCATIONS
);
4000 NFS_BITMAP_CLR(newmattrs
, NFS_MATTR_MNTFROM
);
4002 NFS_BITMAP_SET(newmattrs
, NFS_MATTR_FH
);
4004 NFS_BITMAP_SET(newmattrs
, NFS_MATTR_FLAGS
);
4005 NFS_BITMAP_SET(newmattrs
, NFS_MATTR_MNTFLAGS
);
4006 NFS_BITMAP_SET(newmattrs
, NFS_MATTR_SET_MOUNT_OWNER
);
4007 xb_add_bitmap(error
, &xbnew
, newmattrs
, NFS_MATTR_BITMAP_LEN
);
4008 attrslength_offset
= xb_offset(&xbnew
);
4009 xb_copy_32(error
, &xb
, &xbnew
, val
); /* attrs length */
4010 NFS_BITMAP_ZERO(newmflags_mask
, NFS_MFLAG_BITMAP_LEN
);
4011 NFS_BITMAP_ZERO(newmflags
, NFS_MFLAG_BITMAP_LEN
);
4012 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_FLAGS
)) {
4013 count
= NFS_MFLAG_BITMAP_LEN
;
4014 xb_get_bitmap(error
, &xb
, newmflags_mask
, count
); /* mount flag mask bitmap */
4015 count
= NFS_MFLAG_BITMAP_LEN
;
4016 xb_get_bitmap(error
, &xb
, newmflags
, count
); /* mount flag bitmap */
4018 NFS_BITMAP_SET(newmflags_mask
, NFS_MFLAG_EPHEMERAL
);
4019 NFS_BITMAP_SET(newmflags
, NFS_MFLAG_EPHEMERAL
);
4020 xb_add_bitmap(error
, &xbnew
, newmflags_mask
, NFS_MFLAG_BITMAP_LEN
);
4021 xb_add_bitmap(error
, &xbnew
, newmflags
, NFS_MFLAG_BITMAP_LEN
);
4022 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_VERSION
)) {
4023 xb_copy_32(error
, &xb
, &xbnew
, val
);
4025 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_MINOR_VERSION
)) {
4026 xb_copy_32(error
, &xb
, &xbnew
, val
);
4028 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_VERSION_RANGE
)) {
4029 xb_copy_32(error
, &xb
, &xbnew
, val
);
4030 xb_copy_32(error
, &xb
, &xbnew
, val
);
4032 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READ_SIZE
)) {
4033 xb_copy_32(error
, &xb
, &xbnew
, val
);
4035 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_WRITE_SIZE
)) {
4036 xb_copy_32(error
, &xb
, &xbnew
, val
);
4038 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READDIR_SIZE
)) {
4039 xb_copy_32(error
, &xb
, &xbnew
, val
);
4041 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_READAHEAD
)) {
4042 xb_copy_32(error
, &xb
, &xbnew
, val
);
4044 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MIN
)) {
4045 xb_copy_32(error
, &xb
, &xbnew
, val
);
4046 xb_copy_32(error
, &xb
, &xbnew
, val
);
4048 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MAX
)) {
4049 xb_copy_32(error
, &xb
, &xbnew
, val
);
4050 xb_copy_32(error
, &xb
, &xbnew
, val
);
4052 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MIN
)) {
4053 xb_copy_32(error
, &xb
, &xbnew
, val
);
4054 xb_copy_32(error
, &xb
, &xbnew
, val
);
4056 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MAX
)) {
4057 xb_copy_32(error
, &xb
, &xbnew
, val
);
4058 xb_copy_32(error
, &xb
, &xbnew
, val
);
4060 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCK_MODE
)) {
4061 xb_copy_32(error
, &xb
, &xbnew
, val
);
4063 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SECURITY
)) {
4064 xb_copy_32(error
, &xb
, &xbnew
, count
);
4065 while (!error
&& (count
-- > 0)) {
4066 xb_copy_32(error
, &xb
, &xbnew
, val
);
4069 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_KERB_ETYPE
)) {
4070 xb_copy_32(error
, &xb
, &xbnew
, count
);
4071 xb_add_32(error
, &xbnew
, -1);
4072 while (!error
&& (count
-- > 0)) {
4073 xb_copy_32(error
, &xb
, &xbnew
, val
);
4076 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MAX_GROUP_LIST
)) {
4077 xb_copy_32(error
, &xb
, &xbnew
, val
);
4079 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SOCKET_TYPE
)) {
4080 xb_copy_opaque(error
, &xb
, &xbnew
);
4082 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_NFS_PORT
)) {
4083 xb_copy_32(error
, &xb
, &xbnew
, val
);
4085 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MOUNT_PORT
)) {
4086 xb_copy_32(error
, &xb
, &xbnew
, val
);
4088 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_REQUEST_TIMEOUT
)) {
4089 xb_copy_32(error
, &xb
, &xbnew
, val
);
4090 xb_copy_32(error
, &xb
, &xbnew
, val
);
4092 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SOFT_RETRY_COUNT
)) {
4093 xb_copy_32(error
, &xb
, &xbnew
, val
);
4095 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_DEAD_TIMEOUT
)) {
4096 xb_copy_32(error
, &xb
, &xbnew
, val
);
4097 xb_copy_32(error
, &xb
, &xbnew
, val
);
4099 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_FH
)) {
4100 xb_get_32(error
, &xb
, count
);
4101 xb_skip(error
, &xb
, count
);
4104 /* set the initial file handle to the directory's file handle */
4105 xb_add_fh(error
, &xbnew
, np
->n_fhp
, np
->n_fhsize
);
4107 /* copy/extend/skip fs locations */
4108 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_FS_LOCATIONS
)) {
4109 numlocs
= numserv
= numaddr
= numcomp
= 0;
4110 if (referral
) { /* don't copy the fs locations for a referral */
4113 xb_copy_32(error
, &xb
, &xbnew
, numlocs
); /* location count */
4114 for (loc
= 0; !error
&& (loc
< numlocs
); loc
++) {
4115 xb_copy_32(error
, &xb
, &xbnew
, numserv
); /* server count */
4116 for (serv
= 0; !error
&& (serv
< numserv
); serv
++) {
4117 xb_copy_opaque(error
, &xb
, &xbnew
); /* server name */
4118 xb_copy_32(error
, &xb
, &xbnew
, numaddr
); /* address count */
4119 for (addr
= 0; !error
&& (addr
< numaddr
); addr
++) {
4120 xb_copy_opaque(error
, &xb
, &xbnew
); /* address */
4122 xb_copy_opaque(error
, &xb
, &xbnew
); /* server info */
4125 xb_get_32(error
, &xb
, numcomp
); /* component count */
4127 uint64_t totalcomps
= numcomp
+ relpathcomps
;
4129 /* set error to ERANGE in the event of overflow */
4130 if (totalcomps
> UINT32_MAX
) {
4131 nfsmerr_if((error
= ERANGE
));
4134 xb_add_32(error
, &xbnew
, (uint32_t) totalcomps
); /* new component count */
4136 for (comp
= 0; !error
&& (comp
< numcomp
); comp
++) {
4137 xb_copy_opaque(error
, &xb
, &xbnew
); /* component */
4139 /* add additional components */
4141 while (*p
&& (*p
== '/')) {
4144 while (*p
&& !error
) {
4146 while (*p
&& (*p
!= '/')) {
4149 xb_add_string(error
, &xbnew
, cp
, (p
- cp
)); /* component */
4150 while (*p
&& (*p
== '/')) {
4154 xb_copy_opaque(error
, &xb
, &xbnew
); /* fs location info */
4161 /* add referral's fs locations */
4162 xb_add_32(error
, &xbnew
, nfsls
.nl_numlocs
); /* FS_LOCATIONS */
4163 for (loc
= 0; !error
&& (loc
< nfsls
.nl_numlocs
); loc
++) {
4164 xb_add_32(error
, &xbnew
, nfsls
.nl_locations
[loc
]->nl_servcount
);
4165 for (serv
= 0; !error
&& (serv
< nfsls
.nl_locations
[loc
]->nl_servcount
); serv
++) {
4166 xb_add_string(error
, &xbnew
, nfsls
.nl_locations
[loc
]->nl_servers
[serv
]->ns_name
,
4167 strlen(nfsls
.nl_locations
[loc
]->nl_servers
[serv
]->ns_name
));
4168 xb_add_32(error
, &xbnew
, nfsls
.nl_locations
[loc
]->nl_servers
[serv
]->ns_addrcount
);
4169 for (addr
= 0; !error
&& (addr
< nfsls
.nl_locations
[loc
]->nl_servers
[serv
]->ns_addrcount
); addr
++) {
4170 xb_add_string(error
, &xbnew
, nfsls
.nl_locations
[loc
]->nl_servers
[serv
]->ns_addresses
[addr
],
4171 strlen(nfsls
.nl_locations
[loc
]->nl_servers
[serv
]->ns_addresses
[addr
]));
4173 xb_add_32(error
, &xbnew
, 0); /* empty server info */
4175 xb_add_32(error
, &xbnew
, nfsls
.nl_locations
[loc
]->nl_path
.np_compcount
);
4176 for (comp
= 0; !error
&& (comp
< nfsls
.nl_locations
[loc
]->nl_path
.np_compcount
); comp
++) {
4177 xb_add_string(error
, &xbnew
, nfsls
.nl_locations
[loc
]->nl_path
.np_components
[comp
],
4178 strlen(nfsls
.nl_locations
[loc
]->nl_path
.np_components
[comp
]));
4180 xb_add_32(error
, &xbnew
, 0); /* empty fs location info */
4183 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MNTFLAGS
)) {
4184 xb_get_32(error
, &xb
, mntflags
);
4187 * We add the following mount flags to the ones for the mounted-on mount:
4188 * MNT_DONTBROWSE - to keep the mount from showing up as a separate volume
4189 * MNT_AUTOMOUNTED - to keep DiskArb from retriggering the mount after
4190 * an unmount (looking for /.autodiskmounted)
4192 mntflags
|= (MNT_AUTOMOUNTED
| MNT_DONTBROWSE
);
4193 xb_add_32(error
, &xbnew
, mntflags
);
4194 if (!referral
&& NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MNTFROM
)) {
4195 /* copy mntfrom string and add relpath */
4196 rlen
= strlen(relpath
);
4197 xb_get_32(error
, &xb
, mlen
);
4199 mlen2
= mlen
+ ((relpath
[0] != '/') ? 1 : 0) + rlen
;
4200 xb_add_32(error
, &xbnew
, mlen2
);
4201 count
= mlen
/ XDRWORD
;
4202 /* copy the original string */
4203 while (count
-- > 0) {
4204 xb_copy_32(error
, &xb
, &xbnew
, val
);
4206 if (!error
&& (mlen
% XDRWORD
)) {
4207 error
= xb_get_bytes(&xb
, buf
, mlen
% XDRWORD
, 0);
4209 error
= xb_add_bytes(&xbnew
, buf
, mlen
% XDRWORD
, 1);
4212 /* insert a '/' if the relative path doesn't start with one */
4213 if (!error
&& (relpath
[0] != '/')) {
4215 error
= xb_add_bytes(&xbnew
, buf
, 1, 1);
4217 /* add the additional relative path */
4219 error
= xb_add_bytes(&xbnew
, relpath
, rlen
, 1);
4221 /* make sure the resulting string has the right number of pad bytes */
4222 if (!error
&& (mlen2
!= nfsm_rndup(mlen2
))) {
4223 bzero(buf
, sizeof(buf
));
4224 count
= nfsm_rndup(mlen2
) - mlen2
;
4225 error
= xb_add_bytes(&xbnew
, buf
, count
, 1);
4229 * The following string copies rely on the fact that we already validated
4230 * these data when creating the initial mount point.
4232 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_REALM
)) {
4233 xb_add_string(error
, &xbnew
, nmp
->nm_realm
, strlen(nmp
->nm_realm
));
4235 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_PRINCIPAL
)) {
4236 xb_add_string(error
, &xbnew
, nmp
->nm_principal
, strlen(nmp
->nm_principal
));
4238 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SVCPRINCIPAL
)) {
4239 xb_add_string(error
, &xbnew
, nmp
->nm_sprinc
, strlen(nmp
->nm_sprinc
));
4241 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCAL_NFS_PORT
)) {
4242 xb_add_string(error
, &xbnew
, nmp
->nm_nfs_localport
, strlen(nmp
->nm_nfs_localport
));
4244 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCAL_MOUNT_PORT
)) {
4245 xb_add_string(error
, &xbnew
, nmp
->nm_mount_localport
, strlen(nmp
->nm_mount_localport
));
4247 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SET_MOUNT_OWNER
)) {
4248 /* drop embedded owner value */
4249 xb_get_32(error
, &xb
, count
);
4251 /* New mount always gets same owner as this mount */
4252 xb_add_32(error
, &xbnew
, vnode_mount(vp
)->mnt_vfsstat
.f_owner
);
4253 xb_build_done(error
, &xbnew
);
4255 /* update opaque counts */
4256 end_offset
= xb_offset(&xbnew
);
4258 error
= xb_seek(&xbnew
, argslength_offset
);
4259 argslength
= end_offset
- argslength_offset
+ XDRWORD
/*version*/;
4260 xb_add_32(error
, &xbnew
, argslength
);
4263 error
= xb_seek(&xbnew
, attrslength_offset
);
4264 xb_add_32(error
, &xbnew
, end_offset
- attrslength_offset
- XDRWORD
/*don't include length field*/);
4269 * For kernel_mount() call, use the existing mount flags (instead of the
4270 * original flags) because flags like MNT_NOSUID and MNT_NODEV may have
4271 * been silently enforced. Also, in terms of MACF, the _kernel_ is
4272 * performing the mount (and enforcing all of the mount options), so we
4273 * use the kernel context for the mount call.
4275 mntflags
= vnode_vfsvisflags(vp
);
4276 mntflags
|= (MNT_AUTOMOUNTED
| MNT_DONTBROWSE
);
4277 ctx
= vfs_context_kernel();
4280 error
= kernel_mount(fstype
, dvp
, vp
, path
, xb_buffer_base(&xbnew
), argslength
,
4281 mntflags
, KERNEL_MOUNT_PERMIT_UNMOUNT
| KERNEL_MOUNT_NOAUTH
, ctx
);
4285 printf("nfs: mirror mount of %s on %s failed (%d)\n",
4286 mntfromname
, path
, error
);
4291 nfs_fs_locations_cleanup(&nfsls
);
4294 FREE_ZONE(path
, MAXPATHLEN
, M_NAMEI
);
4297 FREE_ZONE(mntfromname
, MAXPATHLEN
, M_NAMEI
);
4300 nfs_ephemeral_mount_harvester_start();
4306 * trigger vnode functions
4308 #define NFS_TRIGGER_DEBUG 1
4311 nfs_mirror_mount_trigger_resolve(
4313 const struct componentname
*cnp
,
4314 enum path_operation pop
,
4316 __unused
void *data
,
4319 nfsnode_t np
= VTONFS(vp
);
4320 vnode_t pvp
= NULLVP
;
4323 resolver_result_t result
;
4326 * We have a trigger node that doesn't have anything mounted on it yet.
4327 * We'll do the mount if either:
4328 * (a) this isn't the last component of the path OR
4329 * (b) this is an op that looks like it should trigger the mount.
4331 if (cnp
->cn_flags
& ISLASTCN
) {
4349 /* don't perform the mount for these operations */
4350 result
= vfs_resolver_result(np
->n_trigseq
, RESOLVER_NOCHANGE
, 0);
4351 #ifdef NFS_TRIGGER_DEBUG
4352 NP(np
, "nfs trigger RESOLVE: no change, last %d nameiop %d, seq %d",
4353 (cnp
->cn_flags
& ISLASTCN
) ? 1 : 0, cnp
->cn_nameiop
, np
->n_trigseq
);
4364 case OP_EXCHANGEDATA
:
4368 case OP_REMOVEXATTR
:
4370 /* go ahead and do the mount */
4375 if (vnode_mountedhere(vp
) != NULL
) {
4377 * Um... there's already something mounted.
4378 * Been there. Done that. Let's just say it succeeded.
4384 if ((error
= nfs_node_set_busy(np
, vfs_context_thread(ctx
)))) {
4385 result
= vfs_resolver_result(np
->n_trigseq
, RESOLVER_ERROR
, error
);
4386 #ifdef NFS_TRIGGER_DEBUG
4387 NP(np
, "nfs trigger RESOLVE: busy error %d, last %d nameiop %d, seq %d",
4388 error
, (cnp
->cn_flags
& ISLASTCN
) ? 1 : 0, cnp
->cn_nameiop
, np
->n_trigseq
);
4394 /* Check again, in case the mount happened while we were setting busy */
4395 if (vnode_mountedhere(vp
) != NULL
) {
4396 /* Been there. Done that. Let's just say it succeeded. */
4400 nfs_node_lock_force(np
);
4401 if (np
->n_flag
& NDISARMTRIGGER
) {
4403 nfs_node_unlock(np
);
4406 nfs_node_unlock(np
);
4408 pvp
= vnode_getparent(vp
);
4409 if (pvp
== NULLVP
) {
4413 error
= nfs_mirror_mount_domount(pvp
, vp
, ctx
);
4419 result
= vfs_resolver_result(np
->n_trigseq
, error
? RESOLVER_ERROR
: RESOLVER_RESOLVED
, error
);
4420 #ifdef NFS_TRIGGER_DEBUG
4421 NP(np
, "nfs trigger RESOLVE: %s %d, last %d nameiop %d, seq %d",
4422 error
? "error" : "resolved", error
,
4423 (cnp
->cn_flags
& ISLASTCN
) ? 1 : 0, cnp
->cn_nameiop
, np
->n_trigseq
);
4426 if (pvp
!= NULLVP
) {
4430 nfs_node_clear_busy(np
);
4436 nfs_mirror_mount_trigger_unresolve(
4439 __unused
void *data
,
4442 nfsnode_t np
= VTONFS(vp
);
4445 resolver_result_t result
;
4447 if ((error
= nfs_node_set_busy(np
, vfs_context_thread(ctx
)))) {
4448 result
= vfs_resolver_result(np
->n_trigseq
, RESOLVER_ERROR
, error
);
4449 #ifdef NFS_TRIGGER_DEBUG
4450 NP(np
, "nfs trigger UNRESOLVE: busy error %d, seq %d", error
, np
->n_trigseq
);
4455 mp
= vnode_mountedhere(vp
);
4460 error
= vfs_unmountbyfsid(&(vfs_statfs(mp
)->f_fsid
), flags
, ctx
);
4465 result
= vfs_resolver_result(np
->n_trigseq
, error
? RESOLVER_ERROR
: RESOLVER_UNRESOLVED
, error
);
4466 #ifdef NFS_TRIGGER_DEBUG
4467 NP(np
, "nfs trigger UNRESOLVE: %s %d, seq %d",
4468 error
? "error" : "unresolved", error
, np
->n_trigseq
);
4470 nfs_node_clear_busy(np
);
4475 nfs_mirror_mount_trigger_rearm(
4478 __unused
void *data
,
4481 nfsnode_t np
= VTONFS(vp
);
4483 resolver_result_t result
;
4485 if ((error
= nfs_node_set_busy(np
, vfs_context_thread(ctx
)))) {
4486 result
= vfs_resolver_result(np
->n_trigseq
, RESOLVER_ERROR
, error
);
4487 #ifdef NFS_TRIGGER_DEBUG
4488 NP(np
, "nfs trigger REARM: busy error %d, seq %d", error
, np
->n_trigseq
);
4494 result
= vfs_resolver_result(np
->n_trigseq
,
4495 vnode_mountedhere(vp
) ? RESOLVER_RESOLVED
: RESOLVER_UNRESOLVED
, 0);
4496 #ifdef NFS_TRIGGER_DEBUG
4497 NP(np
, "nfs trigger REARM: %s, seq %d",
4498 vnode_mountedhere(vp
) ? "resolved" : "unresolved", np
->n_trigseq
);
4500 nfs_node_clear_busy(np
);
4505 * Periodically attempt to unmount ephemeral (mirror) mounts in an attempt to limit
4506 * the number of unused mounts.
4509 #define NFS_EPHEMERAL_MOUNT_HARVEST_INTERVAL 120 /* how often the harvester runs */
4510 struct nfs_ephemeral_mount_harvester_info
{
4511 fsid_t fsid
; /* FSID that we need to try to unmount */
4512 uint32_t mountcount
; /* count of ephemeral mounts seen in scan */
4514 /* various globals for the harvester */
4515 static thread_call_t nfs_ephemeral_mount_harvester_timer
= NULL
;
4516 static int nfs_ephemeral_mount_harvester_on
= 0;
4518 kern_return_t
thread_terminate(thread_t
);
4521 nfs_ephemeral_mount_harvester_callback(mount_t mp
, void *arg
)
4523 struct nfs_ephemeral_mount_harvester_info
*hinfo
= arg
;
4524 struct nfsmount
*nmp
;
4527 if (strcmp(mp
->mnt_vfsstat
.f_fstypename
, "nfs")) {
4528 return VFS_RETURNED
;
4531 if (!nmp
|| !NMFLAG(nmp
, EPHEMERAL
)
4533 return VFS_RETURNED
;
4535 hinfo
->mountcount
++;
4537 /* avoid unmounting mounts that have been triggered within the last harvest interval */
4539 if ((nmp
->nm_mounttime
>> 32) > ((uint32_t)now
.tv_sec
- NFS_EPHEMERAL_MOUNT_HARVEST_INTERVAL
)) {
4540 return VFS_RETURNED
;
4543 if (hinfo
->fsid
.val
[0] || hinfo
->fsid
.val
[1]) {
4544 /* attempt to unmount previously-found ephemeral mount */
4545 vfs_unmountbyfsid(&hinfo
->fsid
, 0, vfs_context_kernel());
4546 hinfo
->fsid
.val
[0] = hinfo
->fsid
.val
[1] = 0;
4550 * We can't call unmount here since we hold a mount iter ref
4551 * on mp so save its fsid for the next call iteration to unmount.
4553 hinfo
->fsid
.val
[0] = mp
->mnt_vfsstat
.f_fsid
.val
[0];
4554 hinfo
->fsid
.val
[1] = mp
->mnt_vfsstat
.f_fsid
.val
[1];
4556 return VFS_RETURNED
;
4560 * Spawn a thread to do the ephemeral mount harvesting.
4563 nfs_ephemeral_mount_harvester_timer_func(void)
4567 if (kernel_thread_start(nfs_ephemeral_mount_harvester
, NULL
, &thd
) == KERN_SUCCESS
) {
4568 thread_deallocate(thd
);
4573 * Iterate all mounts looking for NFS ephemeral mounts to try to unmount.
4576 nfs_ephemeral_mount_harvester(__unused
void *arg
, __unused wait_result_t wr
)
4578 struct nfs_ephemeral_mount_harvester_info hinfo
;
4581 hinfo
.mountcount
= 0;
4582 hinfo
.fsid
.val
[0] = hinfo
.fsid
.val
[1] = 0;
4583 vfs_iterate(VFS_ITERATE_TAIL_FIRST
, nfs_ephemeral_mount_harvester_callback
, &hinfo
);
4584 if (hinfo
.fsid
.val
[0] || hinfo
.fsid
.val
[1]) {
4585 /* attempt to unmount last found ephemeral mount */
4586 vfs_unmountbyfsid(&hinfo
.fsid
, 0, vfs_context_kernel());
4589 lck_mtx_lock(nfs_global_mutex
);
4590 if (!hinfo
.mountcount
) {
4591 /* no more ephemeral mounts - don't need timer */
4592 nfs_ephemeral_mount_harvester_on
= 0;
4594 /* re-arm the timer */
4595 clock_interval_to_deadline(NFS_EPHEMERAL_MOUNT_HARVEST_INTERVAL
, NSEC_PER_SEC
, &deadline
);
4596 thread_call_enter_delayed(nfs_ephemeral_mount_harvester_timer
, deadline
);
4597 nfs_ephemeral_mount_harvester_on
= 1;
4599 lck_mtx_unlock(nfs_global_mutex
);
4602 thread_terminate(current_thread());
4606 * Make sure the NFS ephemeral mount harvester timer is running.
4609 nfs_ephemeral_mount_harvester_start(void)
4613 lck_mtx_lock(nfs_global_mutex
);
4614 if (nfs_ephemeral_mount_harvester_on
) {
4615 lck_mtx_unlock(nfs_global_mutex
);
4618 if (nfs_ephemeral_mount_harvester_timer
== NULL
) {
4619 nfs_ephemeral_mount_harvester_timer
= thread_call_allocate((thread_call_func_t
)nfs_ephemeral_mount_harvester_timer_func
, NULL
);
4621 clock_interval_to_deadline(NFS_EPHEMERAL_MOUNT_HARVEST_INTERVAL
, NSEC_PER_SEC
, &deadline
);
4622 thread_call_enter_delayed(nfs_ephemeral_mount_harvester_timer
, deadline
);
4623 nfs_ephemeral_mount_harvester_on
= 1;
4624 lck_mtx_unlock(nfs_global_mutex
);
4630 * Send a MOUNT protocol MOUNT request to the server to get the initial file handle (and security).
4633 nfs3_mount_rpc(struct nfsmount
*nmp
, struct sockaddr
*sa
, int sotype
, int nfsvers
, char *path
, vfs_context_t ctx
, int timeo
, fhandle_t
*fh
, struct nfs_sec
*sec
)
4635 int error
= 0, slen
, mntproto
;
4636 thread_t thd
= vfs_context_thread(ctx
);
4637 kauth_cred_t cred
= vfs_context_ucred(ctx
);
4639 struct nfsm_chain nmreq
, nmrep
;
4641 uint32_t mntvers
, mntport
, val
;
4642 struct sockaddr_storage ss
;
4643 struct sockaddr
*saddr
= (struct sockaddr
*)&ss
;
4644 struct sockaddr_un
*sun
= (struct sockaddr_un
*)saddr
;
4646 nfsm_chain_null(&nmreq
);
4647 nfsm_chain_null(&nmrep
);
4649 mntvers
= (nfsvers
== NFS_VER2
) ? RPCMNT_VER1
: RPCMNT_VER3
;
4650 mntproto
= (NM_OMFLAG(nmp
, MNTUDP
) || (sotype
== SOCK_DGRAM
)) ? IPPROTO_UDP
: IPPROTO_TCP
;
4653 bcopy(sa
, saddr
, min(sizeof(ss
), sa
->sa_len
));
4654 if (saddr
->sa_family
== AF_INET
) {
4655 if (nmp
->nm_mountport
) {
4656 ((struct sockaddr_in
*)saddr
)->sin_port
= htons(nmp
->nm_mountport
);
4658 mntport
= ntohs(((struct sockaddr_in
*)saddr
)->sin_port
);
4659 } else if (saddr
->sa_family
== AF_INET6
) {
4660 if (nmp
->nm_mountport
) {
4661 ((struct sockaddr_in6
*)saddr
)->sin6_port
= htons(nmp
->nm_mountport
);
4663 mntport
= ntohs(((struct sockaddr_in6
*)saddr
)->sin6_port
);
4664 } else { /* Local domain socket */
4665 mntport
= ((struct sockaddr_un
*)saddr
)->sun_path
[0]; /* Do we have and address? */
4666 mntproto
= IPPROTO_TCP
; /* XXX rpcbind only listens on streams sockets for now */
4670 error
= nfs_portmap_lookup(nmp
, ctx
, saddr
, NULL
, RPCPROG_MNT
, mntvers
,
4671 mntproto
== IPPROTO_UDP
? SOCK_DGRAM
: SOCK_STREAM
, timeo
);
4673 if (saddr
->sa_family
== AF_INET
) {
4674 mntport
= ntohs(((struct sockaddr_in
*)saddr
)->sin_port
);
4675 } else if (saddr
->sa_family
== AF_INET6
) {
4676 mntport
= ntohs(((struct sockaddr_in6
*)saddr
)->sin6_port
);
4677 } else if (saddr
->sa_family
== AF_LOCAL
) {
4678 mntport
= ((struct sockaddr_un
*)saddr
)->sun_path
[0];
4681 /* if not found and TCP, then retry with UDP */
4682 if (mntproto
== IPPROTO_UDP
) {
4683 error
= EPROGUNAVAIL
;
4686 mntproto
= IPPROTO_UDP
;
4687 bcopy(sa
, saddr
, min(sizeof(ss
), sa
->sa_len
));
4688 if (saddr
->sa_family
== AF_LOCAL
) {
4689 strlcpy(sun
->sun_path
, RPCB_TICLTS_PATH
, sizeof(sun
->sun_path
));
4693 nfsmout_if(error
|| !mntport
);
4695 /* MOUNT protocol MOUNT request */
4696 slen
= strlen(path
);
4697 nfsm_chain_build_alloc_init(error
, &nmreq
, NFSX_UNSIGNED
+ nfsm_rndup(slen
));
4698 nfsm_chain_add_name(error
, &nmreq
, path
, slen
, nmp
);
4699 nfsm_chain_build_done(error
, &nmreq
);
4701 error
= nfsm_rpchead2(nmp
, (mntproto
== IPPROTO_UDP
) ? SOCK_DGRAM
: SOCK_STREAM
,
4702 RPCPROG_MNT
, mntvers
, RPCMNT_MOUNT
,
4703 RPCAUTH_SYS
, cred
, NULL
, nmreq
.nmc_mhead
, &xid
, &mreq
);
4705 nmreq
.nmc_mhead
= NULL
;
4706 error
= nfs_aux_request(nmp
, thd
, saddr
, NULL
,
4707 ((mntproto
== IPPROTO_UDP
) ? SOCK_DGRAM
: SOCK_STREAM
),
4708 mreq
, R_XID32(xid
), 1, timeo
, &nmrep
);
4710 nfsm_chain_get_32(error
, &nmrep
, val
);
4711 if (!error
&& val
) {
4714 nfsm_chain_get_fh(error
, &nmrep
, nfsvers
, fh
);
4715 if (!error
&& (nfsvers
> NFS_VER2
)) {
4716 sec
->count
= NX_MAX_SEC_FLAVORS
;
4717 error
= nfsm_chain_get_secinfo(&nmrep
, &sec
->flavors
[0], &sec
->count
);
4720 nfsm_chain_cleanup(&nmreq
);
4721 nfsm_chain_cleanup(&nmrep
);
4727 * Send a MOUNT protocol UNMOUNT request to tell the server we've unmounted it.
4730 nfs3_umount_rpc(struct nfsmount
*nmp
, vfs_context_t ctx
, int timeo
)
4732 int error
= 0, slen
, mntproto
;
4733 thread_t thd
= vfs_context_thread(ctx
);
4734 kauth_cred_t cred
= vfs_context_ucred(ctx
);
4737 struct nfsm_chain nmreq
, nmrep
;
4739 uint32_t mntvers
, mntport
;
4740 struct sockaddr_storage ss
;
4741 struct sockaddr
*saddr
= (struct sockaddr
*)&ss
;
4743 if (!nmp
->nm_saddr
) {
4747 nfsm_chain_null(&nmreq
);
4748 nfsm_chain_null(&nmrep
);
4750 mntvers
= (nmp
->nm_vers
== NFS_VER2
) ? RPCMNT_VER1
: RPCMNT_VER3
;
4751 mntproto
= (NM_OMFLAG(nmp
, MNTUDP
) || (nmp
->nm_sotype
== SOCK_DGRAM
)) ? IPPROTO_UDP
: IPPROTO_TCP
;
4752 mntport
= nmp
->nm_mountport
;
4754 bcopy(nmp
->nm_saddr
, saddr
, min(sizeof(ss
), nmp
->nm_saddr
->sa_len
));
4755 if (saddr
->sa_family
== AF_INET
) {
4756 ((struct sockaddr_in
*)saddr
)->sin_port
= htons(mntport
);
4757 } else if (saddr
->sa_family
== AF_INET6
) {
4758 ((struct sockaddr_in6
*)saddr
)->sin6_port
= htons(mntport
);
4759 } else { /* Local domain socket */
4760 mntport
= ((struct sockaddr_un
*)saddr
)->sun_path
[0]; /* Do we have and address? */
4764 error
= nfs_portmap_lookup(nmp
, ctx
, saddr
, NULL
, RPCPROG_MNT
, mntvers
, mntproto
, timeo
);
4766 if (saddr
->sa_family
== AF_INET
) {
4767 mntport
= ntohs(((struct sockaddr_in
*)saddr
)->sin_port
);
4768 } else if (saddr
->sa_family
== AF_INET6
) {
4769 mntport
= ntohs(((struct sockaddr_in6
*)saddr
)->sin6_port
);
4770 } else { /* Local domain socket */
4771 mntport
= ((struct sockaddr_un
*)saddr
)->sun_path
[0]; /* Do we have and address? */
4773 /* if not found and mntvers > VER1, then retry with VER1 */
4775 if (mntvers
> RPCMNT_VER1
) {
4776 mntvers
= RPCMNT_VER1
;
4777 } else if (mntproto
== IPPROTO_TCP
) {
4778 mntproto
= IPPROTO_UDP
;
4779 mntvers
= (nmp
->nm_vers
== NFS_VER2
) ? RPCMNT_VER1
: RPCMNT_VER3
;
4783 bcopy(nmp
->nm_saddr
, saddr
, min(sizeof(ss
), nmp
->nm_saddr
->sa_len
));
4786 nfsmout_if(!mntport
);
4788 /* MOUNT protocol UNMOUNT request */
4789 path
= &vfs_statfs(nmp
->nm_mountp
)->f_mntfromname
[0];
4790 while (*path
&& (*path
!= '/')) {
4793 slen
= strlen(path
);
4794 nfsm_chain_build_alloc_init(error
, &nmreq
, NFSX_UNSIGNED
+ nfsm_rndup(slen
));
4795 nfsm_chain_add_name(error
, &nmreq
, path
, slen
, nmp
);
4796 nfsm_chain_build_done(error
, &nmreq
);
4798 error
= nfsm_rpchead2(nmp
, (mntproto
== IPPROTO_UDP
) ? SOCK_DGRAM
: SOCK_STREAM
,
4799 RPCPROG_MNT
, RPCMNT_VER1
, RPCMNT_UMOUNT
,
4800 RPCAUTH_SYS
, cred
, NULL
, nmreq
.nmc_mhead
, &xid
, &mreq
);
4802 nmreq
.nmc_mhead
= NULL
;
4803 error
= nfs_aux_request(nmp
, thd
, saddr
, NULL
,
4804 ((mntproto
== IPPROTO_UDP
) ? SOCK_DGRAM
: SOCK_STREAM
),
4805 mreq
, R_XID32(xid
), 1, timeo
, &nmrep
);
4807 nfsm_chain_cleanup(&nmreq
);
4808 nfsm_chain_cleanup(&nmrep
);
4812 * unmount system call
4818 __unused vfs_context_t ctx
)
4820 struct nfsmount
*nmp
;
4822 int error
, flags
= 0;
4823 struct timespec ts
= { .tv_sec
= 1, .tv_nsec
= 0 };
4826 lck_mtx_lock(&nmp
->nm_lock
);
4828 * Set the flag indicating that an unmount attempt is in progress.
4830 nmp
->nm_state
|= NFSSTA_UNMOUNTING
;
4832 * During a force unmount we want to...
4833 * Mark that we are doing a force unmount.
4834 * Make the mountpoint soft.
4836 if (mntflags
& MNT_FORCE
) {
4837 flags
|= FORCECLOSE
;
4838 nmp
->nm_state
|= NFSSTA_FORCE
;
4839 NFS_BITMAP_SET(nmp
->nm_flags
, NFS_MFLAG_SOFT
);
4842 * Wait for any in-progress monitored node scan to complete.
4844 while (nmp
->nm_state
& NFSSTA_MONITOR_SCAN
) {
4845 msleep(&nmp
->nm_state
, &nmp
->nm_lock
, PZERO
- 1, "nfswaitmonscan", &ts
);
4848 * Goes something like this..
4849 * - Call vflush() to clear out vnodes for this file system,
4850 * except for the swap files. Deal with them in 2nd pass.
4851 * - Decrement reference on the vnode representing remote root.
4852 * - Clean up the NFS mount structure.
4854 vp
= NFSTOV(nmp
->nm_dnp
);
4855 lck_mtx_unlock(&nmp
->nm_lock
);
4858 * vflush will check for busy vnodes on mountpoint.
4859 * Will do the right thing for MNT_FORCE. That is, we should
4860 * not get EBUSY back.
4862 error
= vflush(mp
, vp
, SKIPSWAP
| flags
);
4863 if (mntflags
& MNT_FORCE
) {
4864 error
= vflush(mp
, NULLVP
, flags
); /* locks vp in the process */
4866 if (vnode_isinuse(vp
, 1)) {
4869 error
= vflush(mp
, vp
, flags
);
4873 lck_mtx_lock(&nmp
->nm_lock
);
4874 nmp
->nm_state
&= ~NFSSTA_UNMOUNTING
;
4875 lck_mtx_unlock(&nmp
->nm_lock
);
4879 lck_mtx_lock(&nmp
->nm_lock
);
4881 lck_mtx_unlock(&nmp
->nm_lock
);
4884 * Release the root vnode reference held by mountnfs()
4886 error
= vnode_get(vp
);
4892 vflush(mp
, NULLVP
, FORCECLOSE
);
4894 /* Wait for all other references to be released and free the mount */
4895 nfs_mount_drain_and_cleanup(nmp
);
4901 * cleanup/destroy NFS fs locations structure
4904 nfs_fs_locations_cleanup(struct nfs_fs_locations
*nfslsp
)
4906 struct nfs_fs_location
*fsl
;
4907 struct nfs_fs_server
*fss
;
4908 struct nfs_fs_path
*fsp
;
4909 uint32_t loc
, serv
, addr
, comp
;
4911 /* free up fs locations */
4912 if (!nfslsp
->nl_numlocs
|| !nfslsp
->nl_locations
) {
4916 for (loc
= 0; loc
< nfslsp
->nl_numlocs
; loc
++) {
4917 fsl
= nfslsp
->nl_locations
[loc
];
4921 if ((fsl
->nl_servcount
> 0) && fsl
->nl_servers
) {
4922 for (serv
= 0; serv
< fsl
->nl_servcount
; serv
++) {
4923 fss
= fsl
->nl_servers
[serv
];
4927 if ((fss
->ns_addrcount
> 0) && fss
->ns_addresses
) {
4928 for (addr
= 0; addr
< fss
->ns_addrcount
; addr
++) {
4929 FREE(fss
->ns_addresses
[addr
], M_TEMP
);
4931 FREE(fss
->ns_addresses
, M_TEMP
);
4933 FREE(fss
->ns_name
, M_TEMP
);
4936 FREE(fsl
->nl_servers
, M_TEMP
);
4938 fsp
= &fsl
->nl_path
;
4939 if (fsp
->np_compcount
&& fsp
->np_components
) {
4940 for (comp
= 0; comp
< fsp
->np_compcount
; comp
++) {
4941 if (fsp
->np_components
[comp
]) {
4942 FREE(fsp
->np_components
[comp
], M_TEMP
);
4945 FREE(fsp
->np_components
, M_TEMP
);
4949 FREE(nfslsp
->nl_locations
, M_TEMP
);
4950 nfslsp
->nl_numlocs
= 0;
4951 nfslsp
->nl_locations
= NULL
;
4955 nfs_mount_rele(struct nfsmount
*nmp
)
4959 lck_mtx_lock(&nmp
->nm_lock
);
4960 if (nmp
->nm_ref
< 1) {
4961 panic("nfs zombie mount underflow\n");
4964 if (nmp
->nm_ref
== 0) {
4965 wup
= nmp
->nm_state
& NFSSTA_MOUNT_DRAIN
;
4967 lck_mtx_unlock(&nmp
->nm_lock
);
4969 wakeup(&nmp
->nm_ref
);
4974 nfs_mount_drain_and_cleanup(struct nfsmount
*nmp
)
4976 lck_mtx_lock(&nmp
->nm_lock
);
4977 nmp
->nm_state
|= NFSSTA_MOUNT_DRAIN
;
4978 while (nmp
->nm_ref
> 0) {
4979 msleep(&nmp
->nm_ref
, &nmp
->nm_lock
, PZERO
- 1, "nfs_mount_drain", NULL
);
4981 assert(nmp
->nm_ref
== 0);
4982 lck_mtx_unlock(&nmp
->nm_lock
);
4983 nfs_mount_cleanup(nmp
);
4990 nfs_mount_zombie(struct nfsmount
*nmp
, int nm_state_flags
)
4992 struct nfsreq
*req
, *treq
;
4993 struct nfs_reqqhead iodq
, resendq
;
4994 struct timespec ts
= { .tv_sec
= 1, .tv_nsec
= 0 };
4995 struct nfs_open_owner
*noop
, *nextnoop
;
4999 lck_mtx_lock(&nmp
->nm_lock
);
5000 nmp
->nm_state
|= nm_state_flags
;
5002 lck_mtx_unlock(&nmp
->nm_lock
);
5004 /* stop callbacks */
5005 if ((nmp
->nm_vers
>= NFS_VER4
) && !NMFLAG(nmp
, NOCALLBACK
) && nmp
->nm_cbid
) {
5006 nfs4_mount_callback_shutdown(nmp
);
5010 /* Destroy any RPCSEC_GSS contexts */
5011 nfs_gss_clnt_ctx_unmount(nmp
);
5014 /* mark the socket for termination */
5015 lck_mtx_lock(&nmp
->nm_lock
);
5016 nmp
->nm_sockflags
|= NMSOCK_UNMOUNT
;
5018 /* Have the socket thread send the unmount RPC, if requested/appropriate. */
5019 if ((nmp
->nm_vers
< NFS_VER4
) && (nmp
->nm_state
& NFSSTA_MOUNTED
) &&
5020 !(nmp
->nm_state
& (NFSSTA_FORCE
| NFSSTA_DEAD
)) && NMFLAG(nmp
, CALLUMNT
)) {
5021 nfs_mount_sock_thread_wake(nmp
);
5024 /* wait for the socket thread to terminate */
5025 while (nmp
->nm_sockthd
&& current_thread() != nmp
->nm_sockthd
) {
5026 wakeup(&nmp
->nm_sockthd
);
5027 msleep(&nmp
->nm_sockthd
, &nmp
->nm_lock
, PZERO
- 1, "nfswaitsockthd", &ts
);
5029 lck_mtx_unlock(&nmp
->nm_lock
);
5031 /* tear down the socket */
5032 nfs_disconnect(nmp
);
5034 lck_mtx_lock(&nmp
->nm_lock
);
5037 if ((nmp
->nm_vers
>= NFS_VER4
) && !NMFLAG(nmp
, NOCALLBACK
) && nmp
->nm_cbid
) {
5038 /* clear out any pending delegation return requests */
5039 while ((np
= TAILQ_FIRST(&nmp
->nm_dreturnq
))) {
5040 TAILQ_REMOVE(&nmp
->nm_dreturnq
, np
, n_dreturn
);
5041 np
->n_dreturn
.tqe_next
= NFSNOLIST
;
5045 /* cancel any renew timer */
5046 if ((nmp
->nm_vers
>= NFS_VER4
) && nmp
->nm_renew_timer
) {
5047 thread_call_cancel(nmp
->nm_renew_timer
);
5048 thread_call_free(nmp
->nm_renew_timer
);
5049 nmp
->nm_renew_timer
= NULL
;
5052 lck_mtx_unlock(&nmp
->nm_lock
);
5054 if (nmp
->nm_state
& NFSSTA_MOUNTED
) {
5055 switch (nmp
->nm_lockmode
) {
5056 case NFS_LOCK_MODE_DISABLED
:
5057 case NFS_LOCK_MODE_LOCAL
:
5059 case NFS_LOCK_MODE_ENABLED
:
5061 if (nmp
->nm_vers
<= NFS_VER3
) {
5062 nfs_lockd_mount_unregister(nmp
);
5063 nmp
->nm_lockmode
= NFS_LOCK_MODE_DISABLED
;
5070 if ((nmp
->nm_vers
>= NFS_VER4
) && nmp
->nm_longid
) {
5071 /* remove/deallocate the client ID data */
5072 lck_mtx_lock(nfs_global_mutex
);
5073 TAILQ_REMOVE(&nfsclientids
, nmp
->nm_longid
, nci_link
);
5074 if (nmp
->nm_longid
->nci_id
) {
5075 FREE(nmp
->nm_longid
->nci_id
, M_TEMP
);
5077 FREE(nmp
->nm_longid
, M_TEMP
);
5078 nmp
->nm_longid
= NULL
;
5079 lck_mtx_unlock(nfs_global_mutex
);
5083 * Be sure all requests for this mount are completed
5084 * and removed from the resend queue.
5086 TAILQ_INIT(&resendq
);
5087 lck_mtx_lock(nfs_request_mutex
);
5088 TAILQ_FOREACH(req
, &nfs_reqq
, r_chain
) {
5089 if (req
->r_nmp
== nmp
) {
5090 lck_mtx_lock(&req
->r_mtx
);
5091 if (!req
->r_error
&& req
->r_nmrep
.nmc_mhead
== NULL
) {
5094 if (req
->r_flags
& R_RESENDQ
) {
5095 lck_mtx_lock(&nmp
->nm_lock
);
5096 req
->r_flags
&= ~R_RESENDQ
;
5097 if (req
->r_rchain
.tqe_next
!= NFSREQNOLIST
) {
5098 TAILQ_REMOVE(&nmp
->nm_resendq
, req
, r_rchain
);
5100 * Queue up the request so that we can unreference them
5101 * with out holding nfs_request_mutex
5103 TAILQ_INSERT_TAIL(&resendq
, req
, r_rchain
);
5105 lck_mtx_unlock(&nmp
->nm_lock
);
5108 lck_mtx_unlock(&req
->r_mtx
);
5111 lck_mtx_unlock(nfs_request_mutex
);
5113 /* Since we've drop the request mutex we can now safely unreference the request */
5114 TAILQ_FOREACH_SAFE(req
, &resendq
, r_rchain
, treq
) {
5115 TAILQ_REMOVE(&resendq
, req
, r_rchain
);
5116 /* Make sure we don't try and remove again in nfs_request_destroy */
5117 req
->r_rchain
.tqe_next
= NFSREQNOLIST
;
5118 nfs_request_rele(req
);
5122 * Now handle and outstanding async requests. We need to walk the
5123 * request queue again this time with the nfsiod_mutex held. No
5124 * other iods can grab our requests until we've put them on our own
5125 * local iod queue for processing.
5128 lck_mtx_lock(nfs_request_mutex
);
5129 lck_mtx_lock(nfsiod_mutex
);
5130 TAILQ_FOREACH(req
, &nfs_reqq
, r_chain
) {
5131 if (req
->r_nmp
== nmp
) {
5132 lck_mtx_lock(&req
->r_mtx
);
5133 if (req
->r_callback
.rcb_func
5134 && !(req
->r_flags
& R_WAITSENT
) && !(req
->r_flags
& R_IOD
)) {
5136 * Since R_IOD is not set then we need to handle it. If
5137 * we're not on a list add it to our iod queue. Otherwise
5138 * we must already be on nm_iodq which is added to our
5139 * local queue below.
5140 * %%% We should really keep a back pointer to our iod queue
5143 req
->r_flags
|= R_IOD
;
5144 if (req
->r_achain
.tqe_next
== NFSREQNOLIST
) {
5145 TAILQ_INSERT_TAIL(&iodq
, req
, r_achain
);
5148 lck_mtx_unlock(&req
->r_mtx
);
5152 /* finish any async I/O RPCs queued up */
5153 if (nmp
->nm_iodlink
.tqe_next
!= NFSNOLIST
) {
5154 TAILQ_REMOVE(&nfsiodmounts
, nmp
, nm_iodlink
);
5156 TAILQ_CONCAT(&iodq
, &nmp
->nm_iodq
, r_achain
);
5157 lck_mtx_unlock(nfsiod_mutex
);
5158 lck_mtx_unlock(nfs_request_mutex
);
5160 TAILQ_FOREACH_SAFE(req
, &iodq
, r_achain
, treq
) {
5161 TAILQ_REMOVE(&iodq
, req
, r_achain
);
5162 req
->r_achain
.tqe_next
= NFSREQNOLIST
;
5163 lck_mtx_lock(&req
->r_mtx
);
5164 docallback
= !(req
->r_flags
& R_WAITSENT
);
5165 lck_mtx_unlock(&req
->r_mtx
);
5167 req
->r_callback
.rcb_func(req
);
5171 /* clean up common state */
5172 lck_mtx_lock(&nmp
->nm_lock
);
5173 while ((np
= LIST_FIRST(&nmp
->nm_monlist
))) {
5174 LIST_REMOVE(np
, n_monlink
);
5175 np
->n_monlink
.le_next
= NFSNOLIST
;
5177 TAILQ_FOREACH_SAFE(noop
, &nmp
->nm_open_owners
, noo_link
, nextnoop
) {
5178 os_ref_count_t newcount
;
5180 TAILQ_REMOVE(&nmp
->nm_open_owners
, noop
, noo_link
);
5181 noop
->noo_flags
&= ~NFS_OPEN_OWNER_LINK
;
5182 newcount
= os_ref_release_locked(&noop
->noo_refcnt
);
5187 nfs_open_owner_destroy(noop
);
5189 lck_mtx_unlock(&nmp
->nm_lock
);
5192 /* clean up NFSv4 state */
5193 if (nmp
->nm_vers
>= NFS_VER4
) {
5194 lck_mtx_lock(&nmp
->nm_lock
);
5195 while ((np
= TAILQ_FIRST(&nmp
->nm_delegations
))) {
5196 TAILQ_REMOVE(&nmp
->nm_delegations
, np
, n_dlink
);
5197 np
->n_dlink
.tqe_next
= NFSNOLIST
;
5199 lck_mtx_unlock(&nmp
->nm_lock
);
5202 nfs_mount_rele(nmp
);
5206 * cleanup/destroy an nfsmount
5209 nfs_mount_cleanup(struct nfsmount
*nmp
)
5215 nfs_mount_zombie(nmp
, 0);
5217 NFS_VFS_DBG("Unmounting %s from %s\n",
5218 vfs_statfs(nmp
->nm_mountp
)->f_mntfromname
,
5219 vfs_statfs(nmp
->nm_mountp
)->f_mntonname
);
5220 NFS_VFS_DBG("nfs state = 0x%8.8x\n", nmp
->nm_state
);
5221 NFS_VFS_DBG("nfs socket flags = 0x%8.8x\n", nmp
->nm_sockflags
);
5222 NFS_VFS_DBG("nfs mount ref count is %d\n", nmp
->nm_ref
);
5223 NFS_VFS_DBG("mount ref count is %d\n", nmp
->nm_mountp
->mnt_count
);
5225 if (nmp
->nm_mountp
) {
5226 vfs_setfsprivate(nmp
->nm_mountp
, NULL
);
5229 lck_mtx_lock(&nmp
->nm_lock
);
5231 panic("Some one has grabbed a ref %d state flags = 0x%8.8x\n", nmp
->nm_ref
, nmp
->nm_state
);
5234 if (nmp
->nm_saddr
) {
5235 FREE(nmp
->nm_saddr
, M_SONAME
);
5237 if ((nmp
->nm_vers
< NFS_VER4
) && nmp
->nm_rqsaddr
) {
5238 FREE(nmp
->nm_rqsaddr
, M_SONAME
);
5241 if (IS_VALID_CRED(nmp
->nm_mcred
)) {
5242 kauth_cred_unref(&nmp
->nm_mcred
);
5245 nfs_fs_locations_cleanup(&nmp
->nm_locations
);
5247 if (nmp
->nm_realm
) {
5248 FREE(nmp
->nm_realm
, M_TEMP
);
5250 if (nmp
->nm_principal
) {
5251 FREE(nmp
->nm_principal
, M_TEMP
);
5253 if (nmp
->nm_sprinc
) {
5254 FREE(nmp
->nm_sprinc
, M_TEMP
);
5258 xb_free(nmp
->nm_args
);
5261 lck_mtx_unlock(&nmp
->nm_lock
);
5263 lck_mtx_destroy(&nmp
->nm_lock
, nfs_mount_grp
);
5265 FREE(nmp
->nm_fh
, M_TEMP
);
5269 FREE_ZONE(nmp
, sizeof(struct nfsmount
), M_NFSMNT
);
5273 * Return root of a filesystem
5276 nfs_vfs_root(mount_t mp
, vnode_t
*vpp
, __unused vfs_context_t ctx
)
5279 struct nfsmount
*nmp
;
5284 if (!nmp
|| !nmp
->nm_dnp
) {
5287 vp
= NFSTOV(nmp
->nm_dnp
);
5288 vpid
= vnode_vid(vp
);
5289 while ((error
= vnode_getwithvid(vp
, vpid
))) {
5290 /* vnode_get() may return ENOENT if the dir changes. */
5291 /* If that happens, just try it again, else return the error. */
5292 if ((error
!= ENOENT
) || (vnode_vid(vp
) == vpid
)) {
5295 vpid
= vnode_vid(vp
);
5302 * Do operations associated with quotas
5307 __unused mount_t mp
,
5310 __unused caddr_t datap
,
5311 __unused vfs_context_t context
)
5318 nfs_sa_getport(struct sockaddr
*sa
, int *error
)
5322 if (sa
->sa_family
== AF_INET6
) {
5323 port
= ntohs(((struct sockaddr_in6
*)sa
)->sin6_port
);
5324 } else if (sa
->sa_family
== AF_INET
) {
5325 port
= ntohs(((struct sockaddr_in
*)sa
)->sin_port
);
5334 nfs_sa_setport(struct sockaddr
*sa
, int port
)
5336 if (sa
->sa_family
== AF_INET6
) {
5337 ((struct sockaddr_in6
*)sa
)->sin6_port
= htons(port
);
5338 } else if (sa
->sa_family
== AF_INET
) {
5339 ((struct sockaddr_in
*)sa
)->sin_port
= htons(port
);
5344 nfs3_getquota(struct nfsmount
*nmp
, vfs_context_t ctx
, uid_t id
, int type
, struct dqblk
*dqb
)
5346 int error
= 0, slen
, timeo
;
5347 int rqport
= 0, rqproto
, rqvers
= (type
== GRPQUOTA
) ? RPCRQUOTA_EXT_VER
: RPCRQUOTA_VER
;
5348 thread_t thd
= vfs_context_thread(ctx
);
5349 kauth_cred_t cred
= vfs_context_ucred(ctx
);
5352 struct nfsm_chain nmreq
, nmrep
;
5354 uint32_t val
= 0, bsize
= 0;
5355 struct sockaddr
*rqsaddr
;
5357 struct timespec ts
= { .tv_sec
= 1, .tv_nsec
= 0 };
5359 if (!nmp
->nm_saddr
) {
5363 if (NMFLAG(nmp
, NOQUOTA
) || nmp
->nm_saddr
->sa_family
== AF_LOCAL
/* XXX for now */) {
5368 * Allocate an address for rquotad if needed
5370 if (!nmp
->nm_rqsaddr
) {
5373 MALLOC(rqsaddr
, struct sockaddr
*, sizeof(struct sockaddr_storage
), M_SONAME
, M_WAITOK
| M_ZERO
);
5374 bcopy(nmp
->nm_saddr
, rqsaddr
, min(sizeof(struct sockaddr_storage
), nmp
->nm_saddr
->sa_len
));
5375 /* Set the port to zero, will call rpcbind to get the port below */
5376 nfs_sa_setport(rqsaddr
, 0);
5379 lck_mtx_lock(&nmp
->nm_lock
);
5380 if (!nmp
->nm_rqsaddr
) {
5381 nmp
->nm_rqsaddr
= rqsaddr
;
5382 nmp
->nm_rqsaddrstamp
= now
.tv_sec
;
5386 lck_mtx_unlock(&nmp
->nm_lock
);
5388 FREE(rqsaddr
, M_SONAME
);
5392 timeo
= NMFLAG(nmp
, SOFT
) ? 10 : 60;
5393 rqproto
= IPPROTO_UDP
; /* XXX should prefer TCP if mount is TCP */
5395 /* check if we have a recently cached rquota port */
5397 lck_mtx_lock(&nmp
->nm_lock
);
5398 rqsaddr
= nmp
->nm_rqsaddr
;
5399 rqport
= nfs_sa_getport(rqsaddr
, &error
);
5400 while (!error
&& (!rqport
|| ((nmp
->nm_rqsaddrstamp
+ 60) <= (uint32_t)now
.tv_sec
))) {
5401 error
= nfs_sigintr(nmp
, NULL
, thd
, 1);
5403 lck_mtx_unlock(&nmp
->nm_lock
);
5406 if (nmp
->nm_state
& NFSSTA_RQUOTAINPROG
) {
5407 nmp
->nm_state
|= NFSSTA_WANTRQUOTA
;
5408 msleep(&nmp
->nm_rqsaddr
, &nmp
->nm_lock
, PZERO
- 1, "nfswaitrquotaaddr", &ts
);
5409 rqport
= nfs_sa_getport(rqsaddr
, &error
);
5412 nmp
->nm_state
|= NFSSTA_RQUOTAINPROG
;
5413 lck_mtx_unlock(&nmp
->nm_lock
);
5415 /* send portmap request to get rquota port */
5416 error
= nfs_portmap_lookup(nmp
, ctx
, rqsaddr
, NULL
, RPCPROG_RQUOTA
, rqvers
, rqproto
, timeo
);
5420 rqport
= nfs_sa_getport(rqsaddr
, &error
);
5427 * We overload PMAPPORT for the port if rquotad is not
5428 * currently registered or up at the server. In the
5429 * while loop above, port will be set and we will defer
5430 * for a bit. Perhaps the service isn't online yet.
5432 * Note that precludes using indirect, but we're not doing
5436 nfs_sa_setport(rqsaddr
, rqport
);
5439 nmp
->nm_rqsaddrstamp
= now
.tv_sec
;
5441 lck_mtx_lock(&nmp
->nm_lock
);
5442 nmp
->nm_state
&= ~NFSSTA_RQUOTAINPROG
;
5443 if (nmp
->nm_state
& NFSSTA_WANTRQUOTA
) {
5444 nmp
->nm_state
&= ~NFSSTA_WANTRQUOTA
;
5445 wakeup(&nmp
->nm_rqsaddr
);
5448 lck_mtx_unlock(&nmp
->nm_lock
);
5453 /* Using PMAPPORT for unavailabe rquota service */
5454 if (rqport
== PMAPPORT
) {
5458 /* rquota request */
5459 nfsm_chain_null(&nmreq
);
5460 nfsm_chain_null(&nmrep
);
5461 path
= &vfs_statfs(nmp
->nm_mountp
)->f_mntfromname
[0];
5462 while (*path
&& (*path
!= '/')) {
5465 slen
= strlen(path
);
5466 nfsm_chain_build_alloc_init(error
, &nmreq
, 3 * NFSX_UNSIGNED
+ nfsm_rndup(slen
));
5467 nfsm_chain_add_name(error
, &nmreq
, path
, slen
, nmp
);
5468 if (type
== GRPQUOTA
) {
5469 nfsm_chain_add_32(error
, &nmreq
, type
);
5471 nfsm_chain_add_32(error
, &nmreq
, id
);
5472 nfsm_chain_build_done(error
, &nmreq
);
5474 error
= nfsm_rpchead2(nmp
, (rqproto
== IPPROTO_UDP
) ? SOCK_DGRAM
: SOCK_STREAM
,
5475 RPCPROG_RQUOTA
, rqvers
, RPCRQUOTA_GET
,
5476 RPCAUTH_SYS
, cred
, NULL
, nmreq
.nmc_mhead
, &xid
, &mreq
);
5478 nmreq
.nmc_mhead
= NULL
;
5479 error
= nfs_aux_request(nmp
, thd
, rqsaddr
, NULL
,
5480 (rqproto
== IPPROTO_UDP
) ? SOCK_DGRAM
: SOCK_STREAM
,
5481 mreq
, R_XID32(xid
), 0, timeo
, &nmrep
);
5484 /* parse rquota response */
5485 nfsm_chain_get_32(error
, &nmrep
, val
);
5486 if (!error
&& (val
!= RQUOTA_STAT_OK
)) {
5487 if (val
== RQUOTA_STAT_NOQUOTA
) {
5489 } else if (val
== RQUOTA_STAT_EPERM
) {
5495 nfsm_chain_get_32(error
, &nmrep
, bsize
);
5496 nfsm_chain_adv(error
, &nmrep
, NFSX_UNSIGNED
);
5497 nfsm_chain_get_32(error
, &nmrep
, val
);
5499 dqb
->dqb_bhardlimit
= (uint64_t)val
* bsize
;
5500 nfsm_chain_get_32(error
, &nmrep
, val
);
5502 dqb
->dqb_bsoftlimit
= (uint64_t)val
* bsize
;
5503 nfsm_chain_get_32(error
, &nmrep
, val
);
5505 dqb
->dqb_curbytes
= (uint64_t)val
* bsize
;
5506 nfsm_chain_get_32(error
, &nmrep
, dqb
->dqb_ihardlimit
);
5507 nfsm_chain_get_32(error
, &nmrep
, dqb
->dqb_isoftlimit
);
5508 nfsm_chain_get_32(error
, &nmrep
, dqb
->dqb_curinodes
);
5509 nfsm_chain_get_32(error
, &nmrep
, dqb
->dqb_btime
);
5510 nfsm_chain_get_32(error
, &nmrep
, dqb
->dqb_itime
);
5514 nfsm_chain_cleanup(&nmreq
);
5515 nfsm_chain_cleanup(&nmrep
);
5520 nfs4_getquota(struct nfsmount
*nmp
, vfs_context_t ctx
, uid_t id
, int type
, struct dqblk
*dqb
)
5523 int error
= 0, status
, nfsvers
, numops
;
5525 struct nfsm_chain nmreq
, nmrep
;
5526 uint32_t bitmap
[NFS_ATTR_BITMAP_LEN
];
5527 thread_t thd
= vfs_context_thread(ctx
);
5528 kauth_cred_t cred
= vfs_context_ucred(ctx
);
5529 struct nfsreq_secinfo_args si
;
5531 if (type
!= USRQUOTA
) { /* NFSv4 only supports user quotas */
5535 /* first check that the server supports any of the quota attributes */
5536 if (!NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_supp_attr
, NFS_FATTR_QUOTA_AVAIL_HARD
) &&
5537 !NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_supp_attr
, NFS_FATTR_QUOTA_AVAIL_SOFT
) &&
5538 !NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_supp_attr
, NFS_FATTR_QUOTA_USED
)) {
5543 * The credential passed to the server needs to have
5544 * an effective uid that matches the given uid.
5546 if (id
!= kauth_cred_getuid(cred
)) {
5547 struct posix_cred temp_pcred
;
5548 posix_cred_t pcred
= posix_cred_get(cred
);
5549 bzero(&temp_pcred
, sizeof(temp_pcred
));
5550 temp_pcred
.cr_uid
= id
;
5551 temp_pcred
.cr_ngroups
= pcred
->cr_ngroups
;
5552 bcopy(pcred
->cr_groups
, temp_pcred
.cr_groups
, sizeof(temp_pcred
.cr_groups
));
5553 cred
= posix_cred_create(&temp_pcred
);
5554 if (!IS_VALID_CRED(cred
)) {
5558 kauth_cred_ref(cred
);
5561 nfsvers
= nmp
->nm_vers
;
5566 if (error
|| ((error
= vnode_get(NFSTOV(np
))))) {
5567 kauth_cred_unref(&cred
);
5571 NFSREQ_SECINFO_SET(&si
, np
, NULL
, 0, NULL
, 0);
5572 nfsm_chain_null(&nmreq
);
5573 nfsm_chain_null(&nmrep
);
5577 nfsm_chain_build_alloc_init(error
, &nmreq
, 15 * NFSX_UNSIGNED
);
5578 nfsm_chain_add_compound_header(error
, &nmreq
, "quota", nmp
->nm_minor_vers
, numops
);
5580 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_PUTFH
);
5581 nfsm_chain_add_fh(error
, &nmreq
, nfsvers
, np
->n_fhp
, np
->n_fhsize
);
5583 nfsm_chain_add_32(error
, &nmreq
, NFS_OP_GETATTR
);
5584 NFS_CLEAR_ATTRIBUTES(bitmap
);
5585 NFS_BITMAP_SET(bitmap
, NFS_FATTR_QUOTA_AVAIL_HARD
);
5586 NFS_BITMAP_SET(bitmap
, NFS_FATTR_QUOTA_AVAIL_SOFT
);
5587 NFS_BITMAP_SET(bitmap
, NFS_FATTR_QUOTA_USED
);
5588 nfsm_chain_add_bitmap_supported(error
, &nmreq
, bitmap
, nmp
, NULL
);
5589 nfsm_chain_build_done(error
, &nmreq
);
5590 nfsm_assert(error
, (numops
== 0), EPROTO
);
5592 error
= nfs_request2(np
, NULL
, &nmreq
, NFSPROC4_COMPOUND
, thd
, cred
, &si
, 0, &nmrep
, &xid
, &status
);
5593 nfsm_chain_skip_tag(error
, &nmrep
);
5594 nfsm_chain_get_32(error
, &nmrep
, numops
);
5595 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_PUTFH
);
5596 nfsm_chain_op_check(error
, &nmrep
, NFS_OP_GETATTR
);
5597 nfsm_assert(error
, NFSTONMP(np
), ENXIO
);
5599 error
= nfs4_parsefattr(&nmrep
, NULL
, NULL
, NULL
, dqb
, NULL
);
5601 nfsm_assert(error
, NFSTONMP(np
), ENXIO
);
5603 nfsm_chain_cleanup(&nmreq
);
5604 nfsm_chain_cleanup(&nmrep
);
5605 vnode_put(NFSTOV(np
));
5606 kauth_cred_unref(&cred
);
5609 #endif /* CONFIG_NFS4 */
5611 nfs_vfs_quotactl(mount_t mp
, int cmds
, uid_t uid
, caddr_t datap
, vfs_context_t ctx
)
5613 struct nfsmount
*nmp
;
5614 int cmd
, type
, error
, nfsvers
;
5615 uid_t euid
= kauth_cred_getuid(vfs_context_ucred(ctx
));
5616 struct dqblk
*dqb
= (struct dqblk
*)datap
;
5619 if (nfs_mount_gone(nmp
)) {
5622 nfsvers
= nmp
->nm_vers
;
5628 /* we can only support Q_GETQUOTA */
5629 cmd
= cmds
>> SUBCMDSHIFT
;
5644 type
= cmds
& SUBCMDMASK
;
5645 if ((u_int
)type
>= MAXQUOTAS
) {
5648 if ((uid
!= euid
) && ((error
= vfs_context_suser(ctx
)))) {
5652 if (vfs_busy(mp
, LK_NOWAIT
)) {
5655 bzero(dqb
, sizeof(*dqb
));
5656 error
= nmp
->nm_funcs
->nf_getquota(nmp
, ctx
, uid
, type
, dqb
);
5663 * Flush out the buffer cache
5665 int nfs_sync_callout(vnode_t
, void *);
5667 struct nfs_sync_cargs
{
5674 nfs_sync_callout(vnode_t vp
, void *arg
)
5676 struct nfs_sync_cargs
*cargs
= (struct nfs_sync_cargs
*)arg
;
5677 nfsnode_t np
= VTONFS(vp
);
5680 if (np
->n_flag
& NREVOKE
) {
5681 vn_revoke(vp
, REVOKEALL
, cargs
->ctx
);
5682 return VNODE_RETURNED
;
5685 if (LIST_EMPTY(&np
->n_dirtyblkhd
)) {
5686 return VNODE_RETURNED
;
5688 if (np
->n_wrbusy
> 0) {
5689 return VNODE_RETURNED
;
5691 if (np
->n_bflag
& (NBFLUSHINPROG
| NBINVALINPROG
)) {
5692 return VNODE_RETURNED
;
5695 error
= nfs_flush(np
, cargs
->waitfor
, vfs_context_thread(cargs
->ctx
), 0);
5697 cargs
->error
= error
;
5700 return VNODE_RETURNED
;
5704 nfs_vfs_sync(mount_t mp
, int waitfor
, vfs_context_t ctx
)
5706 struct nfs_sync_cargs cargs
;
5708 cargs
.waitfor
= waitfor
;
5712 vnode_iterate(mp
, 0, nfs_sync_callout
, &cargs
);
5718 * NFS flat namespace lookup.
5719 * Currently unsupported.
5724 __unused mount_t mp
,
5725 __unused ino64_t ino
,
5726 __unused vnode_t
*vpp
,
5727 __unused vfs_context_t ctx
)
5733 * At this point, this should never happen
5738 __unused mount_t mp
,
5740 __unused
unsigned char *fhp
,
5741 __unused vnode_t
*vpp
,
5742 __unused vfs_context_t ctx
)
5748 * Vnode pointer to File handle, should never happen either
5753 __unused vnode_t vp
,
5754 __unused
int *fhlenp
,
5755 __unused
unsigned char *fhp
,
5756 __unused vfs_context_t ctx
)
5762 * Vfs start routine, a no-op.
5767 __unused mount_t mp
,
5769 __unused vfs_context_t ctx
)
5775 * Build the mount info buffer for NFS_MOUNTINFO.
5778 nfs_mountinfo_assemble(struct nfsmount
*nmp
, struct xdrbuf
*xb
)
5780 struct xdrbuf xbinfo
, xborig
;
5782 uint32_t origargsvers
, origargslength
;
5783 uint32_t infolength_offset
, curargsopaquelength_offset
, curargslength_offset
, attrslength_offset
, curargs_end_offset
, end_offset
;
5784 uint32_t miattrs
[NFS_MIATTR_BITMAP_LEN
];
5785 uint32_t miflags_mask
[NFS_MIFLAG_BITMAP_LEN
];
5786 uint32_t miflags
[NFS_MIFLAG_BITMAP_LEN
];
5787 uint32_t mattrs
[NFS_MATTR_BITMAP_LEN
];
5788 uint32_t mflags_mask
[NFS_MFLAG_BITMAP_LEN
];
5789 uint32_t mflags
[NFS_MFLAG_BITMAP_LEN
];
5790 uint32_t loc
, serv
, addr
, comp
;
5791 int i
, timeo
, error
= 0;
5793 /* set up mount info attr and flag bitmaps */
5794 NFS_BITMAP_ZERO(miattrs
, NFS_MIATTR_BITMAP_LEN
);
5795 NFS_BITMAP_SET(miattrs
, NFS_MIATTR_FLAGS
);
5796 NFS_BITMAP_SET(miattrs
, NFS_MIATTR_ORIG_ARGS
);
5797 NFS_BITMAP_SET(miattrs
, NFS_MIATTR_CUR_ARGS
);
5798 NFS_BITMAP_SET(miattrs
, NFS_MIATTR_CUR_LOC_INDEX
);
5799 NFS_BITMAP_ZERO(miflags_mask
, NFS_MIFLAG_BITMAP_LEN
);
5800 NFS_BITMAP_ZERO(miflags
, NFS_MIFLAG_BITMAP_LEN
);
5801 NFS_BITMAP_SET(miflags_mask
, NFS_MIFLAG_DEAD
);
5802 NFS_BITMAP_SET(miflags_mask
, NFS_MIFLAG_NOTRESP
);
5803 NFS_BITMAP_SET(miflags_mask
, NFS_MIFLAG_RECOVERY
);
5804 if (nmp
->nm_state
& NFSSTA_DEAD
) {
5805 NFS_BITMAP_SET(miflags
, NFS_MIFLAG_DEAD
);
5807 if ((nmp
->nm_state
& (NFSSTA_TIMEO
| NFSSTA_JUKEBOXTIMEO
)) ||
5808 ((nmp
->nm_state
& NFSSTA_LOCKTIMEO
) && (nmp
->nm_lockmode
== NFS_LOCK_MODE_ENABLED
))) {
5809 NFS_BITMAP_SET(miflags
, NFS_MIFLAG_NOTRESP
);
5811 if (nmp
->nm_state
& NFSSTA_RECOVER
) {
5812 NFS_BITMAP_SET(miflags
, NFS_MIFLAG_RECOVERY
);
5815 /* get original mount args length */
5816 xb_init_buffer(&xborig
, nmp
->nm_args
, 2 * XDRWORD
);
5817 xb_get_32(error
, &xborig
, origargsvers
); /* version */
5818 xb_get_32(error
, &xborig
, origargslength
); /* args length */
5821 /* set up current mount attributes bitmap */
5822 NFS_BITMAP_ZERO(mattrs
, NFS_MATTR_BITMAP_LEN
);
5823 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FLAGS
);
5824 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_VERSION
);
5826 if (nmp
->nm_vers
>= NFS_VER4
) {
5827 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_MINOR_VERSION
);
5830 NFS_BITMAP_SET(mattrs
, NFS_MATTR_READ_SIZE
);
5831 NFS_BITMAP_SET(mattrs
, NFS_MATTR_WRITE_SIZE
);
5832 NFS_BITMAP_SET(mattrs
, NFS_MATTR_READDIR_SIZE
);
5833 NFS_BITMAP_SET(mattrs
, NFS_MATTR_READAHEAD
);
5834 NFS_BITMAP_SET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MIN
);
5835 NFS_BITMAP_SET(mattrs
, NFS_MATTR_ATTRCACHE_REG_MAX
);
5836 NFS_BITMAP_SET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MIN
);
5837 NFS_BITMAP_SET(mattrs
, NFS_MATTR_ATTRCACHE_DIR_MAX
);
5838 NFS_BITMAP_SET(mattrs
, NFS_MATTR_LOCK_MODE
);
5839 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SECURITY
);
5840 if (nmp
->nm_etype
.selected
< nmp
->nm_etype
.count
) {
5841 NFS_BITMAP_SET(mattrs
, NFS_MATTR_KERB_ETYPE
);
5843 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MAX_GROUP_LIST
);
5844 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SOCKET_TYPE
);
5845 if (nmp
->nm_saddr
->sa_family
!= AF_LOCAL
) {
5846 NFS_BITMAP_SET(mattrs
, NFS_MATTR_NFS_PORT
);
5848 if ((nmp
->nm_vers
< NFS_VER4
) && nmp
->nm_mountport
&& !nmp
->nm_mount_localport
) {
5849 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MOUNT_PORT
);
5851 NFS_BITMAP_SET(mattrs
, NFS_MATTR_REQUEST_TIMEOUT
);
5852 if (NMFLAG(nmp
, SOFT
)) {
5853 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SOFT_RETRY_COUNT
);
5855 if (nmp
->nm_deadtimeout
) {
5856 NFS_BITMAP_SET(mattrs
, NFS_MATTR_DEAD_TIMEOUT
);
5859 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FH
);
5861 NFS_BITMAP_SET(mattrs
, NFS_MATTR_FS_LOCATIONS
);
5862 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MNTFLAGS
);
5863 if (origargsvers
< NFS_ARGSVERSION_XDR
) {
5864 NFS_BITMAP_SET(mattrs
, NFS_MATTR_MNTFROM
);
5866 if (nmp
->nm_realm
) {
5867 NFS_BITMAP_SET(mattrs
, NFS_MATTR_REALM
);
5869 if (nmp
->nm_principal
) {
5870 NFS_BITMAP_SET(mattrs
, NFS_MATTR_PRINCIPAL
);
5872 if (nmp
->nm_sprinc
) {
5873 NFS_BITMAP_SET(mattrs
, NFS_MATTR_SVCPRINCIPAL
);
5875 if (nmp
->nm_nfs_localport
) {
5876 NFS_BITMAP_SET(mattrs
, NFS_MATTR_LOCAL_NFS_PORT
);
5878 if ((nmp
->nm_vers
< NFS_VER4
) && nmp
->nm_mount_localport
) {
5879 NFS_BITMAP_SET(mattrs
, NFS_MATTR_LOCAL_MOUNT_PORT
);
5882 /* set up current mount flags bitmap */
5883 /* first set the flags that we will be setting - either on OR off */
5884 NFS_BITMAP_ZERO(mflags_mask
, NFS_MFLAG_BITMAP_LEN
);
5885 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_SOFT
);
5886 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_INTR
);
5887 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_RESVPORT
);
5888 if (nmp
->nm_sotype
== SOCK_DGRAM
) {
5889 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NOCONNECT
);
5891 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_DUMBTIMER
);
5892 if (nmp
->nm_vers
< NFS_VER4
) {
5893 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_CALLUMNT
);
5895 if (nmp
->nm_vers
>= NFS_VER3
) {
5896 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_RDIRPLUS
);
5898 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NONEGNAMECACHE
);
5899 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_MUTEJUKEBOX
);
5901 if (nmp
->nm_vers
>= NFS_VER4
) {
5902 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_EPHEMERAL
);
5903 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NOCALLBACK
);
5904 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NAMEDATTR
);
5905 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NOACL
);
5906 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_ACLONLY
);
5909 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NFC
);
5910 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_NOQUOTA
);
5911 if (nmp
->nm_vers
< NFS_VER4
) {
5912 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_MNTUDP
);
5914 NFS_BITMAP_SET(mflags_mask
, NFS_MFLAG_MNTQUICK
);
5915 /* now set the flags that should be set */
5916 NFS_BITMAP_ZERO(mflags
, NFS_MFLAG_BITMAP_LEN
);
5917 if (NMFLAG(nmp
, SOFT
)) {
5918 NFS_BITMAP_SET(mflags
, NFS_MFLAG_SOFT
);
5920 if (NMFLAG(nmp
, INTR
)) {
5921 NFS_BITMAP_SET(mflags
, NFS_MFLAG_INTR
);
5923 if (NMFLAG(nmp
, RESVPORT
)) {
5924 NFS_BITMAP_SET(mflags
, NFS_MFLAG_RESVPORT
);
5926 if ((nmp
->nm_sotype
== SOCK_DGRAM
) && NMFLAG(nmp
, NOCONNECT
)) {
5927 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NOCONNECT
);
5929 if (NMFLAG(nmp
, DUMBTIMER
)) {
5930 NFS_BITMAP_SET(mflags
, NFS_MFLAG_DUMBTIMER
);
5932 if ((nmp
->nm_vers
< NFS_VER4
) && NMFLAG(nmp
, CALLUMNT
)) {
5933 NFS_BITMAP_SET(mflags
, NFS_MFLAG_CALLUMNT
);
5935 if ((nmp
->nm_vers
>= NFS_VER3
) && NMFLAG(nmp
, RDIRPLUS
)) {
5936 NFS_BITMAP_SET(mflags
, NFS_MFLAG_RDIRPLUS
);
5938 if (NMFLAG(nmp
, NONEGNAMECACHE
)) {
5939 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NONEGNAMECACHE
);
5941 if (NMFLAG(nmp
, MUTEJUKEBOX
)) {
5942 NFS_BITMAP_SET(mflags
, NFS_MFLAG_MUTEJUKEBOX
);
5945 if (nmp
->nm_vers
>= NFS_VER4
) {
5946 if (NMFLAG(nmp
, EPHEMERAL
)) {
5947 NFS_BITMAP_SET(mflags
, NFS_MFLAG_EPHEMERAL
);
5949 if (NMFLAG(nmp
, NOCALLBACK
)) {
5950 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NOCALLBACK
);
5952 if (NMFLAG(nmp
, NAMEDATTR
)) {
5953 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NAMEDATTR
);
5955 if (NMFLAG(nmp
, NOACL
)) {
5956 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NOACL
);
5958 if (NMFLAG(nmp
, ACLONLY
)) {
5959 NFS_BITMAP_SET(mflags
, NFS_MFLAG_ACLONLY
);
5963 if (NMFLAG(nmp
, NFC
)) {
5964 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NFC
);
5966 if (NMFLAG(nmp
, NOQUOTA
) || ((nmp
->nm_vers
>= NFS_VER4
) &&
5967 !NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_supp_attr
, NFS_FATTR_QUOTA_AVAIL_HARD
) &&
5968 !NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_supp_attr
, NFS_FATTR_QUOTA_AVAIL_SOFT
) &&
5969 !NFS_BITMAP_ISSET(nmp
->nm_fsattr
.nfsa_supp_attr
, NFS_FATTR_QUOTA_USED
))) {
5970 NFS_BITMAP_SET(mflags
, NFS_MFLAG_NOQUOTA
);
5972 if ((nmp
->nm_vers
< NFS_VER4
) && NMFLAG(nmp
, MNTUDP
)) {
5973 NFS_BITMAP_SET(mflags
, NFS_MFLAG_MNTUDP
);
5975 if (NMFLAG(nmp
, MNTQUICK
)) {
5976 NFS_BITMAP_SET(mflags
, NFS_MFLAG_MNTQUICK
);
5979 /* assemble info buffer: */
5980 xb_init_buffer(&xbinfo
, NULL
, 0);
5981 xb_add_32(error
, &xbinfo
, NFS_MOUNT_INFO_VERSION
);
5982 infolength_offset
= xb_offset(&xbinfo
);
5983 xb_add_32(error
, &xbinfo
, 0);
5984 xb_add_bitmap(error
, &xbinfo
, miattrs
, NFS_MIATTR_BITMAP_LEN
);
5985 xb_add_bitmap(error
, &xbinfo
, miflags
, NFS_MIFLAG_BITMAP_LEN
);
5986 xb_add_32(error
, &xbinfo
, origargslength
);
5988 error
= xb_add_bytes(&xbinfo
, nmp
->nm_args
, origargslength
, 0);
5991 /* the opaque byte count for the current mount args values: */
5992 curargsopaquelength_offset
= xb_offset(&xbinfo
);
5993 xb_add_32(error
, &xbinfo
, 0);
5995 /* Encode current mount args values */
5996 xb_add_32(error
, &xbinfo
, NFS_ARGSVERSION_XDR
);
5997 curargslength_offset
= xb_offset(&xbinfo
);
5998 xb_add_32(error
, &xbinfo
, 0);
5999 xb_add_32(error
, &xbinfo
, NFS_XDRARGS_VERSION_0
);
6000 xb_add_bitmap(error
, &xbinfo
, mattrs
, NFS_MATTR_BITMAP_LEN
);
6001 attrslength_offset
= xb_offset(&xbinfo
);
6002 xb_add_32(error
, &xbinfo
, 0);
6003 xb_add_bitmap(error
, &xbinfo
, mflags_mask
, NFS_MFLAG_BITMAP_LEN
);
6004 xb_add_bitmap(error
, &xbinfo
, mflags
, NFS_MFLAG_BITMAP_LEN
);
6005 xb_add_32(error
, &xbinfo
, nmp
->nm_vers
); /* NFS_VERSION */
6007 if (nmp
->nm_vers
>= NFS_VER4
) {
6008 xb_add_32(error
, &xbinfo
, nmp
->nm_minor_vers
); /* NFS_MINOR_VERSION */
6011 xb_add_32(error
, &xbinfo
, nmp
->nm_rsize
); /* READ_SIZE */
6012 xb_add_32(error
, &xbinfo
, nmp
->nm_wsize
); /* WRITE_SIZE */
6013 xb_add_32(error
, &xbinfo
, nmp
->nm_readdirsize
); /* READDIR_SIZE */
6014 xb_add_32(error
, &xbinfo
, nmp
->nm_readahead
); /* READAHEAD */
6015 xb_add_32(error
, &xbinfo
, nmp
->nm_acregmin
); /* ATTRCACHE_REG_MIN */
6016 xb_add_32(error
, &xbinfo
, 0); /* ATTRCACHE_REG_MIN */
6017 xb_add_32(error
, &xbinfo
, nmp
->nm_acregmax
); /* ATTRCACHE_REG_MAX */
6018 xb_add_32(error
, &xbinfo
, 0); /* ATTRCACHE_REG_MAX */
6019 xb_add_32(error
, &xbinfo
, nmp
->nm_acdirmin
); /* ATTRCACHE_DIR_MIN */
6020 xb_add_32(error
, &xbinfo
, 0); /* ATTRCACHE_DIR_MIN */
6021 xb_add_32(error
, &xbinfo
, nmp
->nm_acdirmax
); /* ATTRCACHE_DIR_MAX */
6022 xb_add_32(error
, &xbinfo
, 0); /* ATTRCACHE_DIR_MAX */
6023 xb_add_32(error
, &xbinfo
, nmp
->nm_lockmode
); /* LOCK_MODE */
6024 if (nmp
->nm_sec
.count
) {
6025 xb_add_32(error
, &xbinfo
, nmp
->nm_sec
.count
); /* SECURITY */
6027 for (i
= 0; i
< nmp
->nm_sec
.count
; i
++) {
6028 xb_add_32(error
, &xbinfo
, nmp
->nm_sec
.flavors
[i
]);
6030 } else if (nmp
->nm_servsec
.count
) {
6031 xb_add_32(error
, &xbinfo
, nmp
->nm_servsec
.count
); /* SECURITY */
6033 for (i
= 0; i
< nmp
->nm_servsec
.count
; i
++) {
6034 xb_add_32(error
, &xbinfo
, nmp
->nm_servsec
.flavors
[i
]);
6037 xb_add_32(error
, &xbinfo
, 1); /* SECURITY */
6038 xb_add_32(error
, &xbinfo
, nmp
->nm_auth
);
6040 if (nmp
->nm_etype
.selected
< nmp
->nm_etype
.count
) {
6041 xb_add_32(error
, &xbinfo
, nmp
->nm_etype
.count
);
6042 xb_add_32(error
, &xbinfo
, nmp
->nm_etype
.selected
);
6043 for (uint32_t j
= 0; j
< nmp
->nm_etype
.count
; j
++) {
6044 xb_add_32(error
, &xbinfo
, nmp
->nm_etype
.etypes
[j
]);
6048 xb_add_32(error
, &xbinfo
, nmp
->nm_numgrps
); /* MAX_GROUP_LIST */
6051 switch (nmp
->nm_saddr
->sa_family
) {
6054 snprintf(sotype
, sizeof(sotype
), "%s%s", (nmp
->nm_sotype
== SOCK_DGRAM
) ? "udp" : "tcp",
6055 nmp
->nm_sofamily
? (nmp
->nm_sofamily
== AF_INET
) ? "4" : "6" : "");
6056 xb_add_string(error
, &xbinfo
, sotype
, strlen(sotype
)); /* SOCKET_TYPE */
6057 xb_add_32(error
, &xbinfo
, ntohs(((struct sockaddr_in
*)nmp
->nm_saddr
)->sin_port
)); /* NFS_PORT */
6058 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_MOUNT_PORT
)) {
6059 xb_add_32(error
, &xbinfo
, nmp
->nm_mountport
); /* MOUNT_PORT */
6063 strlcpy(sotype
, (nmp
->nm_sotype
== SOCK_DGRAM
) ? "ticlts" : "ticotsord", sizeof(sotype
));
6064 xb_add_string(error
, &xbinfo
, sotype
, strlen(sotype
));
6067 NFS_VFS_DBG("Unsupported address family %d\n", nmp
->nm_saddr
->sa_family
);
6068 printf("Unsupported address family %d\n", nmp
->nm_saddr
->sa_family
);
6073 timeo
= (nmp
->nm_timeo
* 10) / NFS_HZ
;
6074 xb_add_32(error
, &xbinfo
, timeo
/ 10); /* REQUEST_TIMEOUT */
6075 xb_add_32(error
, &xbinfo
, (timeo
% 10) * 100000000); /* REQUEST_TIMEOUT */
6076 if (NMFLAG(nmp
, SOFT
)) {
6077 xb_add_32(error
, &xbinfo
, nmp
->nm_retry
); /* SOFT_RETRY_COUNT */
6079 if (nmp
->nm_deadtimeout
) {
6080 xb_add_32(error
, &xbinfo
, nmp
->nm_deadtimeout
); /* DEAD_TIMEOUT */
6081 xb_add_32(error
, &xbinfo
, 0); /* DEAD_TIMEOUT */
6084 xb_add_fh(error
, &xbinfo
, &nmp
->nm_fh
->fh_data
[0], nmp
->nm_fh
->fh_len
); /* FH */
6086 xb_add_32(error
, &xbinfo
, nmp
->nm_locations
.nl_numlocs
); /* FS_LOCATIONS */
6087 for (loc
= 0; !error
&& (loc
< nmp
->nm_locations
.nl_numlocs
); loc
++) {
6088 xb_add_32(error
, &xbinfo
, nmp
->nm_locations
.nl_locations
[loc
]->nl_servcount
);
6089 for (serv
= 0; !error
&& (serv
< nmp
->nm_locations
.nl_locations
[loc
]->nl_servcount
); serv
++) {
6090 xb_add_string(error
, &xbinfo
, nmp
->nm_locations
.nl_locations
[loc
]->nl_servers
[serv
]->ns_name
,
6091 strlen(nmp
->nm_locations
.nl_locations
[loc
]->nl_servers
[serv
]->ns_name
));
6092 xb_add_32(error
, &xbinfo
, nmp
->nm_locations
.nl_locations
[loc
]->nl_servers
[serv
]->ns_addrcount
);
6093 for (addr
= 0; !error
&& (addr
< nmp
->nm_locations
.nl_locations
[loc
]->nl_servers
[serv
]->ns_addrcount
); addr
++) {
6094 xb_add_string(error
, &xbinfo
, nmp
->nm_locations
.nl_locations
[loc
]->nl_servers
[serv
]->ns_addresses
[addr
],
6095 strlen(nmp
->nm_locations
.nl_locations
[loc
]->nl_servers
[serv
]->ns_addresses
[addr
]));
6097 xb_add_32(error
, &xbinfo
, 0); /* empty server info */
6099 xb_add_32(error
, &xbinfo
, nmp
->nm_locations
.nl_locations
[loc
]->nl_path
.np_compcount
);
6100 for (comp
= 0; !error
&& (comp
< nmp
->nm_locations
.nl_locations
[loc
]->nl_path
.np_compcount
); comp
++) {
6101 xb_add_string(error
, &xbinfo
, nmp
->nm_locations
.nl_locations
[loc
]->nl_path
.np_components
[comp
],
6102 strlen(nmp
->nm_locations
.nl_locations
[loc
]->nl_path
.np_components
[comp
]));
6104 xb_add_32(error
, &xbinfo
, 0); /* empty fs location info */
6106 xb_add_32(error
, &xbinfo
, vfs_flags(nmp
->nm_mountp
)); /* MNTFLAGS */
6107 if (origargsvers
< NFS_ARGSVERSION_XDR
) {
6108 xb_add_string(error
, &xbinfo
, vfs_statfs(nmp
->nm_mountp
)->f_mntfromname
,
6109 strlen(vfs_statfs(nmp
->nm_mountp
)->f_mntfromname
)); /* MNTFROM */
6111 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_REALM
)) {
6112 xb_add_string(error
, &xbinfo
, nmp
->nm_realm
, strlen(nmp
->nm_realm
));
6114 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_PRINCIPAL
)) {
6115 xb_add_string(error
, &xbinfo
, nmp
->nm_principal
, strlen(nmp
->nm_principal
));
6117 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_SVCPRINCIPAL
)) {
6118 xb_add_string(error
, &xbinfo
, nmp
->nm_sprinc
, strlen(nmp
->nm_sprinc
));
6120 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCAL_NFS_PORT
)) {
6121 struct sockaddr_un
*un
= (struct sockaddr_un
*)nmp
->nm_saddr
;
6122 xb_add_string(error
, &xbinfo
, un
->sun_path
, strlen(un
->sun_path
));
6124 if (NFS_BITMAP_ISSET(mattrs
, NFS_MATTR_LOCAL_MOUNT_PORT
)) {
6125 xb_add_string(error
, &xbinfo
, nmp
->nm_mount_localport
, strlen(nmp
->nm_mount_localport
));
6127 curargs_end_offset
= xb_offset(&xbinfo
);
6129 /* NFS_MIATTR_CUR_LOC_INDEX */
6130 xb_add_32(error
, &xbinfo
, nmp
->nm_locations
.nl_current
.nli_flags
);
6131 xb_add_32(error
, &xbinfo
, nmp
->nm_locations
.nl_current
.nli_loc
);
6132 xb_add_32(error
, &xbinfo
, nmp
->nm_locations
.nl_current
.nli_serv
);
6133 xb_add_32(error
, &xbinfo
, nmp
->nm_locations
.nl_current
.nli_addr
);
6135 xb_build_done(error
, &xbinfo
);
6137 /* update opaque counts */
6138 end_offset
= xb_offset(&xbinfo
);
6140 error
= xb_seek(&xbinfo
, attrslength_offset
);
6141 xb_add_32(error
, &xbinfo
, curargs_end_offset
- attrslength_offset
- XDRWORD
/*don't include length field*/);
6144 error
= xb_seek(&xbinfo
, curargslength_offset
);
6145 xb_add_32(error
, &xbinfo
, curargs_end_offset
- curargslength_offset
+ XDRWORD
/*version*/);
6148 error
= xb_seek(&xbinfo
, curargsopaquelength_offset
);
6149 xb_add_32(error
, &xbinfo
, curargs_end_offset
- curargslength_offset
+ XDRWORD
/*version*/);
6152 error
= xb_seek(&xbinfo
, infolength_offset
);
6153 xb_add_32(error
, &xbinfo
, end_offset
- infolength_offset
+ XDRWORD
/*version*/);
6157 /* copy result xdrbuf to caller */
6160 /* and mark the local copy as not needing cleanup */
6161 xbinfo
.xb_flags
&= ~XB_CLEANUP
;
6163 xb_cleanup(&xbinfo
);
6168 * Do that sysctl thang...
6171 nfs_vfs_sysctl(int *name
, u_int namelen
, user_addr_t oldp
, size_t *oldlenp
,
6172 user_addr_t newp
, size_t newlen
, vfs_context_t ctx
)
6175 #ifndef CONFIG_EMBEDDED
6178 struct sysctl_req
*req
= NULL
;
6179 union union_vfsidctl vc
;
6181 struct nfsmount
*nmp
= NULL
;
6184 boolean_t is_64_bit
;
6187 struct netfs_status
*nsp
= NULL
;
6189 uint totlen
, count
, numThreads
;
6190 #if CONFIG_NFS_SERVER
6192 struct nfs_exportfs
*nxfs
;
6193 struct nfs_export
*nx
;
6194 struct nfs_active_user_list
*ulist
;
6195 struct nfs_export_stat_desc stat_desc
= {};
6196 struct nfs_export_stat_rec statrec
;
6197 struct nfs_user_stat_node
*unode
, *unode_next
;
6198 struct nfs_user_stat_desc ustat_desc
= {};
6199 struct nfs_user_stat_user_rec ustat_rec
;
6200 struct nfs_user_stat_path_rec upath_rec
;
6201 uint bytes_avail
, bytes_total
, recs_copied
;
6202 uint numExports
, numRecs
;
6203 #endif /* CONFIG_NFS_SERVER */
6206 * All names at this level are terminal.
6209 return ENOTDIR
; /* overloaded */
6211 is_64_bit
= vfs_context_is64bit(ctx
);
6213 /* common code for "new style" VFS_CTL sysctl, get the mount. */
6216 case VFS_CTL_NOLOCKS
:
6217 case VFS_CTL_NSTATUS
:
6218 #ifndef CONFIG_EMBEDDED
6221 req
= CAST_DOWN(struct sysctl_req
*, oldp
);
6225 error
= SYSCTL_IN(req
, &vc
, is_64_bit
? sizeof(vc
.vc64
):sizeof(vc
.vc32
));
6229 mp
= vfs_getvfs(&vc
.vc32
.vc_fsid
); /* works for 32 and 64 */
6237 bzero(&vq
, sizeof(vq
));
6240 req
->newptr
= vc
.vc64
.vc_ptr
;
6241 req
->newlen
= (size_t)vc
.vc64
.vc_len
;
6243 req
->newptr
= CAST_USER_ADDR_T(vc
.vc32
.vc_ptr
);
6244 req
->newlen
= vc
.vc32
.vc_len
;
6256 *oldlenp
= sizeof nfsstats
;
6260 if (*oldlenp
< sizeof nfsstats
) {
6261 *oldlenp
= sizeof nfsstats
;
6265 error
= copyout(&nfsstats
, oldp
, sizeof nfsstats
);
6270 if (newp
&& newlen
!= sizeof nfsstats
) {
6275 return copyin(newp
, &nfsstats
, sizeof nfsstats
);
6279 /* read in the fsid */
6280 if (*oldlenp
< sizeof(fsid
)) {
6283 if ((error
= copyin(oldp
, &fsid
, sizeof(fsid
)))) {
6286 /* swizzle it back to host order */
6287 fsid
.val
[0] = ntohl(fsid
.val
[0]);
6288 fsid
.val
[1] = ntohl(fsid
.val
[1]);
6289 /* find mount and make sure it's NFS */
6290 if (((mp
= vfs_getvfs(&fsid
))) == NULL
) {
6293 if (strcmp(mp
->mnt_vfsstat
.f_fstypename
, "nfs")) {
6296 if (((nmp
= VFSTONFS(mp
))) == NULL
) {
6299 xb_init(&xb
, XDRBUF_NONE
);
6300 if ((error
= nfs_mountinfo_assemble(nmp
, &xb
))) {
6303 if (*oldlenp
< xb
.xb_u
.xb_buffer
.xbb_len
) {
6306 error
= copyout(xb_buffer_base(&xb
), oldp
, xb
.xb_u
.xb_buffer
.xbb_len
);
6308 *oldlenp
= xb
.xb_u
.xb_buffer
.xbb_len
;
6311 #if CONFIG_NFS_SERVER
6312 case NFS_EXPORTSTATS
:
6313 /* setup export stat descriptor */
6314 stat_desc
.rec_vers
= NFS_EXPORT_STAT_REC_VERSION
;
6316 if (!nfsrv_is_initialized()) {
6317 stat_desc
.rec_count
= 0;
6318 if (oldp
&& (*oldlenp
>= sizeof(struct nfs_export_stat_desc
))) {
6319 error
= copyout(&stat_desc
, oldp
, sizeof(struct nfs_export_stat_desc
));
6321 *oldlenp
= sizeof(struct nfs_export_stat_desc
);
6325 /* Count the number of exported directories */
6326 lck_rw_lock_shared(&nfsrv_export_rwlock
);
6328 LIST_FOREACH(nxfs
, &nfsrv_exports
, nxfs_next
)
6329 LIST_FOREACH(nx
, &nxfs
->nxfs_exports
, nx_next
)
6332 /* update stat descriptor's export record count */
6333 stat_desc
.rec_count
= numExports
;
6335 /* calculate total size of required buffer */
6336 totlen
= sizeof(struct nfs_export_stat_desc
) + (numExports
* sizeof(struct nfs_export_stat_rec
));
6338 /* Check caller's buffer */
6340 lck_rw_done(&nfsrv_export_rwlock
);
6341 /* indicate required buffer len */
6346 /* We require the caller's buffer to be at least large enough to hold the descriptor */
6347 if (*oldlenp
< sizeof(struct nfs_export_stat_desc
)) {
6348 lck_rw_done(&nfsrv_export_rwlock
);
6349 /* indicate required buffer len */
6354 /* indicate required buffer len */
6357 /* check if export table is empty */
6359 lck_rw_done(&nfsrv_export_rwlock
);
6360 error
= copyout(&stat_desc
, oldp
, sizeof(struct nfs_export_stat_desc
));
6364 /* calculate how many actual export stat records fit into caller's buffer */
6365 numRecs
= (*oldlenp
- sizeof(struct nfs_export_stat_desc
)) / sizeof(struct nfs_export_stat_rec
);
6368 /* caller's buffer can only accomodate descriptor */
6369 lck_rw_done(&nfsrv_export_rwlock
);
6370 stat_desc
.rec_count
= 0;
6371 error
= copyout(&stat_desc
, oldp
, sizeof(struct nfs_export_stat_desc
));
6375 /* adjust to actual number of records to copyout to caller's buffer */
6376 if (numRecs
> numExports
) {
6377 numRecs
= numExports
;
6380 /* set actual number of records we are returning */
6381 stat_desc
.rec_count
= numRecs
;
6383 /* first copy out the stat descriptor */
6385 error
= copyout(&stat_desc
, oldp
+ pos
, sizeof(struct nfs_export_stat_desc
));
6387 lck_rw_done(&nfsrv_export_rwlock
);
6390 pos
+= sizeof(struct nfs_export_stat_desc
);
6392 /* Loop through exported directories */
6394 LIST_FOREACH(nxfs
, &nfsrv_exports
, nxfs_next
) {
6395 LIST_FOREACH(nx
, &nxfs
->nxfs_exports
, nx_next
) {
6396 if (count
>= numRecs
) {
6400 /* build exported filesystem path */
6401 memset(statrec
.path
, 0, sizeof(statrec
.path
));
6402 snprintf(statrec
.path
, sizeof(statrec
.path
), "%s%s%s",
6403 nxfs
->nxfs_path
, ((nxfs
->nxfs_path
[1] && nx
->nx_path
[0]) ? "/" : ""),
6406 /* build the 64-bit export stat counters */
6407 statrec
.ops
= ((uint64_t)nx
->nx_stats
.ops
.hi
<< 32) |
6408 nx
->nx_stats
.ops
.lo
;
6409 statrec
.bytes_read
= ((uint64_t)nx
->nx_stats
.bytes_read
.hi
<< 32) |
6410 nx
->nx_stats
.bytes_read
.lo
;
6411 statrec
.bytes_written
= ((uint64_t)nx
->nx_stats
.bytes_written
.hi
<< 32) |
6412 nx
->nx_stats
.bytes_written
.lo
;
6413 error
= copyout(&statrec
, oldp
+ pos
, sizeof(statrec
));
6415 lck_rw_done(&nfsrv_export_rwlock
);
6418 /* advance buffer position */
6419 pos
+= sizeof(statrec
);
6422 lck_rw_done(&nfsrv_export_rwlock
);
6425 /* init structures used for copying out of kernel */
6426 ustat_desc
.rec_vers
= NFS_USER_STAT_REC_VERSION
;
6427 ustat_rec
.rec_type
= NFS_USER_STAT_USER_REC
;
6428 upath_rec
.rec_type
= NFS_USER_STAT_PATH_REC
;
6430 /* initialize counters */
6431 bytes_total
= sizeof(struct nfs_user_stat_desc
);
6432 bytes_avail
= *oldlenp
;
6435 if (!nfsrv_is_initialized()) { /* NFS server not initialized, so no stats */
6439 /* reclaim old expired user nodes */
6440 nfsrv_active_user_list_reclaim();
6442 /* reserve space for the buffer descriptor */
6443 if (bytes_avail
>= sizeof(struct nfs_user_stat_desc
)) {
6444 bytes_avail
-= sizeof(struct nfs_user_stat_desc
);
6449 /* put buffer position past the buffer descriptor */
6450 pos
= sizeof(struct nfs_user_stat_desc
);
6452 /* Loop through exported directories */
6453 lck_rw_lock_shared(&nfsrv_export_rwlock
);
6454 LIST_FOREACH(nxfs
, &nfsrv_exports
, nxfs_next
) {
6455 LIST_FOREACH(nx
, &nxfs
->nxfs_exports
, nx_next
) {
6457 if (bytes_avail
>= sizeof(struct nfs_user_stat_path_rec
)) {
6458 memset(upath_rec
.path
, 0, sizeof(upath_rec
.path
));
6459 snprintf(upath_rec
.path
, sizeof(upath_rec
.path
), "%s%s%s",
6460 nxfs
->nxfs_path
, ((nxfs
->nxfs_path
[1] && nx
->nx_path
[0]) ? "/" : ""),
6463 error
= copyout(&upath_rec
, oldp
+ pos
, sizeof(struct nfs_user_stat_path_rec
));
6469 pos
+= sizeof(struct nfs_user_stat_path_rec
);
6470 bytes_avail
-= sizeof(struct nfs_user_stat_path_rec
);
6473 /* Caller's buffer is exhausted */
6477 bytes_total
+= sizeof(struct nfs_user_stat_path_rec
);
6479 /* Scan through all user nodes of this export */
6480 ulist
= &nx
->nx_user_list
;
6481 lck_mtx_lock(&ulist
->user_mutex
);
6482 for (unode
= TAILQ_FIRST(&ulist
->user_lru
); unode
; unode
= unode_next
) {
6483 unode_next
= TAILQ_NEXT(unode
, lru_link
);
6485 /* copy out node if there is space */
6486 if (bytes_avail
>= sizeof(struct nfs_user_stat_user_rec
)) {
6487 /* prepare a user stat rec for copying out */
6488 ustat_rec
.uid
= unode
->uid
;
6489 memset(&ustat_rec
.sock
, 0, sizeof(ustat_rec
.sock
));
6490 bcopy(&unode
->sock
, &ustat_rec
.sock
, unode
->sock
.ss_len
);
6491 ustat_rec
.ops
= unode
->ops
;
6492 ustat_rec
.bytes_read
= unode
->bytes_read
;
6493 ustat_rec
.bytes_written
= unode
->bytes_written
;
6494 ustat_rec
.tm_start
= unode
->tm_start
;
6495 ustat_rec
.tm_last
= unode
->tm_last
;
6497 error
= copyout(&ustat_rec
, oldp
+ pos
, sizeof(struct nfs_user_stat_user_rec
));
6501 lck_mtx_unlock(&ulist
->user_mutex
);
6505 pos
+= sizeof(struct nfs_user_stat_user_rec
);
6506 bytes_avail
-= sizeof(struct nfs_user_stat_user_rec
);
6509 /* Caller's buffer is exhausted */
6512 bytes_total
+= sizeof(struct nfs_user_stat_user_rec
);
6514 /* can unlock this export's list now */
6515 lck_mtx_unlock(&ulist
->user_mutex
);
6520 /* unlock the export table */
6521 lck_rw_done(&nfsrv_export_rwlock
);
6524 /* indicate number of actual records copied */
6525 ustat_desc
.rec_count
= recs_copied
;
6528 /* check if there was enough room for the buffer descriptor */
6529 if (*oldlenp
>= sizeof(struct nfs_user_stat_desc
)) {
6530 error
= copyout(&ustat_desc
, oldp
, sizeof(struct nfs_user_stat_desc
));
6535 /* always indicate required buffer size */
6536 *oldlenp
= bytes_total
;
6541 *oldlenp
= sizeof(nfsrv_user_stat_node_count
);
6545 if (*oldlenp
< sizeof(nfsrv_user_stat_node_count
)) {
6546 *oldlenp
= sizeof(nfsrv_user_stat_node_count
);
6550 if (nfsrv_is_initialized()) {
6551 /* reclaim old expired user nodes */
6552 nfsrv_active_user_list_reclaim();
6555 error
= copyout(&nfsrv_user_stat_node_count
, oldp
, sizeof(nfsrv_user_stat_node_count
));
6557 #endif /* CONFIG_NFS_SERVER */
6558 case VFS_CTL_NOLOCKS
:
6559 if (req
->oldptr
!= USER_ADDR_NULL
) {
6560 lck_mtx_lock(&nmp
->nm_lock
);
6561 val
= (nmp
->nm_lockmode
== NFS_LOCK_MODE_DISABLED
) ? 1 : 0;
6562 lck_mtx_unlock(&nmp
->nm_lock
);
6563 error
= SYSCTL_OUT(req
, &val
, sizeof(val
));
6568 if (req
->newptr
!= USER_ADDR_NULL
) {
6569 error
= SYSCTL_IN(req
, &val
, sizeof(val
));
6573 lck_mtx_lock(&nmp
->nm_lock
);
6574 if (nmp
->nm_lockmode
== NFS_LOCK_MODE_LOCAL
) {
6575 /* can't toggle locks when using local locks */
6578 } else if ((nmp
->nm_vers
>= NFS_VER4
) && val
) {
6579 /* can't disable locks for NFSv4 */
6583 if ((nmp
->nm_vers
<= NFS_VER3
) && (nmp
->nm_lockmode
== NFS_LOCK_MODE_ENABLED
)) {
6584 nfs_lockd_mount_unregister(nmp
);
6586 nmp
->nm_lockmode
= NFS_LOCK_MODE_DISABLED
;
6587 nmp
->nm_state
&= ~NFSSTA_LOCKTIMEO
;
6589 if ((nmp
->nm_vers
<= NFS_VER3
) && (nmp
->nm_lockmode
== NFS_LOCK_MODE_DISABLED
)) {
6590 nfs_lockd_mount_register(nmp
);
6592 nmp
->nm_lockmode
= NFS_LOCK_MODE_ENABLED
;
6594 lck_mtx_unlock(&nmp
->nm_lock
);
6597 #ifndef CONFIG_EMBEDDED
6599 lck_mtx_lock(&nmp
->nm_lock
);
6600 /* XXX don't allow users to know about/disconnect unresponsive, soft, nobrowse mounts */
6601 softnobrowse
= (NMFLAG(nmp
, SOFT
) && (vfs_flags(nmp
->nm_mountp
) & MNT_DONTBROWSE
));
6602 if (!softnobrowse
&& (nmp
->nm_state
& NFSSTA_TIMEO
)) {
6603 vq
.vq_flags
|= VQ_NOTRESP
;
6605 if (!softnobrowse
&& (nmp
->nm_state
& NFSSTA_JUKEBOXTIMEO
) && !NMFLAG(nmp
, MUTEJUKEBOX
)) {
6606 vq
.vq_flags
|= VQ_NOTRESP
;
6608 if (!softnobrowse
&& (nmp
->nm_state
& NFSSTA_LOCKTIMEO
) &&
6609 (nmp
->nm_lockmode
== NFS_LOCK_MODE_ENABLED
)) {
6610 vq
.vq_flags
|= VQ_NOTRESP
;
6612 if (nmp
->nm_state
& NFSSTA_DEAD
) {
6613 vq
.vq_flags
|= VQ_DEAD
;
6615 lck_mtx_unlock(&nmp
->nm_lock
);
6616 error
= SYSCTL_OUT(req
, &vq
, sizeof(vq
));
6620 if (req
->oldptr
!= USER_ADDR_NULL
) {
6621 lck_mtx_lock(&nmp
->nm_lock
);
6622 val
= nmp
->nm_tprintf_initial_delay
;
6623 lck_mtx_unlock(&nmp
->nm_lock
);
6624 error
= SYSCTL_OUT(req
, &val
, sizeof(val
));
6629 if (req
->newptr
!= USER_ADDR_NULL
) {
6630 error
= SYSCTL_IN(req
, &val
, sizeof(val
));
6634 lck_mtx_lock(&nmp
->nm_lock
);
6636 nmp
->nm_tprintf_initial_delay
= 0;
6638 nmp
->nm_tprintf_initial_delay
= val
;
6640 lck_mtx_unlock(&nmp
->nm_lock
);
6643 case VFS_CTL_NSTATUS
:
6645 * Return the status of this mount. This is much more
6646 * information than VFS_CTL_QUERY. In addition to the
6647 * vq_flags return the significant mount options along
6648 * with the list of threads blocked on the mount and
6649 * how long the threads have been waiting.
6652 lck_mtx_lock(nfs_request_mutex
);
6653 lck_mtx_lock(&nmp
->nm_lock
);
6656 * Count the number of requests waiting for a reply.
6657 * Note: there could be multiple requests from the same thread.
6660 TAILQ_FOREACH(rq
, &nfs_reqq
, r_chain
) {
6661 if (rq
->r_nmp
== nmp
) {
6666 /* Calculate total size of result buffer */
6667 totlen
= sizeof(struct netfs_status
) + (numThreads
* sizeof(uint64_t));
6669 if (req
->oldptr
== USER_ADDR_NULL
) { // Caller is querying buffer size
6670 lck_mtx_unlock(&nmp
->nm_lock
);
6671 lck_mtx_unlock(nfs_request_mutex
);
6672 return SYSCTL_OUT(req
, NULL
, totlen
);
6674 if (req
->oldlen
< totlen
) { // Check if caller's buffer is big enough
6675 lck_mtx_unlock(&nmp
->nm_lock
);
6676 lck_mtx_unlock(nfs_request_mutex
);
6680 MALLOC(nsp
, struct netfs_status
*, totlen
, M_TEMP
, M_WAITOK
| M_ZERO
);
6682 lck_mtx_unlock(&nmp
->nm_lock
);
6683 lck_mtx_unlock(nfs_request_mutex
);
6686 timeoutmask
= NFSSTA_TIMEO
| NFSSTA_LOCKTIMEO
| NFSSTA_JUKEBOXTIMEO
;
6687 if (nmp
->nm_state
& timeoutmask
) {
6688 nsp
->ns_status
|= VQ_NOTRESP
;
6690 if (nmp
->nm_state
& NFSSTA_DEAD
) {
6691 nsp
->ns_status
|= VQ_DEAD
;
6694 (void) nfs_mountopts(nmp
, nsp
->ns_mountopts
, sizeof(nsp
->ns_mountopts
));
6695 nsp
->ns_threadcount
= numThreads
;
6698 * Get the thread ids of threads waiting for a reply
6699 * and find the longest wait time.
6701 if (numThreads
> 0) {
6707 sendtime
= now
.tv_sec
;
6708 TAILQ_FOREACH(rq
, &nfs_reqq
, r_chain
) {
6709 if (rq
->r_nmp
== nmp
) {
6710 if (rq
->r_start
< sendtime
) {
6711 sendtime
= rq
->r_start
;
6713 // A thread_id of zero is used to represent an async I/O request.
6714 nsp
->ns_threadids
[count
] =
6715 rq
->r_thread
? thread_tid(rq
->r_thread
) : 0;
6716 if (++count
>= numThreads
) {
6721 nsp
->ns_waittime
= now
.tv_sec
- sendtime
;
6724 lck_mtx_unlock(&nmp
->nm_lock
);
6725 lck_mtx_unlock(nfs_request_mutex
);
6727 error
= SYSCTL_OUT(req
, nsp
, totlen
);
6736 #endif /* CONFIG_NFS_CLIENT */