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