diff mbox series

[19/23] uts: Add uts namespaces into ns_idr

Message ID 159611046266.535980.16940792342033728104.stgit@localhost.localdomain (mailing list archive)
State New, archived
Headers show
Series proc: Introduce /proc/namespaces/ directory to expose namespaces lineary | expand

Commit Message

Kirill Tkhai July 30, 2020, 12:01 p.m. UTC
Now they are exposed in /proc/namespace/ directory.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
---
 kernel/utsname.c |   10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/kernel/utsname.c b/kernel/utsname.c
index aebf4df5f592..883855ca16cd 100644
--- a/kernel/utsname.c
+++ b/kernel/utsname.c
@@ -70,8 +70,16 @@  static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
 	memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
 	ns->user_ns = get_user_ns(user_ns);
 	up_read(&uts_sem);
+
+	err = ns_idr_register(&ns->ns);
+	if (err)
+		goto fail_put;
+
 	return ns;
 
+fail_put:
+	put_user_ns(user_ns);
+	ns_free_inum(&ns->ns);
 fail_free:
 	kmem_cache_free(uts_ns_cache, ns);
 fail_dec:
@@ -113,6 +121,7 @@  static void free_uts_ns_rcu(struct rcu_head *head)
 
 void free_uts_ns(struct uts_namespace *ns)
 {
+	ns_idr_unregister(&ns->ns);
 	dec_uts_namespaces(ns->ucounts);
 	put_user_ns(ns->user_ns);
 	ns_free_inum(&ns->ns);
@@ -182,4 +191,5 @@  void __init uts_ns_init(void)
 			offsetof(struct uts_namespace, name),
 			sizeof_field(struct uts_namespace, name),
 			NULL);
+	WARN_ON(ns_idr_register(&init_uts_ns.ns) < 0);
 }