xref: /openbmc/linux/fs/mount.h (revision 74e83122)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2b2dba1afSAl Viro #include <linux/mount.h>
30226f492SAl Viro #include <linux/seq_file.h>
40226f492SAl Viro #include <linux/poll.h>
5435d5f4bSAl Viro #include <linux/ns_common.h>
687b95ce0SAl Viro #include <linux/fs_pin.h>
70226f492SAl Viro 
80226f492SAl Viro struct mnt_namespace {
90226f492SAl Viro 	atomic_t		count;
10435d5f4bSAl Viro 	struct ns_common	ns;
11be08d6d2SAl Viro 	struct mount *	root;
120226f492SAl Viro 	struct list_head	list;
13771b1371SEric W. Biederman 	struct user_namespace	*user_ns;
14537f7ccbSEric W. Biederman 	struct ucounts		*ucounts;
158823c079SEric W. Biederman 	u64			seq;	/* Sequence number to prevent loops */
160226f492SAl Viro 	wait_queue_head_t poll;
17c7999c36SAl Viro 	u64 event;
18d2921684SEric W. Biederman 	unsigned int		mounts; /* # of mounts in the namespace */
19d2921684SEric W. Biederman 	unsigned int		pending_mounts;
203859a271SKees Cook } __randomize_layout;
21b2dba1afSAl Viro 
2268e8a9feSAl Viro struct mnt_pcp {
2368e8a9feSAl Viro 	int mnt_count;
2468e8a9feSAl Viro 	int mnt_writers;
2568e8a9feSAl Viro };
2668e8a9feSAl Viro 
2784d17192SAl Viro struct mountpoint {
280818bf27SAl Viro 	struct hlist_node m_hash;
2984d17192SAl Viro 	struct dentry *m_dentry;
300a5eb7c8SEric W. Biederman 	struct hlist_head m_list;
3184d17192SAl Viro 	int m_count;
3284d17192SAl Viro };
3384d17192SAl Viro 
347d6fec45SAl Viro struct mount {
3538129a13SAl Viro 	struct hlist_node mnt_hash;
360714a533SAl Viro 	struct mount *mnt_parent;
37a73324daSAl Viro 	struct dentry *mnt_mountpoint;
387d6fec45SAl Viro 	struct vfsmount mnt;
399ea459e1SAl Viro 	union {
4048a066e7SAl Viro 		struct rcu_head mnt_rcu;
419ea459e1SAl Viro 		struct llist_node mnt_llist;
429ea459e1SAl Viro 	};
4368e8a9feSAl Viro #ifdef CONFIG_SMP
4468e8a9feSAl Viro 	struct mnt_pcp __percpu *mnt_pcp;
4568e8a9feSAl Viro #else
4668e8a9feSAl Viro 	int mnt_count;
4768e8a9feSAl Viro 	int mnt_writers;
4868e8a9feSAl Viro #endif
496b41d536SAl Viro 	struct list_head mnt_mounts;	/* list of children, anchored here */
506b41d536SAl Viro 	struct list_head mnt_child;	/* and going through their mnt_child */
5139f7c4dbSMiklos Szeredi 	struct list_head mnt_instance;	/* mount instance on sb->s_mounts */
5252ba1621SAl Viro 	const char *mnt_devname;	/* Name of device e.g. /dev/dsk/hda1 */
531a4eeaf2SAl Viro 	struct list_head mnt_list;
546776db3dSAl Viro 	struct list_head mnt_expire;	/* link in fs-specific expiry list */
556776db3dSAl Viro 	struct list_head mnt_share;	/* circular list of shared mounts */
566776db3dSAl Viro 	struct list_head mnt_slave_list;/* list of slave mounts */
576776db3dSAl Viro 	struct list_head mnt_slave;	/* slave list entry */
5832301920SAl Viro 	struct mount *mnt_master;	/* slave is on master->mnt_slave_list */
59143c8c91SAl Viro 	struct mnt_namespace *mnt_ns;	/* containing namespace */
6084d17192SAl Viro 	struct mountpoint *mnt_mp;	/* where is it mounted */
610a5eb7c8SEric W. Biederman 	struct hlist_node mnt_mp_list;	/* list mounts with the same mountpoint */
6299b19d16SEric W. Biederman 	struct list_head mnt_umounting; /* list entry for umount propagation */
63c63181e6SAl Viro #ifdef CONFIG_FSNOTIFY
6408991e83SJan Kara 	struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
65c63181e6SAl Viro 	__u32 mnt_fsnotify_mask;
66c63181e6SAl Viro #endif
6715169fe7SAl Viro 	int mnt_id;			/* mount identifier */
6815169fe7SAl Viro 	int mnt_group_id;		/* peer group identifier */
69863d684fSAl Viro 	int mnt_expiry_mark;		/* true if marked for expiry */
70215752fcSAl Viro 	struct hlist_head mnt_pins;
7187b95ce0SAl Viro 	struct fs_pin mnt_umount;
7287b95ce0SAl Viro 	struct dentry *mnt_ex_mountpoint;
733859a271SKees Cook } __randomize_layout;
747d6fec45SAl Viro 
75f7a99c5bSAl Viro #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
76f7a99c5bSAl Viro 
777d6fec45SAl Viro static inline struct mount *real_mount(struct vfsmount *mnt)
787d6fec45SAl Viro {
797d6fec45SAl Viro 	return container_of(mnt, struct mount, mnt);
807d6fec45SAl Viro }
817d6fec45SAl Viro 
82676da58dSAl Viro static inline int mnt_has_parent(struct mount *mnt)
83b2dba1afSAl Viro {
840714a533SAl Viro 	return mnt != mnt->mnt_parent;
85b2dba1afSAl Viro }
86c7105365SAl Viro 
87f7a99c5bSAl Viro static inline int is_mounted(struct vfsmount *mnt)
88f7a99c5bSAl Viro {
89f7a99c5bSAl Viro 	/* neither detached nor internal? */
90260a459dSEric W. Biederman 	return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
91f7a99c5bSAl Viro }
92f7a99c5bSAl Viro 
93474279dcSAl Viro extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
940226f492SAl Viro 
95294d71ffSAl Viro extern int __legitimize_mnt(struct vfsmount *, unsigned);
9648a066e7SAl Viro extern bool legitimize_mnt(struct vfsmount *, unsigned);
9748a066e7SAl Viro 
98c6609c0aSIan Kent static inline bool __path_is_mountpoint(const struct path *path)
99c6609c0aSIan Kent {
100c6609c0aSIan Kent 	struct mount *m = __lookup_mnt(path->mnt, path->dentry);
101c6609c0aSIan Kent 	return m && likely(!(m->mnt.mnt_flags & MNT_SYNC_UMOUNT));
102c6609c0aSIan Kent }
103c6609c0aSIan Kent 
10480b5dce8SEric W. Biederman extern void __detach_mounts(struct dentry *dentry);
10580b5dce8SEric W. Biederman 
10680b5dce8SEric W. Biederman static inline void detach_mounts(struct dentry *dentry)
10780b5dce8SEric W. Biederman {
10880b5dce8SEric W. Biederman 	if (!d_mountpoint(dentry))
10980b5dce8SEric W. Biederman 		return;
11080b5dce8SEric W. Biederman 	__detach_mounts(dentry);
11180b5dce8SEric W. Biederman }
11280b5dce8SEric W. Biederman 
1130226f492SAl Viro static inline void get_mnt_ns(struct mnt_namespace *ns)
1140226f492SAl Viro {
1150226f492SAl Viro 	atomic_inc(&ns->count);
1160226f492SAl Viro }
1170226f492SAl Viro 
11848a066e7SAl Viro extern seqlock_t mount_lock;
119719ea2fbSAl Viro 
120719ea2fbSAl Viro static inline void lock_mount_hash(void)
121719ea2fbSAl Viro {
12248a066e7SAl Viro 	write_seqlock(&mount_lock);
123719ea2fbSAl Viro }
124719ea2fbSAl Viro 
125719ea2fbSAl Viro static inline void unlock_mount_hash(void)
126719ea2fbSAl Viro {
12748a066e7SAl Viro 	write_sequnlock(&mount_lock);
128719ea2fbSAl Viro }
129719ea2fbSAl Viro 
1300226f492SAl Viro struct proc_mounts {
1310226f492SAl Viro 	struct mnt_namespace *ns;
1320226f492SAl Viro 	struct path root;
1330226f492SAl Viro 	int (*show)(struct seq_file *, struct vfsmount *);
134c7999c36SAl Viro 	void *cached_mount;
135c7999c36SAl Viro 	u64 cached_event;
136c7999c36SAl Viro 	loff_t cached_index;
1370226f492SAl Viro };
1380226f492SAl Viro 
1390226f492SAl Viro extern const struct seq_operations mounts_op;
1407af1364fSEric W. Biederman 
1417af1364fSEric W. Biederman extern bool __is_local_mountpoint(struct dentry *dentry);
1427af1364fSEric W. Biederman static inline bool is_local_mountpoint(struct dentry *dentry)
1437af1364fSEric W. Biederman {
1447af1364fSEric W. Biederman 	if (!d_mountpoint(dentry))
1457af1364fSEric W. Biederman 		return false;
1467af1364fSEric W. Biederman 
1477af1364fSEric W. Biederman 	return __is_local_mountpoint(dentry);
1487af1364fSEric W. Biederman }
14974e83122SAl Viro 
15074e83122SAl Viro static inline bool is_anon_ns(struct mnt_namespace *ns)
15174e83122SAl Viro {
15274e83122SAl Viro 	return ns->seq == 0;
15374e83122SAl Viro }
154