[Devel] [PATCH RHEL7 COMMIT] new helpers: ns_alloc_inum/ns_free_inum

Konstantin Khorenko khorenko at virtuozzo.com
Thu Jun 11 19:20:03 MSK 2020


The commit is pushed to "branch-rh7-3.10.0-1127.10.1.vz7.162.x-ovz" and will appear at https://src.openvz.org/scm/ovz/vzkernel.git
after rh7-3.10.0-1127.10.1.vz7.162.2
------>
commit 05652ea552836f00e8aad0d87366eaf1463c564f
Author: Al Viro <viro at zeniv.linux.org.uk>
Date:   Thu Jun 11 19:20:03 2020 +0300

    new helpers: ns_alloc_inum/ns_free_inum
    
    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>
    
    =====================
    Patchset description:
    port nsfs from vz8
    
    We have problems with /proc/pid/ns/name bind-mounts in CRIU
    
    1) Currently (without nsfs) such a bind mount have same superblock with
    /proc mount, but in case of nested pid-namespaces container can have
    multiple different /proc mounts and for ns-bind-mount we need to bind it
    from the right pidns. So we will need to enter proper pid-namespace to
    reopen ns-file fd from proper proc, it looks too complex.
    
    If we port nsfs ns-bind-mounts will be all on the same superblock which
    does not depend from procfs's we opened the ns-file on.
    
    2) Bigger problem will come then we will wan't to migrate ns-bind-mounts
    from non-nsfs to nsfs (vz8) kernel this would bring a lot of crutches,
    we will need to workaround the fact that before migration mounts were
    with same superblock and after migration they can't be.
    
    To overcome those we can port nsfs to vz7 and do ns-bind-mount support in
    a new world of nsfs, looks like it would be easier.
    
    First we need to revert all patches which depend from nsfs:
    
    8782a0069f1b proc: add a proc_show_path method to fix mountinfo
    b823f8df2fcb ms/tun: Add ioctl() TUNGETDEVNETNS cmd to allow obtaining real net ns of tun device
    302889fa2e3d ms/net: add an ioctl to get a socket network namespace
    7cb9e7ae7041 ms/tun: Add ioctl() SIOCGSKNS cmd to allow obtaining net ns of tun device
    ac08c64138ac nsfs: add ioctl to get a parent namespace
    a8e0dd94d5cd nsfs: add ioctl to get an owning user namespace for ns file descriptor
    93dca538d184 kernel: add a helper to get an owning user namespace for a namespace
    edaecdb8adac ms/pidns: expose task pid_ns_for_children to userspace
    2b151c3f8909 ms/ns: allow ns_entries to have custom symlink content
    
    Cherry-pick nsfs from VZ8:
    
    435d5f4bb2cc common object embedded into various struct ....ns
    58be28256d98 make mntns ->get()/->put()/->install()/->inum() work with &mnt_ns->ns
    ff24870f46d5 netns: switch ->get()/->put()/->install()/->inum() to working with &net->ns
    3c0411846118 switch the rest of proc_ns_operations to working with &...->ns
    64964528b24e make proc_ns_operations work with struct ns_common * instead of void *
    6344c433a452 new helpers: ns_alloc_inum/ns_free_inum
    33c429405a2c copy address of proc_ns_ops into ns_common
    f77c80142e1a bury struct proc_ns in fs/proc
    292662014509 dcache.c: call ->d_prune() regardless of d_unhashed()
    e149ed2b805f take the targets of /proc/*/ns/* symlinks to separate fs
    
    Cherry-pick part of reverted patches back from VZ8:
    
    bcac25a58bfc kernel: add a helper to get an owning user namespace for a namespace
    6786741dbf99 nsfs: add ioctl to get an owning user namespace for ns file descriptor
    a7306ed8d94a nsfs: add ioctl to get a parent namespace
    c62cce2caee5 net: add an ioctl to get a socket network namespace
    25b14e92af1a ns: allow ns_entries to have custom symlink content
    eaa0d190bfe1 pidns: expose task pid_ns_for_children to userspace
    
    Cherry-pick reverted patches back from MS (we also need them to vz8):
    
    75509fd88fbd nsfs: Add a show_path method to fix mountinfo
    24dce0800baa net: Export open_related_ns()
    d8d211a2a0c3 net: Make extern and export get_net_ns()
    f2780d6d7475 tun: Add ioctl() SIOCGSKNS cmd to allow obtaining net ns of tun device
    0c3e0e3bb623 tun: Add ioctl() TUNGETDEVNETNS cmd to allow obtaining real net ns of tun device
    073c516ff735 nsfs: mark dentry with DCACHE_RCUACCESS
    
    On this kernel I've runed zdtm, so the change should not break interfaces.
    
    https://jira.sw.ru/browse/PSBM-102357
    
    Al Viro (10):
      ms: common object embedded into various struct ....ns
      make mntns ->get()/->put()/->install()/->inum() work with &mnt_ns->ns
      netns: switch ->get()/->put()/->install()/->inum() to working with
        &net->ns
      switch the rest of proc_ns_operations to working with &...->ns
      make proc_ns_operations work with struct ns_common * instead of void *
      new helpers: ns_alloc_inum/ns_free_inum
      copy address of proc_ns_ops into ns_common
      bury struct proc_ns in fs/proc
      dcache.c: call ->d_prune() regardless of d_unhashed()
      take the targets of /proc/*/ns/* symlinks to separate fs
    
    Andrey Vagin (4):
      kernel: add a helper to get an owning user namespace for a namespace
      nsfs: add ioctl to get an owning user namespace for ns file descriptor
      nsfs: add ioctl to get a parent namespace
      net: add an ioctl to get a socket network namespace
    
    Cong Wang (1):
      nsfs: mark dentry with DCACHE_RCUACCESS
    
    Eric W. Biederman (1):
      nsfs: Add a show_path method to fix mountinfo
    
    Kirill Tkhai (6):
      ns: allow ns_entries to have custom symlink content
      pidns: expose task pid_ns_for_children to userspace
      net: Export open_related_ns()
      net: Make extern and export get_net_ns()
      tun: Add ioctl() SIOCGSKNS cmd to allow obtaining net ns of tun device
      tun: Add ioctl() TUNGETDEVNETNS cmd to allow obtaining real net ns of
        tun device
    
    Pavel Tikhomirov (10):
      Revert "proc: add a proc_show_path method to fix mountinfo"
      Revert "ms/tun: Add ioctl() TUNGETDEVNETNS cmd to allow obtaining real
        net ns of tun device"
      Revert "ms/net: add an ioctl to get a socket network namespace"
      Revert "ms/tun: Add ioctl() SIOCGSKNS cmd to allow obtaining net ns of
        tun device"
      Revert "nsfs: add ioctl to get a parent namespace"
      Revert "nsfs: add ioctl to get an owning user namespace for ns file
        descriptor"
      Revert "kernel: add a helper to get an owning user namespace for a
        namespace"
      Revert "ms/pidns: expose task pid_ns_for_children to userspace"
      Revert "ms/ns: allow ns_entries to have custom symlink content"
      userns: move EXPORT_SYMBOL closer to current_in_userns
---
 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 bd1bfa481f574..6a6d9ccf3bde8 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 3bd0aab958775..f447c5a59aef2 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 84545678707e8..d3002af16e681 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 29c9d06cf8fb7..80030a07b4857 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 af9ff26c72b49..6f542333200ff 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 4247306327fa1..0ac05ebcb3db6 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 9564d242f941d..73f077d3edd3e 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 = {


More information about the Devel mailing list