From: "Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Cc: viro@zeniv.linux.org.uk, ebiederm@xmission.com,
rostedt@goodmis.org, mingo@redhat.com, hagen@jauu.net,
rppt@kernel.org, James.Bottomley@HansenPartnership.com,
akpm@linux-foundation.org, vvs@virtuozzo.com,
shakeelb@google.com, christian.brauner@ubuntu.com,
mkoutny@suse.com,
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com>
Subject: [RFC PATCH 3/4] namespacefs: Couple namespacefs to the PID namespace
Date: Thu, 18 Nov 2021 20:12:09 +0200 [thread overview]
Message-ID: <20211118181210.281359-4-y.karadz@gmail.com> (raw)
In-Reply-To: <20211118181210.281359-1-y.karadz@gmail.com>
When the PID namespace gets initialized, a directory called 'pid' is
added to 'namespacesfs'. This directory represents the main PID namespace
and also serves as a trunk (parent) of all child PID namespaces. Every
time when a new PID namespace is created a corresponding directory is
added to 'namespacefs/pid/parent/hierarchy/'. The 'inum' of the new
namespace gives the name of its directory. When the PID namespace is
destroyed the corresponding directory is removed.
Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
fs/namespacefs/inode.c | 21 +++++++++++++++++++++
kernel/pid_namespace.c | 9 +++++++++
2 files changed, 30 insertions(+)
diff --git a/fs/namespacefs/inode.c b/fs/namespacefs/inode.c
index 012c1c43b44d..55d71733164c 100644
--- a/fs/namespacefs/inode.c
+++ b/fs/namespacefs/inode.c
@@ -11,7 +11,9 @@
#include <linux/fsnotify.h>
#include <linux/magic.h>
#include <linux/idr.h>
+#include <linux/proc_ns.h>
#include <linux/seq_file.h>
+#include <linux/pid_namespace.h>
static struct vfsmount *namespacefs_mount;
static int namespacefs_mount_count;
@@ -307,6 +309,19 @@ void namespacefs_remove_pid_ns_dir(struct pid_namespace *ns)
namespacefs_remove_dir(ns->ns.dentry);
}
+static int add_ns_dentry(struct ns_common *ns)
+{
+ struct dentry *dentry =
+ namespacefs_create_dir(ns->ops->name, NULL, &init_user_ns);
+
+ if (IS_ERR(dentry))
+ return PTR_ERR(dentry);
+
+ ns->dentry = dentry;
+
+ return 0;
+}
+
#define _NS_MOUNT_DIR "namespaces"
static int __init namespacefs_init(void)
@@ -321,8 +336,14 @@ static int __init namespacefs_init(void)
if (err)
goto rm_mount;
+ err = add_ns_dentry(&init_pid_ns.ns);
+ if (err)
+ goto unreg;
+
return 0;
+ unreg:
+ unregister_filesystem(&namespacefs_fs_type);
rm_mount:
sysfs_remove_mount_point(fs_kobj, _NS_MOUNT_DIR);
fail:
diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
index a46a3723bc66..1690b2c87661 100644
--- a/kernel/pid_namespace.c
+++ b/kernel/pid_namespace.c
@@ -12,6 +12,7 @@
#include <linux/pid.h>
#include <linux/pid_namespace.h>
#include <linux/user_namespace.h>
+#include <linux/namespacefs.h>
#include <linux/syscalls.h>
#include <linux/cred.h>
#include <linux/err.h>
@@ -101,6 +102,7 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
err = ns_alloc_inum(&ns->ns);
if (err)
goto out_free_idr;
+
ns->ns.ops = &pidns_operations;
refcount_set(&ns->ns.count, 1);
@@ -110,8 +112,14 @@ static struct pid_namespace *create_pid_namespace(struct user_namespace *user_ns
ns->ucounts = ucounts;
ns->pid_allocated = PIDNS_ADDING;
+ err = namespacefs_create_pid_ns_dir(ns);
+ if (err)
+ goto out_free_inum;
+
return ns;
+out_free_inum:
+ ns_free_inum(&ns->ns);
out_free_idr:
idr_destroy(&ns->idr);
kmem_cache_free(pid_ns_cachep, ns);
@@ -133,6 +141,7 @@ static void delayed_free_pidns(struct rcu_head *p)
static void destroy_pid_namespace(struct pid_namespace *ns)
{
+ namespacefs_remove_pid_ns_dir(ns);
ns_free_inum(&ns->ns);
idr_destroy(&ns->idr);
--
2.33.1
next prev parent reply other threads:[~2021-11-18 18:13 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-18 18:12 [RFC PATCH 0/4] namespacefs: Proof-of-Concept Yordan Karadzhov (VMware)
2021-11-18 18:12 ` [RFC PATCH 1/4] namespacefs: Introduce 'namespacefs' Yordan Karadzhov (VMware)
2021-11-18 18:12 ` [RFC PATCH 2/4] namespacefs: Add methods to create/remove PID namespace directories Yordan Karadzhov (VMware)
2021-11-18 18:12 ` Yordan Karadzhov (VMware) [this message]
2021-11-18 18:12 ` [RFC PATCH 4/4] namespacefs: Couple namespacefs to the UTS namespace Yordan Karadzhov (VMware)
2021-11-18 18:55 ` [RFC PATCH 0/4] namespacefs: Proof-of-Concept Eric W. Biederman
2021-11-18 19:02 ` Steven Rostedt
2021-11-18 19:22 ` Eric W. Biederman
2021-11-18 19:36 ` Steven Rostedt
2021-11-18 19:24 ` Steven Rostedt
2021-11-19 9:50 ` Kirill Tkhai
2021-11-19 12:45 ` James Bottomley
[not found] ` <20211119092758.1012073e@gandalf.local.home>
2021-11-19 16:42 ` James Bottomley
2021-11-19 17:14 ` Yordan Karadzhov
2021-11-19 17:22 ` Steven Rostedt
2021-11-19 23:22 ` James Bottomley
2021-11-20 0:07 ` Steven Rostedt
2021-11-20 0:14 ` James Bottomley
[not found] ` <f6ca1f5bdb3b516688f291d9685a6a59f49f1393.camel@HansenPartnership.com>
2021-11-19 16:47 ` Steven Rostedt
2021-11-19 16:49 ` Steven Rostedt
2021-11-19 23:08 ` James Bottomley
2021-11-22 13:02 ` Yordan Karadzhov
2021-11-22 13:44 ` James Bottomley
2021-11-22 15:00 ` Yordan Karadzhov
2021-11-22 15:47 ` James Bottomley
2021-11-22 16:15 ` Yordan Karadzhov
2021-11-19 14:26 ` Yordan Karadzhov
2021-11-18 21:24 ` Mike Rapoport
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211118181210.281359-4-y.karadz@gmail.com \
--to=y.karadz@gmail.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=christian.brauner@ubuntu.com \
--cc=ebiederm@xmission.com \
--cc=hagen@jauu.net \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=rostedt@goodmis.org \
--cc=rppt@kernel.org \
--cc=shakeelb@google.com \
--cc=viro@zeniv.linux.org.uk \
--cc=vvs@virtuozzo.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).