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; 138823c079SEric W. Biederman u64 seq; /* Sequence number to prevent loops */ 140226f492SAl Viro wait_queue_head_t poll; 15c7999c36SAl Viro u64 event; 160226f492SAl Viro }; 17b2dba1afSAl Viro 1868e8a9feSAl Viro struct mnt_pcp { 1968e8a9feSAl Viro int mnt_count; 2068e8a9feSAl Viro int mnt_writers; 2168e8a9feSAl Viro }; 2268e8a9feSAl Viro 2384d17192SAl Viro struct mountpoint { 240818bf27SAl Viro struct hlist_node m_hash; 2584d17192SAl Viro struct dentry *m_dentry; 260a5eb7c8SEric W. Biederman struct hlist_head m_list; 2784d17192SAl Viro int m_count; 2884d17192SAl Viro }; 2984d17192SAl Viro 307d6fec45SAl Viro struct mount { 3138129a13SAl Viro struct hlist_node mnt_hash; 320714a533SAl Viro struct mount *mnt_parent; 33a73324daSAl Viro struct dentry *mnt_mountpoint; 347d6fec45SAl Viro struct vfsmount mnt; 359ea459e1SAl Viro union { 3648a066e7SAl Viro struct rcu_head mnt_rcu; 379ea459e1SAl Viro struct llist_node mnt_llist; 389ea459e1SAl Viro }; 3968e8a9feSAl Viro #ifdef CONFIG_SMP 4068e8a9feSAl Viro struct mnt_pcp __percpu *mnt_pcp; 4168e8a9feSAl Viro #else 4268e8a9feSAl Viro int mnt_count; 4368e8a9feSAl Viro int mnt_writers; 4468e8a9feSAl Viro #endif 456b41d536SAl Viro struct list_head mnt_mounts; /* list of children, anchored here */ 466b41d536SAl Viro struct list_head mnt_child; /* and going through their mnt_child */ 4739f7c4dbSMiklos Szeredi struct list_head mnt_instance; /* mount instance on sb->s_mounts */ 4852ba1621SAl Viro const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */ 491a4eeaf2SAl Viro struct list_head mnt_list; 506776db3dSAl Viro struct list_head mnt_expire; /* link in fs-specific expiry list */ 516776db3dSAl Viro struct list_head mnt_share; /* circular list of shared mounts */ 526776db3dSAl Viro struct list_head mnt_slave_list;/* list of slave mounts */ 536776db3dSAl Viro struct list_head mnt_slave; /* slave list entry */ 5432301920SAl Viro struct mount *mnt_master; /* slave is on master->mnt_slave_list */ 55143c8c91SAl Viro struct mnt_namespace *mnt_ns; /* containing namespace */ 5684d17192SAl Viro struct mountpoint *mnt_mp; /* where is it mounted */ 570a5eb7c8SEric W. Biederman struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */ 58c63181e6SAl Viro #ifdef CONFIG_FSNOTIFY 59c63181e6SAl Viro struct hlist_head mnt_fsnotify_marks; 60c63181e6SAl Viro __u32 mnt_fsnotify_mask; 61c63181e6SAl Viro #endif 6215169fe7SAl Viro int mnt_id; /* mount identifier */ 6315169fe7SAl Viro int mnt_group_id; /* peer group identifier */ 64863d684fSAl Viro int mnt_expiry_mark; /* true if marked for expiry */ 65215752fcSAl Viro struct hlist_head mnt_pins; 6687b95ce0SAl Viro struct fs_pin mnt_umount; 6787b95ce0SAl Viro struct dentry *mnt_ex_mountpoint; 687d6fec45SAl Viro }; 697d6fec45SAl Viro 70f7a99c5bSAl Viro #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */ 71f7a99c5bSAl Viro 727d6fec45SAl Viro static inline struct mount *real_mount(struct vfsmount *mnt) 737d6fec45SAl Viro { 747d6fec45SAl Viro return container_of(mnt, struct mount, mnt); 757d6fec45SAl Viro } 767d6fec45SAl Viro 77676da58dSAl Viro static inline int mnt_has_parent(struct mount *mnt) 78b2dba1afSAl Viro { 790714a533SAl Viro return mnt != mnt->mnt_parent; 80b2dba1afSAl Viro } 81c7105365SAl Viro 82f7a99c5bSAl Viro static inline int is_mounted(struct vfsmount *mnt) 83f7a99c5bSAl Viro { 84f7a99c5bSAl Viro /* neither detached nor internal? */ 85260a459dSEric W. Biederman return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns); 86f7a99c5bSAl Viro } 87f7a99c5bSAl Viro 88474279dcSAl Viro extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *); 89474279dcSAl Viro extern struct mount *__lookup_mnt_last(struct vfsmount *, struct dentry *); 900226f492SAl Viro 9148a066e7SAl Viro extern bool legitimize_mnt(struct vfsmount *, unsigned); 9248a066e7SAl Viro 9380b5dce8SEric W. Biederman extern void __detach_mounts(struct dentry *dentry); 9480b5dce8SEric W. Biederman 9580b5dce8SEric W. Biederman static inline void detach_mounts(struct dentry *dentry) 9680b5dce8SEric W. Biederman { 9780b5dce8SEric W. Biederman if (!d_mountpoint(dentry)) 9880b5dce8SEric W. Biederman return; 9980b5dce8SEric W. Biederman __detach_mounts(dentry); 10080b5dce8SEric W. Biederman } 10180b5dce8SEric W. Biederman 1020226f492SAl Viro static inline void get_mnt_ns(struct mnt_namespace *ns) 1030226f492SAl Viro { 1040226f492SAl Viro atomic_inc(&ns->count); 1050226f492SAl Viro } 1060226f492SAl Viro 10748a066e7SAl Viro extern seqlock_t mount_lock; 108719ea2fbSAl Viro 109719ea2fbSAl Viro static inline void lock_mount_hash(void) 110719ea2fbSAl Viro { 11148a066e7SAl Viro write_seqlock(&mount_lock); 112719ea2fbSAl Viro } 113719ea2fbSAl Viro 114719ea2fbSAl Viro static inline void unlock_mount_hash(void) 115719ea2fbSAl Viro { 11648a066e7SAl Viro write_sequnlock(&mount_lock); 117719ea2fbSAl Viro } 118719ea2fbSAl Viro 1190226f492SAl Viro struct proc_mounts { 1206ce6e24eSAl Viro struct seq_file m; 1210226f492SAl Viro struct mnt_namespace *ns; 1220226f492SAl Viro struct path root; 1230226f492SAl Viro int (*show)(struct seq_file *, struct vfsmount *); 124c7999c36SAl Viro void *cached_mount; 125c7999c36SAl Viro u64 cached_event; 126c7999c36SAl Viro loff_t cached_index; 1270226f492SAl Viro }; 1280226f492SAl Viro 1296ce6e24eSAl Viro #define proc_mounts(p) (container_of((p), struct proc_mounts, m)) 1306ce6e24eSAl Viro 1310226f492SAl Viro extern const struct seq_operations mounts_op; 1327af1364fSEric W. Biederman 1337af1364fSEric W. Biederman extern bool __is_local_mountpoint(struct dentry *dentry); 1347af1364fSEric W. Biederman static inline bool is_local_mountpoint(struct dentry *dentry) 1357af1364fSEric W. Biederman { 1367af1364fSEric W. Biederman if (!d_mountpoint(dentry)) 1377af1364fSEric W. Biederman return false; 1387af1364fSEric W. Biederman 1397af1364fSEric W. Biederman return __is_local_mountpoint(dentry); 1407af1364fSEric W. Biederman } 141