mount.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. #include <linux/mount.h>
  2. #include <linux/seq_file.h>
  3. #include <linux/poll.h>
  4. #include <linux/ns_common.h>
  5. #include <linux/fs_pin.h>
  6. struct mnt_namespace {
  7. atomic_t count;
  8. struct ns_common ns;
  9. struct mount * root;
  10. struct list_head list;
  11. struct user_namespace *user_ns;
  12. struct ucounts *ucounts;
  13. u64 seq; /* Sequence number to prevent loops */
  14. wait_queue_head_t poll;
  15. u64 event;
  16. unsigned int mounts; /* # of mounts in the namespace */
  17. unsigned int pending_mounts;
  18. } __randomize_layout;
  19. struct mnt_pcp {
  20. int mnt_count;
  21. int mnt_writers;
  22. };
  23. struct mountpoint {
  24. struct hlist_node m_hash;
  25. struct dentry *m_dentry;
  26. struct hlist_head m_list;
  27. int m_count;
  28. };
  29. struct mount {
  30. struct hlist_node mnt_hash;
  31. struct mount *mnt_parent;
  32. struct dentry *mnt_mountpoint;
  33. struct vfsmount mnt;
  34. union {
  35. struct rcu_head mnt_rcu;
  36. struct llist_node mnt_llist;
  37. };
  38. #ifdef CONFIG_SMP
  39. struct mnt_pcp __percpu *mnt_pcp;
  40. #else
  41. int mnt_count;
  42. int mnt_writers;
  43. #endif
  44. struct list_head mnt_mounts; /* list of children, anchored here */
  45. struct list_head mnt_child; /* and going through their mnt_child */
  46. struct list_head mnt_instance; /* mount instance on sb->s_mounts */
  47. const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
  48. struct list_head mnt_list;
  49. struct list_head mnt_expire; /* link in fs-specific expiry list */
  50. struct list_head mnt_share; /* circular list of shared mounts */
  51. struct list_head mnt_slave_list;/* list of slave mounts */
  52. struct list_head mnt_slave; /* slave list entry */
  53. struct mount *mnt_master; /* slave is on master->mnt_slave_list */
  54. struct mnt_namespace *mnt_ns; /* containing namespace */
  55. struct mountpoint *mnt_mp; /* where is it mounted */
  56. struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
  57. #ifdef CONFIG_FSNOTIFY
  58. struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
  59. __u32 mnt_fsnotify_mask;
  60. #endif
  61. int mnt_id; /* mount identifier */
  62. int mnt_group_id; /* peer group identifier */
  63. int mnt_expiry_mark; /* true if marked for expiry */
  64. struct hlist_head mnt_pins;
  65. struct fs_pin mnt_umount;
  66. struct dentry *mnt_ex_mountpoint;
  67. } __randomize_layout;
  68. #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
  69. static inline struct mount *real_mount(struct vfsmount *mnt)
  70. {
  71. return container_of(mnt, struct mount, mnt);
  72. }
  73. static inline int mnt_has_parent(struct mount *mnt)
  74. {
  75. return mnt != mnt->mnt_parent;
  76. }
  77. static inline int is_mounted(struct vfsmount *mnt)
  78. {
  79. /* neither detached nor internal? */
  80. return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
  81. }
  82. extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
  83. extern int __legitimize_mnt(struct vfsmount *, unsigned);
  84. extern bool legitimize_mnt(struct vfsmount *, unsigned);
  85. static inline bool __path_is_mountpoint(const struct path *path)
  86. {
  87. struct mount *m = __lookup_mnt(path->mnt, path->dentry);
  88. return m && likely(!(m->mnt.mnt_flags & MNT_SYNC_UMOUNT));
  89. }
  90. extern void __detach_mounts(struct dentry *dentry);
  91. static inline void detach_mounts(struct dentry *dentry)
  92. {
  93. if (!d_mountpoint(dentry))
  94. return;
  95. __detach_mounts(dentry);
  96. }
  97. static inline void get_mnt_ns(struct mnt_namespace *ns)
  98. {
  99. atomic_inc(&ns->count);
  100. }
  101. extern seqlock_t mount_lock;
  102. static inline void lock_mount_hash(void)
  103. {
  104. write_seqlock(&mount_lock);
  105. }
  106. static inline void unlock_mount_hash(void)
  107. {
  108. write_sequnlock(&mount_lock);
  109. }
  110. struct proc_mounts {
  111. struct mnt_namespace *ns;
  112. struct path root;
  113. int (*show)(struct seq_file *, struct vfsmount *);
  114. void *cached_mount;
  115. u64 cached_event;
  116. loff_t cached_index;
  117. };
  118. extern const struct seq_operations mounts_op;
  119. extern bool __is_local_mountpoint(struct dentry *dentry);
  120. static inline bool is_local_mountpoint(struct dentry *dentry)
  121. {
  122. if (!d_mountpoint(dentry))
  123. return false;
  124. return __is_local_mountpoint(dentry);
  125. }