mount.h 3.5 KB

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