From: Will Drewry <wad@chromium.org>
To: Andi Kleen <andi@firstfloor.org>, linux-kernel@vger.kernel.org
Cc: Alexander Viro <viro@zeniv.linux.org.uk>,
Andrew Morton <akpm@linux-foundation.org>,
Oleg Nesterov <oleg@redhat.com>,
KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>,
Roland McGrath <roland@redhat.com>,
Neil Horman <nhorman@tuxdriver.com>,
"Eric W. Biederman" <ebiederm@xmission.com>,
containers@lists.linux-foundation.org,
Eugene Teo <eteo@redhat.com>, Tejun Heo <tj@kernel.org>,
Serge Hallyn <serue@us.ibm.com>,
Alexey Dobriyan <adobriyan@gmail.com>,
linux-fsdevel@vger.kernel.org, Will Drewry <wad@chromium.org>
Subject: [PATCH 1/2] nsproxy: add copy_namespaces_unattached
Date: Fri, 17 Sep 2010 10:16:57 -0500 [thread overview]
Message-ID: <1284736618-27153-1-git-send-email-wad@chromium.org> (raw)
In-Reply-To: <20100917152639.0e88341a@basil.nowhere.org>
This changes adds copy_namespaces_unattached which provides similar
behavior to copy_namespaces() for clone, but is meant for use when a
new namespace needs to be derived from an existing process outside
of process creation.
The next patch in this series shows this function used in fs/exec.c to
insert the core_pattern pipe thread into the crashed processes
namespaces.
This patch is similar to the setns patches floated earlier this year,
but the goal is less lofty though not incompatible!
Any and all input, thoughts, etc will be appreciated.
Signed-off-by: Will Drewry <wad@chromium.org>
---
include/linux/nsproxy.h | 2 ++
kernel/nsproxy.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 41 insertions(+), 0 deletions(-)
diff --git a/include/linux/nsproxy.h b/include/linux/nsproxy.h
index 7b370c7..4c823d2 100644
--- a/include/linux/nsproxy.h
+++ b/include/linux/nsproxy.h
@@ -63,6 +63,8 @@ static inline struct nsproxy *task_nsproxy(struct task_struct *tsk)
}
int copy_namespaces(unsigned long flags, struct task_struct *tsk);
+int copy_namespaces_unattached(unsigned long flags, struct task_struct *tsk,
+ struct nsproxy **nsproxy, struct fs_struct **fs);
void exit_task_namespaces(struct task_struct *tsk);
void switch_task_namespaces(struct task_struct *tsk, struct nsproxy *new);
void free_nsproxy(struct nsproxy *ns);
diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index f74e6c0..ddaea4d 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -22,6 +22,7 @@
#include <linux/pid_namespace.h>
#include <net/net_namespace.h>
#include <linux/ipc_namespace.h>
+#include <linux/fs_struct.h>
static struct kmem_cache *nsproxy_cachep;
@@ -161,6 +162,44 @@ out:
return err;
}
+/**
+ * copy_namespaces_unattached: creates a new nsproxy and fs from a given task
+ * @flags: clone flags to change namespace creation/copy behavior
+ * @tsk: task's namespace to base the nsproxy and fs on
+ * @nsproxy: pointer which will contain the newly created nsproxy
+ * @fs: pointer which will contain the newly created fs_struct
+ *
+ * Returns 0 on success and non-zero on failure.
+ *
+ * This function should aid in migrating processes across namespaces when after
+ * creation.
+ */
+int copy_namespaces_unattached(unsigned long flags, struct task_struct *tsk,
+ struct nsproxy **nsproxy, struct fs_struct **fs)
+{
+ int err = 0;
+ if (!fs || !nsproxy) {
+ err = -EINVAL;
+ goto out;
+ }
+
+ *fs = copy_fs_struct(tsk->fs);
+ if (!*fs) {
+ err = -ENOMEM;
+ goto out;
+ }
+
+ *nsproxy = create_new_namespaces(flags, tsk, *fs);
+ if (IS_ERR(*nsproxy)) {
+ err = PTR_ERR(*nsproxy);
+ free_fs_struct(*fs);
+ goto out;
+ }
+
+out:
+ return err;
+}
+
void free_nsproxy(struct nsproxy *ns)
{
if (ns->mnt_ns)
--
1.7.0.4
next prev parent reply other threads:[~2010-09-17 15:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-16 18:59 [PATCH][RFC] fs/exec.c: provide the correct process pid to the pipe helper Will Drewry
2010-09-16 19:35 ` Oleg Nesterov
2010-09-16 20:12 ` Eric W. Biederman
2010-09-16 21:02 ` Will Drewry
2010-09-17 19:08 ` Roland McGrath
2010-09-17 13:26 ` Andi Kleen
2010-09-17 14:52 ` Will Drewry
2010-09-17 15:16 ` Will Drewry [this message]
2010-09-17 15:16 ` [PATCH 2/2] exec: move core_pattern pipe helper into the crashing namespace Will Drewry
2010-09-17 18:15 ` Neil Horman
2010-09-18 2:33 ` Will Drewry
[not found] ` <1284736618-27153-2-git-send-email-wad-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2010-09-18 1:29 ` Oleg Nesterov
[not found] ` <20100918012939.GA25046-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2010-09-18 2:34 ` Will Drewry
2010-09-18 3:14 ` Will Drewry
2010-09-20 18:50 ` Oleg Nesterov
2010-09-20 20:28 ` Will Drewry
2010-09-18 3:13 ` [PATCH][RFC] v2 " Will Drewry
2010-09-20 18:34 ` Eric W. Biederman
2010-09-20 19:12 ` Andi Kleen
2010-09-20 20:26 ` Will Drewry
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=1284736618-27153-1-git-send-email-wad@chromium.org \
--to=wad@chromium.org \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andi@firstfloor.org \
--cc=containers@lists.linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=eteo@redhat.com \
--cc=kosaki.motohiro@jp.fujitsu.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nhorman@tuxdriver.com \
--cc=oleg@redhat.com \
--cc=roland@redhat.com \
--cc=serue@us.ibm.com \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
/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).