OpenVZ Forum


Home » Mailing lists » Devel » [RFC][PATCH 0/5] uts namespaces: Introduction
[RFC][PATCH 0/5] uts namespaces: Introduction [message #2484] Fri, 07 April 2006 18:36 Go to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Introduce utsname namespaces. Instead of a single system_utsname
containing hostname domainname etc, a process can request it's
copy of the uts info to be cloned. The data will be copied from
it's original, but any further changes will not be seen by processes
which are not it's children, and vice versa.

This is useful, for instance, for vserver/openvz, which can now clone
a new uts namespace for each new virtual server.

This patchset is based on Kirill Korotaev's Mar 24 submission, taking
comments (in particular from James Morris and Eric Biederman) into
account.

Some performance results are attached. I was mainly curious whether
it would be worth putting the task_struct->uts_ns pointer inside
a #ifdef CONFIG_UTS_NS. The result show that leaving it in when
CONFIG_UTS_NS=n has negligable performance impact, so that is the
approach this patch takes.

-serge

Performance testing was done on a 2-cpu hyperthreaded
x86 box with 16G ram. The following tests were run:
dbench (20 times, four clients, on reiser fs non-isolated partition)
tbench (20 times, 5 connections)
kernbench (20 times)
reaim (20 times ranging from 1 to 15 users)

They were run on 2.6.17-rc1:
pristine
patched, but with !CONFIG_UTS_NS ("disabled")
patched with CONFIG_UTS_NS=y ("enabled")

All results are presented as means +/- 95% confidence interval.

Dbench results:
pristine: 387.080727 +/- 9.344585
patched disabled: 389.524364 +/- 9.574921
patched enabled: 370.155600 +/- 30.127808

Tbench results:
pristine: 388.940100 +/- 18.095104
patched disabled: 389.173700 +/- 23.658035
patched enabled: 394.333200 +/- 25.813393

Kernbench results:
pristine: 70.317500 +/- 0.210833
patched, disabled: 70.860000 +/- 0.179292
patched, enabled: 70.346500 +/- 0.184784

Reaim results:
pristine:
Nclients Mean 95% CI
1 106080.000000 11327.896029
3 236057.142000 18205.544810
5 247867.136000 23536.800062
7 265370.000000 21284.335743
9 262969.936000 18225.497529
11 278256.000000 6230.342816
13 284288.016000 8924.589388
15 286987.170000 7881.034658

patched, disabled:
Nclients Mean 95% CI
1 105400.000000 8739.978241
3 229500.000000 0.000000
5 252325.176667 16685.663423
7 265125.000000 6747.777319
9 271258.645000 11715.635212
11 280662.608333 7775.229351
13 277719.706667 8173.390359
15 278515.421667 10963.211450

patched, enabled:
Nclients Mean 95% CI
1 102000.000000 0.000000
3 224400.000000 14159.870036
5 242963.288000 40529.490781
7 255150.000000 8745.802081
9 270154.284000 8918.863136
11 283134.260000 12239.361252
13 288497.540000 11336.550964
15 280022.728000 8804.882369
[RFC][PATCH 1/5] uts namespaces: Implement utsname namespaces [message #2485 is a reply to message #2484] Fri, 07 April 2006 18:36 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
This patch defines the uts namespace and some manipulators.
Adds the uts namespace to task_struct, and initializes a
system-wide init namespace which will continue to be used when
it makes sense.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
include/linux/init_task.h | 2 +
include/linux/sched.h | 2 +
include/linux/utsname.h | 40 +++++++++++++++++++++++++-
init/Kconfig | 8 +++++
init/version.c | 70 ++++++++++++++++++++++++++++++++++++++++-----
kernel/exit.c | 2 +
kernel/fork.c | 9 +++++-
7 files changed, 122 insertions(+), 11 deletions(-)

14c326d603d88d9ed40a1ddafbf23fc3da68a645
diff --git a/include/linux/init_task.h b/include/linux/init_task.h
index 41ecbb8..21b1751 100644
--- a/include/linux/init_task.h
+++ b/include/linux/init_task.h
@@ -3,6 +3,7 @@

#include <linux/file.h>
#include <linux/rcupdate.h>
+#include <linux/utsname.h>

#define INIT_FDTABLE \
{ \
@@ -123,6 +124,7 @@ extern struct group_info init_groups;
.journal_info = NULL, \
.cpu_timers = INIT_CPU_TIMERS(tsk.cpu_timers), \
.fs_excl = ATOMIC_INIT(0), \
+ .uts_ns = &init_uts_ns, \
}


diff --git a/include/linux/sched.h b/include/linux/sched.h
index 541f482..97c7990 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -684,6 +684,7 @@ static inline void prefetch_stack(struct

struct audit_context; /* See audit.c */
struct mempolicy;
+struct uts_namespace;

enum sleep_type {
SLEEP_NORMAL,
@@ -807,6 +808,7 @@ struct task_struct {
struct files_struct *files;
/* namespace */
struct namespace *namespace;
+ struct uts_namespace *uts_ns;
/* signal handlers */
struct signal_struct *signal;
struct sighand_struct *sighand;
diff --git a/include/linux/utsname.h b/include/linux/utsname.h
index 13e1da0..cc28ac5 100644
--- a/include/linux/utsname.h
+++ b/include/linux/utsname.h
@@ -1,5 +1,8 @@
#ifndef _LINUX_UTSNAME_H
#define _LINUX_UTSNAME_H
+#include <linux/sched.h>
+#include <linux/kref.h>
+#include <asm/atomic.h>

#define __OLD_UTS_LEN 8

@@ -30,7 +33,42 @@ struct new_utsname {
char domainname[65];
};

-extern struct new_utsname system_utsname;
+struct uts_namespace {
+ struct kref kref;
+ struct new_utsname name;
+};
+extern struct uts_namespace init_uts_ns;
+
+#ifdef CONFIG_UTS_NS
+
+extern struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns);
+extern struct uts_namespace *unshare_uts_ns(void);
+extern void free_uts_ns(struct kref *kref);
+
+static inline void get_uts_ns(struct uts_namespace *ns)
+{
+ kref_get(&ns->kref);
+}
+
+static inline void put_uts_ns(struct uts_namespace *ns)
+{
+ kref_put(&ns->kref, free_uts_ns);
+}
+
+#else
+static inline void get_uts_ns(struct uts_namespace *ns)
+{
+}
+static inline void put_uts_ns(struct uts_namespace *ns)
+{
+}
+#endif
+
+static inline struct new_utsname *utsname(void)
+{
+ return &current->uts_ns->name;
+}
+

extern struct rw_semaphore uts_sem;
#endif
diff --git a/init/Kconfig b/init/Kconfig
index 3b36a1d..8460e5a 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -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
diff --git a/init/version.c b/init/version.c
index 3ddc3ce..e128d72 100644
--- a/init/version.c
+++ b/init/version.c
@@ -11,22 +11,76 @@
#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);
+#ifdef CONFIG_UTS_NS
+/*
+ * Clone a new ns copying an original utsname, setting refcount to 1
+ * @old_ns: namespace to clone
+ * Return NULL on error (failure to kmalloc), new ns otherwise
+ */
+struct uts_namespace *clone_uts_ns(struct uts_namespace *old_ns)
+{
+ struct uts_namespace *ns;
+
+ ns = kmalloc(sizeof(struct uts_namespace), GFP_KERNEL);
+ if (ns) {
+ memcpy(&ns->name, &old_ns->name, sizeof(ns->name));
+ kref_init(&ns->kref);
+ }
+ return ns;
+}
+
+/*
+ * unshare the current process' utsname namespace. Changes
+ * to the utsname of this process won't be seen by parent, and
+ * vice versa
+ *
+ * Return NULL on error (failure to kmalloc), new ns otherwise
+ *
+ * TODO: decide where this should be locked (depends on how/where
+ * we decide to use this)
+ */
+struct uts_namespace *unshare_uts_ns(void)
+{
+ struct uts_namespace *old_ns = current->uts_ns;
+ struct uts_namespace *new_ns = clone_uts_ns(old_ns);
+ if (new_ns) {
+ current->uts_ns = new_ns;
+ put_uts_ns(old_ns);
+ }
+ return new_ns;
+}
+EXPORT_SYMBOL(unshare_uts_ns);
+
+void free_uts_ns(struct kref *kref)
+{
+ struct uts_namespace *ns;
+
+ ns = container_of(kref, struct uts_namespace, kref);
+ kfree(ns);
+}
+EXPORT_SYMBOL(free_uts_ns);
+#endif

const char linux_banner[] =
"Linux version " UTS_RELEASE " (" LINUX_COMPILE_BY "@"
diff --git a/kernel/exit.c b/kernel/exit.c
index 6c2eeb8..97c5405 100644
--- a/kernel/exit.c
+++ b/kernel/exit.c
@@ -34,6 +34,7 @@
#include <linux/mutex.h>
#include <linux/futex.h>
#include <linux/compat.h>
+#include <linux/utsname.h>

#include <asm/uaccess.h>
#include <asm/unistd.h>
@@ -173,6 +174,7 @@ repeat:
spin_unlock(&p->proc_lock);
proc_pid_flush(proc_dentry);
release_thread(p);
+ put_uts_ns(p->uts_ns);
call_rcu(&p->rcu, delayed_put_task_struct);

p = leader;
diff --git a/kernel/fork.c b/kernel/fork.c
index 3384eb8..62e4479 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -44,6 +44,7 @@
#include <linux/rmap.h>
#include <linux/acct.h>
#include <linux/cn_proc.h>
+#include <linux/utsname.h>

#include <asm/pgtable.h>
#include <asm/pgalloc.h>
@@ -1119,6 +1120,8 @@ static task_t *copy_process(unsigned lon
/* Perform scheduler related setup. Assign this task to a CPU. */
sched_fork(p, clone_flags);

+ get_uts_ns(p->uts_ns);
+
/* Need tasklist lock for parent etc handling! */
write_lock_irq(&tasklist_lock);

@@ -1158,7 +1161,7 @@ static task_t *copy_process(unsigned lon
spin_unlock(&current->sighand->siglock);
write_unlock_irq(&tasklist_lock);
retval = -ERESTARTNOINTR;
- goto bad_fork_cleanup_namespace;
+ goto bad_fork_cleanup_utsns;
}

if (clone_flags & CLONE_THREAD) {
@@ -1171,7 +1174,7 @@ static task_t *copy_process(unsigned lon
spin_unlock(&current->sighand->siglock);
write_unlock_irq(&tasklist_lock);
retval = -EAGAIN;
- goto bad_fork_cleanup_namespace;
+ goto bad_fork_cleanup_utsns;
}

p->group_leader = current->group_leader;
@@ -1223,6 +1226,8 @@ static task_t *copy_process(unsigned lon
proc_fork_connector(p);
return p;

+bad_fork_cleanup_utsns:
+ put_uts_ns(p->uts_ns);
bad_fork_cleanup_namespace:
exit_namespace(p);
bad_fork_cleanup_keys:
--
1.2.4
[RFC][PATCH 5/5] uts namespaces: Enable UTS namespaces debugging [message #2486 is a reply to message #2484] Fri, 07 April 2006 18:36 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Adds a /uts directory in debugfs which exposes the current UTS
namespace. If a file in this directory is changed, it will
unshare and modify the UTS namespace of the current process.

Clearly this is purely for testing purposes. Testing namespaces
in this fashion allows us to postpone concensus on a namespace
unsharing mechanism.

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
---
fs/debugfs/Makefile | 2 -
fs/debugfs/uts.c | 170 +++++++++++++++++++++++++++++++++++++++++++++++++++
lib/Kconfig.debug | 11 +++
3 files changed, 182 insertions(+), 1 deletions(-)
create mode 100644 fs/debugfs/uts.c

67f3dc966381313f31ee3643183161a8c230199b
diff --git a/fs/debugfs/Makefile b/fs/debugfs/Makefile
index 840c456..e5df8b9 100644
--- a/fs/debugfs/Makefile
+++ b/fs/debugfs/Makefile
@@ -1,4 +1,4 @@
debugfs-objs := inode.o file.o

obj-$(CONFIG_DEBUG_FS) += debugfs.o
-
+obj-$(CONFIG_DEBUG_UTS_NS) += uts.o
diff --git a/fs/debugfs/uts.c b/fs/debugfs/uts.c
new file mode 100644
index 0000000..45b29af
--- /dev/null
+++ b/fs/debugfs/uts.c
@@ -0,0 +1,170 @@
+/*
+ * uts.c - adds a uts/ directory to debug UTS namespaces
+ *
+ * Copyright (C) 2006 IBM
+ *
+ * Author: Cedric Le Goater <clg@fr.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2 of the
+ * License.
+ */
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/pagemap.h>
+#include <linux/debugfs.h>
+#include <linux/utsname.h>
+
+static struct dentry *uts_dentry;
+static struct dentry *uts_dentry_sysname;
+static struct dentry *uts_dentry_nodename;
+static struct dentry *uts_dentry_release;
+static struct dentry *uts_dentry_version;
+static struct dentry *uts_dentry_machine;
+static struct dentry *uts_dentry_domainname;
+
+static inline char* uts_buffer(struct dentry *dentry)
+{
+ if (dentry == uts_dentry_sysname)
+ return utsname()->sysname;
+ else if (dentry == uts_dentry_nodename)
+ return utsname()->nodename;
+ else if (dentry == uts_dentry_release)
+ return utsname()->release;
+ else if (dentry == uts_dentry_version)
+ return utsname()->version;
+ else if (dentry == uts_dentry_machine)
+ return utsname()->machine;
+ else if (dentry == uts_dentry_domainname)
+ return utsname()->domainname;
+ else
+ return NULL;
+}
+
+static ssize_t uts_read_file(struct file *file, char __user *user_buf,
+ size_t count, loff_t *ppos)
+{
+ size_t len;
+ char* buf;
+
+ if (*ppos < 0)
+ return -EINVAL;
+ if (*ppos >= count)
+ return 0;
+
+ buf = uts_buffer(file->f_dentry);
+ if (!buf)
+ return -ENOENT;
+
+ len = strlen(buf);
+ if (len > count)
+ len = count;
+ if (len)
+ if (copy_to_user(user_buf, buf, len))
+ return -EFAULT;
+ if (len < count) {
+ if (put_user('\n', ((char __user *) user_buf) + len))
+ return -EFAULT;
+ len++;
+ }
+
+ *ppos += count;
+ return count;
+}
+
+
+static ssize_t uts_write_file(struct file * file, const char __user * user_buf,
+ size_t count, loff_t *ppos)
+
+{
+ size_t len;
+ const char __user *p;
+ char c;
+ char* buf;
+
+ if (!unshare_uts_ns())
+ return -ENOMEM;
+
+ buf = uts_buffer(file->f_dentry);
+ if (!buf)
+ return -ENOENT;
+
+ len = 0;
+ p = user_buf;
+ while (len < count) {
+ if (get_user(c, p++))
+ return -EFAULT;
+ if (c == 0 || c == '\n')
+ break;
+ len++;
+ }
+
+ if (len >= __NEW_UTS_LEN)
+ len = __NEW_UTS_LEN - 1;
+
+ if (copy_from_user(buf, user_buf, len))
+ return -EFAULT;
+
+ buf[len] = 0;
+
+ *ppos += count;
+ return count;
+}
+
+static int uts_open(struct inode *inode, struct file *file)
+{
+ return 0;
+}
+
+static struct file_operations uts_file_operations = {
+ .read = uts_read_file,
+ .write = uts_write_file,
+ .open = uts_open,
+};
+
+static int __init uts_init(void)
+{
+ uts_dentry = debugfs_create_dir("uts", NULL);
+
+ uts_dentry_sysname = debugfs_create_file("sysname", 0666,
+ uts_dentry, NULL,
+ &uts_file_operations);
+ uts_dentry_nodename = debugfs_create_file("nodename", 0666,
+ uts_dentry, NULL,
+ &uts_file_operations);
+ uts_dentry_release = debugfs_create_file("release", 0666,
+ uts_dentry, NULL,
+ &uts_file_operations);
+ uts_dentry_version = debugfs_create_file("version", 0666,
+ uts_dentry, NULL,
+ &uts_file_operations);
+ uts_dentry_machine = debugfs_create_file("machine", 0666,
+ uts_dentry, NULL,
+ &uts_file_operations);
+ uts_dentry_domainname = debugfs_create_file("domainname", 0666,
+ uts_dentry, NULL,
+ &uts_file_operations);
+ return 0;
+}
+
+static void __exit uts_exit(void)
+{
+ debugfs_remove(uts_dentry_sysname);
+ debugfs_remove(uts_dentry_nodename);
+ debugfs_remove(uts_dentry_release);
+ debugfs_remove(uts_dentry_version);
+ debugfs_remove(uts_dentry_machine);
+ debugfs_remove(uts_dentry_domainname);
+ debugfs_remove(uts_dentry);
+}
+
+module_init(uts_init);
+module_exit(uts_exit);
+
+
+MODULE_DESCRIPTION("UTS namespace debugfs");
+MODULE_AUTHOR("Cedric Le Goater <clg@fr.ibm.com>");
+MODULE_LICENSE("GPL");
+
diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index d57fd91..5ed09b8 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -223,3 +223,14 @@ config RCU_TORTURE_TEST
at boot time (you probably don't).
Say M if you want the RCU torture tests to build as a module.
Say N if you are unsure.
+
+config DEBUG_UTS_NS
+ tristate "UTS Namespaces debugging"
+ depends on UTS_NS
+ select DEBUG_FS
+ default n
+ help
+ This option provides a kernel module that adds a uts/ directory
+ in debugfs which can be used to unshare and modify the uts namespace
+ of the current process and children. If unsure, say N.
+
--
1.2.4
[RFC][PATCH 2/5] uts namespaces: Switch to using uts namespaces [message #2487 is a reply to message #2484] Fri, 07 April 2006 18:36 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Replace references to system_utsname to the per-process uts namespace
where appropriate. This includes things like uname.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
arch/alpha/kernel/osf_sys.c | 24 ++++++++++++------------
arch/i386/kernel/sys_i386.c | 12 ++++++------
arch/ia64/sn/kernel/sn2/sn_hwperf.c | 2 +-
arch/m32r/kernel/sys_m32r.c | 2 +-
arch/mips/kernel/linux32.c | 2 +-
arch/mips/kernel/syscall.c | 18 +++++++++---------
arch/mips/kernel/sysirix.c | 12 ++++++------
arch/parisc/hpux/sys_hpux.c | 22 +++++++++++-----------
arch/powerpc/kernel/syscalls.c | 14 +++++++-------
arch/sh/kernel/sys_sh.c | 2 +-
arch/sh64/kernel/sys_sh64.c | 2 +-
arch/sparc/kernel/sys_sparc.c | 4 ++--
arch/sparc/kernel/sys_sunos.c | 10 +++++-----
arch/sparc64/kernel/sys_sparc.c | 4 ++--
arch/sparc64/kernel/sys_sunos32.c | 10 +++++-----
arch/sparc64/solaris/misc.c | 6 +++---
arch/um/drivers/mconsole_kern.c | 6 +++---
arch/um/kernel/syscall_kern.c | 12 ++++++------
arch/um/sys-x86_64/syscalls.c | 2 +-
arch/x86_64/ia32/sys_ia32.c | 10 +++++-----
arch/x86_64/kernel/sys_x86_64.c | 2 +-
arch/xtensa/kernel/syscalls.c | 2 +-
drivers/char/random.c | 4 ++--
fs/cifs/connect.c | 28 ++++++++++++++--------------
fs/exec.c | 2 +-
fs/lockd/clntproc.c | 4 ++--
fs/lockd/mon.c | 2 +-
fs/lockd/svclock.c | 2 +-
fs/lockd/xdr.c | 2 +-
fs/nfs/nfsroot.c | 2 +-
include/linux/lockd/lockd.h | 2 +-
kernel/sys.c | 14 +++++++-------
32 files changed, 121 insertions(+), 121 deletions(-)

92a8cf13a78415ed5ec9068698b5039ddcc00210
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 31afe3d..b793b96 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -402,15 +402,15 @@ osf_utsname(char __user *name)

down_read(&uts_sem);
error = -EFAULT;
- if (copy_to_user(name + 0, system_utsname.sysname, 32))
+ if (copy_to_user(name + 0, utsname()->sysname, 32))
goto out;
- if (copy_to_user(name + 32, system_utsname.nodename, 32))
+ if (copy_to_user(name + 32, utsname()->nodename, 32))
goto out;
- if (copy_to_user(name + 64, system_utsname.release, 32))
+ if (copy_to_user(name + 64, utsname()->release, 32))
goto out;
- if (copy_to_user(name + 96, system_utsname.version, 32))
+ if (copy_to_user(name + 96, utsname()->version, 32))
goto out;
- if (copy_to_user(name + 128, system_utsname.machine, 32))
+ if (copy_to_user(name + 128, utsname()->machine, 32))
goto out;

error = 0;
@@ -449,8 +449,8 @@ osf_getdomainname(char __user *name, int

down_read(&uts_sem);
for (i = 0; i < len; ++i) {
- __put_user(system_utsname.domainname[i], name + i);
- if (system_utsname.domainname[i] == '\0')
+ __put_user(utsname()->domainname[i], name + i);
+ if (utsname()->domainname[i] == '\0')
break;
}
up_read(&uts_sem);
@@ -608,11 +608,11 @@ asmlinkage long
osf_sysinfo(int command, char __user *buf, long count)
{
static char * sysinfo_table[] = {
- system_utsname.sysname,
- system_utsname.nodename,
- system_utsname.release,
- system_utsname.version,
- system_utsname.machine,
+ utsname()->sysname,
+ utsname()->nodename,
+ utsname()->release,
+ utsname()->version,
+ utsname()->machine,
"alpha", /* instruction set architecture */
"dummy", /* hardware serial number */
"dummy", /* hardware manufacturer */
diff --git a/arch/i386/kernel/sys_i386.c b/arch/i386/kernel/sys_i386.c
index 8fdb1fb..4af731d 100644
--- a/arch/i386/kernel/sys_i386.c
+++ b/arch/i386/kernel/sys_i386.c
@@ -210,7 +210,7 @@ asmlinkage int sys_uname(struct old_utsn
if (!name)
return -EFAULT;
down_read(&uts_sem);
- err=copy_to_user(name, &system_utsname, sizeof (*name));
+ err=copy_to_user(name, utsname(), sizeof (*name));
up_read(&uts_sem);
return err?-EFAULT:0;
}
@@ -226,15 +226,15 @@ asmlinkage int sys_olduname(struct oldol

down_read(&uts_sem);

- error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
+ error = __copy_to_user(&name->sysname,&utsname()->sysname,__OLD_UTS_LEN);
error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
- error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
+ error |= __copy_to_user(&name->nodename,&utsname()->nodename,__OLD_UTS_LEN);
error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
- error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
+ error |= __copy_to_user(&name->release,&utsname()->release,__OLD_UTS_LEN);
error |= __put_user(0,name->release+__OLD_UTS_LEN);
- error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
+ error |= __copy_to_user(&name->version,&utsname()->version,__OLD_UTS_LEN);
error |= __put_user(0,name->version+__OLD_UTS_LEN);
- error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
+ error |= __copy_to_user(&name->machine,&utsname()->machine,__OLD_UTS_LEN);
error |= __put_user(0,name->machine+__OLD_UTS_LEN);

up_read(&uts_sem);
diff --git a/arch/ia64/sn/kernel/sn2/sn_hwperf.c b/arch/ia64/sn/kernel/sn2/sn_hwperf.c
index d917afa..a0632a9 100644
--- a/arch/ia64/sn/kernel/sn2/sn_hwperf.c
+++ b/arch/ia64/sn/kernel/sn2/sn_hwperf.c
@@ -420,7 +420,7 @@ static int sn_topology_show(struct seq_f
"coherency_domain %d, "
"region_size %d\n",

- partid, system_utsname.nodename,
+ partid, utsname()->nodename,
shubtype ? "shub2" : "shub1",
(u64)nasid_mask << nasid_shift, nasid_msb, nasid_shift,
system_size, sharing_size, coher, region_size);
diff --git a/arch/m32r/kernel/sys_m32r.c b/arch/m32r/kernel/sys_m32r.c
index 670cb49..11412c0 100644
--- a/arch/m32r/kernel/sys_m32r.c
+++ b/arch/m32r/kernel/sys_m32r.c
@@ -206,7 +206,7 @@ asmlinkage int sys_uname(struct old_utsn
if (!name)
return -EFAULT;
down_read(&uts_sem);
- err=copy_to_user(name, &system_utsname, sizeof (*name));
+ err=copy_to_user(name, utsname(), sizeof (*name));
up_read(&uts_sem);
return err?-EFAULT:0;
}
diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c
index 3f40c37..b9b702f 100644
--- a/arch/mips/kernel/linux32.c
+++ b/arch/mips/kernel/linux32.c
@@ -1100,7 +1100,7 @@ asmlinkage long sys32_newuname(struct ne
int ret = 0;

down_read(&uts_sem);
- if (copy_to_user(name,&system_utsname,sizeof *name))
+ if (copy_to_user(name,utsname(),sizeof *name))
ret = -EFAULT;
up_read(&uts_sem);

diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
index 2aeaa2f..8b13d57 100644
--- a/arch/mips/kernel/syscall.c
+++ b/arch/mips/kernel/syscall.c
@@ -232,7 +232,7 @@ out:
*/
asmlinkage int sys_uname(struct old_utsname __user * name)
{
- if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
+ if (name && !copy_to_user(name, utsname(), sizeof (*name)))
return 0;
return -EFAULT;
}
@@ -249,15 +249,15 @@ asmlinkage int sys_olduname(struct oldol
if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
return -EFAULT;

- error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
+ error = __copy_to_user(&name->sysname,&utsname()->sysname,__OLD_UTS_LEN);
error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
- error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
+ error -= __copy_to_user(&name->nodename,&utsname()->nodename,__OLD_UTS_LEN);
error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
- error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
+ error -= __copy_to_user(&name->release,&utsname()->release,__OLD_UTS_LEN);
error -= __put_user(0,name->release+__OLD_UTS_LEN);
- error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
+ error -= __copy_to_user(&name->version,&utsname()->version,__OLD_UTS_LEN);
error -= __put_user(0,name->version+__OLD_UTS_LEN);
- error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
+ error -= __copy_to_user(&name->machine,&utsname()->machine,__OLD_UTS_LEN);
error = __put_user(0,name->machine+__OLD_UTS_LEN);
error = error ? -EFAULT : 0;

@@ -293,10 +293,10 @@ asmlinkage int _sys_sysmips(int cmd, lon
return -EFAULT;

down_write(&uts_sem);
- strncpy(system_utsname.nodename, nodename, len);
+ strncpy(utsname()->nodename, nodename, len);
nodename[__NEW_UTS_LEN] = '\0';
- strlcpy(system_utsname.nodename, nodename,
- sizeof(system_utsname.nodename));
+ strlcpy(utsname()->nodename, nodename,
+ sizeof(utsname()->nodename));
up_write(&uts_sem);
return 0;
}
diff --git a/arch/mips/kernel/sysirix.c b/arch/mips/kernel/sysirix.c
index 5407b78..1b4e7e7 100644
--- a/arch/mips/kernel/sysirix.c
+++ b/arch/mips/kernel/sysirix.c
@@ -884,7 +884,7 @@ asmlinkage int irix_getdomainname(char _
down_read(&uts_sem);
if (len > __NEW_UTS_LEN)
len = __NEW_UTS_LEN;
- err = copy_to_user(name, system_utsname.domainname, len) ? -EFAULT : 0;
+ err = copy_to_user(name, utsname()->domainname, len) ? -EFAULT : 0;
up_read(&uts_sem);

return err;
@@ -1127,11 +1127,11 @@ struct iuname {
asmlinkage int irix_uname(struct iuname __user *buf)
{
down_read(&uts_sem);
- i
...

[RFC][PATCH 3/5] uts namespaces: Use init uts_namespace when appropriate [message #2488 is a reply to message #2484] Fri, 07 April 2006 18:36 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
In some places, particularly drivers and __init code, the init uts namespace is the
appropriate one to use. This patch replaces those with a direct reference to
init_uts_ns.name. Note that we can drop this patch and simply
do #define system_utsname (init_uts_ns.name)
however by using this patch we make explicit, for the sake of review, those
places where we do and do not use the utsname namespace.

Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
---
arch/arm/kernel/setup.c | 2 +-
arch/arm26/kernel/setup.c | 2 +-
arch/cris/kernel/setup.c | 2 +-
arch/i386/kernel/process.c | 6 +++---
arch/i386/kernel/traps.c | 6 +++---
arch/powerpc/kernel/process.c | 2 +-
arch/powerpc/kernel/setup_64.c | 2 +-
arch/powerpc/platforms/pseries/setup.c | 2 +-
arch/sh/kernel/setup.c | 2 +-
arch/um/kernel/um_arch.c | 6 +++---
arch/um/sys-x86_64/sysrq.c | 2 +-
arch/x86_64/kernel/process.c | 6 +++---
drivers/infiniband/hw/ipath/ipath_verbs.c | 2 +-
drivers/parisc/led.c | 2 +-
drivers/scsi/lpfc/lpfc_ct.c | 8 ++++----
drivers/usb/core/hcd.c | 4 ++--
drivers/usb/gadget/ether.c | 2 +-
drivers/usb/gadget/file_storage.c | 2 +-
drivers/usb/gadget/serial.c | 2 +-
drivers/usb/gadget/zero.c | 2 +-
include/asm-i386/bugs.h | 2 +-
include/asm-i386/elf.h | 2 +-
include/asm-sh/bugs.h | 2 +-
kernel/power/snapshot.c | 10 +++++-----
net/ipv4/ipconfig.c | 16 ++++++++--------
net/sunrpc/clnt.c | 4 ++--
sound/core/info_oss.c | 10 +++++-----
27 files changed, 55 insertions(+), 55 deletions(-)

ef54ab30a75ae83207b385090d3f1ff6c912f0d5
diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
index 4375284..647c516 100644
--- a/arch/arm/kernel/setup.c
+++ b/arch/arm/kernel/setup.c
@@ -319,7 +319,7 @@ static void __init setup_processor(void)
cpu_name, processor_id, (int)processor_id & 15,
proc_arch[cpu_architecture()]);

- sprintf(system_utsname.machine, "%s%c", list->arch_name, ENDIANNESS);
+ sprintf(init_uts_ns.name.machine, "%s%c", list->arch_name, ENDIANNESS);
sprintf(elf_platform, "%s%c", list->elf_name, ENDIANNESS);
elf_hwcap = list->elf_hwcap;

diff --git a/arch/arm26/kernel/setup.c b/arch/arm26/kernel/setup.c
index 4eb329e..6564e73 100644
--- a/arch/arm26/kernel/setup.c
+++ b/arch/arm26/kernel/setup.c
@@ -144,7 +144,7 @@ static void __init setup_processor(void)

dump_cpu_info();

- sprintf(system_utsname.machine, "%s", list->arch_name);
+ sprintf(init_uts_ns.name.machine, "%s", list->arch_name);
sprintf(elf_platform, "%s", list->elf_name);
elf_hwcap = list->elf_hwcap;

diff --git a/arch/cris/kernel/setup.c b/arch/cris/kernel/setup.c
index 619a6ee..f9a29a4 100644
--- a/arch/cris/kernel/setup.c
+++ b/arch/cris/kernel/setup.c
@@ -161,7 +161,7 @@ setup_arch(char **cmdline_p)
show_etrax_copyright();

/* Setup utsname */
- strcpy(system_utsname.machine, cris_machine_name);
+ strcpy(init_uts_ns.name.machine, cris_machine_name);
}

static void *c_start(struct seq_file *m, loff_t *pos)
diff --git a/arch/i386/kernel/process.c b/arch/i386/kernel/process.c
index 6259afe..89fac4c 100644
--- a/arch/i386/kernel/process.c
+++ b/arch/i386/kernel/process.c
@@ -297,9 +297,9 @@ void show_regs(struct pt_regs * regs)
if (user_mode_vm(regs))
printk(" ESP: %04x:%08lx",0xffff & regs->xss,regs->esp);
printk(" EFLAGS: %08lx %s (%s %.*s)\n",
- regs->eflags, print_tainted(), system_utsname.release,
- (int)strcspn(system_utsname.version, " "),
- system_utsname.version);
+ regs->eflags, print_tainted(), init_uts_ns.name.release,
+ (int)strcspn(init_uts_ns.name.version, " "),
+ init_uts_ns.name.version);
printk("EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
regs->eax,regs->ebx,regs->ecx,regs->edx);
printk("ESI: %08lx EDI: %08lx EBP: %08lx",
diff --git a/arch/i386/kernel/traps.c b/arch/i386/kernel/traps.c
index e385279..addff65 100644
--- a/arch/i386/kernel/traps.c
+++ b/arch/i386/kernel/traps.c
@@ -260,9 +260,9 @@ void show_registers(struct pt_regs *regs
printk(KERN_EMERG "CPU: %d\nEIP: %04x:[<%08lx>] %s VLI\n"
"EFLAGS: %08lx (%s %.*s) \n",
smp_processor_id(), 0xffff & regs->xcs, regs->eip,
- print_tainted(), regs->eflags, system_utsname.release,
- (int)strcspn(system_utsname.version, " "),
- system_utsname.version);
+ print_tainted(), regs->eflags, init_uts_ns.name.release,
+ (int)strcspn(init_uts_ns.name.version, " "),
+ init_uts_ns.name.version);
print_symbol(KERN_EMERG "EIP is at %s\n", regs->eip);
printk(KERN_EMERG "eax: %08lx ebx: %08lx ecx: %08lx edx: %08lx\n",
regs->eax, regs->ebx, regs->ecx, regs->edx);
diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
index 2dd47d2..7c21450 100644
--- a/arch/powerpc/kernel/process.c
+++ b/arch/powerpc/kernel/process.c
@@ -425,7 +425,7 @@ void show_regs(struct pt_regs * regs)
printk("NIP: "REG" LR: "REG" CTR: "REG"\n",
regs->nip, regs->link, regs->ctr);
printk("REGS: %p TRAP: %04lx %s (%s)\n",
- regs, regs->trap, print_tainted(), system_utsname.release);
+ regs, regs->trap, print_tainted(), init_uts_ns.name.release);
printk("MSR: "REG" ", regs->msr);
printbits(regs->msr, msr_bits);
printk(" CR: %08lX XER: %08lX\n", regs->ccr, regs->xer);
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 13e91c4..26f0477 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -435,7 +435,7 @@ void __init setup_system(void)
smp_release_cpus();
#endif

- printk("Starting Linux PPC64 %s\n", system_utsname.version);
+ printk("Starting Linux PPC64 %s\n", init_uts_ns.name.version);

printk("-----------------------------------------------------\n ");
printk("ppc64_pft_size = 0x%lx\n", ppc64_pft_size);
diff --git a/arch/powerpc/platforms/pseries/setup.c b/arch/powerpc/platforms/pseries/setup.c
index 5eb55ef..9df0d0e 100644
--- a/arch/powerpc/platforms/pseries/setup.c
+++ b/arch/powerpc/platforms/pseries/setup.c
@@ -255,7 +255,7 @@ static int __init pSeries_init_panel(voi
{
/* Manually leave the kernel version on the panel. */
ppc_md.progress("Linux ppc64\n", 0);
- ppc_md.progress(system_utsname.version, 0);
+ ppc_md.progress(init_uts_ns.name.version, 0);

return 0;
}
diff --git a/arch/sh/kernel/setup.c b/arch/sh/kernel/setup.c
index bb229ef..fab811b 100644
--- a/arch/sh/kernel/setup.c
+++ b/arch/sh/kernel/setup.c
@@ -481,7 +481,7 @@ static int show_cpuinfo(struct seq_file
seq_printf(m, "machine\t\t: %s\n", get_system_type());

seq_printf(m, "processor\t: %d\n", cpu);
- seq_printf(m, "cpu family\t: %s\n", system_utsname.machine);
+ seq_printf(m, "cpu family\t: %s\n", init_uts_ns.name.machine);
seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());

show_cpuflags(m);
diff --git a/arch/um/kernel/um_arch.c b/arch/um/kernel/um_arch.c
index 7d51dd7..4caad31 100644
--- a/arch/um/kernel/um_arch.c
+++ b/arch/um/kernel/um_arch.c
@@ -167,7 +167,7 @@ static char *usage_string =

static int __init uml_version_setup(char *line, int *add)
{
- printf("%s\n", system_utsname.release);
+ printf("%s\n", init_uts_ns.name.release);
exit(0);

return 0;
@@ -278,7 +278,7 @@ static int __init Usage(char *line, int
{
const char **p;

- printf(usage_string, system_utsname.release);
+ printf(usage_string, init_uts_ns.name.release);
p = &__uml_help_start;
while (p < &__uml_help_end) {
printf("%s", *p);
@@ -400,7 +400,7 @@ int linux_main(int argc, char **argv)
/* Reserve up to 4M after the current brk */
uml_reserved = ROUND_4M(brk_start) + (1 << 22);

- setup_machinename(system_utsname.machine);
+ setup_machinename(init_uts_ns.name.machine);

#ifdef CONFIG_CMDLINE_ON_HOST
argv1_begin = argv[1];
diff --git a/arch/um/sys-x86_64/sysrq.c b/arch/um/sys-x86_64/sysrq.c
index d0a25af..49a549a 100644
--- a/arch/um/sys-x86_64/sysrq.c
+++ b/arch/um/sys-x86_64/sysrq.c
@@ -16,7 +16,7 @@ void __show_regs(struct pt_regs * regs)
printk("\n");
print_modules();
printk("Pid: %d, comm: %.20s %s %s\n",
- current->pid, current->comm, print_tainted(), system_utsname.release);
+ current->pid, current->comm, print_tainted(), init_uts_ns.name.release);
printk("RIP: %04lx:[<%016lx>] ", PT_REGS_CS(regs) & 0xffff,
PT_REGS_RIP(regs));
printk("\nRSP: %016lx EFLAGS: %08lx\n", PT_REGS_RSP(regs),
diff --git a/arch/x86_64/kernel/process.c b/arch/x86_64/kernel/process.c
index 70dd8e5..f79a080 100644
--- a/arch/x86_64/kernel/process.c
+++ b/arch/x86_64/kernel/process.c
@@ -292,9 +292,9 @@ void __show_regs(struct pt_regs * regs)
print_modules();
printk("Pid: %d, comm: %.20s %s %s %.*s\n",
current->pid, current->comm, print_tainted(),
- system_utsname.release,
- (int)strcspn(system_utsname.version, " "),
- system_utsname.version);
+ init_uts_ns.name.release,
+ (int)strcspn(init_uts_ns.name.version, " "),
+
...

Re: [RFC][PATCH 0/5] uts namespaces: Introduction [message #2489 is a reply to message #2484] Fri, 07 April 2006 19:06 Go to previous messageGo to next message
ebiederm is currently offline  ebiederm
Messages: 1354
Registered: February 2006
Senior Member
"Serge E. Hallyn" <serue@us.ibm.com> writes:

> Introduce utsname namespaces. Instead of a single system_utsname
> containing hostname domainname etc, a process can request it's
> copy of the uts info to be cloned. The data will be copied from
> it's original, but any further changes will not be seen by processes
> which are not it's children, and vice versa.
>
> This is useful, for instance, for vserver/openvz, which can now clone
> a new uts namespace for each new virtual server.
>
> This patchset is based on Kirill Korotaev's Mar 24 submission, taking
> comments (in particular from James Morris and Eric Biederman) into
> account.
>
> Some performance results are attached. I was mainly curious whether
> it would be worth putting the task_struct->uts_ns pointer inside
> a #ifdef CONFIG_UTS_NS. The result show that leaving it in when
> CONFIG_UTS_NS=n has negligable performance impact, so that is the
> approach this patch takes.

Ok. This looks like the best version so far.

I like the utsname() function thing to shorten the
idiom of current->uts_ns->name.

We probably want to introduce utsname() and an init_utsname()
before any of the other changes, and then perform the substitutions,
before we actually change the code so the patchset can make it
through a git-bisect. This will also allows for something
that can be put in compat-mac.h for backports of anything that
cares.

Eric
Re: [RFC][PATCH 1/5] uts namespaces: Implement utsname namespaces [message #2492 is a reply to message #2485] Fri, 07 April 2006 19:20 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Quoting Sam Ravnborg (sam@ravnborg.org):
> On Fri, Apr 07, 2006 at 01:36:00PM -0500, Serge E. Hallyn wrote:
> > This patch defines the uts namespace and some manipulators.
> > Adds the uts namespace to task_struct, and initializes a
> > system-wide init namespace which will continue to be used when
> > it makes sense.
> It also kills system_utsname so you left the kernel uncompileable.
> Can you kill it later?

I can insert a #define system_utsname (init_uts_ns.name) in patch 1
and nuke it at patch 3.

-serge
Re: [RFC][PATCH 2/5] uts namespaces: Switch to using uts namespaces [message #2493 is a reply to message #2487] Fri, 07 April 2006 19:25 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Quoting Sam Ravnborg (sam@ravnborg.org):
> On Fri, Apr 07, 2006 at 01:36:00PM -0500, Serge E. Hallyn wrote:
> > Replace references to system_utsname to the per-process uts namespace
> > where appropriate. This includes things like uname.
> If you define helpers that operates on system_utsname and then apply
> this patch the kernel will still compile, and only later you can
> introduce the new stuff.

Ok, will try structuring the patches that way.

thanks,
-serge
Re: [RFC][PATCH 0/5] uts namespaces: Introduction [message #2494 is a reply to message #2489] Fri, 07 April 2006 19:28 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Quoting Eric W. Biederman (ebiederm@xmission.com):
> "Serge E. Hallyn" <serue@us.ibm.com> writes:
>
> > Introduce utsname namespaces. Instead of a single system_utsname
> > containing hostname domainname etc, a process can request it's
> > copy of the uts info to be cloned. The data will be copied from
> > it's original, but any further changes will not be seen by processes
> > which are not it's children, and vice versa.
> >
> > This is useful, for instance, for vserver/openvz, which can now clone
> > a new uts namespace for each new virtual server.
> >
> > This patchset is based on Kirill Korotaev's Mar 24 submission, taking
> > comments (in particular from James Morris and Eric Biederman) into
> > account.
> >
> > Some performance results are attached. I was mainly curious whether
> > it would be worth putting the task_struct->uts_ns pointer inside
> > a #ifdef CONFIG_UTS_NS. The result show that leaving it in when
> > CONFIG_UTS_NS=n has negligable performance impact, so that is the
> > approach this patch takes.
>
> Ok. This looks like the best version so far.
>
> I like the utsname() function thing to shorten the
> idiom of current->uts_ns->name.
>
> We probably want to introduce utsname() and an init_utsname()
> before any of the other changes, and then perform the substitutions,

This is the same as what Sam is saying, right? Just making sure I
understand.

> before we actually change the code so the patchset can make it
> through a git-bisect. This will also allows for something

Ok, I've finally got the rest of git doing my bidding, I'll go read
up on git-bisect.

thanks for the comments,
-serge
Re: [RFC][PATCH 1/5] uts namespaces: Implement utsname namespaces [message #2496 is a reply to message #2485] Fri, 07 April 2006 19:39 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Quoting Sam Ravnborg (sam@ravnborg.org):
> > diff --git a/include/linux/utsname.h b/include/linux/utsname.h
> > index 13e1da0..cc28ac5 100644
> > --- a/include/linux/utsname.h
> > +++ b/include/linux/utsname.h
> > @@ -1,5 +1,8 @@
> > #ifndef _LINUX_UTSNAME_H
> > #define _LINUX_UTSNAME_H
> You can kill this include
> > +#include <linux/sched.h>
>
> if you move this static inline to sched.h
> +
> > +static inline struct new_utsname *utsname(void)
> > +{
> > + return &current->uts_ns->name;
> > +}
> And since it operates on &current that may make sense.

I had it there originally. Don't mind moving it back if that
seems more appropriate, but of course then we'll need
to #include <linux/utsname.h> in sched.h, since we need to
know struct uts_ns to get uts_ns->name.

So is moving it to sched.h the way to go?

thanks,
-serge
Re: [RFC][PATCH 0/5] uts namespaces: Introduction [message #2497 is a reply to message #2494] Fri, 07 April 2006 19:39 Go to previous messageGo to next message
ebiederm is currently offline  ebiederm
Messages: 1354
Registered: February 2006
Senior Member
"Serge E. Hallyn" <serue@us.ibm.com> writes:

> Quoting Eric W. Biederman (ebiederm@xmission.com):
>> "Serge E. Hallyn" <serue@us.ibm.com> writes:
>>
>> > Introduce utsname namespaces. Instead of a single system_utsname
>> > containing hostname domainname etc, a process can request it's
>> > copy of the uts info to be cloned. The data will be copied from
>> > it's original, but any further changes will not be seen by processes
>> > which are not it's children, and vice versa.
>> >
>> > This is useful, for instance, for vserver/openvz, which can now clone
>> > a new uts namespace for each new virtual server.
>> >
>> > This patchset is based on Kirill Korotaev's Mar 24 submission, taking
>> > comments (in particular from James Morris and Eric Biederman) into
>> > account.
>> >
>> > Some performance results are attached. I was mainly curious whether
>> > it would be worth putting the task_struct->uts_ns pointer inside
>> > a #ifdef CONFIG_UTS_NS. The result show that leaving it in when
>> > CONFIG_UTS_NS=n has negligable performance impact, so that is the
>> > approach this patch takes.
>>
>> Ok. This looks like the best version so far.
>>
>> I like the utsname() function thing to shorten the
>> idiom of current->uts_ns->name.
>>
>> We probably want to introduce utsname() and an init_utsname()
>> before any of the other changes, and then perform the substitutions,
>
> This is the same as what Sam is saying, right? Just making sure I
> understand.

Yes.

>> before we actually change the code so the patchset can make it
>> through a git-bisect. This will also allows for something
>
> Ok, I've finally got the rest of git doing my bidding, I'll go read
> up on git-bisect.

Basically git-bisect is an automated binary search through patches
to help find bugs. If you ever can't compile at an intermediate
patch git-bisect and other people walking through the patches
looking for bugs won't like it.

It's not mandatory that you never break anything in a patchset,
but it is much friendlier when you can avoid breakage.

Eric
Re: [RFC][PATCH 1/5] uts namespaces: Implement utsname namespaces [message #2498 is a reply to message #2485] Fri, 07 April 2006 19:13 Go to previous messageGo to next message
Sam Ravnborg is currently offline  Sam Ravnborg
Messages: 9
Registered: April 2006
Junior Member
On Fri, Apr 07, 2006 at 01:36:00PM -0500, Serge E. Hallyn wrote:
> This patch defines the uts namespace and some manipulators.
> Adds the uts namespace to task_struct, and initializes a
> system-wide init namespace which will continue to be used when
> it makes sense.
It also kills system_utsname so you left the kernel uncompileable.
Can you kill it later?

> diff --git a/include/linux/utsname.h b/include/linux/utsname.h
> index 13e1da0..cc28ac5 100644
> --- a/include/linux/utsname.h
> +++ b/include/linux/utsname.h
> @@ -1,5 +1,8 @@
> #ifndef _LINUX_UTSNAME_H
> #define _LINUX_UTSNAME_H
You can kill this include
> +#include <linux/sched.h>

if you move this static inline to sched.h
+
> +static inline struct new_utsname *utsname(void)
> +{
> + return &current->uts_ns->name;
> +}
And since it operates on &current that may make sense.

Sam
Re: [RFC][PATCH 2/5] uts namespaces: Switch to using uts namespaces [message #2499 is a reply to message #2487] Fri, 07 April 2006 19:17 Go to previous messageGo to next message
Sam Ravnborg is currently offline  Sam Ravnborg
Messages: 9
Registered: April 2006
Junior Member
On Fri, Apr 07, 2006 at 01:36:00PM -0500, Serge E. Hallyn wrote:
> Replace references to system_utsname to the per-process uts namespace
> where appropriate. This includes things like uname.
If you define helpers that operates on system_utsname and then apply
this patch the kernel will still compile, and only later you can
introduce the new stuff.

Sam
Re: [RFC][PATCH 1/5] uts namespaces: Implement utsname namespaces [message #2500 is a reply to message #2485] Fri, 07 April 2006 20:47 Go to previous messageGo to next message
James Morris is currently offline  James Morris
Messages: 10
Registered: March 2006
Junior Member
On Fri, 7 Apr 2006, Serge E. Hallyn wrote:


> +EXPORT_SYMBOL(unshare_uts_ns);
> +EXPORT_SYMBOL(free_uts_ns);

Why not EXPORT_SYMBOL_GPL?

What do you expect the user api to look like, a syscall?

Probably need to think about LSM hooks for creating and updating the
namespaces.


- James
--
James Morris
<jmorris@namei.org>
Re: [RFC][PATCH 1/5] uts namespaces: Implement utsname namespaces [message #2501 is a reply to message #2500] Fri, 07 April 2006 22:13 Go to previous messageGo to next message
serue is currently offline  serue
Messages: 750
Registered: February 2006
Senior Member
Quoting James Morris (jmorris@namei.org):
> On Fri, 7 Apr 2006, Serge E. Hallyn wrote:
>
>
> > +EXPORT_SYMBOL(unshare_uts_ns);
> > +EXPORT_SYMBOL(free_uts_ns);
>
> Why not EXPORT_SYMBOL_GPL?

Actually come to think of it they don't need to be exported.

I will move the exports to the last, debugging, patch.

> What do you expect the user api to look like, a syscall?

This remains to be determined, and this patchset purposely doesn't
address it. AFAIU, the two most likely options are extending clone and
unshare, and using new syscalls. Whatever is decided for the other
namespaces, this should use.

With this patchset (minus the last patch for debugging) uts namespaces
are supported, but processes can't clone their uts namespace yet.

> Probably need to think about LSM hooks for creating and updating the
> namespaces.

True, that is something that needs to be discussed when the topic
of how to implement unsharing comes up again.

thanks,
-serge
Re: [RFC][PATCH 2/5] uts namespaces: Switch to using uts namespaces [message #2607 is a reply to message #2487] Tue, 11 April 2006 12:19 Go to previous messageGo to next message
dev is currently offline  dev
Messages: 1693
Registered: September 2005
Location: Moscow
Senior Member

Serge,

BTW, have you noticed that NFS is using utsname for internal processes
and in general case this makes NFS ns to be coupled with uts ns?

Kirill

> Replace references to system_utsname to the per-process uts namespace
> where appropriate. This includes things like uname.
>
> Signed-off-by: Serge E. Hallyn <serue@us.ibm.com>
> ---
> arch/alpha/kernel/osf_sys.c | 24 ++++++++++++------------
> arch/i386/kernel/sys_i386.c | 12 ++++++------
> arch/ia64/sn/kernel/sn2/sn_hwperf.c | 2 +-
> arch/m32r/kernel/sys_m32r.c | 2 +-
> arch/mips/kernel/linux32.c | 2 +-
> arch/mips/kernel/syscall.c | 18 +++++++++---------
> arch/mips/kernel/sysirix.c | 12 ++++++------
> arch/parisc/hpux/sys_hpux.c | 22 +++++++++++-----------
> arch/powerpc/kernel/syscalls.c | 14 +++++++-------
> arch/sh/kernel/sys_sh.c | 2 +-
> arch/sh64/kernel/sys_sh64.c | 2 +-
> arch/sparc/kernel/sys_sparc.c | 4 ++--
> arch/sparc/kernel/sys_sunos.c | 10 +++++-----
> arch/sparc64/kernel/sys_sparc.c | 4 ++--
> arch/sparc64/kernel/sys_sunos32.c | 10 +++++-----
> arch/sparc64/solaris/misc.c | 6 +++---
> arch/um/drivers/mconsole_kern.c | 6 +++---
> arch/um/kernel/syscall_kern.c | 12 ++++++------
> arch/um/sys-x86_64/syscalls.c | 2 +-
> arch/x86_64/ia32/sys_ia32.c | 10 +++++-----
> arch/x86_64/kernel/sys_x86_64.c | 2 +-
> arch/xtensa/kernel/syscalls.c | 2 +-
> drivers/char/random.c | 4 ++--
> fs/cifs/connect.c | 28 ++++++++++++++--------------
> fs/exec.c | 2 +-
> fs/lockd/clntproc.c | 4 ++--
> fs/lockd/mon.c | 2 +-
> fs/lockd/svclock.c | 2 +-
> fs/lockd/xdr.c | 2 +-
> fs/nfs/nfsroot.c | 2 +-
> include/linux/lockd/lockd.h | 2 +-
> kernel/sys.c | 14 +++++++-------
> 32 files changed, 121 insertions(+), 121 deletions(-)
>
> 92a8cf13a78415ed5ec9068698b5039ddcc00210
> diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
> index 31afe3d..b793b96 100644
> --- a/arch/alpha/kernel/osf_sys.c
> +++ b/arch/alpha/kernel/osf_sys.c
> @@ -402,15 +402,15 @@ osf_utsname(char __user *name)
>
> down_read(&uts_sem);
> error = -EFAULT;
> - if (copy_to_user(name + 0, system_utsname.sysname, 32))
> + if (copy_to_user(name + 0, utsname()->sysname, 32))
> goto out;
> - if (copy_to_user(name + 32, system_utsname.nodename, 32))
> + if (copy_to_user(name + 32, utsname()->nodename, 32))
> goto out;
> - if (copy_to_user(name + 64, system_utsname.release, 32))
> + if (copy_to_user(name + 64, utsname()->release, 32))
> goto out;
> - if (copy_to_user(name + 96, system_utsname.version, 32))
> + if (copy_to_user(name + 96, utsname()->version, 32))
> goto out;
> - if (copy_to_user(name + 128, system_utsname.machine, 32))
> + if (copy_to_user(name + 128, utsname()->machine, 32))
> goto out;
>
> error = 0;
> @@ -449,8 +449,8 @@ osf_getdomainname(char __user *name, int
>
> down_read(&uts_sem);
> for (i = 0; i < len; ++i) {
> - __put_user(system_utsname.domainname[i], name + i);
> - if (system_utsname.domainname[i] == '\0')
> + __put_user(utsname()->domainname[i], name + i);
> + if (utsname()->domainname[i] == '\0')
> break;
> }
> up_read(&uts_sem);
> @@ -608,11 +608,11 @@ asmlinkage long
> osf_sysinfo(int command, char __user *buf, long count)
> {
> static char * sysinfo_table[] = {
> - system_utsname.sysname,
> - system_utsname.nodename,
> - system_utsname.release,
> - system_utsname.version,
> - system_utsname.machine,
> + utsname()->sysname,
> + utsname()->nodename,
> + utsname()->release,
> + utsname()->version,
> + utsname()->machine,
> "alpha", /* instruction set architecture */
> "dummy", /* hardware serial number */
> "dummy", /* hardware manufacturer */
> diff --git a/arch/i386/kernel/sys_i386.c b/arch/i386/kernel/sys_i386.c
> index 8fdb1fb..4af731d 100644
> --- a/arch/i386/kernel/sys_i386.c
> +++ b/arch/i386/kernel/sys_i386.c
> @@ -210,7 +210,7 @@ asmlinkage int sys_uname(struct old_utsn
> if (!name)
> return -EFAULT;
> down_read(&uts_sem);
> - err=copy_to_user(name, &system_utsname, sizeof (*name));
> + err=copy_to_user(name, utsname(), sizeof (*name));
> up_read(&uts_sem);
> return err?-EFAULT:0;
> }
> @@ -226,15 +226,15 @@ asmlinkage int sys_olduname(struct oldol
>
> down_read(&uts_sem);
>
> - error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
> + error = __copy_to_user(&name->sysname,&utsname()->sysname,__OLD_UTS_LEN);
> error |= __put_user(0,name->sysname+__OLD_UTS_LEN);
> - error |= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
> + error |= __copy_to_user(&name->nodename,&utsname()->nodename,__OLD_UTS_LEN);
> error |= __put_user(0,name->nodename+__OLD_UTS_LEN);
> - error |= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
> + error |= __copy_to_user(&name->release,&utsname()->release,__OLD_UTS_LEN);
> error |= __put_user(0,name->release+__OLD_UTS_LEN);
> - error |= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
> + error |= __copy_to_user(&name->version,&utsname()->version,__OLD_UTS_LEN);
> error |= __put_user(0,name->version+__OLD_UTS_LEN);
> - error |= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
> + error |= __copy_to_user(&name->machine,&utsname()->machine,__OLD_UTS_LEN);
> error |= __put_user(0,name->machine+__OLD_UTS_LEN);
>
> up_read(&uts_sem);
> diff --git a/arch/ia64/sn/kernel/sn2/sn_hwperf.c b/arch/ia64/sn/kernel/sn2/sn_hwperf.c
> index d917afa..a0632a9 100644
> --- a/arch/ia64/sn/kernel/sn2/sn_hwperf.c
> +++ b/arch/ia64/sn/kernel/sn2/sn_hwperf.c
> @@ -420,7 +420,7 @@ static int sn_topology_show(struct seq_f
> "coherency_domain %d, "
> "region_size %d\n",
>
> - partid, system_utsname.nodename,
> + partid, utsname()->nodename,
> shubtype ? "shub2" : "shub1",
> (u64)nasid_mask << nasid_shift, nasid_msb, nasid_shift,
> system_size, sharing_size, coher, region_size);
> diff --git a/arch/m32r/kernel/sys_m32r.c b/arch/m32r/kernel/sys_m32r.c
> index 670cb49..11412c0 100644
> --- a/arch/m32r/kernel/sys_m32r.c
> +++ b/arch/m32r/kernel/sys_m32r.c
> @@ -206,7 +206,7 @@ asmlinkage int sys_uname(struct old_utsn
> if (!name)
> return -EFAULT;
> down_read(&uts_sem);
> - err=copy_to_user(name, &system_utsname, sizeof (*name));
> + err=copy_to_user(name, utsname(), sizeof (*name));
> up_read(&uts_sem);
> return err?-EFAULT:0;
> }
> diff --git a/arch/mips/kernel/linux32.c b/arch/mips/kernel/linux32.c
> index 3f40c37..b9b702f 100644
> --- a/arch/mips/kernel/linux32.c
> +++ b/arch/mips/kernel/linux32.c
> @@ -1100,7 +1100,7 @@ asmlinkage long sys32_newuname(struct ne
> int ret = 0;
>
> down_read(&uts_sem);
> - if (copy_to_user(name,&system_utsname,sizeof *name))
> + if (copy_to_user(name,utsname(),sizeof *name))
> ret = -EFAULT;
> up_read(&uts_sem);
>
> diff --git a/arch/mips/kernel/syscall.c b/arch/mips/kernel/syscall.c
> index 2aeaa2f..8b13d57 100644
> --- a/arch/mips/kernel/syscall.c
> +++ b/arch/mips/kernel/syscall.c
> @@ -232,7 +232,7 @@ out:
> */
> asmlinkage int sys_uname(struct old_utsname __user * name)
> {
> - if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
> + if (name && !copy_to_user(name, utsname(), sizeof (*name)))
> return 0;
> return -EFAULT;
> }
> @@ -249,15 +249,15 @@ asmlinkage int sys_olduname(struct oldol
> if (!access_ok(VERIFY_WRITE,name,sizeof(struct oldold_utsname)))
> return -EFAULT;
>
> - error = __copy_to_user(&name->sysname,&system_utsname.sysname,__OLD_UTS_LEN);
> + error = __copy_to_user(&name->sysname,&utsname()->sysname,__OLD_UTS_LEN);
> error -= __put_user(0,name->sysname+__OLD_UTS_LEN);
> - error -= __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
> + error -= __copy_to_user(&name->nodename,&utsname()->nodename,__OLD_UTS_LEN);
> error -= __put_user(0,name->nodename+__OLD_UTS_LEN);
> - error -= __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
> + error -= __copy_to_user(&name->release,&utsname()->release,__OLD_UTS_LEN);
> error -= __put_user(0,name->release+__OLD_UTS_LEN);
> - error -= __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
> + error -= __copy_to_user(&name->version,&utsname()->version,__OLD_UTS_LEN);
> error -= __put_user(0,name->version+__OLD_UTS_LEN);
> - error -= __copy_to_user(&name->machine,&system_utsname.machine,__OLD_UTS_LEN);
> + error -= __copy_to_user(&name->machine,&utsname()->machine,__OLD_UTS_LEN);
> error = __put_user(0,name->machine+__O
...

Re: [RFC][PATCH 0/5] uts namespaces: Introduction [message #2608 is a reply to message #2484] Tue, 11 April 2006 12:27 Go to previous messageGo to next message
dev is currently offline  dev
Messages: 1693
Registered: September 2005
Location: Moscow
Senior Member

Serge,

> This patchset is based on Kirill Korotaev's Mar 24 submission, taking
> comments (in particular from James Morris and Eric Biederman) into
> account.
thanks a lot for doing this!

> Some performance results are attached. I was mainly curious whether
> it would be worth putting the task_struct->uts_ns pointer inside
> a #ifdef CONFIG_UTS_NS. The result show that leaving it in when
> CONFIG_UTS_NS=n has negligable performance impact, so that is the
> approach this patch takes.
Serge, your testing approach looks really strange for me.
First of all, you selected the worst namespace to check performance
overhead on.
1) uts_ns is rarely used and never used on hot paths,
2) also all these test suites below doesn't test the code paths you
modified.

So I wonder what was the goal of these tests, especially dbench?!

Thanks,
Kirill

>
> -serge
>
> Performance testing was done on a 2-cpu hyperthreaded
> x86 box with 16G ram. The following tests were run:
> dbench (20 times, four clients, on reiser fs non-isolated partition)
> tbench (20 times, 5 connections)
> kernbench (20 times)
> reaim (20 times ranging from 1 to 15 users)
>
> They were run on 2.6.17-rc1:
> pristine
> patched, but with !CONFIG_UTS_NS ("disabled")
> patched with CONFIG_UTS_NS=y ("enabled")
>
> All results are presented as means +/- 95% confidence interval.
>
> Dbench results:
> pristine: 387.080727 +/- 9.344585
> patched disabled: 389.524364 +/- 9.574921
> patched enabled: 370.155600 +/- 30.127808
>
> Tbench results:
> pristine: 388.940100 +/- 18.095104
> patched disabled: 389.173700 +/- 23.658035
> patched enabled: 394.333200 +/- 25.813393
>
> Kernbench results:
> pristine: 70.317500 +/- 0.210833
> patched, disabled: 70.860000 +/- 0.179292
> patched, enabled: 70.346500 +/- 0.184784
>
> Reaim results:
> pristine:
> Nclients Mean 95% CI
> 1 106080.000000 11327.896029
> 3 236057.142000 18205.544810
> 5 247867.136000 23536.800062
> 7 265370.000000 21284.335743
> 9 262969.936000 18225.497529
> 11 278256.000000 6230.342816
> 13 284288.016000 8924.589388
> 15 286987.170000 7881.034658
>
> patched, disabled:
> Nclients Mean 95% CI
> 1 105400.000000 8739.978241
> 3 229500.000000 0.000000
> 5 252325.176667 16685.663423
> 7 265125.000000 6747.777319
> 9 271258.645000 11715.635212
> 11 280662.608333 7775.229351
> 13 277719.706667 8173.390359
> 15 278515.421667 10963.211450
>
> patched, enabled:
> Nclients Mean 95% CI
> 1 102000.000000 0.000000
> 3 224400.000000 14159.870036
> 5 242963.288000 40529.490781
> 7 255150.000000 8745.802081
> 9 270154.284000 8918.863136
> 11 283134.260000 12239.361252
> 13 288497.540000 11336.550964
> 15 280022.728000 8804.882369
>
>
Re: [RFC][PATCH 2/5] uts namespaces: Switch to using uts namespaces [message #2621 is a reply to message #2607] Tue, 11 April 2006 21:04 Go to previous message
Sam Vilain is currently offline  Sam Vilain
Messages: 73
Registered: February 2006
Member
Kirill Korotaev wrote:

>Serge,
>
>BTW, have you noticed that NFS is using utsname for internal processes
>and in general case this makes NFS ns to be coupled with uts ns?
>
>

Either that, or each NFS vfsmount has a uts_ns pointer.

Sam.
Previous Topic: Projet openvz
Next Topic: [PATCH COMMIT] diff-merge-2.6.15.5-20060413
Goto Forum:
  


Current Time: Wed Sep 18 07:59:57 GMT 2024

Total time taken to generate the page: 0.04734 seconds