mount.h 4.2 KB

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