Merge tag 'x86-urgent-2025-01-28' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-stable.git] / fs / mount.h
blobffb613cdfeee97b99fe9419e8152c166e0a9ac83
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #include <linux/mount.h>
3 #include <linux/seq_file.h>
4 #include <linux/poll.h>
5 #include <linux/ns_common.h>
6 #include <linux/fs_pin.h>
8 struct mnt_namespace {
9 struct ns_common ns;
10 struct mount * root;
11 struct {
12 struct rb_root mounts; /* Protected by namespace_sem */
13 struct rb_node *mnt_last_node; /* last (rightmost) mount in the rbtree */
14 struct rb_node *mnt_first_node; /* first (leftmost) mount in the rbtree */
16 struct user_namespace *user_ns;
17 struct ucounts *ucounts;
18 u64 seq; /* Sequence number to prevent loops */
19 union {
20 wait_queue_head_t poll;
21 struct rcu_head mnt_ns_rcu;
23 u64 event;
24 unsigned int nr_mounts; /* # of mounts in the namespace */
25 unsigned int pending_mounts;
26 struct rb_node mnt_ns_tree_node; /* node in the mnt_ns_tree */
27 struct list_head mnt_ns_list; /* entry in the sequential list of mounts namespace */
28 refcount_t passive; /* number references not pinning @mounts */
29 } __randomize_layout;
31 struct mnt_pcp {
32 int mnt_count;
33 int mnt_writers;
36 struct mountpoint {
37 struct hlist_node m_hash;
38 struct dentry *m_dentry;
39 struct hlist_head m_list;
40 int m_count;
43 struct mount {
44 struct hlist_node mnt_hash;
45 struct mount *mnt_parent;
46 struct dentry *mnt_mountpoint;
47 struct vfsmount mnt;
48 union {
49 struct rb_node mnt_node; /* node in the ns->mounts rbtree */
50 struct rcu_head mnt_rcu;
51 struct llist_node mnt_llist;
53 #ifdef CONFIG_SMP
54 struct mnt_pcp __percpu *mnt_pcp;
55 #else
56 int mnt_count;
57 int mnt_writers;
58 #endif
59 struct list_head mnt_mounts; /* list of children, anchored here */
60 struct list_head mnt_child; /* and going through their mnt_child */
61 struct list_head mnt_instance; /* mount instance on sb->s_mounts */
62 const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
63 struct list_head mnt_list;
64 struct list_head mnt_expire; /* link in fs-specific expiry list */
65 struct list_head mnt_share; /* circular list of shared mounts */
66 struct list_head mnt_slave_list;/* list of slave mounts */
67 struct list_head mnt_slave; /* slave list entry */
68 struct mount *mnt_master; /* slave is on master->mnt_slave_list */
69 struct mnt_namespace *mnt_ns; /* containing namespace */
70 struct mountpoint *mnt_mp; /* where is it mounted */
71 union {
72 struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
73 struct hlist_node mnt_umount;
75 struct list_head mnt_umounting; /* list entry for umount propagation */
76 #ifdef CONFIG_FSNOTIFY
77 struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
78 __u32 mnt_fsnotify_mask;
79 #endif
80 int mnt_id; /* mount identifier, reused */
81 u64 mnt_id_unique; /* mount ID unique until reboot */
82 int mnt_group_id; /* peer group identifier */
83 int mnt_expiry_mark; /* true if marked for expiry */
84 struct hlist_head mnt_pins;
85 struct hlist_head mnt_stuck_children;
86 } __randomize_layout;
88 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
90 static inline struct mount *real_mount(struct vfsmount *mnt)
92 return container_of(mnt, struct mount, mnt);
95 static inline int mnt_has_parent(struct mount *mnt)
97 return mnt != mnt->mnt_parent;
100 static inline int is_mounted(struct vfsmount *mnt)
102 /* neither detached nor internal? */
103 return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
106 extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
108 extern int __legitimize_mnt(struct vfsmount *, unsigned);
110 static inline bool __path_is_mountpoint(const struct path *path)
112 struct mount *m = __lookup_mnt(path->mnt, path->dentry);
113 return m && likely(!(m->mnt.mnt_flags & MNT_SYNC_UMOUNT));
116 extern void __detach_mounts(struct dentry *dentry);
118 static inline void detach_mounts(struct dentry *dentry)
120 if (!d_mountpoint(dentry))
121 return;
122 __detach_mounts(dentry);
125 static inline void get_mnt_ns(struct mnt_namespace *ns)
127 refcount_inc(&ns->ns.count);
130 extern seqlock_t mount_lock;
132 struct proc_mounts {
133 struct mnt_namespace *ns;
134 struct path root;
135 int (*show)(struct seq_file *, struct vfsmount *);
138 extern const struct seq_operations mounts_op;
140 extern bool __is_local_mountpoint(struct dentry *dentry);
141 static inline bool is_local_mountpoint(struct dentry *dentry)
143 if (!d_mountpoint(dentry))
144 return false;
146 return __is_local_mountpoint(dentry);
149 static inline bool is_anon_ns(struct mnt_namespace *ns)
151 return ns->seq == 0;
154 static inline bool mnt_ns_attached(const struct mount *mnt)
156 return !RB_EMPTY_NODE(&mnt->mnt_node);
159 static inline void move_from_ns(struct mount *mnt, struct list_head *dt_list)
161 struct mnt_namespace *ns = mnt->mnt_ns;
162 WARN_ON(!mnt_ns_attached(mnt));
163 if (ns->mnt_last_node == &mnt->mnt_node)
164 ns->mnt_last_node = rb_prev(&mnt->mnt_node);
165 if (ns->mnt_first_node == &mnt->mnt_node)
166 ns->mnt_first_node = rb_next(&mnt->mnt_node);
167 rb_erase(&mnt->mnt_node, &ns->mounts);
168 RB_CLEAR_NODE(&mnt->mnt_node);
169 list_add_tail(&mnt->mnt_list, dt_list);
172 bool has_locked_children(struct mount *mnt, struct dentry *dentry);
173 struct mnt_namespace *get_sequential_mnt_ns(struct mnt_namespace *mnt_ns,
174 bool previous);
176 static inline struct mnt_namespace *to_mnt_ns(struct ns_common *ns)
178 return container_of(ns, struct mnt_namespace, ns);