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

Konstantin Khorenko khorenko at virtuozzo.com
Wed Oct 20 11:40:50 MSK 2021


The commit is pushed to "branch-rh9-5.14.vz9.1.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh9-5.14.0-4.vz9.10.12
------>
commit 23df46226ff7ea5840446af5722e4dd8b2c21e66
Author: Konstantin Khorenko <khorenko at virtuozzo.com>
Date:   Wed Oct 20 11:40:50 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>
    
    Rebased to vz9:
     - there is 2 new functions that creates mntns. Instead of manually adding it
    to list, modify patch to add new mntns to list during alloc_mnt_ns
     - add all_mntns_list_lock spinlock to protect list instead of
    namespace_(un)lock()
    
    (cherry picked from vz8 commit b08585e9dc7bece4832a11312c9856860633a7a8)
    Signed-off-by: Andrey Zhadchenko <andrey.zhadchenko at virtuozzo.com>
---
 fs/mount.h     |  1 +
 fs/namespace.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/fs/mount.h b/fs/mount.h
index 7c6b7242092d..9043614df477 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -22,6 +22,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 b2f925ac15d5..dc73e945b746 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3575,12 +3575,19 @@ static void dec_mnt_namespaces(struct ucounts *ucounts)
 	dec_ucount(ucounts, UCOUNT_MNT_NAMESPACES);
 }
 
+static LIST_HEAD(all_mntns_list);
+static DEFINE_SPINLOCK(all_mntns_list_lock);
+
 static void free_mnt_ns(struct mnt_namespace *ns)
 {
 	if (!is_anon_ns(ns))
 		ns_free_inum(&ns->ns);
 	dec_mnt_namespaces(ns->ucounts);
 	put_user_ns(ns->user_ns);
+
+	spin_lock(&all_mntns_list_lock);
+	list_del(&ns->mntns_list);
+	spin_unlock(&all_mntns_list_lock);
 	kfree(ns);
 }
 
@@ -3621,6 +3628,10 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns, bool a
 		new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
 	refcount_set(&new_ns->ns.count, 1);
 	INIT_LIST_HEAD(&new_ns->list);
+	INIT_LIST_HEAD(&new_ns->mntns_list);
+	spin_lock(&all_mntns_list_lock);
+	list_add_tail(&new_ns->mntns_list, &all_mntns_list);
+	spin_unlock(&all_mntns_list_lock);
 	init_waitqueue_head(&new_ns->poll);
 	spin_lock_init(&new_ns->ns_lock);
 	new_ns->user_ns = get_user_ns(user_ns);
@@ -3653,6 +3664,7 @@ struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
 		return new_ns;
 
 	namespace_lock();
+
 	/* First pass: copy the tree topology */
 	copy_flags = CL_COPY_UNBINDABLE | CL_EXPIRE;
 	if (user_ns != ns->user_ns)


More information about the Devel mailing list