xref: /openbmc/linux/fs/mount.h (revision 537f7ccb)
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;
170226f492SAl Viro };
18b2dba1afSAl Viro 
1968e8a9feSAl Viro struct mnt_pcp {
2068e8a9feSAl Viro 	int mnt_count;
2168e8a9feSAl Viro 	int mnt_writers;
2268e8a9feSAl Viro };
2368e8a9feSAl Viro 
2484d17192SAl Viro struct mountpoint {
250818bf27SAl Viro 	struct hlist_node m_hash;
2684d17192SAl Viro 	struct dentry *m_dentry;
270a5eb7c8SEric W. Biederman 	struct hlist_head m_list;
2884d17192SAl Viro 	int m_count;
2984d17192SAl Viro };
3084d17192SAl Viro 
317d6fec45SAl Viro struct mount {
3238129a13SAl Viro 	struct hlist_node mnt_hash;
330714a533SAl Viro 	struct mount *mnt_parent;
34a73324daSAl Viro 	struct dentry *mnt_mountpoint;
357d6fec45SAl Viro 	struct vfsmount mnt;
369ea459e1SAl Viro 	union {
3748a066e7SAl Viro 		struct rcu_head mnt_rcu;
389ea459e1SAl Viro 		struct llist_node mnt_llist;
399ea459e1SAl Viro 	};
4068e8a9feSAl Viro #ifdef CONFIG_SMP
4168e8a9feSAl Viro 	struct mnt_pcp __percpu *mnt_pcp;
4268e8a9feSAl Viro #else
4368e8a9feSAl Viro 	int mnt_count;
4468e8a9feSAl Viro 	int mnt_writers;
4568e8a9feSAl Viro #endif
466b41d536SAl Viro 	struct list_head mnt_mounts;	/* list of children, anchored here */
476b41d536SAl Viro 	struct list_head mnt_child;	/* and going through their mnt_child */
4839f7c4dbSMiklos Szeredi 	struct list_head mnt_instance;	/* mount instance on sb->s_mounts */
4952ba1621SAl Viro 	const char *mnt_devname;	/* Name of device e.g. /dev/dsk/hda1 */
501a4eeaf2SAl Viro 	struct list_head mnt_list;
516776db3dSAl Viro 	struct list_head mnt_expire;	/* link in fs-specific expiry list */
526776db3dSAl Viro 	struct list_head mnt_share;	/* circular list of shared mounts */
536776db3dSAl Viro 	struct list_head mnt_slave_list;/* list of slave mounts */
546776db3dSAl Viro 	struct list_head mnt_slave;	/* slave list entry */
5532301920SAl Viro 	struct mount *mnt_master;	/* slave is on master->mnt_slave_list */
56143c8c91SAl Viro 	struct mnt_namespace *mnt_ns;	/* containing namespace */
5784d17192SAl Viro 	struct mountpoint *mnt_mp;	/* where is it mounted */
580a5eb7c8SEric W. Biederman 	struct hlist_node mnt_mp_list;	/* list mounts with the same mountpoint */
59c63181e6SAl Viro #ifdef CONFIG_FSNOTIFY
60c63181e6SAl Viro 	struct hlist_head mnt_fsnotify_marks;
61c63181e6SAl Viro 	__u32 mnt_fsnotify_mask;
62c63181e6SAl Viro #endif
6315169fe7SAl Viro 	int mnt_id;			/* mount identifier */
6415169fe7SAl Viro 	int mnt_group_id;		/* peer group identifier */
65863d684fSAl Viro 	int mnt_expiry_mark;		/* true if marked for expiry */
66215752fcSAl Viro 	struct hlist_head mnt_pins;
6787b95ce0SAl Viro 	struct fs_pin mnt_umount;
6887b95ce0SAl Viro 	struct dentry *mnt_ex_mountpoint;
697d6fec45SAl Viro };
707d6fec45SAl Viro 
71f7a99c5bSAl Viro #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
72f7a99c5bSAl Viro 
737d6fec45SAl Viro static inline struct mount *real_mount(struct vfsmount *mnt)
747d6fec45SAl Viro {
757d6fec45SAl Viro 	return container_of(mnt, struct mount, mnt);
767d6fec45SAl Viro }
777d6fec45SAl Viro 
78676da58dSAl Viro static inline int mnt_has_parent(struct mount *mnt)
79b2dba1afSAl Viro {
800714a533SAl Viro 	return mnt != mnt->mnt_parent;
81b2dba1afSAl Viro }
82c7105365SAl Viro 
83f7a99c5bSAl Viro static inline int is_mounted(struct vfsmount *mnt)
84f7a99c5bSAl Viro {
85f7a99c5bSAl Viro 	/* neither detached nor internal? */
86260a459dSEric W. Biederman 	return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
87f7a99c5bSAl Viro }
88f7a99c5bSAl Viro 
89474279dcSAl Viro extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
90474279dcSAl Viro extern struct mount *__lookup_mnt_last(struct vfsmount *, struct dentry *);
910226f492SAl Viro 
92294d71ffSAl Viro extern int __legitimize_mnt(struct vfsmount *, unsigned);
9348a066e7SAl Viro extern bool legitimize_mnt(struct vfsmount *, unsigned);
9448a066e7SAl Viro 
9580b5dce8SEric W. Biederman extern void __detach_mounts(struct dentry *dentry);
9680b5dce8SEric W. Biederman 
9780b5dce8SEric W. Biederman static inline void detach_mounts(struct dentry *dentry)
9880b5dce8SEric W. Biederman {
9980b5dce8SEric W. Biederman 	if (!d_mountpoint(dentry))
10080b5dce8SEric W. Biederman 		return;
10180b5dce8SEric W. Biederman 	__detach_mounts(dentry);
10280b5dce8SEric W. Biederman }
10380b5dce8SEric W. Biederman 
1040226f492SAl Viro static inline void get_mnt_ns(struct mnt_namespace *ns)
1050226f492SAl Viro {
1060226f492SAl Viro 	atomic_inc(&ns->count);
1070226f492SAl Viro }
1080226f492SAl Viro 
10948a066e7SAl Viro extern seqlock_t mount_lock;
110719ea2fbSAl Viro 
111719ea2fbSAl Viro static inline void lock_mount_hash(void)
112719ea2fbSAl Viro {
11348a066e7SAl Viro 	write_seqlock(&mount_lock);
114719ea2fbSAl Viro }
115719ea2fbSAl Viro 
116719ea2fbSAl Viro static inline void unlock_mount_hash(void)
117719ea2fbSAl Viro {
11848a066e7SAl Viro 	write_sequnlock(&mount_lock);
119719ea2fbSAl Viro }
120719ea2fbSAl Viro 
1210226f492SAl Viro struct proc_mounts {
1220226f492SAl Viro 	struct mnt_namespace *ns;
1230226f492SAl Viro 	struct path root;
1240226f492SAl Viro 	int (*show)(struct seq_file *, struct vfsmount *);
125c7999c36SAl Viro 	void *cached_mount;
126c7999c36SAl Viro 	u64 cached_event;
127c7999c36SAl Viro 	loff_t cached_index;
1280226f492SAl Viro };
1290226f492SAl Viro 
1300226f492SAl Viro extern const struct seq_operations mounts_op;
1317af1364fSEric W. Biederman 
1327af1364fSEric W. Biederman extern bool __is_local_mountpoint(struct dentry *dentry);
1337af1364fSEric W. Biederman static inline bool is_local_mountpoint(struct dentry *dentry)
1347af1364fSEric W. Biederman {
1357af1364fSEric W. Biederman 	if (!d_mountpoint(dentry))
1367af1364fSEric W. Biederman 		return false;
1377af1364fSEric W. Biederman 
1387af1364fSEric W. Biederman 	return __is_local_mountpoint(dentry);
1397af1364fSEric W. Biederman }
140