Commit 0a5eb7c8 authored by Eric W. Biederman's avatar Eric W. Biederman Committed by Al Viro

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: default avatarMiklos Szeredi <miklos@szeredi.hu>
Signed-off-by: default avatarEric W. Biederman <ebiederman@twitter.com>
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
parent 7af1364f
...@@ -21,6 +21,7 @@ struct mnt_pcp { ...@@ -21,6 +21,7 @@ struct mnt_pcp {
struct mountpoint { struct mountpoint {
struct hlist_node m_hash; struct hlist_node m_hash;
struct dentry *m_dentry; struct dentry *m_dentry;
struct hlist_head m_list;
int m_count; int m_count;
}; };
...@@ -51,6 +52,7 @@ struct mount { ...@@ -51,6 +52,7 @@ struct mount {
struct mount *mnt_master; /* slave is on master->mnt_slave_list */ struct mount *mnt_master; /* slave is on master->mnt_slave_list */
struct mnt_namespace *mnt_ns; /* containing namespace */ struct mnt_namespace *mnt_ns; /* containing namespace */
struct mountpoint *mnt_mp; /* where is it mounted */ struct mountpoint *mnt_mp; /* where is it mounted */
struct hlist_node mnt_mp_list; /* list mounts with the same mountpoint */
#ifdef CONFIG_FSNOTIFY #ifdef CONFIG_FSNOTIFY
struct hlist_head mnt_fsnotify_marks; struct hlist_head mnt_fsnotify_marks;
__u32 mnt_fsnotify_mask; __u32 mnt_fsnotify_mask;
......
...@@ -225,6 +225,7 @@ static struct mount *alloc_vfsmnt(const char *name) ...@@ -225,6 +225,7 @@ static struct mount *alloc_vfsmnt(const char *name)
INIT_LIST_HEAD(&mnt->mnt_share); INIT_LIST_HEAD(&mnt->mnt_share);
INIT_LIST_HEAD(&mnt->mnt_slave_list); INIT_LIST_HEAD(&mnt->mnt_slave_list);
INIT_LIST_HEAD(&mnt->mnt_slave); INIT_LIST_HEAD(&mnt->mnt_slave);
INIT_HLIST_NODE(&mnt->mnt_mp_list);
#ifdef CONFIG_FSNOTIFY #ifdef CONFIG_FSNOTIFY
INIT_HLIST_HEAD(&mnt->mnt_fsnotify_marks); INIT_HLIST_HEAD(&mnt->mnt_fsnotify_marks);
#endif #endif
...@@ -731,6 +732,7 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry) ...@@ -731,6 +732,7 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry)
mp->m_dentry = dentry; mp->m_dentry = dentry;
mp->m_count = 1; mp->m_count = 1;
hlist_add_head(&mp->m_hash, chain); hlist_add_head(&mp->m_hash, chain);
INIT_HLIST_HEAD(&mp->m_list);
return mp; return mp;
} }
...@@ -738,6 +740,7 @@ static void put_mountpoint(struct mountpoint *mp) ...@@ -738,6 +740,7 @@ static void put_mountpoint(struct mountpoint *mp)
{ {
if (!--mp->m_count) { if (!--mp->m_count) {
struct dentry *dentry = mp->m_dentry; struct dentry *dentry = mp->m_dentry;
BUG_ON(!hlist_empty(&mp->m_list));
spin_lock(&dentry->d_lock); spin_lock(&dentry->d_lock);
dentry->d_flags &= ~DCACHE_MOUNTED; dentry->d_flags &= ~DCACHE_MOUNTED;
spin_unlock(&dentry->d_lock); spin_unlock(&dentry->d_lock);
...@@ -784,6 +787,7 @@ static void detach_mnt(struct mount *mnt, struct path *old_path) ...@@ -784,6 +787,7 @@ static void detach_mnt(struct mount *mnt, struct path *old_path)
mnt->mnt_mountpoint = mnt->mnt.mnt_root; mnt->mnt_mountpoint = mnt->mnt.mnt_root;
list_del_init(&mnt->mnt_child); list_del_init(&mnt->mnt_child);
hlist_del_init_rcu(&mnt->mnt_hash); hlist_del_init_rcu(&mnt->mnt_hash);
hlist_del_init(&mnt->mnt_mp_list);
put_mountpoint(mnt->mnt_mp); put_mountpoint(mnt->mnt_mp);
mnt->mnt_mp = NULL; mnt->mnt_mp = NULL;
} }
...@@ -800,6 +804,7 @@ void mnt_set_mountpoint(struct mount *mnt, ...@@ -800,6 +804,7 @@ void mnt_set_mountpoint(struct mount *mnt,
child_mnt->mnt_mountpoint = dget(mp->m_dentry); child_mnt->mnt_mountpoint = dget(mp->m_dentry);
child_mnt->mnt_parent = mnt; child_mnt->mnt_parent = mnt;
child_mnt->mnt_mp = mp; child_mnt->mnt_mp = mp;
hlist_add_head(&child_mnt->mnt_mp_list, &mp->m_list);
} }
/* /*
...@@ -1342,6 +1347,7 @@ void umount_tree(struct mount *mnt, int how) ...@@ -1342,6 +1347,7 @@ void umount_tree(struct mount *mnt, int how)
if (how < 2) if (how < 2)
p->mnt.mnt_flags |= MNT_SYNC_UMOUNT; p->mnt.mnt_flags |= MNT_SYNC_UMOUNT;
if (mnt_has_parent(p)) { if (mnt_has_parent(p)) {
hlist_del_init(&p->mnt_mp_list);
put_mountpoint(p->mnt_mp); put_mountpoint(p->mnt_mp);
mnt_add_count(p->mnt_parent, -1); mnt_add_count(p->mnt_parent, -1);
/* move the reference to mountpoint into ->mnt_ex_mountpoint */ /* move the reference to mountpoint into ->mnt_ex_mountpoint */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment