xref: /openbmc/linux/fs/mount.h (revision 3859a271)
1b2dba1afSAl Viro #include <linux/mount.h>
20226f492SAl Viro #include <linux/seq_file.h>
30226f492SAl Viro #include <linux/poll.h>
4435d5f4bSAl Viro #include <linux/ns_common.h>
587b95ce0SAl Viro #include <linux/fs_pin.h>
60226f492SAl Viro 
70226f492SAl Viro struct mnt_namespace {
80226f492SAl Viro 	atomic_t		count;
9435d5f4bSAl Viro 	struct ns_common	ns;
10be08d6d2SAl Viro 	struct mount *	root;
110226f492SAl Viro 	struct list_head	list;
12771b1371SEric W. Biederman 	struct user_namespace	*user_ns;
13537f7ccbSEric W. Biederman 	struct ucounts		*ucounts;
148823c079SEric W. Biederman 	u64			seq;	/* Sequence number to prevent loops */
150226f492SAl Viro 	wait_queue_head_t poll;
16c7999c36SAl Viro 	u64 event;
17d2921684SEric W. Biederman 	unsigned int		mounts; /* # of mounts in the namespace */
18d2921684SEric W. Biederman 	unsigned int		pending_mounts;
193859a271SKees Cook } __randomize_layout;
20b2dba1afSAl Viro 
2168e8a9feSAl Viro struct mnt_pcp {
2268e8a9feSAl Viro 	int mnt_count;
2368e8a9feSAl Viro 	int mnt_writers;
2468e8a9feSAl Viro };
2568e8a9feSAl Viro 
2684d17192SAl Viro struct mountpoint {
270818bf27SAl Viro 	struct hlist_node m_hash;
2884d17192SAl Viro 	struct dentry *m_dentry;
290a5eb7c8SEric W. Biederman 	struct hlist_head m_list;
3084d17192SAl Viro 	int m_count;
3184d17192SAl Viro };
3284d17192SAl Viro 
337d6fec45SAl Viro struct mount {
3438129a13SAl Viro 	struct hlist_node mnt_hash;
350714a533SAl Viro 	struct mount *mnt_parent;
36a73324daSAl Viro 	struct dentry *mnt_mountpoint;
377d6fec45SAl Viro 	struct vfsmount mnt;
389ea459e1SAl Viro 	union {
3948a066e7SAl Viro 		struct rcu_head mnt_rcu;
409ea459e1SAl Viro 		struct llist_node mnt_llist;
419ea459e1SAl Viro 	};
4268e8a9feSAl Viro #ifdef CONFIG_SMP
4368e8a9feSAl Viro 	struct mnt_pcp __percpu *mnt_pcp;
4468e8a9feSAl Viro #else
4568e8a9feSAl Viro 	int mnt_count;
4668e8a9feSAl Viro 	int mnt_writers;
4768e8a9feSAl Viro #endif
486b41d536SAl Viro 	struct list_head mnt_mounts;	/* list of children, anchored here */
496b41d536SAl Viro 	struct list_head mnt_child;	/* and going through their mnt_child */
5039f7c4dbSMiklos Szeredi 	struct list_head mnt_instance;	/* mount instance on sb->s_mounts */
5152ba1621SAl Viro 	const char *mnt_devname;	/* Name of device e.g. /dev/dsk/hda1 */
521a4eeaf2SAl Viro 	struct list_head mnt_list;
536776db3dSAl Viro 	struct list_head mnt_expire;	/* link in fs-specific expiry list */
546776db3dSAl Viro 	struct list_head mnt_share;	/* circular list of shared mounts */
556776db3dSAl Viro 	struct list_head mnt_slave_list;/* list of slave mounts */
566776db3dSAl Viro 	struct list_head mnt_slave;	/* slave list entry */
5732301920SAl Viro 	struct mount *mnt_master;	/* slave is on master->mnt_slave_list */
58143c8c91SAl Viro 	struct mnt_namespace *mnt_ns;	/* containing namespace */
5984d17192SAl Viro 	struct mountpoint *mnt_mp;	/* where is it mounted */
600a5eb7c8SEric W. Biederman 	struct hlist_node mnt_mp_list;	/* list mounts with the same mountpoint */
61c63181e6SAl Viro #ifdef CONFIG_FSNOTIFY
6208991e83SJan Kara 	struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
63c63181e6SAl Viro 	__u32 mnt_fsnotify_mask;
64c63181e6SAl Viro #endif
6515169fe7SAl Viro 	int mnt_id;			/* mount identifier */
6615169fe7SAl Viro 	int mnt_group_id;		/* peer group identifier */
67863d684fSAl Viro 	int mnt_expiry_mark;		/* true if marked for expiry */
68215752fcSAl Viro 	struct hlist_head mnt_pins;
6987b95ce0SAl Viro 	struct fs_pin mnt_umount;
7087b95ce0SAl Viro 	struct dentry *mnt_ex_mountpoint;
713859a271SKees Cook } __randomize_layout;
727d6fec45SAl Viro 
73f7a99c5bSAl Viro #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
74f7a99c5bSAl Viro 
757d6fec45SAl Viro static inline struct mount *real_mount(struct vfsmount *mnt)
767d6fec45SAl Viro {
777d6fec45SAl Viro 	return container_of(mnt, struct mount, mnt);
787d6fec45SAl Viro }
797d6fec45SAl Viro 
80676da58dSAl Viro static inline int mnt_has_parent(struct mount *mnt)
81b2dba1afSAl Viro {
820714a533SAl Viro 	return mnt != mnt->mnt_parent;
83b2dba1afSAl Viro }
84c7105365SAl Viro 
85f7a99c5bSAl Viro static inline int is_mounted(struct vfsmount *mnt)
86f7a99c5bSAl Viro {
87f7a99c5bSAl Viro 	/* neither detached nor internal? */
88260a459dSEric W. Biederman 	return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
89f7a99c5bSAl Viro }
90f7a99c5bSAl Viro 
91474279dcSAl Viro extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
920226f492SAl Viro 
93294d71ffSAl Viro extern int __legitimize_mnt(struct vfsmount *, unsigned);
9448a066e7SAl Viro extern bool legitimize_mnt(struct vfsmount *, unsigned);
9548a066e7SAl Viro 
96c6609c0aSIan Kent static inline bool __path_is_mountpoint(const struct path *path)
97c6609c0aSIan Kent {
98c6609c0aSIan Kent 	struct mount *m = __lookup_mnt(path->mnt, path->dentry);
99c6609c0aSIan Kent 	return m && likely(!(m->mnt.mnt_flags & MNT_SYNC_UMOUNT));
100c6609c0aSIan Kent }
101c6609c0aSIan Kent 
10280b5dce8SEric W. Biederman extern void __detach_mounts(struct dentry *dentry);
10380b5dce8SEric W. Biederman 
10480b5dce8SEric W. Biederman static inline void detach_mounts(struct dentry *dentry)
10580b5dce8SEric W. Biederman {
10680b5dce8SEric W. Biederman 	if (!d_mountpoint(dentry))
10780b5dce8SEric W. Biederman 		return;
10880b5dce8SEric W. Biederman 	__detach_mounts(dentry);
10980b5dce8SEric W. Biederman }
11080b5dce8SEric W. Biederman 
1110226f492SAl Viro static inline void get_mnt_ns(struct mnt_namespace *ns)
1120226f492SAl Viro {
1130226f492SAl Viro 	atomic_inc(&ns->count);
1140226f492SAl Viro }
1150226f492SAl Viro 
11648a066e7SAl Viro extern seqlock_t mount_lock;
117719ea2fbSAl Viro 
118719ea2fbSAl Viro static inline void lock_mount_hash(void)
119719ea2fbSAl Viro {
12048a066e7SAl Viro 	write_seqlock(&mount_lock);
121719ea2fbSAl Viro }
122719ea2fbSAl Viro 
123719ea2fbSAl Viro static inline void unlock_mount_hash(void)
124719ea2fbSAl Viro {
12548a066e7SAl Viro 	write_sequnlock(&mount_lock);
126719ea2fbSAl Viro }
127719ea2fbSAl Viro 
1280226f492SAl Viro struct proc_mounts {
1290226f492SAl Viro 	struct mnt_namespace *ns;
1300226f492SAl Viro 	struct path root;
1310226f492SAl Viro 	int (*show)(struct seq_file *, struct vfsmount *);
132c7999c36SAl Viro 	void *cached_mount;
133c7999c36SAl Viro 	u64 cached_event;
134c7999c36SAl Viro 	loff_t cached_index;
1350226f492SAl Viro };
1360226f492SAl Viro 
1370226f492SAl Viro extern const struct seq_operations mounts_op;
1387af1364fSEric W. Biederman 
1397af1364fSEric W. Biederman extern bool __is_local_mountpoint(struct dentry *dentry);
1407af1364fSEric W. Biederman static inline bool is_local_mountpoint(struct dentry *dentry)
1417af1364fSEric W. Biederman {
1427af1364fSEric W. Biederman 	if (!d_mountpoint(dentry))
1437af1364fSEric W. Biederman 		return false;
1447af1364fSEric W. Biederman 
1457af1364fSEric W. Biederman 	return __is_local_mountpoint(dentry);
1467af1364fSEric W. Biederman }
147