summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--fs/nsfs.c2
-rw-r--r--include/linux/ns_common.h47
-rw-r--r--kernel/nscommon.c21
-rw-r--r--kernel/nstree.c8
4 files changed, 17 insertions, 61 deletions
diff --git a/fs/nsfs.c b/fs/nsfs.c
index ba6c8975c82e..a80f8d2a4122 100644
--- a/fs/nsfs.c
+++ b/fs/nsfs.c
@@ -430,7 +430,7 @@ static int nsfs_init_inode(struct inode *inode, void *data)
* ioctl on such a socket will resurrect the relevant namespace
* subtree.
*/
- __ns_ref_active_resurrect(ns);
+ __ns_ref_active_get(ns);
return 0;
}
diff --git a/include/linux/ns_common.h b/include/linux/ns_common.h
index 791b18dc77d0..3aaba2ca31d7 100644
--- a/include/linux/ns_common.h
+++ b/include/linux/ns_common.h
@@ -287,47 +287,8 @@ static __always_inline __must_check int __ns_ref_read(const struct ns_common *ns
#define ns_ref_active_read(__ns) \
((__ns) ? __ns_ref_active_read(to_ns_common(__ns)) : 0)
-void __ns_ref_active_get_owner(struct ns_common *ns);
+void __ns_ref_active_put(struct ns_common *ns);
-static __always_inline void __ns_ref_active_get(struct ns_common *ns)
-{
- /* Initial namespaces are always active. */
- if (!is_ns_init_id(ns))
- WARN_ON_ONCE(atomic_add_negative(1, &ns->__ns_ref_active));
-}
-#define ns_ref_active_get(__ns) \
- do { if (__ns) __ns_ref_active_get(to_ns_common(__ns)); } while (0)
-
-static __always_inline bool __ns_ref_active_get_not_zero(struct ns_common *ns)
-{
- /* Initial namespaces are always active. */
- if (is_ns_init_id(ns))
- return true;
-
- if (atomic_inc_not_zero(&ns->__ns_ref_active)) {
- VFS_WARN_ON_ONCE(!__ns_ref_read(ns));
- return true;
- }
- return false;
-}
-
-#define ns_ref_active_get_owner(__ns) \
- do { if (__ns) __ns_ref_active_get_owner(to_ns_common(__ns)); } while (0)
-
-void __ns_ref_active_put_owner(struct ns_common *ns);
-
-static __always_inline void __ns_ref_active_put(struct ns_common *ns)
-{
- /* Initial namespaces are always active. */
- if (is_ns_init_id(ns))
- return;
-
- if (atomic_dec_and_test(&ns->__ns_ref_active)) {
- VFS_WARN_ON_ONCE(is_initial_namespace(ns));
- VFS_WARN_ON_ONCE(!__ns_ref_read(ns));
- __ns_ref_active_put_owner(ns);
- }
-}
#define ns_ref_active_put(__ns) \
do { if (__ns) __ns_ref_active_put(to_ns_common(__ns)); } while (0)
@@ -343,9 +304,9 @@ static __always_inline struct ns_common *__must_check ns_get_unless_inactive(str
return ns;
}
-void __ns_ref_active_resurrect(struct ns_common *ns);
+void __ns_ref_active_get(struct ns_common *ns);
-#define ns_ref_active_resurrect(__ns) \
- do { if (__ns) __ns_ref_active_resurrect(to_ns_common(__ns)); } while (0)
+#define ns_ref_active_get(__ns) \
+ do { if (__ns) __ns_ref_active_get(to_ns_common(__ns)); } while (0)
#endif
diff --git a/kernel/nscommon.c b/kernel/nscommon.c
index 70cb66232e4c..bfd2d6805776 100644
--- a/kernel/nscommon.c
+++ b/kernel/nscommon.c
@@ -114,13 +114,6 @@ struct ns_common *__must_check ns_owner(struct ns_common *ns)
return to_ns_common(owner);
}
-void __ns_ref_active_get_owner(struct ns_common *ns)
-{
- ns = ns_owner(ns);
- if (ns)
- WARN_ON_ONCE(atomic_add_negative(1, &ns->__ns_ref_active));
-}
-
/*
* The active reference count works by having each namespace that gets
* created take a single active reference on its owning user namespace.
@@ -171,8 +164,18 @@ void __ns_ref_active_get_owner(struct ns_common *ns)
* The iteration stops once we reach a namespace that still has active
* references.
*/
-void __ns_ref_active_put_owner(struct ns_common *ns)
+void __ns_ref_active_put(struct ns_common *ns)
{
+ /* Initial namespaces are always active. */
+ if (is_ns_init_id(ns))
+ return;
+
+ if (!atomic_dec_and_test(&ns->__ns_ref_active))
+ return;
+
+ VFS_WARN_ON_ONCE(is_ns_init_id(ns));
+ VFS_WARN_ON_ONCE(!__ns_ref_read(ns));
+
for (;;) {
ns = ns_owner(ns);
if (!ns)
@@ -275,7 +278,7 @@ void __ns_ref_active_put_owner(struct ns_common *ns)
* it also needs to take another reference on its owning user namespace
* and so on.
*/
-void __ns_ref_active_resurrect(struct ns_common *ns)
+void __ns_ref_active_get(struct ns_common *ns)
{
/* Initial namespaces are always active. */
if (is_ns_init_id(ns))
diff --git a/kernel/nstree.c b/kernel/nstree.c
index f27f772a6762..97404fb90749 100644
--- a/kernel/nstree.c
+++ b/kernel/nstree.c
@@ -173,14 +173,6 @@ void __ns_tree_add_raw(struct ns_common *ns, struct ns_tree *ns_tree)
write_sequnlock(&ns_tree_lock);
VFS_WARN_ON_ONCE(node);
-
- /*
- * Take an active reference on the owner namespace. This ensures
- * that the owner remains visible while any of its child namespaces
- * are active. For init namespaces this is a no-op as ns_owner()
- * returns NULL for namespaces owned by init_user_ns.
- */
- __ns_ref_active_get_owner(ns);
}
void __ns_tree_remove(struct ns_common *ns, struct ns_tree *ns_tree)