ignatenkobrain / rpms / kernel

Forked from rpms/kernel 3 years ago
Clone
b312fc
From 9cc2c0f41c403a05989bc3ca2af650247d452f65 Mon Sep 17 00:00:00 2001
b312fc
From: "T.kabe" <kabe@>
b312fc
Date: Mon, 6 Mar 2017 15:18:55 +0900
b312fc
Subject: [PATCH 2/4] vfs: Keep a list of mounts on a mount point
b312fc
b312fc
[upstream commit 0a5eb7c8189922e86a840972cd0b57e41de6f031]
b312fc
Author: Eric W. Biederman <ebiederman@twitter.com>
b312fc
Date:   Sun Sep 22 19:37:01 2013 -0700
b312fc
b312fc
    vfs: Keep a list of mounts on a mount point
b312fc
b312fc
    To spot any possible problems call BUG if a mountpoint
b312fc
    is put when it's list of mounts is not empty.
b312fc
b312fc
    AV: use hlist instead of list_head
b312fc
b312fc
    Reviewed-by: Miklos Szeredi <miklos@szeredi.hu>
b312fc
    Signed-off-by: Eric W. Biederman <ebiederman@twitter.com>
b312fc
    Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
b312fc
---
b312fc
 fs/mount.h     | 2 ++
b312fc
 fs/namespace.c | 6 ++++++
b312fc
 2 files changed, 8 insertions(+)
b312fc
b312fc
diff --git a/fs/mount.h b/fs/mount.h
b312fc
index b870800..92fecbe 100644
b312fc
--- a/fs/mount.h
b312fc
+++ b/fs/mount.h
b312fc
@@ -21,6 +21,7 @@ struct mnt_pcp {
b312fc
 struct mountpoint {
b312fc
 	struct list_head m_hash;
b312fc
 	struct dentry *m_dentry;
b312fc
+	struct hlist_head m_list;
b312fc
 	int m_count;
b312fc
 };
b312fc
 
b312fc
@@ -47,6 +48,7 @@ struct mount {
b312fc
 	struct mount *mnt_master;	/* slave is on master->mnt_slave_list */
b312fc
 	struct mnt_namespace *mnt_ns;	/* containing namespace */
b312fc
 	struct mountpoint *mnt_mp;	/* where is it mounted */
b312fc
+	struct hlist_node mnt_mp_list;	/* list mounts with the same mountpoint */
b312fc
 #ifdef CONFIG_FSNOTIFY
b312fc
 	struct hlist_head mnt_fsnotify_marks;
b312fc
 	__u32 mnt_fsnotify_mask;
b312fc
diff --git a/fs/namespace.c b/fs/namespace.c
b312fc
index 0053bfc..c238481 100644
b312fc
--- a/fs/namespace.c
b312fc
+++ b/fs/namespace.c
b312fc
@@ -197,6 +197,7 @@ static struct mount *alloc_vfsmnt(const char *name)
b312fc
 		INIT_LIST_HEAD(&mnt->mnt_share);
b312fc
 		INIT_LIST_HEAD(&mnt->mnt_slave_list);
b312fc
 		INIT_LIST_HEAD(&mnt->mnt_slave);
b312fc
+		INIT_HLIST_NODE(&mnt->mnt_mp_list);
b312fc
 #ifdef CONFIG_FSNOTIFY
b312fc
 		INIT_HLIST_HEAD(&mnt->mnt_fsnotify_marks);
b312fc
 #endif
b312fc
@@ -636,6 +637,7 @@ static struct mountpoint *new_mountpoint(struct dentry *dentry)
b312fc
 	mp->m_dentry = dentry;
b312fc
 	mp->m_count = 1;
b312fc
 	list_add(&mp->m_hash, chain);
b312fc
+	INIT_HLIST_HEAD(&mp->m_list);
b312fc
 	return mp;
b312fc
 }
b312fc
 
b312fc
@@ -643,6 +645,7 @@ static void put_mountpoint(struct mountpoint *mp)
b312fc
 {
b312fc
 	if (!--mp->m_count) {
b312fc
 		struct dentry *dentry = mp->m_dentry;
b312fc
+		BUG_ON(!hlist_empty(&mp->m_list));
b312fc
 		spin_lock(&dentry->d_lock);
b312fc
 		dentry->d_flags &= ~DCACHE_MOUNTED;
b312fc
 		spin_unlock(&dentry->d_lock);
b312fc
@@ -689,6 +692,7 @@ static void detach_mnt(struct mount *mnt, struct path *old_path)
b312fc
 	mnt->mnt_mountpoint = mnt->mnt.mnt_root;
b312fc
 	list_del_init(&mnt->mnt_child);
b312fc
 	list_del_init(&mnt->mnt_hash);
b312fc
+	hlist_del_init(&mnt->mnt_mp_list);
b312fc
 	put_mountpoint(mnt->mnt_mp);
b312fc
 	mnt->mnt_mp = NULL;
b312fc
 }
b312fc
@@ -705,6 +709,7 @@ void mnt_set_mountpoint(struct mount *mnt,
b312fc
 	child_mnt->mnt_mountpoint = dget(mp->m_dentry);
b312fc
 	child_mnt->mnt_parent = mnt;
b312fc
 	child_mnt->mnt_mp = mp;
b312fc
+	hlist_add_head(&child_mnt->mnt_mp_list, &mp->m_list);
b312fc
 }
b312fc
 
b312fc
 /*
b312fc
@@ -1207,6 +1212,7 @@ void umount_tree(struct mount *mnt, int propagate)
b312fc
 		__touch_mnt_namespace(p->mnt_ns);
b312fc
 		p->mnt_ns = NULL;
b312fc
 		if (mnt_has_parent(p)) {
b312fc
+			hlist_del_init(&p->mnt_mp_list);
b312fc
 			p->mnt_parent->mnt_ghosts++;
b312fc
 			put_mountpoint(p->mnt_mp);
b312fc
 			p->mnt_mp = NULL;
b312fc
-- 
b312fc
1.8.3.1
b312fc