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