Skip to contentSkip to conversation

uts namespaces: implement utsname namespaces

PATCH In review Serge E. Hallyn 1 participant 1 message May 10, 2006 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 6/9 uts namespaces: implement utsname namespaces

This patch defines the uts namespace and some manipulators. Adds the uts namespace to task_struct, and initializes a system-wide init namespace.

It leaves a #define for system_utsname so sysctl will compile. This define will be removed in a separate patch.

Changes:
Moved code from init/version.c to kernel/utsname.c. Modified the clone/unshare functions to better fit
unsharing at clone and sys_unshare, vs allowing other parts of the kernel to unshare.

---

 include/linux/init_task.h |    2 ++
 include/linux/nsproxy.h   |    1 +
 include/linux/sched.h     |    1 +
 include/linux/utsname.h   |   55 ++++++++++++++++++++++++++++++++++++++++++---
 init/Kconfig              |    8 +++++++
 init/version.c            |   22 +++++++++++-------
 kernel/Makefile           |    1 +
 kernel/exit.c             |    7 +++++-
 kernel/fork.c             |    7 +++++-
 kernel/utsname.c          |   43 +++++++++++++++++++++++++++++++++++
 10 files changed, 132 insertions(+), 15 deletions(-)
 create mode 100644 kernel/utsname.c

d7e342120496af2cd8520bc89f7b1e54b7ab2749

include/linux/init_task.h +2 -0
index 672dc04..ceb68b7 100644
@@ -3,6 +3,7 @@ #define _LINUX__INIT_TASK_H
 
 #include <linux/file.h>
 #include <linux/rcupdate.h>
+#include <linux/utsname.h>
 
 #define INIT_FDTABLE \
 {							\
@@ -70,6 +71,7 @@ extern struct nsproxy init_nsproxy;
 #define INIT_NSPROXY(nsproxy) {						\
 	.count		= ATOMIC_INIT(1),				\
 	.nslock		= SPIN_LOCK_UNLOCKED,				\
+	.uts_ns		= &init_uts_ns,					\
 	.namespace	= NULL,						\
 }
 
include/linux/nsproxy.h +1 -0
index 64e9075..18fcd8f 100644
@@ -9,6 +9,7 @@ struct namespace;
 struct nsproxy {
 	atomic_t count;
 	spinlock_t nslock;
+	struct uts_namespace *uts_ns;
 	struct namespace *namespace;
 };
 extern struct nsproxy init_nsproxy;
include/linux/sched.h +1 -0
index f2c945b..3332d5e 100644
@@ -685,6 +685,7 @@ #endif
 struct audit_context;		/* See audit.c */
 struct mempolicy;
 struct pipe_inode_info;
+struct uts_namespace;
 
 enum sleep_type {
 	SLEEP_NORMAL,
include/linux/utsname.h +51 -4

72 lines not on this page · raw message

init/Kconfig +8 -0
index 3b36a1d..8460e5a 100644
@@ -166,6 +166,14 @@ config SYSCTL
 	  building a kernel for install/rescue disks or your system is very
 	  limited in memory.
 
+config UTS_NS
+	bool "UTS Namespaces"
+	default n
+	help
+	  Support uts namespaces.  This allows containers, i.e.
+	  vservers, to use uts namespaces to provide different
+	  uts info for different servers.  If unsure, say N.
+
 config AUDIT
 	bool "Auditing support"
 	depends on NET
init/version.c +13 -9
index 3ddc3ce..78cef48 100644
@@ -11,23 +11,27 @@ #include <linux/module.h>
 #include <linux/uts.h>
 #include <linux/utsname.h>
 #include <linux/version.h>
+#include <linux/sched.h>
 
 #define version(a) Version_ ## a
 #define version_string(a) version(a)
 
 int version_string(LINUX_VERSION_CODE);
 
-struct new_utsname system_utsname = {
-	.sysname	= UTS_SYSNAME,
-	.nodename	= UTS_NODENAME,
-	.release	= UTS_RELEASE,
-	.version	= UTS_VERSION,
-	.machine	= UTS_MACHINE,
-	.domainname	= UTS_DOMAINNAME,
+struct uts_namespace init_uts_ns = {
+	.kref = {
+		.refcount	= ATOMIC_INIT(2),
+	},
+	.name = {
+		.sysname	= UTS_SYSNAME,
+		.nodename	= UTS_NODENAME,
+		.release	= UTS_RELEASE,
+		.version	= UTS_VERSION,
+		.machine	= UTS_MACHINE,
+		.domainname	= UTS_DOMAINNAME,
+	},
 };
 
-EXPORT_SYMBOL(system_utsname);
-
 const char linux_banner[] =
 	"Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@"
 	LINUX_COMPILE_HOST ") (" LINUX_COMPILER ") " UTS_VERSION "\n";
kernel/Makefile +1 -0
index 215fb33..ab7426c 100644
@@ -38,6 +38,7 @@ obj-$(CONFIG_GENERIC_HARDIRQS) += irq/
 obj-$(CONFIG_SECCOMP) += seccomp.o
 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
 obj-$(CONFIG_RELAY) += relay.o
+obj-$(CONFIG_UTS_NS) += utsname.o
 
 ifneq ($(CONFIG_SCHED_NO_NO_OMIT_FRAME_POINTER),y)
 # According to Alan Modra <[email protected]>, the -fno-omit-frame-pointer is
kernel/exit.c +6 -1
index 1862d36..921a4b7 100644
@@ -14,7 +14,7 @@ #include <linux/capability.h>
 #include <linux/completion.h>
 #include <linux/personality.h>
 #include <linux/tty.h>
-#include <linux/nsproxy.h>
+#include <linux/utsname.h>
 #include <linux/namespace.h>
 #include <linux/key.h>
 #include <linux/security.h>
@@ -415,11 +415,15 @@ void daemonize(const char *name, ...)
 	fs = init_task.fs;
 	current->fs = fs;
 	atomic_inc(&fs->count);
+
+	exit_utsname(current);
 	exit_namespace(current);
 	exit_nsproxy(current);
 	current->nsproxy = init_task.nsproxy;
 	get_nsproxy(current->nsproxy);
 	get_namespace(current->nsproxy->namespace);
+	get_uts_ns(current->nsproxy->uts_ns);
+
  	exit_files(current);
 	current->files = init_task.files;
 	atomic_inc(&current->files->count);
@@ -922,6 +926,7 @@ #endif
 	exit_sem(tsk);
 	__exit_files(tsk);
 	__exit_fs(tsk);
+	exit_utsname(current);
 	exit_namespace(current);
 	exit_nsproxy(current);
 	exit_thread();
kernel/fork.c +6 -1
index 06cc87a..4d7cbae 100644
@@ -45,6 +45,7 @@ #include <linux/rmap.h>
 #include <linux/acct.h>
 #include <linux/cn_proc.h>
 #include <linux/nsproxy.h>
+#include <linux/utsname.h>
 
 #include <asm/pgtable.h>
 #include <asm/pgalloc.h>
@@ -1063,8 +1064,10 @@ #endif
 		goto bad_fork_cleanup_mm;
 	if ((retval = copy_nsproxy(clone_flags, p)))
 		goto bad_fork_cleanup_keys;
-	if ((retval = copy_namespace(clone_flags, p)))
+	if ((retval = copy_utsname(clone_flags, p)))
 		goto bad_fork_cleanup_nsproxy;
+	if ((retval = copy_namespace(clone_flags, p)))
+		goto bad_fork_cleanup_utsname;
 	retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
 	if (retval)
 		goto bad_fork_cleanup_namespace;
@@ -1221,6 +1224,8 @@ #endif
 
 bad_fork_cleanup_namespace:
 	exit_namespace(p);
+bad_fork_cleanup_utsname:
+	exit_utsname(p);
 bad_fork_cleanup_nsproxy:
 	exit_nsproxy(p);
 bad_fork_cleanup_keys:
kernel/utsname.c new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
1.3.0