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