[Devel] [PATCH RH7 16/32] new helpers: ns_alloc_inum/ns_free_inum

Pavel Tikhomirov ptikhomirov at virtuozzo.com
Mon Jun 8 20:05:46 MSK 2020


From: Al Viro <viro at zeniv.linux.org.uk>

take struct ns_common *, for now simply wrappers around proc_{alloc,free}_inum()

(cherry picked from VZ8 commit 6344c433a452b1a05d03a61a6a85d89f793bb7b8)

https://jira.sw.ru/browse/PSBM-102357

Signed-off-by: Al Viro <viro at zeniv.linux.org.uk>
Signed-off-by: Pavel Tikhomirov <ptikhomirov at virtuozzo.com>
---
 fs/namespace.c           | 4 ++--
 include/linux/proc_ns.h  | 3 +++
 ipc/namespace.c          | 6 +++---
 kernel/pid_namespace.c   | 4 ++--
 kernel/user_namespace.c  | 8 ++++----
 kernel/utsname.c         | 4 ++--
 net/core/net_namespace.c | 4 ++--
 7 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/fs/namespace.c b/fs/namespace.c
index bd1bfa481f57..6a6d9ccf3bde 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -3250,7 +3250,7 @@ static void dec_mnt_namespaces(struct ucounts *ucounts)
 
 static void free_mnt_ns(struct mnt_namespace *ns)
 {
-	proc_free_inum(ns->ns.inum);
+	ns_free_inum(&ns->ns);
 	dec_mnt_namespaces(ns->ucounts);
 	put_user_ns(ns->user_ns);
 
@@ -3285,7 +3285,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
 		dec_mnt_namespaces(ucounts);
 		return ERR_PTR(-ENOMEM);
 	}
-	ret = proc_alloc_inum(&new_ns->ns.inum);
+	ret = ns_alloc_inum(&new_ns->ns);
 	if (ret) {
 		kfree(new_ns);
 		dec_mnt_namespaces(ucounts);
diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
index 3bd0aab95877..f447c5a59aef 100644
--- a/include/linux/proc_ns.h
+++ b/include/linux/proc_ns.h
@@ -74,4 +74,7 @@ static inline bool proc_ns_inode(struct inode *inode) { return false; }
 
 #endif /* CONFIG_PROC_FS */
 
+#define ns_alloc_inum(ns) proc_alloc_inum(&(ns)->inum)
+#define ns_free_inum(ns) proc_free_inum((ns)->inum)
+
 #endif /* _LINUX_PROC_NS_H */
diff --git a/ipc/namespace.c b/ipc/namespace.c
index 84545678707e..d3002af16e68 100644
--- a/ipc/namespace.c
+++ b/ipc/namespace.c
@@ -43,7 +43,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
 	if (ns == NULL)
 		goto fail_dec;
 
-	err = proc_alloc_inum(&ns->ns.inum);
+	err = ns_alloc_inum(&ns->ns);
 	if (err)
 		goto fail_free;
 
@@ -64,7 +64,7 @@ static struct ipc_namespace *create_ipc_ns(struct user_namespace *user_ns,
 
 fail_put:
 	put_user_ns(ns->user_ns);
-	proc_free_inum(ns->ns.inum);
+	ns_free_inum(&ns->ns);
 fail_free:
 	kfree(ns);
 fail_dec:
@@ -121,7 +121,7 @@ static void free_ipc_ns(struct ipc_namespace *ns)
 
 	dec_ipc_namespaces(ns->ucounts);
 	put_user_ns(ns->user_ns);
-	proc_free_inum(ns->ns.inum);
+	ns_free_inum(&ns->ns);
 	kfree(ns);
 }
 
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index 29c9d06cf8fb..80030a07b485 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -124,7 +124,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
 	if (ns->pid_cachep == NULL)
 		goto out_free_map;
 
-	err = proc_alloc_inum(&ns->ns.inum);
+	err = ns_alloc_inum(&ns->ns);
 	if (err)
 		goto out_free_map;
 
@@ -165,7 +165,7 @@ static void destroy_pid_namespace(struct pid_namespace *ns)
 {
 	int i;
 
-	proc_free_inum(ns->ns.inum);
+	ns_free_inum(&ns->ns);
 	for (i = 0; i < PIDMAP_ENTRIES; i++)
 		kfree(ns->pidmap[i].page);
 	dec_pid_namespaces(ns->ucounts);
diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
index af9ff26c72b4..6f542333200f 100644
--- a/kernel/user_namespace.c
+++ b/kernel/user_namespace.c
@@ -121,7 +121,7 @@ int create_user_ns(struct cred *new)
 	if (!ns)
 		goto fail_dec;
 
-	ret = proc_alloc_inum(&ns->ns.inum);
+	ret = ns_alloc_inum(&ns->ns);
 	if (ret)
 		goto fail_free;
 
@@ -130,7 +130,7 @@ int create_user_ns(struct cred *new)
 
 	new_user = alloc_uid_ns(ns, owner);
 	if (!new_user) {
-		proc_free_inum(ns->ns.inum);
+		ns_free_inum(&ns->ns);
 		kmem_cache_free(user_ns_cachep, ns);
 		return -ENOMEM;
 	}
@@ -170,7 +170,7 @@ int create_user_ns(struct cred *new)
 	key_put(ns->persistent_keyring_register);
 #endif
 fail_free:
-	proc_free_inum(ns->ns.inum);
+	ns_free_inum(&ns->ns);
 	kmem_cache_free(user_ns_cachep, ns);
 fail_dec:
 	dec_user_namespaces(ucounts);
@@ -210,7 +210,7 @@ static void free_user_ns(struct work_struct *work)
 #ifdef CONFIG_PERSISTENT_KEYRINGS
 		key_put(ns->persistent_keyring_register);
 #endif
-		proc_free_inum(ns->ns.inum);
+		ns_free_inum(&ns->ns);
 		kmem_cache_free(user_ns_cachep, ns);
 		dec_user_namespaces(ucounts);
 		ns = parent;
diff --git a/kernel/utsname.c b/kernel/utsname.c
index 4247306327fa..0ac05ebcb3db 100644
--- a/kernel/utsname.c
+++ b/kernel/utsname.c
@@ -69,7 +69,7 @@ static struct uts_namespace *clone_uts_ns(struct user_namespace *user_ns,
 	if (!ns)
 		goto fail_dec;
 
-	err = proc_alloc_inum(&ns->ns.inum);
+	err = ns_alloc_inum(&ns->ns);
 	if (err)
 		goto fail_free;
 
@@ -119,7 +119,7 @@ void free_uts_ns(struct kref *kref)
 	ns = container_of(kref, struct uts_namespace, kref);
 	dec_uts_namespaces(ns->ucounts);
 	put_user_ns(ns->user_ns);
-	proc_free_inum(ns->ns.inum);
+	ns_free_inum(&ns->ns);
 #ifdef CONFIG_X86
 #ifdef CONFIG_X86_64
 	if (ns->vdso.pages) {
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 9564d242f941..73f077d3edd3 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -613,12 +613,12 @@ EXPORT_SYMBOL_GPL(get_net_ns_by_pid);
 
 static __net_init int net_ns_net_init(struct net *net)
 {
-	return proc_alloc_inum(&net->ns.inum);
+	return ns_alloc_inum(&net->ns);
 }
 
 static __net_exit void net_ns_net_exit(struct net *net)
 {
-	proc_free_inum(net->ns.inum);
+	ns_free_inum(&net->ns);
 }
 
 static struct pernet_operations __net_initdata net_ns_ops = {
-- 
2.24.1



More information about the Devel mailing list