[Devel] [PATCH RHEL8 COMMIT] mnt_ns: introduce global list of mount namespaces for debug

Konstantin Khorenko khorenko at virtuozzo.com
Wed Jun 9 18:16:01 MSK 2021


The commit is pushed to "branch-rh8-4.18.0-240.1.1.vz8.5.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh8-4.18.0-240.1.1.vz8.5.38
------>
commit d986e2a72ad3e92ba95dac9bb4f720cdb5206be1
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Wed Jun 9 18:16:01 2021 +0300

    mnt_ns: introduce global list of mount namespaces for debug
    
    We've got several cases when ploop could not be unmounted resulting in
    -EBUSY. Sometimes we could find what holds it sometimes not, so let's
    introduce the global list of mount namespaces: it will make it easier to
    debug such cases.
    
    https://jira.sw.ru/browse/PSBM-80869
    
    Signed-off-by: Konstantin Khorenko <khorenko at virtuozzo.com>
    Reviewed-by: Andrey Ryabinin <aryabinin at virtuozzo.com>
    
    (cherry picked from vz7 commit abee9d40a8d1 ("mnt_ns: introduce global list of
    mount namespaces for debug"))
    
    VZ 8 rebase part https://jira.sw.ru/browse/PSBM-127837
    
    Signed-off-by: Alexander Mikhalitsyn <alexander.mikhalitsyn at virtuozzo.com>
---
 fs/mount.h     |  1 +
 fs/namespace.c | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/fs/mount.h b/fs/mount.h
index e3e0379d5c47..9225fc7bce30 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -17,6 +17,7 @@ struct mnt_namespace {
 	u64 event;
 	unsigned int		mounts; /* # of mounts in the namespace */
 	unsigned int		pending_mounts;
+	struct list_head	mntns_list;
 } __randomize_layout;
 
 struct mnt_pcp {
diff --git a/fs/namespace.c b/fs/namespace.c
index adedb5839907..0096fbb71774 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3262,6 +3262,10 @@ static void free_mnt_ns(struct mnt_namespace *ns)
 		ns_free_inum(&ns->ns);
 	dec_mnt_namespaces(ns->ucounts);
 	put_user_ns(ns->user_ns);
+
+	namespace_lock();
+	list_del(&ns->mntns_list);
+	namespace_unlock();
 	kfree(ns);
 }
 
@@ -3273,6 +3277,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
  * is effectively never, so we can ignore the possibility.
  */
 static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
+static LIST_HEAD(all_mntns_list); /* protected by namespace_sem */
 
 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool anon)
 {
@@ -3302,6 +3307,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
 		new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
 	atomic_set(&new_ns->count, 1);
 	INIT_LIST_HEAD(&new_ns->list);
+	INIT_LIST_HEAD(&new_ns->mntns_list);
 	init_waitqueue_head(&new_ns->poll);
 	new_ns->user_ns = get_user_ns(user_ns);
 	new_ns->ucounts = ucounts;
@@ -3333,6 +3339,8 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
 		return new_ns;
 
 	namespace_lock();
+	list_add_tail(&new_ns->mntns_list, &all_mntns_list);
+
 	/* First pass: copy the tree topology */
 	copy_flags = CL_COPY_UNBINDABLE | CL_EXPIRE;
 	if (user_ns != ns->user_ns)
@@ -3400,6 +3408,9 @@ struct dentry *mount_subtree(struct vfsmount *m, const char *name)
 	ns->root = mnt;
 	ns->mounts++;
 	list_add(&mnt->mnt_list, &ns->list);
+	namespace_lock();
+	list_add_tail(&ns->mntns_list, &all_mntns_list);
+	namespace_unlock();
 
 	err = vfs_path_lookup(m->mnt_root, m,
 			name, LOOKUP_FOLLOW|LOOKUP_AUTOMOUNT, &path);
@@ -3691,6 +3702,9 @@ static void __init init_mount_tree(void)
 	ns->root = m;
 	ns->mounts = 1;
 	list_add(&m->mnt_list, &ns->list);
+	namespace_lock();
+	list_add_tail(&ns->mntns_list, &all_mntns_list);
+	namespace_unlock();
 	init_task.nsproxy->mnt_ns = ns;
 	get_mnt_ns(ns);
 


More information about the Devel mailing list