mount.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #include <linux/mount.h>
  3. #include <linux/seq_file.h>
  4. #include <linux/poll.h>
  5. #include <linux/ns_common.h>
  6. #include <linux/fs_pin.h>
  7. struct mnt_namespace {
  8. struct ns_common ns;
  9. struct mount * root;
  10. struct rb_root mounts; /* Protected by namespace_sem */
  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 nr_mounts; /* # of mounts in the namespace */
  17. unsigned int pending_mounts;
  18. struct rb_node mnt_ns_tree_node; /* node in the mnt_ns_tree */
  19. refcount_t passive; /* number references not pinning @mounts */
  20. } __randomize_layout;
  21. struct mnt_pcp {
  22. int mnt_count;
  23. int mnt_writers;
  24. };
  25. struct mountpoint {
  26. struct hlist_node m_hash;
  27. struct dentry *m_dentry;
  28. struct hlist_head m_list;
  29. int m_count;
  30. };
  31. struct mount {
  32. struct hlist_node mnt_hash;
  33. struct mount *mnt_parent;
  34. struct dentry *mnt_mountpoint;
  35. struct vfsmount mnt;
  36. union {
  37. struct rb_node mnt_node; /* node in the ns->mounts rbtree */
  38. struct rcu_head mnt_rcu;
  39. struct llist_node mnt_llist;
  40. };
  41. #ifdef CONFIG_SMP
  42. struct mnt_pcp __percpu *mnt_pcp;
  43. #else
  44. int mnt_count;
  45. int mnt_writers;
  46. #endif
  47. struct list_head mnt_mounts; /* list of children, anchored here */
  48. struct list_head mnt_child; /* and going through their mnt_child */
  49. struct list_head mnt_instance; /* mount instance on sb->s_mounts */
  50. const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
  51. struct list_head mnt_list;
  52. struct list_head mnt_expire; /* link in fs-specific expiry list */
  53. struct list_head mnt_share; /* circular list of shared mounts */
  54. struct list_head mnt_slave_list;/* list of slave mounts */
  55. struct list_head mnt_slave; /* slave list entry */
  56. struct mount *mnt_master; /* slave is on master->mnt_slave_list */
  57. struct mnt_namespace *mnt_ns; /* containing namespace */
  58. struct mountpoint *mnt_mp; /* where is it mounted */
  59. union {
  60. struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
  61. struct hlist_node mnt_umount;
  62. };
  63. struct list_head mnt_umounting; /* list entry for umount propagation */
  64. #ifdef CONFIG_FSNOTIFY
  65. struct fsnotify_mark_connector __rcu *mnt_fsnotify_marks;
  66. __u32 mnt_fsnotify_mask;
  67. #endif
  68. int mnt_id; /* mount identifier, reused */
  69. u64 mnt_id_unique; /* mount ID unique until reboot */
  70. int mnt_group_id; /* peer group identifier */
  71. int mnt_expiry_mark; /* true if marked for expiry */
  72. struct hlist_head mnt_pins;
  73. struct hlist_head mnt_stuck_children;
  74. } __randomize_layout;
  75. #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
  76. static inline struct mount *real_mount(struct vfsmount *mnt)
  77. {
  78. return container_of(mnt, struct mount, mnt);
  79. }
  80. static inline int mnt_has_parent(struct mount *mnt)
  81. {
  82. return mnt != mnt->mnt_parent;
  83. }
  84. static inline int is_mounted(struct vfsmount *mnt)
  85. {
  86. /* neither detached nor internal? */
  87. return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
  88. }
  89. extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
  90. extern int __legitimize_mnt(struct vfsmount *, unsigned);
  91. static inline bool __path_is_mountpoint(const struct path *path)
  92. {
  93. struct mount *m = __lookup_mnt(path->mnt, path->dentry);
  94. return m && likely(!(m->mnt.mnt_flags & MNT_SYNC_UMOUNT));
  95. }
  96. extern void __detach_mounts(struct dentry *dentry);
  97. static inline void detach_mounts(struct dentry *dentry)
  98. {
  99. if (!d_mountpoint(dentry))
  100. return;
  101. __detach_mounts(dentry);
  102. }
  103. static inline void get_mnt_ns(struct mnt_namespace *ns)
  104. {
  105. refcount_inc(&ns->ns.count);
  106. }
  107. extern seqlock_t mount_lock;
  108. struct proc_mounts {
  109. struct mnt_namespace *ns;
  110. struct path root;
  111. int (*show)(struct seq_file *, struct vfsmount *);
  112. };
  113. extern const struct seq_operations mounts_op;
  114. extern bool __is_local_mountpoint(struct dentry *dentry);
  115. static inline bool is_local_mountpoint(struct dentry *dentry)
  116. {
  117. if (!d_mountpoint(dentry))
  118. return false;
  119. return __is_local_mountpoint(dentry);
  120. }
  121. static inline bool is_anon_ns(struct mnt_namespace *ns)
  122. {
  123. return ns->seq == 0;
  124. }
  125. static inline bool mnt_ns_attached(const struct mount *mnt)
  126. {
  127. return !RB_EMPTY_NODE(&mnt->mnt_node);
  128. }
  129. static inline void move_from_ns(struct mount *mnt, struct list_head *dt_list)
  130. {
  131. WARN_ON(!mnt_ns_attached(mnt));
  132. rb_erase(&mnt->mnt_node, &mnt->mnt_ns->mounts);
  133. RB_CLEAR_NODE(&mnt->mnt_node);
  134. list_add_tail(&mnt->mnt_list, dt_list);
  135. }
  136. bool has_locked_children(struct mount *mnt, struct dentry *dentry);
  137. struct mnt_namespace *__lookup_next_mnt_ns(struct mnt_namespace *mnt_ns, bool previous);
  138. static inline struct mnt_namespace *lookup_next_mnt_ns(struct mnt_namespace *mntns)
  139. {
  140. return __lookup_next_mnt_ns(mntns, false);
  141. }
  142. static inline struct mnt_namespace *lookup_prev_mnt_ns(struct mnt_namespace *mntns)
  143. {
  144. return __lookup_next_mnt_ns(mntns, true);
  145. }
  146. static inline struct mnt_namespace *to_mnt_ns(struct ns_common *ns)
  147. {
  148. return container_of(ns, struct mnt_namespace, ns);
  149. }