original development tree for Linux kernel GTP module; now long in mainline.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
2.8 KiB

RCU'd vfsmounts * RCU-delayed freeing of vfsmounts * vfsmount_lock replaced with a seqlock (mount_lock) * sequence number from mount_lock is stored in nameidata->m_seq and used when we exit RCU mode * new vfsmount flag - MNT_SYNC_UMOUNT. Set by umount_tree() when its caller knows that vfsmount will have no surviving references. * synchronize_rcu() done between unlocking namespace_sem in namespace_unlock() and doing pending mntput(). * new helper: legitimize_mnt(mnt, seq). Checks the mount_lock sequence number against seq, then grabs reference to mnt. Then it rechecks mount_lock again to close the race and either returns success or drops the reference it has acquired. The subtle point is that in case of MNT_SYNC_UMOUNT we can simply decrement the refcount and sod off - aforementioned synchronize_rcu() makes sure that final mntput() won't come until we leave RCU mode. We need that, since we don't want to end up with some lazy pathwalk racing with umount() and stealing the final mntput() from it - caller of umount() may expect it to return only once the fs is shut down and we don't want to break that. In other cases (i.e. with MNT_SYNC_UMOUNT absent) we have to do full-blown mntput() in case of mount_lock sequence number mismatch happening just as we'd grabbed the reference, but in those cases we won't be stealing the final mntput() from anything that would care. * mntput_no_expire() doesn't lock anything on the fast path now. Incidentally, SMP and UP cases are handled the same way - no ifdefs there. * normal pathname resolution does *not* do any writes to mount_lock. It does, of course, bump the refcounts of vfsmount and dentry in the very end, but that's it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
8 years ago
RCU'd vfsmounts * RCU-delayed freeing of vfsmounts * vfsmount_lock replaced with a seqlock (mount_lock) * sequence number from mount_lock is stored in nameidata->m_seq and used when we exit RCU mode * new vfsmount flag - MNT_SYNC_UMOUNT. Set by umount_tree() when its caller knows that vfsmount will have no surviving references. * synchronize_rcu() done between unlocking namespace_sem in namespace_unlock() and doing pending mntput(). * new helper: legitimize_mnt(mnt, seq). Checks the mount_lock sequence number against seq, then grabs reference to mnt. Then it rechecks mount_lock again to close the race and either returns success or drops the reference it has acquired. The subtle point is that in case of MNT_SYNC_UMOUNT we can simply decrement the refcount and sod off - aforementioned synchronize_rcu() makes sure that final mntput() won't come until we leave RCU mode. We need that, since we don't want to end up with some lazy pathwalk racing with umount() and stealing the final mntput() from it - caller of umount() may expect it to return only once the fs is shut down and we don't want to break that. In other cases (i.e. with MNT_SYNC_UMOUNT absent) we have to do full-blown mntput() in case of mount_lock sequence number mismatch happening just as we'd grabbed the reference, but in those cases we won't be stealing the final mntput() from anything that would care. * mntput_no_expire() doesn't lock anything on the fast path now. Incidentally, SMP and UP cases are handled the same way - no ifdefs there. * normal pathname resolution does *not* do any writes to mount_lock. It does, of course, bump the refcounts of vfsmount and dentry in the very end, but that's it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
8 years ago
RCU'd vfsmounts * RCU-delayed freeing of vfsmounts * vfsmount_lock replaced with a seqlock (mount_lock) * sequence number from mount_lock is stored in nameidata->m_seq and used when we exit RCU mode * new vfsmount flag - MNT_SYNC_UMOUNT. Set by umount_tree() when its caller knows that vfsmount will have no surviving references. * synchronize_rcu() done between unlocking namespace_sem in namespace_unlock() and doing pending mntput(). * new helper: legitimize_mnt(mnt, seq). Checks the mount_lock sequence number against seq, then grabs reference to mnt. Then it rechecks mount_lock again to close the race and either returns success or drops the reference it has acquired. The subtle point is that in case of MNT_SYNC_UMOUNT we can simply decrement the refcount and sod off - aforementioned synchronize_rcu() makes sure that final mntput() won't come until we leave RCU mode. We need that, since we don't want to end up with some lazy pathwalk racing with umount() and stealing the final mntput() from it - caller of umount() may expect it to return only once the fs is shut down and we don't want to break that. In other cases (i.e. with MNT_SYNC_UMOUNT absent) we have to do full-blown mntput() in case of mount_lock sequence number mismatch happening just as we'd grabbed the reference, but in those cases we won't be stealing the final mntput() from anything that would care. * mntput_no_expire() doesn't lock anything on the fast path now. Incidentally, SMP and UP cases are handled the same way - no ifdefs there. * normal pathname resolution does *not* do any writes to mount_lock. It does, of course, bump the refcounts of vfsmount and dentry in the very end, but that's it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
8 years ago
RCU'd vfsmounts * RCU-delayed freeing of vfsmounts * vfsmount_lock replaced with a seqlock (mount_lock) * sequence number from mount_lock is stored in nameidata->m_seq and used when we exit RCU mode * new vfsmount flag - MNT_SYNC_UMOUNT. Set by umount_tree() when its caller knows that vfsmount will have no surviving references. * synchronize_rcu() done between unlocking namespace_sem in namespace_unlock() and doing pending mntput(). * new helper: legitimize_mnt(mnt, seq). Checks the mount_lock sequence number against seq, then grabs reference to mnt. Then it rechecks mount_lock again to close the race and either returns success or drops the reference it has acquired. The subtle point is that in case of MNT_SYNC_UMOUNT we can simply decrement the refcount and sod off - aforementioned synchronize_rcu() makes sure that final mntput() won't come until we leave RCU mode. We need that, since we don't want to end up with some lazy pathwalk racing with umount() and stealing the final mntput() from it - caller of umount() may expect it to return only once the fs is shut down and we don't want to break that. In other cases (i.e. with MNT_SYNC_UMOUNT absent) we have to do full-blown mntput() in case of mount_lock sequence number mismatch happening just as we'd grabbed the reference, but in those cases we won't be stealing the final mntput() from anything that would care. * mntput_no_expire() doesn't lock anything on the fast path now. Incidentally, SMP and UP cases are handled the same way - no ifdefs there. * normal pathname resolution does *not* do any writes to mount_lock. It does, of course, bump the refcounts of vfsmount and dentry in the very end, but that's it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
8 years ago
RCU'd vfsmounts * RCU-delayed freeing of vfsmounts * vfsmount_lock replaced with a seqlock (mount_lock) * sequence number from mount_lock is stored in nameidata->m_seq and used when we exit RCU mode * new vfsmount flag - MNT_SYNC_UMOUNT. Set by umount_tree() when its caller knows that vfsmount will have no surviving references. * synchronize_rcu() done between unlocking namespace_sem in namespace_unlock() and doing pending mntput(). * new helper: legitimize_mnt(mnt, seq). Checks the mount_lock sequence number against seq, then grabs reference to mnt. Then it rechecks mount_lock again to close the race and either returns success or drops the reference it has acquired. The subtle point is that in case of MNT_SYNC_UMOUNT we can simply decrement the refcount and sod off - aforementioned synchronize_rcu() makes sure that final mntput() won't come until we leave RCU mode. We need that, since we don't want to end up with some lazy pathwalk racing with umount() and stealing the final mntput() from it - caller of umount() may expect it to return only once the fs is shut down and we don't want to break that. In other cases (i.e. with MNT_SYNC_UMOUNT absent) we have to do full-blown mntput() in case of mount_lock sequence number mismatch happening just as we'd grabbed the reference, but in those cases we won't be stealing the final mntput() from anything that would care. * mntput_no_expire() doesn't lock anything on the fast path now. Incidentally, SMP and UP cases are handled the same way - no ifdefs there. * normal pathname resolution does *not* do any writes to mount_lock. It does, of course, bump the refcounts of vfsmount and dentry in the very end, but that's it. Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
8 years ago
  1. #include <linux/mount.h>
  2. #include <linux/seq_file.h>
  3. #include <linux/poll.h>
  4. struct mnt_namespace {
  5. atomic_t count;
  6. unsigned int proc_inum;
  7. struct mount * root;
  8. struct list_head list;
  9. struct user_namespace *user_ns;
  10. u64 seq; /* Sequence number to prevent loops */
  11. wait_queue_head_t poll;
  12. int event;
  13. };
  14. struct mnt_pcp {
  15. int mnt_count;
  16. int mnt_writers;
  17. };
  18. struct mountpoint {
  19. struct list_head m_hash;
  20. struct dentry *m_dentry;
  21. int m_count;
  22. };
  23. struct mount {
  24. struct list_head mnt_hash;
  25. struct mount *mnt_parent;
  26. struct dentry *mnt_mountpoint;
  27. struct vfsmount mnt;
  28. struct rcu_head mnt_rcu;
  29. #ifdef CONFIG_SMP
  30. struct mnt_pcp __percpu *mnt_pcp;
  31. #else
  32. int mnt_count;
  33. int mnt_writers;
  34. #endif
  35. struct list_head mnt_mounts; /* list of children, anchored here */
  36. struct list_head mnt_child; /* and going through their mnt_child */
  37. struct list_head mnt_instance; /* mount instance on sb->s_mounts */
  38. const char *mnt_devname; /* Name of device e.g. /dev/dsk/hda1 */
  39. struct list_head mnt_list;
  40. struct list_head mnt_expire; /* link in fs-specific expiry list */
  41. struct list_head mnt_share; /* circular list of shared mounts */
  42. struct list_head mnt_slave_list;/* list of slave mounts */
  43. struct list_head mnt_slave; /* slave list entry */
  44. struct mount *mnt_master; /* slave is on master->mnt_slave_list */
  45. struct mnt_namespace *mnt_ns; /* containing namespace */
  46. struct mountpoint *mnt_mp; /* where is it mounted */
  47. #ifdef CONFIG_FSNOTIFY
  48. struct hlist_head mnt_fsnotify_marks;
  49. __u32 mnt_fsnotify_mask;
  50. #endif
  51. int mnt_id; /* mount identifier */
  52. int mnt_group_id; /* peer group identifier */
  53. int mnt_expiry_mark; /* true if marked for expiry */
  54. int mnt_pinned;
  55. struct path mnt_ex_mountpoint;
  56. };
  57. #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
  58. static inline struct mount *real_mount(struct vfsmount *mnt)
  59. {
  60. return container_of(mnt, struct mount, mnt);
  61. }
  62. static inline int mnt_has_parent(struct mount *mnt)
  63. {
  64. return mnt != mnt->mnt_parent;
  65. }
  66. static inline int is_mounted(struct vfsmount *mnt)
  67. {
  68. /* neither detached nor internal? */
  69. return !IS_ERR_OR_NULL(real_mount(mnt));
  70. }
  71. extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
  72. extern struct mount *__lookup_mnt_last(struct vfsmount *, struct dentry *);
  73. extern bool legitimize_mnt(struct vfsmount *, unsigned);
  74. static inline void get_mnt_ns(struct mnt_namespace *ns)
  75. {
  76. atomic_inc(&ns->count);
  77. }
  78. extern seqlock_t mount_lock;
  79. static inline void lock_mount_hash(void)
  80. {
  81. write_seqlock(&mount_lock);
  82. }
  83. static inline void unlock_mount_hash(void)
  84. {
  85. write_sequnlock(&mount_lock);
  86. }
  87. struct proc_mounts {
  88. struct seq_file m;
  89. struct mnt_namespace *ns;
  90. struct path root;
  91. int (*show)(struct seq_file *, struct vfsmount *);
  92. };
  93. #define proc_mounts(p) (container_of((p), struct proc_mounts, m))
  94. extern const struct seq_operations mounts_op;