mount.h 4.2 KB

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