ignatenkobrain / rpms / kernel

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