diff options
author | Eric W. Biederman <ebiederman@twitter.com> | 2013-09-22 22:37:01 -0400 |
---|---|---|
committer | Al Viro <viro@zeniv.linux.org.uk> | 2014-10-09 02:38:54 -0400 |
commit | 0a5eb7c8189922e86a840972cd0b57e41de6f031 (patch) | |
tree | ee3f026727cff4acf5d7adbd7674d4177677f12f | |
parent | 7af1364ffa64db61e386628594836e13d2ef04b5 (diff) |
vfs: Keep a list of mounts on a mount point
To spot any possible problems call BUG if a mountpoint
is put when it's list of mounts is not empty.
AV: use hlist instead of list_head
Reviewed-by: Miklos Szeredi <miklos@szeredi.hu>
Signed-off-by: Eric W. Biederman <ebiederman@twitter.com>
Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
-rw-r--r-- | fs/mount.h | 2 | ||||
-rw-r--r-- | fs/namespace.c | 6 |
2 files changed, 8 insertions, 0 deletions
diff --git a/fs/mount.h b/fs/mount.h index 8c6a2a651254..68bb03ed7f19 100644 --- a/fs/mount.h +++ b/fs/mount.h | |||
@@ -21,6 +21,7 @@ struct mnt_pcp { | |||
21 | struct mountpoint { | 21 | struct mountpoint { |
22 | struct hlist_node m_hash; | 22 | struct hlist_node m_hash; |
23 | struct dentry *m_dentry; | 23 | struct dentry *m_dentry; |
24 | struct hlist_head m_list; | ||
24 | int m_count; | 25 | int m_count; |
25 | }; | 26 | }; |
26 | 27 | ||
@@ -51,6 +52,7 @@ struct mount { | |||
51 | struct mount *mnt_master; /* slave is on master->mnt_slave_list */ | 52 | struct mount *mnt_master; /* slave is on master->mnt_slave_list */ |
52 | struct mnt_namespace *mnt_ns; /* containing namespace */ | 53 | struct mnt_namespace *mnt_ns; /* containing namespace */ |
53 | struct mountpoint *mnt_mp; /* where is it mounted */ | 54 | struct mountpoint *mnt_mp; /* where is it mounted */ |
55 | struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */ | ||
54 | #ifdef CONFIG_FSNOTIFY | 56 | #ifdef CONFIG_FSNOTIFY |
55 | struct hlist_head mnt_fsnotify_marks; | 57 | struct hlist_head mnt_fsnotify_marks; |
56 | __u32 mnt_fsnotify_mask; | 58 | __u32 mnt_fsnotify_mask; |
diff --git a/fs/namespace.c b/fs/namespace.c index 77ffdb82f63f..99572dd08336 100644 --- a/fs/namespace.c +++ b/fs/namespace.c | |||
@@ -225,6 +225,7 @@ static struct mount *alloc_vfsmnt(const char *name) | |||
225 | INIT_LIST_HEAD(&mnt->mnt_share); | 225 | INIT_LIST_HEAD(&mnt->mnt_share); |
226 | INIT_LIST_HEAD(&mnt->mnt_slave_list); | 226 | INIT_LIST_HEAD(&mnt->mnt_slave_list); |
227 | INIT_LIST_HEAD(&mnt->mnt_slave); | 227 | INIT_LIST_HEAD(&mnt->mnt_slave); |
228 | INIT_HLIST_NODE(&mnt->mnt_mp_list); | ||
228 | #ifdef CONFIG_FSNOTIFY | 229 | #ifdef CONFIG_FSNOTIFY |
229 | INIT_HLIST_HEAD(&mnt->mnt_fsnotify_marks); | 230 | INIT_HLIST_HEAD(&mnt->mnt_fsnotify_marks); |
230 | #endif | 231 | #endif |
@@ -731,6 +732,7 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry) | |||
731 | mp->m_dentry = dentry; | 732 | mp->m_dentry = dentry; |
732 | mp->m_count = 1; | 733 | mp->m_count = 1; |
733 | hlist_add_head(&mp->m_hash, chain); | 734 | hlist_add_head(&mp->m_hash, chain); |
735 | INIT_HLIST_HEAD(&mp->m_list); | ||
734 | return mp; | 736 | return mp; |
735 | } | 737 | } |
736 | 738 | ||
@@ -738,6 +740,7 @@ static void put_mountpoint(struct mountpoint *mp) | |||
738 | { | 740 | { |
739 | if (!--mp->m_count) { | 741 | if (!--mp->m_count) { |
740 | struct dentry *dentry = mp->m_dentry; | 742 | struct dentry *dentry = mp->m_dentry; |
743 | BUG_ON(!hlist_empty(&mp->m_list)); | ||
741 | spin_lock(&dentry->d_lock); | 744 | spin_lock(&dentry->d_lock); |
742 | dentry->d_flags &= ~DCACHE_MOUNTED; | 745 | dentry->d_flags &= ~DCACHE_MOUNTED; |
743 | spin_unlock(&dentry->d_lock); | 746 | spin_unlock(&dentry->d_lock); |
@@ -784,6 +787,7 @@ static void detach_mnt(struct mount *mnt, struct path *old_path) | |||
784 | mnt->mnt_mountpoint = mnt->mnt.mnt_root; | 787 | mnt->mnt_mountpoint = mnt->mnt.mnt_root; |
785 | list_del_init(&mnt->mnt_child); | 788 | list_del_init(&mnt->mnt_child); |
786 | hlist_del_init_rcu(&mnt->mnt_hash); | 789 | hlist_del_init_rcu(&mnt->mnt_hash); |
790 | hlist_del_init(&mnt->mnt_mp_list); | ||
787 | put_mountpoint(mnt->mnt_mp); | 791 | put_mountpoint(mnt->mnt_mp); |
788 | mnt->mnt_mp = NULL; | 792 | mnt->mnt_mp = NULL; |
789 | } | 793 | } |
@@ -800,6 +804,7 @@ void mnt_set_mountpoint(struct mount *mnt, | |||
800 | child_mnt->mnt_mountpoint = dget(mp->m_dentry); | 804 | child_mnt->mnt_mountpoint = dget(mp->m_dentry); |
801 | child_mnt->mnt_parent = mnt; | 805 | child_mnt->mnt_parent = mnt; |
802 | child_mnt->mnt_mp = mp; | 806 | child_mnt->mnt_mp = mp; |
807 | hlist_add_head(&child_mnt->mnt_mp_list, &mp->m_list); | ||
803 | } | 808 | } |
804 | 809 | ||
805 | /* | 810 | /* |
@@ -1342,6 +1347,7 @@ void umount_tree(struct mount *mnt, int how) | |||
1342 | if (how < 2) | 1347 | if (how < 2) |
1343 | p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; | 1348 | p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; |
1344 | if (mnt_has_parent(p)) { | 1349 | if (mnt_has_parent(p)) { |
1350 | hlist_del_init(&p->mnt_mp_list); | ||
1345 | put_mountpoint(p->mnt_mp); | 1351 | put_mountpoint(p->mnt_mp); |
1346 | mnt_add_count(p->mnt_parent, -1); | 1352 | mnt_add_count(p->mnt_parent, -1); |
1347 | /* move the reference to mountpoint into ->mnt_ex_mountpoint */ | 1353 | /* move the reference to mountpoint into ->mnt_ex_mountpoint */ |