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