xref: /openbmc/linux/fs/mount.h (revision 80b5dce8)
1b2dba1afSAl Viro #include <linux/mount.h>
20226f492SAl Viro #include <linux/seq_file.h>
30226f492SAl Viro #include <linux/poll.h>
40226f492SAl Viro 
50226f492SAl Viro struct mnt_namespace {
60226f492SAl Viro 	atomic_t		count;
798f842e6SEric W. Biederman 	unsigned int		proc_inum;
8be08d6d2SAl Viro 	struct mount *	root;
90226f492SAl Viro 	struct list_head	list;
10771b1371SEric W. Biederman 	struct user_namespace	*user_ns;
118823c079SEric W. Biederman 	u64			seq;	/* Sequence number to prevent loops */
120226f492SAl Viro 	wait_queue_head_t poll;
13c7999c36SAl Viro 	u64 event;
140226f492SAl Viro };
15b2dba1afSAl Viro 
1668e8a9feSAl Viro struct mnt_pcp {
1768e8a9feSAl Viro 	int mnt_count;
1868e8a9feSAl Viro 	int mnt_writers;
1968e8a9feSAl Viro };
2068e8a9feSAl Viro 
2184d17192SAl Viro struct mountpoint {
220818bf27SAl Viro 	struct hlist_node m_hash;
2384d17192SAl Viro 	struct dentry *m_dentry;
240a5eb7c8SEric W. Biederman 	struct hlist_head m_list;
2584d17192SAl Viro 	int m_count;
2684d17192SAl Viro };
2784d17192SAl Viro 
287d6fec45SAl Viro struct mount {
2938129a13SAl Viro 	struct hlist_node mnt_hash;
300714a533SAl Viro 	struct mount *mnt_parent;
31a73324daSAl Viro 	struct dentry *mnt_mountpoint;
327d6fec45SAl Viro 	struct vfsmount mnt;
339ea459e1SAl Viro 	union {
3448a066e7SAl Viro 		struct rcu_head mnt_rcu;
359ea459e1SAl Viro 		struct llist_node mnt_llist;
369ea459e1SAl Viro 	};
3768e8a9feSAl Viro #ifdef CONFIG_SMP
3868e8a9feSAl Viro 	struct mnt_pcp __percpu *mnt_pcp;
3968e8a9feSAl Viro #else
4068e8a9feSAl Viro 	int mnt_count;
4168e8a9feSAl Viro 	int mnt_writers;
4268e8a9feSAl Viro #endif
436b41d536SAl Viro 	struct list_head mnt_mounts;	/* list of children, anchored here */
446b41d536SAl Viro 	struct list_head mnt_child;	/* and going through their mnt_child */
4539f7c4dbSMiklos Szeredi 	struct list_head mnt_instance;	/* mount instance on sb->s_mounts */
4652ba1621SAl Viro 	const char *mnt_devname;	/* Name of device e.g. /dev/dsk/hda1 */
471a4eeaf2SAl Viro 	struct list_head mnt_list;
486776db3dSAl Viro 	struct list_head mnt_expire;	/* link in fs-specific expiry list */
496776db3dSAl Viro 	struct list_head mnt_share;	/* circular list of shared mounts */
506776db3dSAl Viro 	struct list_head mnt_slave_list;/* list of slave mounts */
516776db3dSAl Viro 	struct list_head mnt_slave;	/* slave list entry */
5232301920SAl Viro 	struct mount *mnt_master;	/* slave is on master->mnt_slave_list */
53143c8c91SAl Viro 	struct mnt_namespace *mnt_ns;	/* containing namespace */
5484d17192SAl Viro 	struct mountpoint *mnt_mp;	/* where is it mounted */
550a5eb7c8SEric W. Biederman 	struct hlist_node mnt_mp_list;	/* list mounts with the same mountpoint */
56c63181e6SAl Viro #ifdef CONFIG_FSNOTIFY
57c63181e6SAl Viro 	struct hlist_head mnt_fsnotify_marks;
58c63181e6SAl Viro 	__u32 mnt_fsnotify_mask;
59c63181e6SAl Viro #endif
6015169fe7SAl Viro 	int mnt_id;			/* mount identifier */
6115169fe7SAl Viro 	int mnt_group_id;		/* peer group identifier */
62863d684fSAl Viro 	int mnt_expiry_mark;		/* true if marked for expiry */
63215752fcSAl Viro 	struct hlist_head mnt_pins;
64aba809cfSAl Viro 	struct path mnt_ex_mountpoint;
657d6fec45SAl Viro };
667d6fec45SAl Viro 
67f7a99c5bSAl Viro #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
68f7a99c5bSAl Viro 
697d6fec45SAl Viro static inline struct mount *real_mount(struct vfsmount *mnt)
707d6fec45SAl Viro {
717d6fec45SAl Viro 	return container_of(mnt, struct mount, mnt);
727d6fec45SAl Viro }
737d6fec45SAl Viro 
74676da58dSAl Viro static inline int mnt_has_parent(struct mount *mnt)
75b2dba1afSAl Viro {
760714a533SAl Viro 	return mnt != mnt->mnt_parent;
77b2dba1afSAl Viro }
78c7105365SAl Viro 
79f7a99c5bSAl Viro static inline int is_mounted(struct vfsmount *mnt)
80f7a99c5bSAl Viro {
81f7a99c5bSAl Viro 	/* neither detached nor internal? */
82260a459dSEric W. Biederman 	return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
83f7a99c5bSAl Viro }
84f7a99c5bSAl Viro 
85474279dcSAl Viro extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
86474279dcSAl Viro extern struct mount *__lookup_mnt_last(struct vfsmount *, struct dentry *);
870226f492SAl Viro 
8848a066e7SAl Viro extern bool legitimize_mnt(struct vfsmount *, unsigned);
8948a066e7SAl Viro 
9080b5dce8SEric W. Biederman extern void __detach_mounts(struct dentry *dentry);
9180b5dce8SEric W. Biederman 
9280b5dce8SEric W. Biederman static inline void detach_mounts(struct dentry *dentry)
9380b5dce8SEric W. Biederman {
9480b5dce8SEric W. Biederman 	if (!d_mountpoint(dentry))
9580b5dce8SEric W. Biederman 		return;
9680b5dce8SEric W. Biederman 	__detach_mounts(dentry);
9780b5dce8SEric W. Biederman }
9880b5dce8SEric W. Biederman 
990226f492SAl Viro static inline void get_mnt_ns(struct mnt_namespace *ns)
1000226f492SAl Viro {
1010226f492SAl Viro 	atomic_inc(&ns->count);
1020226f492SAl Viro }
1030226f492SAl Viro 
10448a066e7SAl Viro extern seqlock_t mount_lock;
105719ea2fbSAl Viro 
106719ea2fbSAl Viro static inline void lock_mount_hash(void)
107719ea2fbSAl Viro {
10848a066e7SAl Viro 	write_seqlock(&mount_lock);
109719ea2fbSAl Viro }
110719ea2fbSAl Viro 
111719ea2fbSAl Viro static inline void unlock_mount_hash(void)
112719ea2fbSAl Viro {
11348a066e7SAl Viro 	write_sequnlock(&mount_lock);
114719ea2fbSAl Viro }
115719ea2fbSAl Viro 
1160226f492SAl Viro struct proc_mounts {
1176ce6e24eSAl Viro 	struct seq_file m;
1180226f492SAl Viro 	struct mnt_namespace *ns;
1190226f492SAl Viro 	struct path root;
1200226f492SAl Viro 	int (*show)(struct seq_file *, struct vfsmount *);
121c7999c36SAl Viro 	void *cached_mount;
122c7999c36SAl Viro 	u64 cached_event;
123c7999c36SAl Viro 	loff_t cached_index;
1240226f492SAl Viro };
1250226f492SAl Viro 
1266ce6e24eSAl Viro #define proc_mounts(p) (container_of((p), struct proc_mounts, m))
1276ce6e24eSAl Viro 
1280226f492SAl Viro extern const struct seq_operations mounts_op;
1297af1364fSEric W. Biederman 
1307af1364fSEric W. Biederman extern bool __is_local_mountpoint(struct dentry *dentry);
1317af1364fSEric W. Biederman static inline bool is_local_mountpoint(struct dentry *dentry)
1327af1364fSEric W. Biederman {
1337af1364fSEric W. Biederman 	if (!d_mountpoint(dentry))
1347af1364fSEric W. Biederman 		return false;
1357af1364fSEric W. Biederman 
1367af1364fSEric W. Biederman 	return __is_local_mountpoint(dentry);
1377af1364fSEric W. Biederman }
138