Merge tag 'pm-6.16-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm
[linux-2.6-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 7
bf630c40
MS
8extern struct list_head notify_list;
9
0226f492 10struct mnt_namespace {
435d5f4b 11 struct ns_common ns;
be08d6d2 12 struct mount * root;
2ce23285
CB
13 struct {
14 struct rb_root mounts; /* Protected by namespace_sem */
15 struct rb_node *mnt_last_node; /* last (rightmost) mount in the rbtree */
16 struct rb_node *mnt_first_node; /* first (leftmost) mount in the rbtree */
17 };
771b1371 18 struct user_namespace *user_ns;
537f7ccb 19 struct ucounts *ucounts;
8823c079 20 u64 seq; /* Sequence number to prevent loops */
5dcbd85d
CB
21 union {
22 wait_queue_head_t poll;
23 struct rcu_head mnt_ns_rcu;
24 };
3b0cdba4 25 u64 seq_origin; /* Sequence number of origin mount namespace */
c7999c36 26 u64 event;
b944249b
MS
27#ifdef CONFIG_FSNOTIFY
28 __u32 n_fsnotify_mask;
29 struct fsnotify_mark_connector __rcu *n_fsnotify_marks;
30#endif
2eea9ce4 31 unsigned int nr_mounts; /* # of mounts in the namespace */
d2921684 32 unsigned int pending_mounts;
1901c924 33 struct rb_node mnt_ns_tree_node; /* node in the mnt_ns_tree */
4368898b 34 struct list_head mnt_ns_list; /* entry in the sequential list of mounts namespace */
1901c924 35 refcount_t passive; /* number references not pinning @mounts */
3859a271 36} __randomize_layout;
b2dba1af 37
68e8a9fe
AV
38struct mnt_pcp {
39 int mnt_count;
40 int mnt_writers;
41};
42
84d17192 43struct mountpoint {
0818bf27 44 struct hlist_node m_hash;
84d17192 45 struct dentry *m_dentry;
0a5eb7c8 46 struct hlist_head m_list;
84d17192
AV
47 int m_count;
48};
49
7d6fec45 50struct mount {
38129a13 51 struct hlist_node mnt_hash;
0714a533 52 struct mount *mnt_parent;
a73324da 53 struct dentry *mnt_mountpoint;
7d6fec45 54 struct vfsmount mnt;
9ea459e1 55 union {
344bac8f 56 struct rb_node mnt_node; /* node in the ns->mounts rbtree */
9ea459e1
AV
57 struct rcu_head mnt_rcu;
58 struct llist_node mnt_llist;
59 };
68e8a9fe
AV
60#ifdef CONFIG_SMP
61 struct mnt_pcp __percpu *mnt_pcp;
68e8a9fe
AV
62#else
63 int mnt_count;
64 int mnt_writers;
65#endif
6b41d536
AV
66 struct list_head mnt_mounts; /* list of children, anchored here */
67 struct list_head mnt_child; /* and going through their mnt_child */
39f7c4db 68 struct list_head mnt_instance; /* mount instance on sb->s_mounts */
52ba1621 69 const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
344bac8f 70 struct list_head mnt_list;
6776db3d
AV
71 struct list_head mnt_expire; /* link in fs-specific expiry list */
72 struct list_head mnt_share; /* circular list of shared mounts */
73 struct list_head mnt_slave_list;/* list of slave mounts */
74 struct list_head mnt_slave; /* slave list entry */
32301920 75 struct mount *mnt_master; /* slave is on master->mnt_slave_list */
143c8c91 76 struct mnt_namespace *mnt_ns; /* containing namespace */
84d17192 77 struct mountpoint *mnt_mp; /* where is it mounted */
56cbb429
AV
78 union {
79 struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
80 struct hlist_node mnt_umount;
81 };
99b19d16 82 struct list_head mnt_umounting; /* list entry for umount propagation */
c63181e6 83#ifdef CONFIG_FSNOTIFY
08991e83 84 struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
c63181e6 85 __u32 mnt_fsnotify_mask;
bf630c40
MS
86 struct list_head to_notify; /* need to queue notification */
87 struct mnt_namespace *prev_ns; /* previous namespace (NULL if none) */
c63181e6 88#endif
98d2b430
MS
89 int mnt_id; /* mount identifier, reused */
90 u64 mnt_id_unique; /* mount ID unique until reboot */
15169fe7 91 int mnt_group_id; /* peer group identifier */
863d684f 92 int mnt_expiry_mark; /* true if marked for expiry */
215752fc 93 struct hlist_head mnt_pins;
56cbb429 94 struct hlist_head mnt_stuck_children;
3859a271 95} __randomize_layout;
7d6fec45 96
f7a99c5b
AV
97#define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
98
7d6fec45
AV
99static inline struct mount *real_mount(struct vfsmount *mnt)
100{
101 return container_of(mnt, struct mount, mnt);
102}
103
676da58d 104static inline int mnt_has_parent(struct mount *mnt)
b2dba1af 105{
0714a533 106 return mnt != mnt->mnt_parent;
b2dba1af 107}
c7105365 108
f7a99c5b
AV
109static inline int is_mounted(struct vfsmount *mnt)
110{
111 /* neither detached nor internal? */
260a459d 112 return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
f7a99c5b
AV
113}
114
474279dc 115extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
0226f492 116
294d71ff 117extern int __legitimize_mnt(struct vfsmount *, unsigned);
48a066e7 118
c6609c0a
IK
119static inline bool __path_is_mountpoint(const struct path *path)
120{
121 struct mount *m = __lookup_mnt(path->mnt, path->dentry);
122 return m && likely(!(m->mnt.mnt_flags & MNT_SYNC_UMOUNT));
123}
124
80b5dce8
EB
125extern void __detach_mounts(struct dentry *dentry);
126
127static inline void detach_mounts(struct dentry *dentry)
128{
129 if (!d_mountpoint(dentry))
130 return;
131 __detach_mounts(dentry);
132}
133
0226f492
AV
134static inline void get_mnt_ns(struct mnt_namespace *ns)
135{
1a7b8969 136 refcount_inc(&ns->ns.count);
0226f492
AV
137}
138
48a066e7 139extern seqlock_t mount_lock;
719ea2fb 140
0226f492 141struct proc_mounts {
0226f492
AV
142 struct mnt_namespace *ns;
143 struct path root;
144 int (*show)(struct seq_file *, struct vfsmount *);
145};
146
147extern const struct seq_operations mounts_op;
7af1364f
EB
148
149extern bool __is_local_mountpoint(struct dentry *dentry);
150static inline bool is_local_mountpoint(struct dentry *dentry)
151{
152 if (!d_mountpoint(dentry))
153 return false;
154
155 return __is_local_mountpoint(dentry);
156}
74e83122
AV
157
158static inline bool is_anon_ns(struct mnt_namespace *ns)
159{
160 return ns->seq == 0;
161}
9f6c61f9 162
344bac8f
CB
163static inline bool mnt_ns_attached(const struct mount *mnt)
164{
165 return !RB_EMPTY_NODE(&mnt->mnt_node);
166}
167
2f576220
CB
168static inline bool mnt_ns_empty(const struct mnt_namespace *ns)
169{
170 return RB_EMPTY_ROOT(&ns->mounts);
171}
172
2eea9ce4
MS
173static inline void move_from_ns(struct mount *mnt, struct list_head *dt_list)
174{
2ce23285 175 struct mnt_namespace *ns = mnt->mnt_ns;
344bac8f 176 WARN_ON(!mnt_ns_attached(mnt));
2ce23285
CB
177 if (ns->mnt_last_node == &mnt->mnt_node)
178 ns->mnt_last_node = rb_prev(&mnt->mnt_node);
179 if (ns->mnt_first_node == &mnt->mnt_node)
180 ns->mnt_first_node = rb_next(&mnt->mnt_node);
181 rb_erase(&mnt->mnt_node, &ns->mounts);
344bac8f 182 RB_CLEAR_NODE(&mnt->mnt_node);
2eea9ce4
MS
183 list_add_tail(&mnt->mnt_list, dt_list);
184}
185
620c266f 186bool has_locked_children(struct mount *mnt, struct dentry *dentry);
4368898b
CB
187struct mnt_namespace *get_sequential_mnt_ns(struct mnt_namespace *mnt_ns,
188 bool previous);
189
a1d220d9
CB
190static inline struct mnt_namespace *to_mnt_ns(struct ns_common *ns)
191{
192 return container_of(ns, struct mnt_namespace, ns);
193}
0f46d81f 194
bf630c40
MS
195#ifdef CONFIG_FSNOTIFY
196static inline void mnt_notify_add(struct mount *m)
197{
198 /* Optimize the case where there are no watches */
199 if ((m->mnt_ns && m->mnt_ns->n_fsnotify_marks) ||
200 (m->prev_ns && m->prev_ns->n_fsnotify_marks))
201 list_add_tail(&m->to_notify, &notify_list);
202 else
203 m->prev_ns = m->mnt_ns;
204}
205#else
206static inline void mnt_notify_add(struct mount *m)
207{
208}
209#endif
210
0f46d81f 211struct mnt_namespace *mnt_ns_from_dentry(struct dentry *dentry);