lkml.org 
[lkml]   [2014]   [Oct]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH RFC] setns: return 0 directly if try to reassociate with current namespace
Date
We could use setns to join the current ns,
which did a lot of unnecessary work.
This patch will check this senario and
return 0 directly.

Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
---
kernel/nsproxy.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/kernel/nsproxy.c b/kernel/nsproxy.c
index ef42d0a..66eea63 100644
--- a/kernel/nsproxy.c
+++ b/kernel/nsproxy.c
@@ -236,6 +236,34 @@ SYSCALL_DEFINE2(setns, int, fd, int, nstype)
ops = ei->ns_ops;
if (nstype && (ops->type != nstype))
goto out;
+ switch (ops->type) {
+ case CLONE_NEWIPC:
+ if (ei->ns == tsk->nsproxy->ipc_ns)
+ return 0;
+ break;
+ case CLONE_NEWNET:
+ if (ei->ns == tsk->nsproxy->net_ns)
+ return 0;
+ break;
+ case CLONE_NEWNS:
+ if (ei->ns == tsk->nsproxy->mnt_ns)
+ return 0;
+ break;
+ case CLONE_NEWPID:
+ if (ei->ns == tsk->nsproxy->pid_ns_for_children)
+ return 0;
+ break;
+ case CLONE_NEWUSER:
+ if (ei->ns == current_user_ns())
+ return 0;
+ break;
+ case CLONE_NEWUTS:
+ if (ei->ns == tsk->nsproxy->uts_ns)
+ return 0;
+ break;
+ default:
+ goto out;
+ }

new_nsproxy = create_new_namespaces(0, tsk, current_user_ns(), tsk->fs);
if (IS_ERR(new_nsproxy)) {
--
1.9.0


\
 
 \ /
  Last update: 2014-10-08 11:42    [W:0.187 / U:0.084 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site