init: add an init_rmdir helper
[linux-block.git] / fs / mount.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
b2dba1af 2#include <linux/mount.h>
0226f492
AV
3#include <linux/seq_file.h>
4#include <linux/poll.h>
435d5f4b 5#include <linux/ns_common.h>
87b95ce0 6#include <linux/fs_pin.h>
0226f492
AV
7
8struct mnt_namespace {
9 atomic_t count;
435d5f4b 10 struct ns_common ns;
be08d6d2 11 struct mount * root;
9f6c61f9
MS
12 /*
13 * Traversal and modification of .list is protected by either
14 * - taking namespace_sem for write, OR
15 * - taking namespace_sem for read AND taking .ns_lock.
16 */
0226f492 17 struct list_head list;
9f6c61f9 18 spinlock_t ns_lock;
771b1371 19 struct user_namespace *user_ns;
537f7ccb 20 struct ucounts *ucounts;
8823c079 21 u64 seq; /* Sequence number to prevent loops */
0226f492 22 wait_queue_head_t poll;
c7999c36 23 u64 event;
d2921684
EB
24 unsigned int mounts; /* # of mounts in the namespace */
25 unsigned int pending_mounts;
3859a271 26} __randomize_layout;
b2dba1af 27
68e8a9fe
AV
28struct mnt_pcp {
29 int mnt_count;
30 int mnt_writers;
31};
32
84d17192 33struct mountpoint {
0818bf27 34 struct hlist_node m_hash;
84d17192 35 struct dentry *m_dentry;
0a5eb7c8 36 struct hlist_head m_list;
84d17192
AV
37 int m_count;
38};
39
7d6fec45 40struct mount {
38129a13 41 struct hlist_node mnt_hash;
0714a533 42 struct mount *mnt_parent;
a73324da 43 struct dentry *mnt_mountpoint;
7d6fec45 44 struct vfsmount mnt;
9ea459e1
AV
45 union {
46 struct rcu_head mnt_rcu;
47 struct llist_node mnt_llist;
48 };
68e8a9fe
AV
49#ifdef CONFIG_SMP
50 struct mnt_pcp __percpu *mnt_pcp;
68e8a9fe
AV
51#else
52 int mnt_count;
53 int mnt_writers;
54#endif
6b41d536
AV
55 struct list_head mnt_mounts; /* list of children, anchored here */
56 struct list_head mnt_child; /* and going through their mnt_child */
39f7c4db 57 struct list_head mnt_instance; /* mount instance on sb->s_mounts */
52ba1621 58 const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
1a4eeaf2 59 struct list_head mnt_list;
6776db3d
AV
60 struct list_head mnt_expire; /* link in fs-specific expiry list */
61 struct list_head mnt_share; /* circular list of shared mounts */
62 struct list_head mnt_slave_list;/* list of slave mounts */
63 struct list_head mnt_slave; /* slave list entry */
32301920 64 struct mount *mnt_master; /* slave is on master->mnt_slave_list */
143c8c91 65 struct mnt_namespace *mnt_ns; /* containing namespace */
84d17192 66 struct mountpoint *mnt_mp; /* where is it mounted */
56cbb429
AV
67 union {
68 struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
69 struct hlist_node mnt_umount;
70 };
99b19d16 71 struct list_head mnt_umounting; /* list entry for umount propagation */
c63181e6 72#ifdef CONFIG_FSNOTIFY
08991e83 73 struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
c63181e6
AV
74 __u32 mnt_fsnotify_mask;
75#endif
15169fe7
AV
76 int mnt_id; /* mount identifier */
77 int mnt_group_id; /* peer group identifier */
863d684f 78 int mnt_expiry_mark; /* true if marked for expiry */
215752fc 79 struct hlist_head mnt_pins;
56cbb429 80 struct hlist_head mnt_stuck_children;
3859a271 81} __randomize_layout;
7d6fec45 82
f7a99c5b
AV
83#define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
84
7d6fec45
AV
85static inline struct mount *real_mount(struct vfsmount *mnt)
86{
87 return container_of(mnt, struct mount, mnt);
88}
89
676da58d 90static inline int mnt_has_parent(struct mount *mnt)
b2dba1af 91{
0714a533 92 return mnt != mnt->mnt_parent;
b2dba1af 93}
c7105365 94
f7a99c5b
AV
95static inline int is_mounted(struct vfsmount *mnt)
96{
97 /* neither detached nor internal? */
260a459d 98 return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
f7a99c5b
AV
99}
100
474279dc 101extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
0226f492 102
294d71ff 103extern int __legitimize_mnt(struct vfsmount *, unsigned);
48a066e7
AV
104extern bool legitimize_mnt(struct vfsmount *, unsigned);
105
c6609c0a
IK
106static inline bool __path_is_mountpoint(const struct path *path)
107{
108 struct mount *m = __lookup_mnt(path->mnt, path->dentry);
109 return m && likely(!(m->mnt.mnt_flags & MNT_SYNC_UMOUNT));
110}
111
80b5dce8
EB
112extern void __detach_mounts(struct dentry *dentry);
113
114static inline void detach_mounts(struct dentry *dentry)
115{
116 if (!d_mountpoint(dentry))
117 return;
118 __detach_mounts(dentry);
119}
120
0226f492
AV
121static inline void get_mnt_ns(struct mnt_namespace *ns)
122{
123 atomic_inc(&ns->count);
124}
125
48a066e7 126extern seqlock_t mount_lock;
719ea2fb
AV
127
128static inline void lock_mount_hash(void)
129{
48a066e7 130 write_seqlock(&mount_lock);
719ea2fb
AV
131}
132
133static inline void unlock_mount_hash(void)
134{
48a066e7 135 write_sequnlock(&mount_lock);
719ea2fb
AV
136}
137
0226f492 138struct proc_mounts {
0226f492
AV
139 struct mnt_namespace *ns;
140 struct path root;
141 int (*show)(struct seq_file *, struct vfsmount *);
9f6c61f9 142 struct mount cursor;
0226f492
AV
143};
144
145extern const struct seq_operations mounts_op;
7af1364f
EB
146
147extern bool __is_local_mountpoint(struct dentry *dentry);
148static inline bool is_local_mountpoint(struct dentry *dentry)
149{
150 if (!d_mountpoint(dentry))
151 return false;
152
153 return __is_local_mountpoint(dentry);
154}
74e83122
AV
155
156static inline bool is_anon_ns(struct mnt_namespace *ns)
157{
158 return ns->seq == 0;
159}
9f6c61f9
MS
160
161extern void mnt_cursor_del(struct mnt_namespace *ns, struct mount *cursor);