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>
11 struct rb_root mounts
; /* Protected by namespace_sem */
12 struct user_namespace
*user_ns
;
13 struct ucounts
*ucounts
;
14 u64 seq
; /* Sequence number to prevent loops */
15 wait_queue_head_t poll
;
17 unsigned int nr_mounts
; /* # of mounts in the namespace */
18 unsigned int pending_mounts
;
19 struct rb_node mnt_ns_tree_node
; /* node in the mnt_ns_tree */
20 refcount_t passive
; /* number references not pinning @mounts */
29 struct hlist_node m_hash
;
30 struct dentry
*m_dentry
;
31 struct hlist_head m_list
;
36 struct hlist_node mnt_hash
;
37 struct mount
*mnt_parent
;
38 struct dentry
*mnt_mountpoint
;
41 struct rcu_head mnt_rcu
;
42 struct llist_node mnt_llist
;
45 struct mnt_pcp __percpu
*mnt_pcp
;
50 struct list_head mnt_mounts
; /* list of children, anchored here */
51 struct list_head mnt_child
; /* and going through their mnt_child */
52 struct list_head mnt_instance
; /* mount instance on sb->s_mounts */
53 const char *mnt_devname
; /* Name of device e.g. /dev/dsk/hda1 */
55 struct rb_node mnt_node
; /* Under ns->mounts */
56 struct list_head mnt_list
;
58 struct list_head mnt_expire
; /* link in fs-specific expiry list */
59 struct list_head mnt_share
; /* circular list of shared mounts */
60 struct list_head mnt_slave_list
;/* list of slave mounts */
61 struct list_head mnt_slave
; /* slave list entry */
62 struct mount
*mnt_master
; /* slave is on master->mnt_slave_list */
63 struct mnt_namespace
*mnt_ns
; /* containing namespace */
64 struct mountpoint
*mnt_mp
; /* where is it mounted */
66 struct hlist_node mnt_mp_list
; /* list mounts with the same mountpoint */
67 struct hlist_node mnt_umount
;
69 struct list_head mnt_umounting
; /* list entry for umount propagation */
70 #ifdef CONFIG_FSNOTIFY
71 struct fsnotify_mark_connector __rcu
*mnt_fsnotify_marks
;
72 __u32 mnt_fsnotify_mask
;
74 int mnt_id
; /* mount identifier, reused */
75 u64 mnt_id_unique
; /* mount ID unique until reboot */
76 int mnt_group_id
; /* peer group identifier */
77 int mnt_expiry_mark
; /* true if marked for expiry */
78 struct hlist_head mnt_pins
;
79 struct hlist_head mnt_stuck_children
;
82 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
84 static inline struct mount
*real_mount(struct vfsmount
*mnt
)
86 return container_of(mnt
, struct mount
, mnt
);
89 static inline int mnt_has_parent(struct mount
*mnt
)
91 return mnt
!= mnt
->mnt_parent
;
94 static inline int is_mounted(struct vfsmount
*mnt
)
96 /* neither detached nor internal? */
97 return !IS_ERR_OR_NULL(real_mount(mnt
)->mnt_ns
);
100 extern struct mount
*__lookup_mnt(struct vfsmount
*, struct dentry
*);
102 extern int __legitimize_mnt(struct vfsmount
*, unsigned);
104 static inline bool __path_is_mountpoint(const struct path
*path
)
106 struct mount
*m
= __lookup_mnt(path
->mnt
, path
->dentry
);
107 return m
&& likely(!(m
->mnt
.mnt_flags
& MNT_SYNC_UMOUNT
));
110 extern void __detach_mounts(struct dentry
*dentry
);
112 static inline void detach_mounts(struct dentry
*dentry
)
114 if (!d_mountpoint(dentry
))
116 __detach_mounts(dentry
);
119 static inline void get_mnt_ns(struct mnt_namespace
*ns
)
121 refcount_inc(&ns
->ns
.count
);
124 extern seqlock_t mount_lock
;
127 struct mnt_namespace
*ns
;
129 int (*show
)(struct seq_file
*, struct vfsmount
*);
132 extern const struct seq_operations mounts_op
;
134 extern bool __is_local_mountpoint(struct dentry
*dentry
);
135 static inline bool is_local_mountpoint(struct dentry
*dentry
)
137 if (!d_mountpoint(dentry
))
140 return __is_local_mountpoint(dentry
);
143 static inline bool is_anon_ns(struct mnt_namespace
*ns
)
148 static inline void move_from_ns(struct mount
*mnt
, struct list_head
*dt_list
)
150 WARN_ON(!(mnt
->mnt
.mnt_flags
& MNT_ONRB
));
151 mnt
->mnt
.mnt_flags
&= ~MNT_ONRB
;
152 rb_erase(&mnt
->mnt_node
, &mnt
->mnt_ns
->mounts
);
153 list_add_tail(&mnt
->mnt_list
, dt_list
);
156 bool has_locked_children(struct mount
*mnt
, struct dentry
*dentry
);
157 struct mnt_namespace
*__lookup_next_mnt_ns(struct mnt_namespace
*mnt_ns
, bool previous
);
158 static inline struct mnt_namespace
*lookup_next_mnt_ns(struct mnt_namespace
*mntns
)
160 return __lookup_next_mnt_ns(mntns
, false);
162 static inline struct mnt_namespace
*lookup_prev_mnt_ns(struct mnt_namespace
*mntns
)
164 return __lookup_next_mnt_ns(mntns
, true);
166 static inline struct mnt_namespace
*to_mnt_ns(struct ns_common
*ns
)
168 return container_of(ns
, struct mnt_namespace
, ns
);