1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1989, 1991, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef _SYS_MOUNT_H_
33#define _SYS_MOUNT_H_
34
35#include <sys/types.h>
36#include <sys/ucred.h>
37#include <sys/queue.h>
38#ifdef _KERNEL
39#include <sys/lock.h>
40#include <sys/lockmgr.h>
41#include <sys/tslog.h>
42#include <sys/_mutex.h>
43#include <sys/_sx.h>
44#elif defined(_WANT_MOUNT)
45#include <sys/_lock.h>
46#include <sys/_lockmgr.h>
47#include <sys/_mutex.h>
48#endif
49
50/*
51 * NOTE: When changing statfs structure, mount structure, MNT_* flags or
52 * MNTK_* flags also update DDB show mount command in vfs_subr.c.
53 */
54
55typedef struct fsid { int32_t val[2]; } fsid_t; /* filesystem id type */
56
57/* Returns non-zero if fsids are different. */
58static __inline int
59fsidcmp(const fsid_t *a, const fsid_t *b)
60{
61 return (a->val[0] != b->val[0] || a->val[1] != b->val[1]);
62}
63
64/*
65 * File identifier.
66 * These are unique per filesystem on a single machine.
67 *
68 * Note that the offset of fid_data is 4 bytes, so care must be taken to avoid
69 * undefined behavior accessing unaligned fields within an embedded struct.
70 */
71#define MAXFIDSZ 16
72
73struct fid {
74 u_short fid_len; /* length of data in bytes */
75 u_short fid_data0; /* force longword alignment */
76 char fid_data[MAXFIDSZ]; /* data (variable length) */
77};
78
79/*
80 * filesystem statistics
81 */
82#define MFSNAMELEN 16 /* length of type name including null */
83#define MNAMELEN 1024 /* size of on/from name bufs */
84#define STATFS_VERSION 0x20140518 /* current version number */
85struct statfs {
86 uint32_t f_version; /* structure version number */
87 uint32_t f_type; /* type of filesystem */
88 uint64_t f_flags; /* copy of mount exported flags */
89 uint64_t f_bsize; /* filesystem fragment size */
90 uint64_t f_iosize; /* optimal transfer block size */
91 uint64_t f_blocks; /* total data blocks in filesystem */
92 uint64_t f_bfree; /* free blocks in filesystem */
93 int64_t f_bavail; /* free blocks avail to non-superuser */
94 uint64_t f_files; /* total file nodes in filesystem */
95 int64_t f_ffree; /* free nodes avail to non-superuser */
96 uint64_t f_syncwrites; /* count of sync writes since mount */
97 uint64_t f_asyncwrites; /* count of async writes since mount */
98 uint64_t f_syncreads; /* count of sync reads since mount */
99 uint64_t f_asyncreads; /* count of async reads since mount */
100 uint32_t f_nvnodelistsize; /* # of vnodes */
101 uint32_t f_spare0; /* unused spare */
102 uint64_t f_spare[9]; /* unused spare */
103 uint32_t f_namemax; /* maximum filename length */
104 uid_t f_owner; /* user that mounted the filesystem */
105 fsid_t f_fsid; /* filesystem id */
106 char f_charspare[80]; /* spare string space */
107 char f_fstypename[MFSNAMELEN]; /* filesystem type name */
108 char f_mntfromname[MNAMELEN]; /* mounted filesystem */
109 char f_mntonname[MNAMELEN]; /* directory on which mounted */
110};
111
112#if defined(_WANT_FREEBSD11_STATFS) || defined(_KERNEL)
113#define FREEBSD11_STATFS_VERSION 0x20030518 /* current version number */
114struct freebsd11_statfs {
115 uint32_t f_version; /* structure version number */
116 uint32_t f_type; /* type of filesystem */
117 uint64_t f_flags; /* copy of mount exported flags */
118 uint64_t f_bsize; /* filesystem fragment size */
119 uint64_t f_iosize; /* optimal transfer block size */
120 uint64_t f_blocks; /* total data blocks in filesystem */
121 uint64_t f_bfree; /* free blocks in filesystem */
122 int64_t f_bavail; /* free blocks avail to non-superuser */
123 uint64_t f_files; /* total file nodes in filesystem */
124 int64_t f_ffree; /* free nodes avail to non-superuser */
125 uint64_t f_syncwrites; /* count of sync writes since mount */
126 uint64_t f_asyncwrites; /* count of async writes since mount */
127 uint64_t f_syncreads; /* count of sync reads since mount */
128 uint64_t f_asyncreads; /* count of async reads since mount */
129 uint64_t f_spare[10]; /* unused spare */
130 uint32_t f_namemax; /* maximum filename length */
131 uid_t f_owner; /* user that mounted the filesystem */
132 fsid_t f_fsid; /* filesystem id */
133 char f_charspare[80]; /* spare string space */
134 char f_fstypename[16]; /* filesystem type name */
135 char f_mntfromname[88]; /* mounted filesystem */
136 char f_mntonname[88]; /* directory on which mounted */
137};
138#endif /* _WANT_FREEBSD11_STATFS || _KERNEL */
139
140#ifdef _KERNEL
141#define OMFSNAMELEN 16 /* length of fs type name, including null */
142#define OMNAMELEN (88 - 2 * sizeof(long)) /* size of on/from name bufs */
143
144/* XXX getfsstat.2 is out of date with write and read counter changes here. */
145/* XXX statfs.2 is out of date with read counter changes here. */
146struct ostatfs {
147 long f_spare2; /* placeholder */
148 long f_bsize; /* fundamental filesystem block size */
149 long f_iosize; /* optimal transfer block size */
150 long f_blocks; /* total data blocks in filesystem */
151 long f_bfree; /* free blocks in fs */
152 long f_bavail; /* free blocks avail to non-superuser */
153 long f_files; /* total file nodes in filesystem */
154 long f_ffree; /* free file nodes in fs */
155 fsid_t f_fsid; /* filesystem id */
156 uid_t f_owner; /* user that mounted the filesystem */
157 int f_type; /* type of filesystem */
158 int f_flags; /* copy of mount exported flags */
159 long f_syncwrites; /* count of sync writes since mount */
160 long f_asyncwrites; /* count of async writes since mount */
161 char f_fstypename[OMFSNAMELEN]; /* fs type name */
162 char f_mntonname[OMNAMELEN]; /* directory on which mounted */
163 long f_syncreads; /* count of sync reads since mount */
164 long f_asyncreads; /* count of async reads since mount */
165 short f_spares1; /* unused spare */
166 char f_mntfromname[OMNAMELEN];/* mounted filesystem */
167 short f_spares2; /* unused spare */
168 /*
169 * XXX on machines where longs are aligned to 8-byte boundaries, there
170 * is an unnamed int32_t here. This spare was after the apparent end
171 * of the struct until we bit off the read counters from f_mntonname.
172 */
173 long f_spare[2]; /* unused spare */
174};
175#endif /* _KERNEL */
176
177#if defined(_WANT_MOUNT) || defined(_KERNEL)
178TAILQ_HEAD(vnodelst, vnode);
179
180/* Mount options list */
181TAILQ_HEAD(vfsoptlist, vfsopt);
182struct vfsopt {
183 TAILQ_ENTRY(vfsopt) link;
184 char *name;
185 void *value;
186 int len;
187 int pos;
188 int seen;
189};
190
191struct mount_pcpu {
192 int mntp_thread_in_ops;
193 int mntp_ref;
194 int mntp_lockref;
195 int mntp_writeopcount;
196};
197
198_Static_assert(sizeof(struct mount_pcpu) == 16,
199 "the struct is allocated from pcpu 16 zone");
200
201/*
202 * Structure for tracking a stacked filesystem mounted above another
203 * filesystem. This is expected to be stored in the upper FS' per-mount data.
204 *
205 * Lock reference:
206 * i - lower mount interlock
207 * c - constant from node initialization
208 */
209struct mount_upper_node {
210 struct mount *mp; /* (c) mount object for upper FS */
211 TAILQ_ENTRY(mount_upper_node) mnt_upper_link; /* (i) position in uppers list */
212};
213
214/*
215 * Structure per mounted filesystem. Each mounted filesystem has an
216 * array of operations and an instance record. The filesystems are
217 * put on a doubly linked list.
218 *
219 * Lock reference:
220 * l - mnt_listmtx
221 * m - mountlist_mtx
222 * i - interlock
223 * v - vnode freelist mutex
224 * d - deferred unmount list mutex
225 * e - mnt_explock
226 *
227 * Unmarked fields are considered stable as long as a ref is held.
228 *
229 */
230struct mount {
231 int mnt_vfs_ops; /* (i) pending vfs ops */
232 int mnt_kern_flag; /* (i) kernel only flags */
233 uint64_t mnt_flag; /* (i) flags shared with user */
234 struct mount_pcpu *mnt_pcpu; /* per-CPU data */
235 struct vnode *mnt_rootvnode;
236 struct vnode *mnt_vnodecovered; /* vnode we mounted on */
237 struct vfsops *mnt_op; /* operations on fs */
238 struct vfsconf *mnt_vfc; /* configuration info */
239 struct mtx __aligned(CACHE_LINE_SIZE) mnt_mtx; /* mount structure interlock */
240 int mnt_gen; /* struct mount generation */
241#define mnt_startzero mnt_list
242 TAILQ_ENTRY(mount) mnt_list; /* (m) mount list */
243 struct vnode *mnt_syncer; /* syncer vnode */
244 int mnt_ref; /* (i) Reference count */
245 struct vnodelst mnt_nvnodelist; /* (i) list of vnodes */
246 int mnt_nvnodelistsize; /* (i) # of vnodes */
247 int mnt_writeopcount; /* (i) write syscalls pending */
248 struct vfsoptlist *mnt_opt; /* current mount options */
249 struct vfsoptlist *mnt_optnew; /* new options passed to fs */
250 struct statfs mnt_stat; /* cache of filesystem stats */
251 struct ucred *mnt_cred; /* credentials of mounter */
252 void * mnt_data; /* private data */
253 time_t mnt_time; /* last time written*/
254 int mnt_iosize_max; /* max size for clusters, etc */
255 struct netexport *mnt_export; /* (e) export list */
256 struct label *mnt_label; /* MAC label for the fs */
257 u_int mnt_hashseed; /* Random seed for vfs_hash */
258 int mnt_lockref; /* (i) Lock reference count */
259 int mnt_secondary_writes; /* (i) # of secondary writes */
260 int mnt_secondary_accwrites;/* (i) secondary wr. starts */
261 struct thread *mnt_susp_owner; /* (i) thread owning suspension */
262 struct ucred *mnt_exjail; /* (i) jail which did exports */
263#define mnt_endzero mnt_gjprovider
264 char *mnt_gjprovider; /* gjournal provider name */
265 struct mtx mnt_listmtx;
266 struct vnodelst mnt_lazyvnodelist; /* (l) list of lazy vnodes */
267 int mnt_lazyvnodelistsize; /* (l) # of lazy vnodes */
268 int mnt_upper_pending; /* (i) # of pending ops on mnt_uppers */
269 struct lock mnt_explock; /* vfs_export walkers lock */
270 struct lock mnt_renamelock; /* renames and O_RESOLVE_BENEATH */
271 TAILQ_HEAD(, mount_upper_node) mnt_uppers; /* (i) upper mounts over us */
272 TAILQ_HEAD(, mount_upper_node) mnt_notify; /* (i) upper mounts for notification */
273 STAILQ_ENTRY(mount) mnt_taskqueue_link; /* (d) our place in deferred unmount list */
274 uint64_t mnt_taskqueue_flags; /* (d) unmount flags passed from taskqueue */
275 unsigned int mnt_unmount_retries; /* (d) # of failed deferred unmount attempts */
276};
277#endif /* _WANT_MOUNT || _KERNEL */
278
279#ifdef _KERNEL
280/*
281 * Definitions for MNT_VNODE_FOREACH_ALL.
282 */
283struct vnode *__mnt_vnode_next_all(struct vnode **mvp, struct mount *mp);
284struct vnode *__mnt_vnode_first_all(struct vnode **mvp, struct mount *mp);
285void __mnt_vnode_markerfree_all(struct vnode **mvp, struct mount *mp);
286
287#define MNT_VNODE_FOREACH_ALL(vp, mp, mvp) \
288 for (vp = __mnt_vnode_first_all(&(mvp), (mp)); \
289 (vp) != NULL; vp = __mnt_vnode_next_all(&(mvp), (mp)))
290
291#define MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp) \
292 do { \
293 MNT_ILOCK(mp); \
294 __mnt_vnode_markerfree_all(&(mvp), (mp)); \
295 /* MNT_IUNLOCK(mp); -- done in above function */ \
296 mtx_assert(MNT_MTX(mp), MA_NOTOWNED); \
297 } while (0)
298
299/*
300 * Definitions for MNT_VNODE_FOREACH_LAZY.
301 */
302typedef int mnt_lazy_cb_t(struct vnode *, void *);
303struct vnode *__mnt_vnode_next_lazy(struct vnode **mvp, struct mount *mp,
304 mnt_lazy_cb_t *cb, void *cbarg);
305struct vnode *__mnt_vnode_first_lazy(struct vnode **mvp, struct mount *mp,
306 mnt_lazy_cb_t *cb, void *cbarg);
307void __mnt_vnode_markerfree_lazy(struct vnode **mvp, struct mount *mp);
308
309#define MNT_VNODE_FOREACH_LAZY(vp, mp, mvp, cb, cbarg) \
310 for (vp = __mnt_vnode_first_lazy(&(mvp), (mp), (cb), (cbarg)); \
311 (vp) != NULL; \
312 vp = __mnt_vnode_next_lazy(&(mvp), (mp), (cb), (cbarg)))
313
314#define MNT_VNODE_FOREACH_LAZY_ABORT(mp, mvp) \
315 __mnt_vnode_markerfree_lazy(&(mvp), (mp))
316
317#define MNT_ILOCK(mp) mtx_lock(&(mp)->mnt_mtx)
318#define MNT_ITRYLOCK(mp) mtx_trylock(&(mp)->mnt_mtx)
319#define MNT_IUNLOCK(mp) mtx_unlock(&(mp)->mnt_mtx)
320#define MNT_MTX(mp) (&(mp)->mnt_mtx)
321
322#define MNT_REF(mp) do { \
323 mtx_assert(MNT_MTX(mp), MA_OWNED); \
324 mp->mnt_ref++; \
325} while (0)
326#define MNT_REL(mp) do { \
327 mtx_assert(MNT_MTX(mp), MA_OWNED); \
328 (mp)->mnt_ref--; \
329 if ((mp)->mnt_vfs_ops && (mp)->mnt_ref < 0) \
330 vfs_dump_mount_counters(mp); \
331 if ((mp)->mnt_ref == 0 && (mp)->mnt_vfs_ops) \
332 wakeup((mp)); \
333} while (0)
334
335#endif /* _KERNEL */
336
337#if defined(_WANT_MNTOPTNAMES) || defined(_KERNEL)
338struct mntoptnames {
339 uint64_t o_opt;
340 const char *o_name;
341};
342#define MNTOPT_NAMES \
343 { MNT_ASYNC, "asynchronous" }, \
344 { MNT_EXPORTED, "NFS exported" }, \
345 { MNT_LOCAL, "local" }, \
346 { MNT_NOATIME, "noatime" }, \
347 { MNT_NOEXEC, "noexec" }, \
348 { MNT_NOSUID, "nosuid" }, \
349 { MNT_NOSYMFOLLOW, "nosymfollow" }, \
350 { MNT_QUOTA, "with quotas" }, \
351 { MNT_RDONLY, "read-only" }, \
352 { MNT_SYNCHRONOUS, "synchronous" }, \
353 { MNT_UNION, "union" }, \
354 { MNT_NOCLUSTERR, "noclusterr" }, \
355 { MNT_NOCLUSTERW, "noclusterw" }, \
356 { MNT_SUIDDIR, "suiddir" }, \
357 { MNT_SOFTDEP, "soft-updates" }, \
358 { MNT_SUJ, "journaled soft-updates" }, \
359 { MNT_MULTILABEL, "multilabel" }, \
360 { MNT_ACLS, "acls" }, \
361 { MNT_NFS4ACLS, "nfsv4acls" }, \
362 { MNT_GJOURNAL, "gjournal" }, \
363 { MNT_AUTOMOUNTED, "automounted" }, \
364 { MNT_VERIFIED, "verified" }, \
365 { MNT_UNTRUSTED, "untrusted" }, \
366 { MNT_NOCOVER, "nocover" }, \
367 { MNT_EMPTYDIR, "emptydir" }, \
368 { MNT_UPDATE, "update" }, \
369 { MNT_DELEXPORT, "delexport" }, \
370 { MNT_RELOAD, "reload" }, \
371 { MNT_FORCE, "force" }, \
372 { MNT_SNAPSHOT, "snapshot" }, \
373 { MNT_NAMEDATTR, "named attributes" }, \
374 { 0, NULL }
375#endif
376
377/*
378 * User specifiable flags, stored in mnt_flag.
379 */
380#define MNT_RDONLY 0x0000000000000001ULL /* read only filesystem */
381#define MNT_SYNCHRONOUS 0x0000000000000002ULL /* fs written synchronously */
382#define MNT_NOEXEC 0x0000000000000004ULL /* can't exec from filesystem */
383#define MNT_NOSUID 0x0000000000000008ULL /* don't honor setuid fs bits */
384#define MNT_NFS4ACLS 0x0000000000000010ULL /* enable NFS version 4 ACLs */
385#define MNT_UNION 0x0000000000000020ULL /* union with underlying fs */
386#define MNT_ASYNC 0x0000000000000040ULL /* fs written asynchronously */
387#define MNT_SUIDDIR 0x0000000000100000ULL /* special SUID dir handling */
388#define MNT_SOFTDEP 0x0000000000200000ULL /* using soft updates */
389#define MNT_NOSYMFOLLOW 0x0000000000400000ULL /* do not follow symlinks */
390#define MNT_GJOURNAL 0x0000000002000000ULL /* GEOM journal support enabled */
391#define MNT_MULTILABEL 0x0000000004000000ULL /* MAC support for objects */
392#define MNT_ACLS 0x0000000008000000ULL /* ACL support enabled */
393#define MNT_NOATIME 0x0000000010000000ULL /* dont update file access time */
394#define MNT_NOCLUSTERR 0x0000000040000000ULL /* disable cluster read */
395#define MNT_NOCLUSTERW 0x0000000080000000ULL /* disable cluster write */
396#define MNT_SUJ 0x0000000100000000ULL /* using journaled soft updates */
397#define MNT_AUTOMOUNTED 0x0000000200000000ULL /* mounted by automountd(8) */
398#define MNT_UNTRUSTED 0x0000000800000000ULL /* filesys metadata untrusted */
399#define MNT_NAMEDATTR 0x0000020000000000ULL /* named attributes enabled */
400
401/*
402 * NFS export related mount flags.
403 */
404#define MNT_EXRDONLY 0x0000000000000080ULL /* exported read only */
405#define MNT_EXPORTED 0x0000000000000100ULL /* filesystem is exported */
406#define MNT_DEFEXPORTED 0x0000000000000200ULL /* exported to the world */
407#define MNT_EXPORTANON 0x0000000000000400ULL /* anon uid mapping for all */
408#define MNT_EXKERB 0x0000000000000800ULL /* exported with Kerberos */
409#define MNT_EXPUBLIC 0x0000000020000000ULL /* public export (WebNFS) */
410#define MNT_EXTLS 0x0000004000000000ULL /* require TLS */
411#define MNT_EXTLSCERT 0x0000008000000000ULL /* require TLS with client cert */
412#define MNT_EXTLSCERTUSER 0x0000010000000000ULL /* require TLS with user cert */
413
414/*
415 * Flags set by internal operations, but visible to the user.
416 */
417#define MNT_LOCAL 0x0000000000001000ULL /* filesystem is stored locally */
418#define MNT_QUOTA 0x0000000000002000ULL /* quotas are enabled on fs */
419#define MNT_ROOTFS 0x0000000000004000ULL /* identifies the root fs */
420#define MNT_USER 0x0000000000008000ULL /* mounted by a user */
421#define MNT_IGNORE 0x0000000000800000ULL /* do not show entry in df */
422#define MNT_VERIFIED 0x0000000400000000ULL /* filesystem is verified */
423
424/*
425 * Mask of flags that are visible to statfs().
426 * XXX I think that this could now become (~(MNT_CMDFLAGS))
427 * but the 'mount' program may need changing to handle this.
428 */
429#define MNT_VISFLAGMASK (MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC | \
430 MNT_NOSUID | MNT_UNION | MNT_SUJ | \
431 MNT_ASYNC | MNT_EXRDONLY | MNT_EXPORTED | \
432 MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB | \
433 MNT_LOCAL | MNT_USER | MNT_QUOTA | \
434 MNT_ROOTFS | MNT_NOATIME | MNT_NOCLUSTERR| \
435 MNT_NOCLUSTERW | MNT_SUIDDIR | MNT_SOFTDEP | \
436 MNT_IGNORE | MNT_EXPUBLIC | MNT_NOSYMFOLLOW | \
437 MNT_GJOURNAL | MNT_MULTILABEL | MNT_ACLS | \
438 MNT_NFS4ACLS | MNT_AUTOMOUNTED | MNT_VERIFIED | \
439 MNT_UNTRUSTED | MNT_NAMEDATTR)
440
441/* Mask of flags that can be updated. */
442#define MNT_UPDATEMASK (MNT_NOSUID | MNT_NOEXEC | \
443 MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC | \
444 MNT_NOATIME | \
445 MNT_NOSYMFOLLOW | MNT_IGNORE | \
446 MNT_NOCLUSTERR | MNT_NOCLUSTERW | MNT_SUIDDIR | \
447 MNT_ACLS | MNT_USER | MNT_NFS4ACLS | \
448 MNT_AUTOMOUNTED | MNT_UNTRUSTED)
449
450/*
451 * External filesystem command modifier flags.
452 * Unmount can use the MNT_FORCE flag.
453 * XXX: These are not STATES and really should be somewhere else.
454 * XXX: MNT_BYFSID and MNT_NONBUSY collide with MNT_ACLS and MNT_MULTILABEL,
455 * but because MNT_ACLS and MNT_MULTILABEL are only used for mount(2),
456 * and MNT_BYFSID and MNT_NONBUSY are only used for unmount(2),
457 * it's harmless.
458 */
459#define MNT_UPDATE 0x0000000000010000ULL /* not real mount, just update */
460#define MNT_DELEXPORT 0x0000000000020000ULL /* delete export host lists */
461#define MNT_RELOAD 0x0000000000040000ULL /* reload filesystem data */
462#define MNT_FORCE 0x0000000000080000ULL /* force unmount or readonly */
463#define MNT_SNAPSHOT 0x0000000001000000ULL /* snapshot the filesystem */
464#define MNT_NONBUSY 0x0000000004000000ULL /* check vnode use counts. */
465#define MNT_BYFSID 0x0000000008000000ULL /* specify filesystem by ID. */
466#define MNT_NOCOVER 0x0000001000000000ULL /* Do not cover a mount point */
467#define MNT_EMPTYDIR 0x0000002000000000ULL /* Only mount on empty dir */
468#define MNT_RECURSE 0x0000100000000000ULL /* recursively unmount uppers */
469#define MNT_DEFERRED 0x0000200000000000ULL /* unmount in async context */
470#define MNT_CMDFLAGS (MNT_UPDATE | MNT_DELEXPORT | MNT_RELOAD | \
471 MNT_FORCE | MNT_SNAPSHOT | MNT_NONBUSY | \
472 MNT_BYFSID | MNT_NOCOVER | MNT_EMPTYDIR | \
473 MNT_RECURSE | MNT_DEFERRED)
474
475/*
476 * Internal filesystem control flags stored in mnt_kern_flag.
477 *
478 * MNTK_UNMOUNT locks the mount entry so that name lookup cannot
479 * proceed past the mount point. This keeps the subtree stable during
480 * mounts and unmounts. When non-forced unmount flushes all vnodes
481 * from the mp queue, the MNTK_UNMOUNT flag prevents insmntque() from
482 * queueing new vnodes.
483 *
484 * MNTK_UNMOUNTF permits filesystems to detect a forced unmount while
485 * dounmount() is still waiting to lock the mountpoint. This allows
486 * the filesystem to cancel operations that might otherwise deadlock
487 * with the unmount attempt (used by NFS).
488 */
489#define MNTK_UNMOUNTF 0x00000001 /* forced unmount in progress */
490#define MNTK_ASYNC 0x00000002 /* filtered async flag */
491#define MNTK_SOFTDEP 0x00000004 /* async disabled by softdep */
492#define MNTK_NOMSYNC 0x00000008 /* don't do msync */
493#define MNTK_DRAINING 0x00000010 /* lock draining is happening */
494#define MNTK_REFEXPIRE 0x00000020 /* refcount expiring is happening */
495#define MNTK_EXTENDED_SHARED 0x00000040 /* Allow shared locking for more ops */
496#define MNTK_SHARED_WRITES 0x00000080 /* Allow shared locking for writes */
497#define MNTK_NO_IOPF 0x00000100 /* Disallow page faults during reads
498 and writes. Filesystem shall
499 properly handle i/o state on
500 EFAULT. */
501#define MNTK_RECURSE 0x00000200 /* pending recursive unmount */
502#define MNTK_UPPER_WAITER 0x00000400 /* waiting to drain MNTK_UPPER_PENDING */
503/* UNUSED 0x00000800 */
504#define MNTK_UNLOCKED_INSMNTQUE 0x00001000 /* fs does not lock the vnode for
505 insmntque */
506#define MNTK_UNMAPPED_BUFS 0x00002000
507#define MNTK_USES_BCACHE 0x00004000 /* FS uses the buffer cache. */
508/* UNUSED 0x00008000 */
509#define MNTK_VMSETSIZE_BUG 0x00010000
510#define MNTK_UNIONFS 0x00020000 /* A hack for F_ISUNIONSTACK */
511#define MNTK_FPLOOKUP 0x00040000 /* fast path lookup is supported */
512#define MNTK_SUSPEND_ALL 0x00080000 /* Suspended by all-fs suspension */
513#define MNTK_TASKQUEUE_WAITER 0x00100000 /* Waiting on unmount taskqueue */
514/* UNUSED 0x00200000 */
515/* UNUSED 0x00400000 */
516#define MNTK_NOASYNC 0x00800000 /* disable async */
517#define MNTK_UNMOUNT 0x01000000 /* unmount in progress */
518#define MNTK_MWAIT 0x02000000 /* waiting for unmount to finish */
519#define MNTK_SUSPEND 0x08000000 /* request write suspension */
520#define MNTK_SUSPEND2 0x04000000 /* block secondary writes */
521#define MNTK_SUSPENDED 0x10000000 /* write operations are suspended */
522#define MNTK_NULL_NOCACHE 0x20000000 /* auto disable cache for nullfs
523 mounts over this fs */
524#define MNTK_LOOKUP_SHARED 0x40000000 /* FS supports shared lock lookups */
525/* UNUSED 0x80000000 */
526
527#ifdef _KERNEL
528static inline int
529MNT_SHARED_WRITES(struct mount *mp)
530{
531
532 return (mp != NULL && (mp->mnt_kern_flag & MNTK_SHARED_WRITES) != 0);
533}
534
535static inline int
536MNT_EXTENDED_SHARED(struct mount *mp)
537{
538
539 return (mp != NULL && (mp->mnt_kern_flag & MNTK_EXTENDED_SHARED) != 0);
540}
541#endif
542
543/*
544 * Sysctl CTL_VFS definitions.
545 *
546 * Second level identifier specifies which filesystem. Second level
547 * identifier VFS_VFSCONF returns information about all filesystems.
548 * Second level identifier VFS_GENERIC is non-terminal.
549 */
550#define VFS_VFSCONF 0 /* get configured filesystems */
551#define VFS_GENERIC 0 /* generic filesystem information */
552/*
553 * Third level identifiers for VFS_GENERIC are given below; third
554 * level identifiers for specific filesystems are given in their
555 * mount specific header files.
556 */
557#define VFS_MAXTYPENUM 1 /* int: highest defined filesystem type */
558#define VFS_CONF 2 /* struct: vfsconf for filesystem given
559 as next argument */
560
561/*
562 * Flags for various system call interfaces.
563 *
564 * waitfor flags to vfs_sync() and getfsstat()
565 */
566#define MNT_WAIT 1 /* synchronously wait for I/O to complete */
567#define MNT_NOWAIT 2 /* start all I/O, but do not wait for it */
568#define MNT_LAZY 3 /* push data not written by filesystem syncer */
569#define MNT_SUSPEND 4 /* Suspend file system after sync */
570
571/*
572 * Generic file handle
573 */
574struct fhandle {
575 fsid_t fh_fsid; /* Filesystem id of mount point */
576 struct fid fh_fid; /* Filesys specific id */
577};
578typedef struct fhandle fhandle_t;
579
580/*
581 * Old export arguments without security flavor list
582 */
583struct oexport_args {
584 int ex_flags; /* export related flags */
585 uid_t ex_root; /* mapping for root uid */
586 struct xucred ex_anon; /* mapping for anonymous user */
587 struct sockaddr *ex_addr; /* net address to which exported */
588 u_char ex_addrlen; /* and the net address length */
589 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
590 u_char ex_masklen; /* and the smask length */
591 char *ex_indexfile; /* index file for WebNFS URLs */
592};
593
594/*
595 * Not quite so old export arguments with 32bit ex_flags and xucred ex_anon.
596 */
597#define MAXSECFLAVORS 5
598struct o2export_args {
599 int ex_flags; /* export related flags */
600 uid_t ex_root; /* mapping for root uid */
601 struct xucred ex_anon; /* mapping for anonymous user */
602 struct sockaddr *ex_addr; /* net address to which exported */
603 u_char ex_addrlen; /* and the net address length */
604 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
605 u_char ex_masklen; /* and the smask length */
606 char *ex_indexfile; /* index file for WebNFS URLs */
607 int ex_numsecflavors; /* security flavor count */
608 int ex_secflavors[MAXSECFLAVORS]; /* list of security flavors */
609};
610
611/*
612 * Export arguments for local filesystem mount calls.
613 */
614struct export_args {
615 uint64_t ex_flags; /* export related flags */
616 uid_t ex_root; /* mapping for root uid */
617 uid_t ex_uid; /* mapping for anonymous user */
618 int ex_ngroups;
619 gid_t *ex_groups;
620 struct sockaddr *ex_addr; /* net address to which exported */
621 u_char ex_addrlen; /* and the net address length */
622 struct sockaddr *ex_mask; /* mask of valid bits in saddr */
623 u_char ex_masklen; /* and the smask length */
624 char *ex_indexfile; /* index file for WebNFS URLs */
625 int ex_numsecflavors; /* security flavor count */
626 int ex_secflavors[MAXSECFLAVORS]; /* list of security flavors */
627};
628
629/*
630 * Structure holding information for a publicly exported filesystem
631 * (WebNFS). Currently the specs allow just for one such filesystem.
632 */
633struct nfs_public {
634 int np_valid; /* Do we hold valid information */
635 fhandle_t np_handle; /* Filehandle for pub fs (internal) */
636 struct mount *np_mount; /* Mountpoint of exported fs */
637 char *np_index; /* Index file */
638};
639
640/*
641 * Filesystem configuration information. One of these exists for each
642 * type of filesystem supported by the kernel. These are searched at
643 * mount time to identify the requested filesystem.
644 *
645 * XXX: Never change the first two arguments!
646 */
647struct vfsconf {
648 u_int vfc_version; /* ABI version number */
649 char vfc_name[MFSNAMELEN]; /* filesystem type name */
650 struct vfsops *vfc_vfsops; /* filesystem operations vector */
651 struct vfsops *vfc_vfsops_sd; /* ... signal-deferred */
652 int vfc_typenum; /* historic filesystem type number */
653 int vfc_refcount; /* number mounted of this type */
654 int vfc_flags; /* permanent flags */
655 int vfc_prison_flag; /* prison allow.mount.* flag */
656 struct vfsoptdecl *vfc_opts; /* mount options */
657 TAILQ_ENTRY(vfsconf) vfc_list; /* list of vfscons */
658};
659
660/* Userland version of the struct vfsconf. */
661struct xvfsconf {
662 struct vfsops *vfc_vfsops; /* filesystem operations vector */
663 char vfc_name[MFSNAMELEN]; /* filesystem type name */
664 int vfc_typenum; /* historic filesystem type number */
665 int vfc_refcount; /* number mounted of this type */
666 int vfc_flags; /* permanent flags */
667 struct vfsconf *vfc_next; /* next in list */
668};
669
670#ifndef BURN_BRIDGES
671struct ovfsconf {
672 void *vfc_vfsops;
673 char vfc_name[32];
674 int vfc_index;
675 int vfc_refcount;
676 int vfc_flags;
677};
678#endif
679
680/*
681 * NB: these flags refer to IMPLEMENTATION properties, not properties of
682 * any actual mounts; i.e., it does not make sense to change the flags.
683 */
684#define VFCF_STATIC 0x00010000 /* statically compiled into kernel */
685#define VFCF_NETWORK 0x00020000 /* may get data over the network */
686#define VFCF_READONLY 0x00040000 /* writes are not implemented */
687#define VFCF_SYNTHETIC 0x00080000 /* data does not represent real files */
688#define VFCF_LOOPBACK 0x00100000 /* aliases some other mounted FS */
689#define VFCF_UNICODE 0x00200000 /* stores file names as Unicode */
690#define VFCF_JAIL 0x00400000 /* can be mounted from within a jail */
691#define VFCF_DELEGADMIN 0x00800000 /* supports delegated administration */
692#define VFCF_SBDRY 0x01000000 /* Stop at Boundary: defer stop requests
693 to kernel->user (AST) transition */
694#define VFCF_FILEMOUNT 0x02000000 /* allow mounting files */
695#define VFCF_FILEREVINC 0x04000000 /* va_filerev is incr. by one */
696#define VFCF_FILEREVCT 0x08000000 /* va_filerev is set to ctime */
697
698typedef uint32_t fsctlop_t;
699
700struct vfsidctl {
701 int vc_vers; /* should be VFSIDCTL_VERS1 (below) */
702 fsid_t vc_fsid; /* fsid to operate on */
703 char vc_fstypename[MFSNAMELEN];
704 /* type of fs 'nfs' or '*' */
705 fsctlop_t vc_op; /* operation VFS_CTL_* (below) */
706 void *vc_ptr; /* pointer to data structure */
707 size_t vc_len; /* sizeof said structure */
708 u_int32_t vc_spare[12]; /* spare (must be zero) */
709};
710
711/* vfsidctl API version. */
712#define VFS_CTL_VERS1 0x01
713
714/*
715 * New style VFS sysctls, do not reuse/conflict with the namespace for
716 * private sysctls.
717 * All "global" sysctl ops have the 33rd bit set:
718 * 0x...1....
719 * Private sysctl ops should have the 33rd bit unset.
720 */
721#define VFS_CTL_QUERY 0x00010001 /* anything wrong? (vfsquery) */
722#define VFS_CTL_TIMEO 0x00010002 /* set timeout for vfs notification */
723#define VFS_CTL_NOLOCKS 0x00010003 /* disable file locking */
724
725struct vfsquery {
726 u_int32_t vq_flags;
727 u_int32_t vq_spare[31];
728};
729
730/* vfsquery flags */
731#define VQ_NOTRESP 0x0001 /* server down */
732#define VQ_NEEDAUTH 0x0002 /* server bad auth */
733#define VQ_LOWDISK 0x0004 /* we're low on space */
734#define VQ_MOUNT 0x0008 /* new filesystem arrived */
735#define VQ_UNMOUNT 0x0010 /* filesystem has left */
736#define VQ_DEAD 0x0020 /* filesystem is dead, needs force unmount */
737#define VQ_ASSIST 0x0040 /* filesystem needs assistance from external
738 program */
739#define VQ_NOTRESPLOCK 0x0080 /* server lockd down */
740#define VQ_FLAG0100 0x0100 /* placeholder */
741#define VQ_FLAG0200 0x0200 /* placeholder */
742#define VQ_FLAG0400 0x0400 /* placeholder */
743#define VQ_FLAG0800 0x0800 /* placeholder */
744#define VQ_FLAG1000 0x1000 /* placeholder */
745#define VQ_FLAG2000 0x2000 /* placeholder */
746#define VQ_FLAG4000 0x4000 /* placeholder */
747#define VQ_FLAG8000 0x8000 /* placeholder */
748
749#ifdef _KERNEL
750/* Point a sysctl request at a vfsidctl's data. */
751#define VCTLTOREQ(vc, req) \
752 do { \
753 (req)->newptr = (vc)->vc_ptr; \
754 (req)->newlen = (vc)->vc_len; \
755 (req)->newidx = 0; \
756 } while (0)
757#endif
758
759struct iovec;
760struct uio;
761
762#ifdef _KERNEL
763
764/*
765 * vfs_busy specific flags and mask.
766 */
767#define MBF_NOWAIT 0x01
768#define MBF_MNTLSTLOCK 0x02
769#define MBF_MASK (MBF_NOWAIT | MBF_MNTLSTLOCK)
770
771#ifdef MALLOC_DECLARE
772MALLOC_DECLARE(M_MOUNT);
773MALLOC_DECLARE(M_STATFS);
774#endif
775extern int maxvfsconf; /* highest defined filesystem type */
776
777TAILQ_HEAD(vfsconfhead, vfsconf);
778extern struct vfsconfhead vfsconf;
779
780/*
781 * Operations supported on mounted filesystem.
782 */
783struct mount_args;
784struct nameidata;
785struct sysctl_req;
786struct mntarg;
787
788/*
789 * N.B., vfs_cmount is the ancient vfsop invoked by the old mount(2) syscall.
790 * The new way is vfs_mount.
791 *
792 * vfs_cmount implementations typically translate arguments from their
793 * respective old per-FS structures into the key-value list supported by
794 * nmount(2), then use kernel_mount(9) to mimic nmount(2) from kernelspace.
795 *
796 * Filesystems with mounters that use nmount(2) do not need to and should not
797 * implement vfs_cmount. Hopefully a future cleanup can remove vfs_cmount and
798 * mount(2) entirely.
799 */
800typedef int vfs_cmount_t(struct mntarg *ma, void *data, uint64_t flags);
801typedef int vfs_unmount_t(struct mount *mp, int mntflags);
802typedef int vfs_root_t(struct mount *mp, int flags, struct vnode **vpp);
803typedef int vfs_quotactl_t(struct mount *mp, int cmds, uid_t uid, void *arg,
804 bool *mp_busy);
805typedef int vfs_statfs_t(struct mount *mp, struct statfs *sbp);
806typedef int vfs_sync_t(struct mount *mp, int waitfor);
807typedef int vfs_vget_t(struct mount *mp, ino_t ino, int flags,
808 struct vnode **vpp);
809typedef int vfs_fhtovp_t(struct mount *mp, struct fid *fhp,
810 int flags, struct vnode **vpp);
811typedef int vfs_checkexp_t(struct mount *mp, struct sockaddr *nam,
812 uint64_t *extflagsp, struct ucred **credanonp,
813 int *numsecflavors, int *secflavors);
814typedef int vfs_init_t(struct vfsconf *);
815typedef int vfs_uninit_t(struct vfsconf *);
816typedef int vfs_extattrctl_t(struct mount *mp, int cmd,
817 struct vnode *filename_vp, int attrnamespace,
818 const char *attrname);
819typedef int vfs_mount_t(struct mount *mp);
820typedef int vfs_sysctl_t(struct mount *mp, fsctlop_t op,
821 struct sysctl_req *req);
822typedef void vfs_susp_clean_t(struct mount *mp);
823typedef void vfs_notify_lowervp_t(struct mount *mp, struct vnode *lowervp);
824typedef void vfs_purge_t(struct mount *mp);
825struct sbuf;
826typedef int vfs_report_lockf_t(struct mount *mp, struct sbuf *sb);
827
828struct vfsops {
829 vfs_mount_t *vfs_mount;
830 vfs_cmount_t *vfs_cmount;
831 vfs_unmount_t *vfs_unmount;
832 vfs_root_t *vfs_root;
833 vfs_root_t *vfs_cachedroot;
834 vfs_quotactl_t *vfs_quotactl;
835 vfs_statfs_t *vfs_statfs;
836 vfs_sync_t *vfs_sync;
837 vfs_vget_t *vfs_vget;
838 vfs_fhtovp_t *vfs_fhtovp;
839 vfs_checkexp_t *vfs_checkexp;
840 vfs_init_t *vfs_init;
841 vfs_uninit_t *vfs_uninit;
842 vfs_extattrctl_t *vfs_extattrctl;
843 vfs_sysctl_t *vfs_sysctl;
844 vfs_susp_clean_t *vfs_susp_clean;
845 vfs_notify_lowervp_t *vfs_reclaim_lowervp;
846 vfs_notify_lowervp_t *vfs_unlink_lowervp;
847 vfs_purge_t *vfs_purge;
848 vfs_report_lockf_t *vfs_report_lockf;
849 vfs_mount_t *vfs_spare[6]; /* spares for ABI compat */
850};
851
852vfs_statfs_t __vfs_statfs;
853
854#define VFS_MOUNT(MP) ({ \
855 int _rc; \
856 \
857 TSRAW(curthread, TS_ENTER, "VFS_MOUNT", (MP)->mnt_vfc->vfc_name);\
858 _rc = (*(MP)->mnt_op->vfs_mount)(MP); \
859 TSRAW(curthread, TS_EXIT, "VFS_MOUNT", (MP)->mnt_vfc->vfc_name);\
860 _rc; })
861
862#define VFS_UNMOUNT(MP, FORCE) ({ \
863 int _rc; \
864 \
865 _rc = (*(MP)->mnt_op->vfs_unmount)(MP, FORCE); \
866 _rc; })
867
868#define VFS_ROOT(MP, FLAGS, VPP) ({ \
869 int _rc; \
870 \
871 _rc = (*(MP)->mnt_op->vfs_root)(MP, FLAGS, VPP); \
872 _rc; })
873
874#define VFS_CACHEDROOT(MP, FLAGS, VPP) ({ \
875 int _rc; \
876 \
877 _rc = (*(MP)->mnt_op->vfs_cachedroot)(MP, FLAGS, VPP); \
878 _rc; })
879
880#define VFS_QUOTACTL(MP, C, U, A, MP_BUSY) ({ \
881 int _rc; \
882 \
883 _rc = (*(MP)->mnt_op->vfs_quotactl)(MP, C, U, A, MP_BUSY); \
884 _rc; })
885
886#define VFS_STATFS(MP, SBP) ({ \
887 int _rc; \
888 \
889 _rc = __vfs_statfs((MP), (SBP)); \
890 _rc; })
891
892#define VFS_SYNC(MP, WAIT) ({ \
893 int _rc; \
894 \
895 _rc = (*(MP)->mnt_op->vfs_sync)(MP, WAIT); \
896 _rc; })
897
898#define VFS_VGET(MP, INO, FLAGS, VPP) ({ \
899 int _rc; \
900 \
901 _rc = (*(MP)->mnt_op->vfs_vget)(MP, INO, FLAGS, VPP); \
902 _rc; })
903
904#define VFS_FHTOVP(MP, FIDP, FLAGS, VPP) ({ \
905 int _rc; \
906 \
907 _rc = (*(MP)->mnt_op->vfs_fhtovp)(MP, FIDP, FLAGS, VPP); \
908 _rc; })
909
910#define VFS_CHECKEXP(MP, NAM, EXFLG, CRED, NUMSEC, SEC) ({ \
911 int _rc; \
912 \
913 _rc = (*(MP)->mnt_op->vfs_checkexp)(MP, NAM, EXFLG, CRED, NUMSEC,\
914 SEC); \
915 _rc; })
916
917#define VFS_EXTATTRCTL(MP, C, FN, NS, N) ({ \
918 int _rc; \
919 \
920 _rc = (*(MP)->mnt_op->vfs_extattrctl)(MP, C, FN, NS, N); \
921 _rc; })
922
923#define VFS_SYSCTL(MP, OP, REQ) ({ \
924 int _rc; \
925 \
926 _rc = (*(MP)->mnt_op->vfs_sysctl)(MP, OP, REQ); \
927 _rc; })
928
929#define VFS_SUSP_CLEAN(MP) do { \
930 if (*(MP)->mnt_op->vfs_susp_clean != NULL) { \
931 (*(MP)->mnt_op->vfs_susp_clean)(MP); \
932 } \
933} while (0)
934
935#define VFS_RECLAIM_LOWERVP(MP, VP) do { \
936 if (*(MP)->mnt_op->vfs_reclaim_lowervp != NULL) { \
937 (*(MP)->mnt_op->vfs_reclaim_lowervp)((MP), (VP)); \
938 } \
939} while (0)
940
941#define VFS_UNLINK_LOWERVP(MP, VP) do { \
942 if (*(MP)->mnt_op->vfs_unlink_lowervp != NULL) { \
943 (*(MP)->mnt_op->vfs_unlink_lowervp)((MP), (VP)); \
944 } \
945} while (0)
946
947#define VFS_PURGE(MP) do { \
948 if (*(MP)->mnt_op->vfs_purge != NULL) { \
949 (*(MP)->mnt_op->vfs_purge)(MP); \
950 } \
951} while (0)
952
953#define VFS_KNOTE_LOCKED(vp, hint) do \
954{ \
955 VN_KNOTE((vp), (hint), KNF_LISTLOCKED); \
956} while (0)
957
958#define VFS_KNOTE_UNLOCKED(vp, hint) do \
959{ \
960 VN_KNOTE((vp), (hint), 0); \
961} while (0)
962
963#include <sys/module.h>
964
965/*
966 * Version numbers.
967 */
968#define VFS_VERSION_00 0x19660120
969#define VFS_VERSION_01 0x20121030
970#define VFS_VERSION_02 0x20180504
971#define VFS_VERSION VFS_VERSION_02
972
973#define VFS_SET(vfsops, fsname, flags) \
974 static struct vfsconf fsname ## _vfsconf = { \
975 .vfc_version = VFS_VERSION, \
976 .vfc_name = #fsname, \
977 .vfc_vfsops = &vfsops, \
978 .vfc_typenum = -1, \
979 .vfc_flags = flags, \
980 }; \
981 static moduledata_t fsname ## _mod = { \
982 #fsname, \
983 vfs_modevent, \
984 & fsname ## _vfsconf \
985 }; \
986 DECLARE_MODULE(fsname, fsname ## _mod, SI_SUB_VFS, SI_ORDER_MIDDLE)
987
988enum vfs_notify_upper_type {
989 VFS_NOTIFY_UPPER_RECLAIM,
990 VFS_NOTIFY_UPPER_UNLINK,
991};
992
993/*
994 * exported vnode operations
995 */
996
997/* Define this to indicate that vfs_exjail_clone() exists for ZFS to use. */
998#define VFS_SUPPORTS_EXJAIL_CLONE 1
999
1000int dounmount(struct mount *, uint64_t, struct thread *);
1001
1002int kernel_mount(struct mntarg *ma, uint64_t flags);
1003struct mntarg *mount_arg(struct mntarg *ma, const char *name, const void *val, int len);
1004struct mntarg *mount_argb(struct mntarg *ma, int flag, const char *name);
1005struct mntarg *mount_argf(struct mntarg *ma, const char *name, const char *fmt, ...);
1006struct mntarg *mount_argsu(struct mntarg *ma, const char *name, const void *val, int len);
1007void statfs_scale_blocks(struct statfs *sf, long max_size);
1008struct vfsconf *vfs_byname(const char *);
1009struct vfsconf *vfs_byname_kld(const char *, struct thread *td, int *);
1010void vfs_unref_vfsconf(struct vfsconf *vfsp);
1011void vfs_mount_destroy(struct mount *);
1012void vfs_event_signal(fsid_t *, u_int32_t, intptr_t);
1013void vfs_freeopts(struct vfsoptlist *opts);
1014void vfs_deleteopt(struct vfsoptlist *opts, const char *name);
1015int vfs_buildopts(struct uio *auio, struct vfsoptlist **options);
1016int vfs_flagopt(struct vfsoptlist *opts, const char *name, uint64_t *w,
1017 uint64_t val);
1018int vfs_getopt(struct vfsoptlist *, const char *, void **, int *);
1019int vfs_getopt_pos(struct vfsoptlist *opts, const char *name);
1020int vfs_getopt_size(struct vfsoptlist *opts, const char *name,
1021 off_t *value);
1022char *vfs_getopts(struct vfsoptlist *, const char *, int *error);
1023int vfs_copyopt(struct vfsoptlist *, const char *, void *, int);
1024int vfs_filteropt(struct vfsoptlist *, const char **legal);
1025void vfs_opterror(struct vfsoptlist *opts, const char *fmt, ...);
1026int vfs_scanopt(struct vfsoptlist *opts, const char *name, const char *fmt, ...);
1027int vfs_setopt(struct vfsoptlist *opts, const char *name, void *value,
1028 int len);
1029int vfs_setopt_part(struct vfsoptlist *opts, const char *name, void *value,
1030 int len);
1031int vfs_setopts(struct vfsoptlist *opts, const char *name,
1032 const char *value);
1033int vfs_setpublicfs /* set publicly exported fs */
1034 (struct mount *, struct netexport *, struct export_args *);
1035void vfs_periodic(struct mount *, int);
1036int vfs_busy(struct mount *, int);
1037void vfs_exjail_clone(struct mount *, struct mount *);
1038void vfs_exjail_delete(struct prison *);
1039int vfs_export /* process mount export info */
1040 (struct mount *, struct export_args *, bool);
1041void vfs_free_addrlist(struct netexport *);
1042void vfs_allocate_syncvnode(struct mount *);
1043void vfs_deallocate_syncvnode(struct mount *);
1044int vfs_donmount(struct thread *td, uint64_t fsflags,
1045 struct uio *fsoptions);
1046void vfs_getnewfsid(struct mount *);
1047struct mount *vfs_getvfs(fsid_t *); /* return vfs given fsid */
1048struct mount *vfs_busyfs(fsid_t *);
1049int vfs_modevent(module_t, int, void *);
1050void vfs_mount_error(struct mount *, const char *, ...);
1051void vfs_mountroot(void); /* mount our root filesystem */
1052void vfs_mountedfrom(struct mount *, const char *from);
1053void vfs_notify_upper(struct vnode *, enum vfs_notify_upper_type);
1054struct mount *vfs_ref_from_vp(struct vnode *);
1055void vfs_ref(struct mount *);
1056void vfs_rel(struct mount *);
1057struct mount *vfs_mount_alloc(struct vnode *, struct vfsconf *, const char *,
1058 struct ucred *);
1059int vfs_suser(struct mount *, struct thread *);
1060void vfs_unbusy(struct mount *);
1061void vfs_unmountall(void);
1062struct mount *vfs_register_upper_from_vp(struct vnode *,
1063 struct mount *ump, struct mount_upper_node *);
1064void vfs_register_for_notification(struct mount *, struct mount *,
1065 struct mount_upper_node *);
1066void vfs_unregister_for_notification(struct mount *,
1067 struct mount_upper_node *);
1068void vfs_unregister_upper(struct mount *, struct mount_upper_node *);
1069int vfs_remount_ro(struct mount *mp);
1070int vfs_report_lockf(struct mount *mp, struct sbuf *sb);
1071
1072extern TAILQ_HEAD(mntlist, mount) mountlist; /* mounted filesystem list */
1073extern struct mtx_padalign mountlist_mtx;
1074extern struct nfs_public nfs_pub;
1075extern struct sx vfsconf_sx;
1076#define vfsconf_lock() sx_xlock(&vfsconf_sx)
1077#define vfsconf_unlock() sx_xunlock(&vfsconf_sx)
1078#define vfsconf_slock() sx_slock(&vfsconf_sx)
1079#define vfsconf_sunlock() sx_sunlock(&vfsconf_sx)
1080struct vnode *mntfs_allocvp(struct mount *, struct vnode *);
1081void mntfs_freevp(struct vnode *);
1082
1083/*
1084 * Declarations for these vfs default operations are located in
1085 * kern/vfs_default.c. They will be automatically used to replace
1086 * null entries in VFS ops tables when registering a new filesystem
1087 * type in the global table.
1088 */
1089vfs_root_t vfs_stdroot;
1090vfs_quotactl_t vfs_stdquotactl;
1091vfs_statfs_t vfs_stdstatfs;
1092vfs_sync_t vfs_stdsync;
1093vfs_sync_t vfs_stdnosync;
1094vfs_vget_t vfs_stdvget;
1095vfs_fhtovp_t vfs_stdfhtovp;
1096vfs_checkexp_t vfs_stdcheckexp;
1097vfs_init_t vfs_stdinit;
1098vfs_uninit_t vfs_stduninit;
1099vfs_extattrctl_t vfs_stdextattrctl;
1100vfs_sysctl_t vfs_stdsysctl;
1101
1102void syncer_suspend(void);
1103void syncer_resume(void);
1104
1105struct vnode *vfs_cache_root_clear(struct mount *);
1106void vfs_cache_root_set(struct mount *, struct vnode *);
1107
1108void vfs_op_barrier_wait(struct mount *);
1109void vfs_op_enter(struct mount *);
1110void vfs_op_exit_locked(struct mount *);
1111void vfs_op_exit(struct mount *);
1112
1113#ifdef DIAGNOSTIC
1114void vfs_assert_mount_counters(struct mount *);
1115void vfs_dump_mount_counters(struct mount *);
1116#else
1117#define vfs_assert_mount_counters(mp) do { } while (0)
1118#define vfs_dump_mount_counters(mp) do { } while (0)
1119#endif
1120
1121enum mount_counter { MNT_COUNT_REF, MNT_COUNT_LOCKREF, MNT_COUNT_WRITEOPCOUNT };
1122int vfs_mount_fetch_counter(struct mount *, enum mount_counter);
1123
1124void suspend_all_fs(void);
1125void resume_all_fs(void);
1126
1127/*
1128 * Code transitioning mnt_vfs_ops to > 0 issues IPIs until it observes
1129 * all CPUs not executing code enclosed by thread_in_ops_pcpu variable.
1130 *
1131 * This provides an invariant that by the time the last CPU is observed not
1132 * executing, everyone else entering will see the counter > 0 and exit.
1133 *
1134 * Note there is no barrier between vfs_ops and the rest of the code in the
1135 * section. It is not necessary as the writer has to wait for everyone to drain
1136 * before making any changes or only make changes safe while the section is
1137 * executed.
1138 */
1139#define vfs_mount_pcpu(mp) zpcpu_get(mp->mnt_pcpu)
1140#define vfs_mount_pcpu_remote(mp, cpu) zpcpu_get_cpu(mp->mnt_pcpu, cpu)
1141
1142#define vfs_op_thread_entered(mp) ({ \
1143 MPASS(curthread->td_critnest > 0); \
1144 struct mount_pcpu *_mpcpu = vfs_mount_pcpu(mp); \
1145 _mpcpu->mntp_thread_in_ops == 1; \
1146})
1147
1148#define vfs_op_thread_enter_crit(mp, _mpcpu) ({ \
1149 bool _retval_crit = true; \
1150 MPASS(curthread->td_critnest > 0); \
1151 _mpcpu = vfs_mount_pcpu(mp); \
1152 MPASS(mpcpu->mntp_thread_in_ops == 0); \
1153 _mpcpu->mntp_thread_in_ops = 1; \
1154 atomic_interrupt_fence(); \
1155 if (__predict_false(mp->mnt_vfs_ops > 0)) { \
1156 vfs_op_thread_exit_crit(mp, _mpcpu); \
1157 _retval_crit = false; \
1158 } \
1159 _retval_crit; \
1160})
1161
1162#define vfs_op_thread_enter(mp, _mpcpu) ({ \
1163 bool _retval; \
1164 critical_enter(); \
1165 _retval = vfs_op_thread_enter_crit(mp, _mpcpu); \
1166 if (__predict_false(!_retval)) \
1167 critical_exit(); \
1168 _retval; \
1169})
1170
1171#define vfs_op_thread_exit_crit(mp, _mpcpu) do { \
1172 MPASS(_mpcpu == vfs_mount_pcpu(mp)); \
1173 MPASS(_mpcpu->mntp_thread_in_ops == 1); \
1174 atomic_interrupt_fence(); \
1175 _mpcpu->mntp_thread_in_ops = 0; \
1176} while (0)
1177
1178#define vfs_op_thread_exit(mp, _mpcpu) do { \
1179 vfs_op_thread_exit_crit(mp, _mpcpu); \
1180 critical_exit(); \
1181} while (0)
1182
1183#define vfs_mp_count_add_pcpu(_mpcpu, count, val) do { \
1184 MPASS(_mpcpu->mntp_thread_in_ops == 1); \
1185 _mpcpu->mntp_##count += val; \
1186} while (0)
1187
1188#define vfs_mp_count_sub_pcpu(_mpcpu, count, val) do { \
1189 MPASS(_mpcpu->mntp_thread_in_ops == 1); \
1190 _mpcpu->mntp_##count -= val; \
1191} while (0)
1192
1193#else /* !_KERNEL */
1194
1195#include <sys/cdefs.h>
1196
1197struct stat;
1198
1199__BEGIN_DECLS
1200int fhlink(struct fhandle *, const char *);
1201int fhlinkat(struct fhandle *, int, const char *);
1202int fhopen(const struct fhandle *, int);
1203int fhreadlink(struct fhandle *, char *, size_t);
1204int fhstat(const struct fhandle *, struct stat *);
1205int fhstatfs(const struct fhandle *, struct statfs *);
1206int fstatfs(int, struct statfs *);
1207int getfh(const char *, fhandle_t *);
1208int getfhat(int, char *, struct fhandle *, int);
1209int getfsstat(struct statfs *, long, int);
1210int getmntinfo(struct statfs **, int);
1211int lgetfh(const char *, fhandle_t *);
1212int mount(const char *, const char *, int, void *);
1213int nmount(struct iovec *, unsigned int, int);
1214int statfs(const char *, struct statfs *);
1215int unmount(const char *, int);
1216
1217/* C library stuff */
1218int getvfsbyname(const char *, struct xvfsconf *);
1219__END_DECLS
1220
1221#endif /* _KERNEL */
1222
1223#endif /* !_SYS_MOUNT_H_ */