Skip to contentSkip to conversation

uts namespaces: switch to using uts namespaces

PATCH In review Serge E. Hallyn 5 participants 27 messages May 1, 2006 – May 5, 2006

Subsystems (26)
Networking Arm (32-bit) VFS SCSI +22 more subsystems
lore
Share & tools
lore
#0 lore raw

PATCH 2/7 uts namespaces: switch to using uts namespaces

Replace references to system_utsname to the per-process uts namespace where appropriate. This includes things like uname.

Changes: Per Eric Biederman's comments, use the per-process uts namespace
for ELF_PLATFORM, sunrpc, and parts of net/ipv4/ipconfig.c

---

 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/asm-i386/elf.h              |    2 +-
 include/linux/lockd/lockd.h         |    2 +-
 kernel/sys.c                        |   14 +++++++-------
 net/ipv4/ipconfig.c                 |   14 +++++++-------
 net/sunrpc/clnt.c                   |    4 ++--
 35 files changed, 131 insertions(+), 131 deletions(-)

2dbe7dc9002109814ee4e3410454aff06bb38f9f

arch/alpha/kernel/osf_sys.c +12 -12
index 31afe3d..b793b96 100644
@@ -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 */
arch/i386/kernel/sys_i386.c +6 -6
index 8fdb1fb..4af731d 100644
@@ -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);
arch/ia64/sn/kernel/sn2/sn_hwperf.c +1 -1
index 739c948..a27b223 100644
@@ -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);
arch/m32r/kernel/sys_m32r.c +1 -1
index 670cb49..11412c0 100644
@@ -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;
 }
arch/mips/kernel/linux32.c +1 -1
index a7d2bb3..66f999b 100644
@@ -1040,7 +1040,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);
 
arch/mips/kernel/syscall.c +9 -9
index 2aeaa2f..8b13d57 100644
@@ -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;
 	}
arch/mips/kernel/sysirix.c +6 -6
index 5407b78..1b4e7e7 100644
@@ -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);
-	if (copy_from_user(system_utsname.sysname, buf->sysname, 65)
-	    || copy_from_user(system_utsname.nodename, buf->nodename, 65)
-	    || copy_from_user(system_utsname.release, buf->release, 65)
-	    || copy_from_user(system_utsname.version, buf->version, 65)
-	    || copy_from_user(system_utsname.machine, buf->machine, 65)) {
+	if (copy_from_user(utsname()->sysname, buf->sysname, 65)
+	    || copy_from_user(utsname()->nodename, buf->nodename, 65)
+	    || copy_from_user(utsname()->release, buf->release, 65)
+	    || copy_from_user(utsname()->version, buf->version, 65)
+	    || copy_from_user(utsname()->machine, buf->machine, 65)) {
 		return -EFAULT;
 	}
 	up_read(&uts_sem);
arch/parisc/hpux/sys_hpux.c +11 -11
index 05273cc..9fc2c08 100644
@@ -266,15 +266,15 @@ static int hpux_uname(struct hpux_utsnam
 
 	down_read(&uts_sem);
 
-	error = __copy_to_user(&name->sysname,&system_utsname.sysname,HPUX_UTSLEN-1);
+	error = __copy_to_user(&name->sysname,&utsname()->sysname,HPUX_UTSLEN-1);
 	error |= __put_user(0,name->sysname+HPUX_UTSLEN-1);
-	error |= __copy_to_user(&name->nodename,&system_utsname.nodename,HPUX_UTSLEN-1);
+	error |= __copy_to_user(&name->nodename,&utsname()->nodename,HPUX_UTSLEN-1);
 	error |= __put_user(0,name->nodename+HPUX_UTSLEN-1);
-	error |= __copy_to_user(&name->release,&system_utsname.release,HPUX_UTSLEN-1);
+	error |= __copy_to_user(&name->release,&utsname()->release,HPUX_UTSLEN-1);
 	error |= __put_user(0,name->release+HPUX_UTSLEN-1);
-	error |= __copy_to_user(&name->version,&system_utsname.version,HPUX_UTSLEN-1);
+	error |= __copy_to_user(&name->version,&utsname()->version,HPUX_UTSLEN-1);
 	error |= __put_user(0,name->version+HPUX_UTSLEN-1);
-	error |= __copy_to_user(&name->machine,&system_utsname.machine,HPUX_UTSLEN-1);
+	error |= __copy_to_user(&name->machine,&utsname()->machine,HPUX_UTSLEN-1);
 	error |= __put_user(0,name->machine+HPUX_UTSLEN-1);
 
 	up_read(&uts_sem);
@@ -373,8 +373,8 @@ int hpux_utssys(char *ubuf, int n, int t
 		/*  TODO:  print a warning about using this?  */
 		down_write(&uts_sem);
 		error = -EFAULT;
-		if (!copy_from_user(system_utsname.sysname, ubuf, len)) {
-			system_utsname.sysname[len] = 0;
+		if (!copy_from_user(utsname()->sysname, ubuf, len)) {
+			utsname()->sysname[len] = 0;
 			error = 0;
 		}
 		up_write(&uts_sem);
@@ -400,8 +400,8 @@ int hpux_utssys(char *ubuf, int n, int t
 		/*  TODO:  print a warning about this?  */
 		down_write(&uts_sem);
 		error = -EFAULT;
-		if (!copy_from_user(system_utsname.release, ubuf, len)) {
-			system_utsname.release[len] = 0;
+		if (!copy_from_user(utsname()->release, ubuf, len)) {
+			utsname()->release[len] = 0;
 			error = 0;
 		}
 		up_write(&uts_sem);
@@ -422,13 +422,13 @@ int hpux_getdomainname(char *name, int l
  	
  	down_read(&uts_sem);
  	
-	nlen = strlen(system_utsname.domainname) + 1;
+	nlen = strlen(utsname()->domainname) + 1;
 
 	if (nlen < len)
 		len = nlen;
 	if(len > __NEW_UTS_LEN)
 		goto done;
-	if(copy_to_user(name, system_utsname.domainname, len))
+	if(copy_to_user(name, utsname()->domainname, len))
 		goto done;
 	err = 0;
 done:
arch/powerpc/kernel/syscalls.c +7 -7
index 9b69d99..d358866 100644
@@ -260,7 +260,7 @@ long ppc_newuname(struct new_utsname __u
 	int err = 0;
 
 	down_read(&uts_sem);
-	if (copy_to_user(name, &system_utsname, sizeof(*name)))
+	if (copy_to_user(name, utsname(), sizeof(*name)))
 		err = -EFAULT;
 	up_read(&uts_sem);
 	if (!err)
@@ -273,7 +273,7 @@ int sys_uname(struct old_utsname __user 
 	int err = 0;
 	
 	down_read(&uts_sem);
-	if (copy_to_user(name, &system_utsname, sizeof(*name)))
+	if (copy_to_user(name, utsname(), sizeof(*name)))
 		err = -EFAULT;
 	up_read(&uts_sem);
 	if (!err)
@@ -289,19 +289,19 @@ int sys_olduname(struct oldold_utsname _
 		return -EFAULT;
   
 	down_read(&uts_sem);
-	error = __copy_to_user(&name->sysname, &system_utsname.sysname,
+	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,
+	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,
+	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,
+	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,
+	error |= __copy_to_user(&name->machine, &utsname()->machine,
 				__OLD_UTS_LEN);
 	error |= override_machine(name->machine);
 	up_read(&uts_sem);
arch/sh/kernel/sys_sh.c +1 -1
index 917b2f3..e4966b2 100644
@@ -267,7 +267,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;
 }
arch/sh64/kernel/sys_sh64.c +1 -1
index 58ff7d5..a8dc88c 100644
@@ -279,7 +279,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;
 }
arch/sparc/kernel/sys_sparc.c +2 -2
index 0cdfc9d..c8ad73c 100644
@@ -470,13 +470,13 @@ asmlinkage int sys_getdomainname(char __
  	
  	down_read(&uts_sem);
  	
-	nlen = strlen(system_utsname.domainname) + 1;
+	nlen = strlen(utsname()->domainname) + 1;
 
 	if (nlen < len)
 		len = nlen;
 	if (len > __NEW_UTS_LEN)
 		goto done;
-	if (copy_to_user(name, system_utsname.domainname, len))
+	if (copy_to_user(name, utsname()->domainname, len))
 		goto done;
 	err = 0;
 done:
arch/sparc/kernel/sys_sunos.c +5 -5
index 288de27..9f9206f 100644
@@ -483,13 +483,13 @@ asmlinkage int sunos_uname(struct sunos_
 {
 	int ret;
 	down_read(&uts_sem);
-	ret = copy_to_user(&name->sname[0], &system_utsname.sysname[0], sizeof(name->sname) - 1);
+	ret = copy_to_user(&name->sname[0], &utsname()->sysname[0], sizeof(name->sname) - 1);
 	if (!ret) {
-		ret |= __copy_to_user(&name->nname[0], &system_utsname.nodename[0], sizeof(name->nname) - 1);
+		ret |= __copy_to_user(&name->nname[0], &utsname()->nodename[0], sizeof(name->nname) - 1);
 		ret |= __put_user('\0', &name->nname[8]);
-		ret |= __copy_to_user(&name->rel[0], &system_utsname.release[0], sizeof(name->rel) - 1);
-		ret |= __copy_to_user(&name->ver[0], &system_utsname.version[0], sizeof(name->ver) - 1);
-		ret |= __copy_to_user(&name->mach[0], &system_utsname.machine[0], sizeof(name->mach) - 1);
+		ret |= __copy_to_user(&name->rel[0], &utsname()->release[0], sizeof(name->rel) - 1);
+		ret |= __copy_to_user(&name->ver[0], &utsname()->version[0], sizeof(name->ver) - 1);
+		ret |= __copy_to_user(&name->mach[0], &utsname()->machine[0], sizeof(name->mach) - 1);
 	}
 	up_read(&uts_sem);
 	return ret ? -EFAULT : 0;
arch/sparc64/kernel/sys_sparc.c +2 -2
index 7a86913..0453bd2 100644
@@ -707,13 +707,13 @@ asmlinkage long sys_getdomainname(char _
 
  	down_read(&uts_sem);
  	
-	nlen = strlen(system_utsname.domainname) + 1;
+	nlen = strlen(utsname()->domainname) + 1;
 
         if (nlen < len)
                 len = nlen;
 	if (len > __NEW_UTS_LEN)
 		goto done;
-	if (copy_to_user(name, system_utsname.domainname, len))
+	if (copy_to_user(name, utsname()->domainname, len))
 		goto done;
 	err = 0;
 done:
arch/sparc64/kernel/sys_sunos32.c +5 -5
index ae5b32f..ba98c47 100644
@@ -439,16 +439,16 @@ asmlinkage int sunos_uname(struct sunos_
 	int ret;
 
 	down_read(&uts_sem);
-	ret = copy_to_user(&name->sname[0], &system_utsname.sysname[0],
+	ret = copy_to_user(&name->sname[0], &utsname()->sysname[0],
 			   sizeof(name->sname) - 1);
-	ret |= copy_to_user(&name->nname[0], &system_utsname.nodename[0],
+	ret |= copy_to_user(&name->nname[0], &utsname()->nodename[0],
 			    sizeof(name->nname) - 1);
 	ret |= put_user('\0', &name->nname[8]);
-	ret |= copy_to_user(&name->rel[0], &system_utsname.release[0],
+	ret |= copy_to_user(&name->rel[0], &utsname()->release[0],
 			    sizeof(name->rel) - 1);
-	ret |= copy_to_user(&name->ver[0], &system_utsname.version[0],
+	ret |= copy_to_user(&name->ver[0], &utsname()->version[0],
 			    sizeof(name->ver) - 1);
-	ret |= copy_to_user(&name->mach[0], &system_utsname.machine[0],
+	ret |= copy_to_user(&name->mach[0], &utsname()->machine[0],
 			    sizeof(name->mach) - 1);
 	up_read(&uts_sem);
 	return (ret ? -EFAULT : 0);
arch/sparc64/solaris/misc.c +3 -3
index 5284996..5d0162a 100644
@@ -239,7 +239,7 @@ asmlinkage int solaris_utssys(u32 buf, u
 		/* Let's cheat */
 		err  = set_utsfield(v->sysname, "SunOS", 1, 0);
 		down_read(&uts_sem);
-		err |= set_utsfield(v->nodename, system_utsname.nodename,
+		err |= set_utsfield(v->nodename, utsname()->nodename,
 				    1, 1);
 		up_read(&uts_sem);
 		err |= set_utsfield(v->release, "2.6", 0, 0);
@@ -263,7 +263,7 @@ asmlinkage int solaris_utsname(u32 buf)
 	/* Why should we not lie a bit? */
 	down_read(&uts_sem);
 	err  = set_utsfield(v->sysname, "SunOS", 0, 0);
-	err |= set_utsfield(v->nodename, system_utsname.nodename, 1, 1);
+	err |= set_utsfield(v->nodename, utsname()->nodename, 1, 1);
 	err |= set_utsfield(v->release, "5.6", 0, 0);
 	err |= set_utsfield(v->version, "Generic", 0, 0);
 	err |= set_utsfield(v->machine, machine(), 0, 0);
@@ -295,7 +295,7 @@ asmlinkage int solaris_sysinfo(int cmd, 
 	case SI_HOSTNAME:
 		r = buffer + 256;
 		down_read(&uts_sem);
-		for (p = system_utsname.nodename, q = buffer; 
+		for (p = utsname()->nodename, q = buffer;
 		     q < r && *p && *p != '.'; *q++ = *p++);
 		up_read(&uts_sem);
 		*q = 0;
arch/um/drivers/mconsole_kern.c +3 -3
index 6d7173f..244244a 100644
@@ -106,9 +106,9 @@ void mconsole_version(struct mc_request 
 {
 	char version[256];
 
-	sprintf(version, "%s %s %s %s %s", system_utsname.sysname,
-		system_utsname.nodename, system_utsname.release,
-		system_utsname.version, system_utsname.machine);
+	sprintf(version, "%s %s %s %s %s", utsname()->sysname,
+		utsname()->nodename, utsname()->release,
+		utsname()->version, utsname()->machine);
 	mconsole_reply(req, version, 0, 0);
 }
 
arch/um/kernel/syscall_kern.c +6 -6
index 37d3978..d90e9ed 100644
@@ -110,7 +110,7 @@ long sys_uname(struct old_utsname __user
 	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;
 }
@@ -126,19 +126,19 @@ long sys_olduname(struct oldold_utsname 
   
   	down_read(&uts_sem);
 	
-	error = __copy_to_user(&name->sysname,&system_utsname.sysname,
+	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,
+	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,
+	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,
+	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,
+	error |= __copy_to_user(&name->machine,&utsname()->machine,
 				__OLD_UTS_LEN);
 	error |= __put_user(0,name->machine+__OLD_UTS_LEN);
 	
arch/um/sys-x86_64/syscalls.c +1 -1
index 6acee5c..3ad014e 100644
@@ -21,7 +21,7 @@ asmlinkage long sys_uname64(struct new_u
 {
 	int err;
 	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);
 	if (personality(current->personality) == PER_LINUX32)
 		err |= copy_to_user(&name->machine, "i686", 5);
arch/x86_64/ia32/sys_ia32.c +5 -5
index f182b20..6e0a19d 100644
@@ -801,13 +801,13 @@ asmlinkage long sys32_olduname(struct ol
   
   	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);
 	 __put_user(0,name->sysname+__OLD_UTS_LEN);
-	 __copy_to_user(&name->nodename,&system_utsname.nodename,__OLD_UTS_LEN);
+	 __copy_to_user(&name->nodename,&utsname()->nodename,__OLD_UTS_LEN);
 	 __put_user(0,name->nodename+__OLD_UTS_LEN);
-	 __copy_to_user(&name->release,&system_utsname.release,__OLD_UTS_LEN);
+	 __copy_to_user(&name->release,&utsname()->release,__OLD_UTS_LEN);
 	 __put_user(0,name->release+__OLD_UTS_LEN);
-	 __copy_to_user(&name->version,&system_utsname.version,__OLD_UTS_LEN);
+	 __copy_to_user(&name->version,&utsname()->version,__OLD_UTS_LEN);
 	 __put_user(0,name->version+__OLD_UTS_LEN);
 	 { 
 		 char *arch = "x86_64";
@@ -830,7 +830,7 @@ long sys32_uname(struct old_utsname __us
 	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);
 	if (personality(current->personality) == PER_LINUX32) 
 		err |= copy_to_user(&name->machine, "i686", 5);
arch/x86_64/kernel/sys_x86_64.c +1 -1
index 6449ea8..76bf7c2 100644
@@ -148,7 +148,7 @@ asmlinkage long sys_uname(struct new_uts
 {
 	int err;
 	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);
 	if (personality(current->personality) == PER_LINUX32) 
 		err |= copy_to_user(&name->machine, "i686", 5); 		
arch/xtensa/kernel/syscalls.c +1 -1
index f20c649..30060c1 100644
@@ -129,7 +129,7 @@ out:
 
 int sys_uname(struct old_utsname * name)
 {
-	if (name && !copy_to_user(name, &system_utsname, sizeof (*name)))
+	if (name && !copy_to_user(name, utsname(), sizeof (*name)))
 		return 0;
 	return -EFAULT;
 }
drivers/char/random.c +2 -2
index 58f3512..a891421 100644
@@ -888,8 +888,8 @@ static void init_std_data(struct entropy
 
 	do_gettimeofday(&tv);
 	add_entropy_words(r, (__u32 *)&tv, sizeof(tv)/4);
-	add_entropy_words(r, (__u32 *)&system_utsname,
-			  sizeof(system_utsname)/4);
+	add_entropy_words(r, (__u32 *)utsname(),
+			  sizeof(*(utsname()))/4);
 }
 
 static int __init rand_initialize(void)
fs/cifs/connect.c +14 -14
index d2ec806..b6c0886 100644
@@ -765,12 +765,12 @@ cifs_parse_mount_options(char *options, 
 	separator[1] = 0; 
 
 	memset(vol->source_rfc1001_name,0x20,15);
-	for(i=0;i < strnlen(system_utsname.nodename,15);i++) {
+	for(i=0;i < strnlen(utsname()->nodename,15);i++) {
 		/* does not have to be a perfect mapping since the field is
 		informational, only used for servers that do not support
 		port 445 and it can be overridden at mount time */
 		vol->source_rfc1001_name[i] = 
-			toupper(system_utsname.nodename[i]);
+			toupper(utsname()->nodename[i]);
 	}
 	vol->source_rfc1001_name[15] = 0;
 	/* null target name indicates to use *SMBSERVR default called name
@@ -2077,7 +2077,7 @@ CIFSSessSetup(unsigned int xid, struct c
 				  32, nls_codepage);
 		bcc_ptr += 2 * bytes_returned;
 		bytes_returned =
-		    cifs_strtoUCS((__le16 *) bcc_ptr, system_utsname.release,
+		    cifs_strtoUCS((__le16 *) bcc_ptr, utsname()->release,
 				  32, nls_codepage);
 		bcc_ptr += 2 * bytes_returned;
 		bcc_ptr += 2;
@@ -2104,8 +2104,8 @@ CIFSSessSetup(unsigned int xid, struct c
 		}
 		strcpy(bcc_ptr, "Linux version ");
 		bcc_ptr += strlen("Linux version ");
-		strcpy(bcc_ptr, system_utsname.release);
-		bcc_ptr += strlen(system_utsname.release) + 1;
+		strcpy(bcc_ptr, utsname()->release);
+		bcc_ptr += strlen(utsname()->release) + 1;
 		strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
 		bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
 	}
@@ -2346,7 +2346,7 @@ CIFSSpnegoSessSetup(unsigned int xid, st
 				  32, nls_codepage);
 		bcc_ptr += 2 * bytes_returned;
 		bytes_returned =
-		    cifs_strtoUCS((__le16 *) bcc_ptr, system_utsname.release, 32,
+		    cifs_strtoUCS((__le16 *) bcc_ptr, utsname()->release, 32,
 				  nls_codepage);
 		bcc_ptr += 2 * bytes_returned;
 		bcc_ptr += 2;
@@ -2371,8 +2371,8 @@ CIFSSpnegoSessSetup(unsigned int xid, st
 		}
 		strcpy(bcc_ptr, "Linux version ");
 		bcc_ptr += strlen("Linux version ");
-		strcpy(bcc_ptr, system_utsname.release);
-		bcc_ptr += strlen(system_utsname.release) + 1;
+		strcpy(bcc_ptr, utsname()->release);
+		bcc_ptr += strlen(utsname()->release) + 1;
 		strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
 		bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
 	}
@@ -2622,7 +2622,7 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned i
 				  32, nls_codepage);
 		bcc_ptr += 2 * bytes_returned;
 		bytes_returned =
-		    cifs_strtoUCS((__le16 *) bcc_ptr, system_utsname.release, 32,
+		    cifs_strtoUCS((__le16 *) bcc_ptr, utsname()->release, 32,
 				  nls_codepage);
 		bcc_ptr += 2 * bytes_returned;
 		bcc_ptr += 2;	/* null terminate Linux version */
@@ -2639,8 +2639,8 @@ CIFSNTLMSSPNegotiateSessSetup(unsigned i
 	} else {		/* ASCII */
 		strcpy(bcc_ptr, "Linux version ");
 		bcc_ptr += strlen("Linux version ");
-		strcpy(bcc_ptr, system_utsname.release);
-		bcc_ptr += strlen(system_utsname.release) + 1;
+		strcpy(bcc_ptr, utsname()->release);
+		bcc_ptr += strlen(utsname()->release) + 1;
 		strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
 		bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
 		bcc_ptr++;	/* empty domain field */
@@ -3001,7 +3001,7 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xi
 				  32, nls_codepage);
 		bcc_ptr += 2 * bytes_returned;
 		bytes_returned =
-		    cifs_strtoUCS((__le16 *) bcc_ptr, system_utsname.release, 32,
+		    cifs_strtoUCS((__le16 *) bcc_ptr, utsname()->release, 32,
 				  nls_codepage);
 		bcc_ptr += 2 * bytes_returned;
 		bcc_ptr += 2;	/* null term version string */
@@ -3053,8 +3053,8 @@ CIFSNTLMSSPAuthSessSetup(unsigned int xi
 
 		strcpy(bcc_ptr, "Linux version ");
 		bcc_ptr += strlen("Linux version ");
-		strcpy(bcc_ptr, system_utsname.release);
-		bcc_ptr += strlen(system_utsname.release) + 1;
+		strcpy(bcc_ptr, utsname()->release);
+		bcc_ptr += strlen(utsname()->release) + 1;
 		strcpy(bcc_ptr, CIFS_NETWORK_OPSYS);
 		bcc_ptr += strlen(CIFS_NETWORK_OPSYS) + 1;
 		bcc_ptr++;	/* null domain */
fs/exec.c +1 -1
index 3a79d97..cbb3270 100644
@@ -1337,7 +1337,7 @@ static void format_corename(char *corena
 			case 'h':
 				down_read(&uts_sem);
 				rc = snprintf(out_ptr, out_end - out_ptr,
-					      "%s", system_utsname.nodename);
+					      "%s", utsname()->nodename);
 				up_read(&uts_sem);
 				if (rc > out_end - out_ptr)
 					goto out;
fs/lockd/clntproc.c +2 -2
index f96e381..915e596 100644
@@ -130,11 +130,11 @@ static void nlmclnt_setlockargs(struct n
 	nlmclnt_next_cookie(&argp->cookie);
 	argp->state   = nsm_local_state;
 	memcpy(&lock->fh, NFS_FH(fl->fl_file->f_dentry->d_inode), sizeof(struct nfs_fh));
-	lock->caller  = system_utsname.nodename;
+	lock->caller  = utsname()->nodename;
 	lock->oh.data = req->a_owner;
 	lock->oh.len  = snprintf(req->a_owner, sizeof(req->a_owner), "%u@%s",
 				(unsigned int)fl->fl_u.nfs_fl.owner->pid,
-				system_utsname.nodename);
+				utsname()->nodename);
 	lock->svid = fl->fl_u.nfs_fl.owner->pid;
 	lock->fl.fl_start = fl->fl_start;
 	lock->fl.fl_end = fl->fl_end;
fs/lockd/mon.c +1 -1
index 3fc683f..547aaa3 100644
@@ -152,7 +152,7 @@ xdr_encode_common(struct rpc_rqst *rqstp
 	 */
 	sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(argp->addr));
 	if (!(p = xdr_encode_string(p, buffer))
-	 || !(p = xdr_encode_string(p, system_utsname.nodename)))
+	 || !(p = xdr_encode_string(p, utsname()->nodename)))
 		return ERR_PTR(-EIO);
 	*p++ = htonl(argp->prog);
 	*p++ = htonl(argp->vers);
fs/lockd/svclock.c +1 -1
index 3ef7391..ec93c35 100644
@@ -326,7 +326,7 @@ static int nlmsvc_setgrantargs(struct nl
 {
 	locks_copy_lock(&call->a_args.lock.fl, &lock->fl);
 	memcpy(&call->a_args.lock.fh, &lock->fh, sizeof(call->a_args.lock.fh));
-	call->a_args.lock.caller = system_utsname.nodename;
+	call->a_args.lock.caller = utsname()->nodename;
 	call->a_args.lock.oh.len = lock->oh.len;
 
 	/* set default data area */
fs/lockd/xdr.c +1 -1
index f22a376..4eec051 100644
@@ -516,7 +516,7 @@ nlmclt_decode_res(struct rpc_rqst *req, 
  */
 #define NLM_void_sz		0
 #define NLM_cookie_sz		1+XDR_QUADLEN(NLM_MAXCOOKIELEN)
-#define NLM_caller_sz		1+XDR_QUADLEN(sizeof(system_utsname.nodename))
+#define NLM_caller_sz		1+XDR_QUADLEN(sizeof(utsname()->nodename))
 #define NLM_netobj_sz		1+XDR_QUADLEN(XDR_MAX_NETOBJ)
 /* #define NLM_owner_sz		1+XDR_QUADLEN(NLM_MAXOWNER) */
 #define NLM_fhandle_sz		1+XDR_QUADLEN(NFS2_FHSIZE)
fs/nfs/nfsroot.c +1 -1
index c0a754e..1d656a6 100644
@@ -312,7 +312,7 @@ static int __init root_nfs_name(char *na
 	/* Override them by options set on kernel command-line */
 	root_nfs_parse(name, buf);
 
-	cp = system_utsname.nodename;
+	cp = utsname()->nodename;
 	if (strlen(buf) + strlen(cp) > NFS_MAXPATHLEN) {
 		printk(KERN_ERR "Root-NFS: Pathname for remote directory too long.\n");
 		return -1;
include/asm-i386/elf.h +1 -1
index 4153d80..1b06c44 100644
@@ -108,7 +108,7 @@ #define ELF_HWCAP	(boot_cpu_data.x86_cap
    For the moment, we have only optimizations for the Intel generations,
    but that could change... */
 
-#define ELF_PLATFORM  (system_utsname.machine)
+#define ELF_PLATFORM  (utsname()->machine)
 
 #ifdef __KERNEL__
 #define SET_PERSONALITY(ex, ibcs2) do { } while (0)
include/linux/lockd/lockd.h +1 -1
index 995f89d..ac15b87 100644
@@ -80,7 +80,7 @@ struct nlm_wait;
 /*
  * Memory chunk for NLM client RPC request.
  */
-#define NLMCLNT_OHSIZE		(sizeof(system_utsname.nodename)+10)
+#define NLMCLNT_OHSIZE		(sizeof(utsname()->nodename)+10)
 struct nlm_rqst {
 	unsigned int		a_flags;	/* initial RPC task flags */
 	struct nlm_host *	a_host;		/* host handle */
kernel/sys.c +7 -7
index 0b6ec0e..bcaa48e 100644
@@ -1671,7 +1671,7 @@ asmlinkage long sys_newuname(struct new_
 	int errno = 0;
 
 	down_read(&uts_sem);
-	if (copy_to_user(name,&system_utsname,sizeof *name))
+	if (copy_to_user(name,utsname(),sizeof *name))
 		errno = -EFAULT;
 	up_read(&uts_sem);
 	return errno;
@@ -1689,8 +1689,8 @@ asmlinkage long sys_sethostname(char __u
 	down_write(&uts_sem);
 	errno = -EFAULT;
 	if (!copy_from_user(tmp, name, len)) {
-		memcpy(system_utsname.nodename, tmp, len);
-		system_utsname.nodename[len] = 0;
+		memcpy(utsname()->nodename, tmp, len);
+		utsname()->nodename[len] = 0;
 		errno = 0;
 	}
 	up_write(&uts_sem);
@@ -1706,11 +1706,11 @@ asmlinkage long sys_gethostname(char __u
 	if (len < 0)
 		return -EINVAL;
 	down_read(&uts_sem);
-	i = 1 + strlen(system_utsname.nodename);
+	i = 1 + strlen(utsname()->nodename);
 	if (i > len)
 		i = len;
 	errno = 0;
-	if (copy_to_user(name, system_utsname.nodename, i))
+	if (copy_to_user(name, utsname()->nodename, i))
 		errno = -EFAULT;
 	up_read(&uts_sem);
 	return errno;
@@ -1735,8 +1735,8 @@ asmlinkage long sys_setdomainname(char _
 	down_write(&uts_sem);
 	errno = -EFAULT;
 	if (!copy_from_user(tmp, name, len)) {
-		memcpy(system_utsname.domainname, tmp, len);
-		system_utsname.domainname[len] = 0;
+		memcpy(utsname()->domainname, tmp, len);
+		utsname()->domainname[len] = 0;
 		errno = 0;
 	}
 	up_write(&uts_sem);
net/ipv4/ipconfig.c +7 -7
index cb8a92f..b9bdf0f 100644
@@ -806,7 +806,7 @@ #endif
 			}
 			break;
 		case 12:	/* Host name */
-			ic_bootp_string(system_utsname.nodename, ext+1, *ext, __NEW_UTS_LEN);
+			ic_bootp_string(utsname()->nodename, ext+1, *ext, __NEW_UTS_LEN);
 			ic_host_name_set = 1;
 			break;
 		case 15:	/* Domain name (DNS) */
@@ -817,7 +817,7 @@ #endif
 				ic_bootp_string(root_server_path, ext+1, *ext, sizeof(root_server_path));
 			break;
 		case 40:	/* NIS Domain name (_not_ DNS) */
-			ic_bootp_string(system_utsname.domainname, ext+1, *ext, __NEW_UTS_LEN);
+			ic_bootp_string(utsname()->domainname, ext+1, *ext, __NEW_UTS_LEN);
 			break;
 	}
 }
@@ -1369,7 +1369,7 @@ #ifndef IPCONFIG_SILENT
 	printk(", mask=%u.%u.%u.%u", NIPQUAD(ic_netmask));
 	printk(", gw=%u.%u.%u.%u", NIPQUAD(ic_gateway));
 	printk(",\n     host=%s, domain=%s, nis-domain=%s",
-	       system_utsname.nodename, ic_domain, system_utsname.domainname);
+	       utsname()->nodename, ic_domain, utsname()->domainname);
 	printk(",\n     bootserver=%u.%u.%u.%u", NIPQUAD(ic_servaddr));
 	printk(", rootserver=%u.%u.%u.%u", NIPQUAD(root_server_addr));
 	printk(", rootpath=%s", root_server_path);
@@ -1479,11 +1479,11 @@ static int __init ip_auto_config_setup(c
 			case 4:
 				if ((dp = strchr(ip, '.'))) {
 					*dp++ = '\0';
-					strlcpy(system_utsname.domainname, dp,
-						sizeof(system_utsname.domainname));
+					strlcpy(utsname()->domainname, dp,
+						sizeof(utsname()->domainname));
 				}
-				strlcpy(system_utsname.nodename, ip,
-					sizeof(system_utsname.nodename));
+				strlcpy(utsname()->nodename, ip,
+					sizeof(utsname()->nodename));
 				ic_host_name_set = 1;
 				break;
 			case 5:
net/sunrpc/clnt.c +2 -2
index aa8965e..1d00e41 100644
@@ -176,10 +176,10 @@ rpc_new_client(struct rpc_xprt *xprt, ch
 	}
 
 	/* save the nodename */
-	clnt->cl_nodelen = strlen(system_utsname.nodename);
+	clnt->cl_nodelen = strlen(utsname()->nodename);
 	if (clnt->cl_nodelen > UNX_MAXNODENAME)
 		clnt->cl_nodelen = UNX_MAXNODENAME;
-	memcpy(clnt->cl_nodename, system_utsname.nodename, clnt->cl_nodelen);
+	memcpy(clnt->cl_nodename, utsname()->nodename, clnt->cl_nodelen);
 	return clnt;
 
 out_no_auth:
Signature · 1 line
1.3.0
#1 lore raw

PATCH 3/7 uts namespaces: use init_utsname when appropriate

In some places, particularly drivers and __init code, the init utsns is the appropriate one to use. This patch replaces those with a the init_utsname helper.

Changes: Removed several uses of init_utsname(). Hope I picked all the
right ones in net/ipv4/ipconfig.c. These are now changed to utsname() (the per-process namespace utsname) in the previous patch (2/7)

---

 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-sh/bugs.h                     |    2 +-
 kernel/power/snapshot.c                   |   10 +++++-----
 net/ipv4/ipconfig.c                       |    2 +-
 sound/core/info_oss.c                     |   10 +++++-----
 25 files changed, 45 insertions(+), 45 deletions(-)

b238f54dae391ea403bb024615eaae03ee191ac9

arch/arm/kernel/setup.c +1 -1
index 9fc9af8..b610568 100644
@@ -319,7 +319,7 @@ #endif
 	       cpu_name, processor_id, (int)processor_id & 15,
 	       proc_arch[cpu_architecture()]);
 
-	sprintf(system_utsname.machine, "%s%c", list->arch_name, ENDIANNESS);
+	sprintf(init_utsname()->machine, "%s%c", list->arch_name, ENDIANNESS);
 	sprintf(elf_platform, "%s%c", list->elf_name, ENDIANNESS);
 	elf_hwcap = list->elf_hwcap;
 #ifndef CONFIG_ARM_THUMB
arch/arm26/kernel/setup.c +1 -1
index 4eb329e..8e6a441 100644
@@ -144,7 +144,7 @@ static void __init setup_processor(void)
 
 	dump_cpu_info();
 
-	sprintf(system_utsname.machine, "%s", list->arch_name);
+	sprintf(init_utsname()->machine, "%s", list->arch_name);
 	sprintf(elf_platform, "%s", list->elf_name);
 	elf_hwcap = list->elf_hwcap;
 
arch/cris/kernel/setup.c +1 -1
index 619a6ee..1974c01 100644
@@ -161,7 +161,7 @@ #endif
 	show_etrax_copyright();
 
 	/* Setup utsname */
-	strcpy(system_utsname.machine, cris_machine_name);
+	strcpy(init_utsname()->machine, cris_machine_name);
 }
 
 static void *c_start(struct seq_file *m, loff_t *pos)
arch/i386/kernel/process.c +3 -3
index 6259afe..da2e439 100644
@@ -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_utsname()->release,
+	       (int)strcspn(init_utsname()->version, " "),
+	       init_utsname()->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",
arch/i386/kernel/traps.c +3 -3
index 2d22f57..c029749 100644
@@ -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_utsname()->release,
+		(int)strcspn(init_utsname()->version, " "),
+		init_utsname()->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);
arch/powerpc/kernel/process.c +1 -1
index 2dd47d2..6ce9e10 100644
@@ -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_utsname()->release);
 	printk("MSR: "REG" ", regs->msr);
 	printbits(regs->msr, msr_bits);
 	printk("  CR: %08lX  XER: %08lX\n", regs->ccr, regs->xer);
arch/powerpc/kernel/setup_64.c +1 -1
index 4467c49..c124e0a 100644
@@ -435,7 +435,7 @@ #ifdef CONFIG_SMP
 	smp_release_cpus();
 #endif
 
-	printk("Starting Linux PPC64 %s\n", system_utsname.version);
+	printk("Starting Linux PPC64 %s\n", init_utsname()->version);
 
 	printk("-----------------------------------------------------\n");
 	printk("ppc64_pft_size                = 0x%lx\n", ppc64_pft_size);
arch/powerpc/platforms/pseries/setup.c +1 -1
index 5eb55ef..58b7a74 100644
@@ -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_utsname()->version, 0);
 
 	return 0;
 }
arch/sh/kernel/setup.c +1 -1
index bb229ef..024401e 100644
@@ -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_utsname()->machine);
 	seq_printf(m, "cpu type\t: %s\n", get_cpu_subtype());
 
 	show_cpuflags(m);
arch/um/kernel/um_arch.c +3 -3
index 7d51dd7..b49dd7d 100644
@@ -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_utsname()->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_utsname()->release);
  	p = &__uml_help_start;
  	while (p < &__uml_help_end) {
  		printf("%s", *p);
@@ -400,7 +400,7 @@ #endif
 	/* Reserve up to 4M after the current brk */
 	uml_reserved = ROUND_4M(brk_start) + (1 << 22);
 
-	setup_machinename(system_utsname.machine);
+	setup_machinename(init_utsname()->machine);
 
 #ifdef CONFIG_CMDLINE_ON_HOST
 	argv1_begin = argv[1];
arch/um/sys-x86_64/sysrq.c +1 -1
index d0a25af..ce3e07f 100644
@@ -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_utsname()->release);
 	printk("RIP: %04lx:[<%016lx>] ", PT_REGS_CS(regs) & 0xffff,
 	       PT_REGS_RIP(regs));
 	printk("\nRSP: %016lx  EFLAGS: %08lx\n", PT_REGS_RSP(regs),
arch/x86_64/kernel/process.c +3 -3
index fb903e6..113d4ac 100644
@@ -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_utsname()->release,
+		(int)strcspn(init_utsname()->version, " "),
+		init_utsname()->version);
 	printk("RIP: %04lx:[<%016lx>] ", regs->cs & 0xffff, regs->rip);
 	printk_address(regs->rip); 
 	printk("\nRSP: %04lx:%016lx  EFLAGS: %08lx\n", regs->ss, regs->rsp,
drivers/infiniband/hw/ipath/ipath_verbs.c +1 -1
index 8d2558a..b07e831 100644
@@ -1048,7 +1048,7 @@ static void *ipath_register_ib_device(in
 	dev->process_mad = ipath_process_mad;
 
 	snprintf(dev->node_desc, sizeof(dev->node_desc),
-		 IPATH_IDSTR " %s kernel_SMA", system_utsname.nodename);
+		 IPATH_IDSTR " %s kernel_SMA", init_utsname()->nodename);
 
 	ret = ib_register_device(dev);
 	if (ret)
drivers/parisc/led.c +1 -1
index 298f2dd..1d778d2 100644
@@ -684,7 +684,7 @@ int __init led_init(void)
 	int ret;
 
 	snprintf(lcd_text_default, sizeof(lcd_text_default),
-		"Linux %s", system_utsname.release);
+		"Linux %s", init_utsname()->release);
 
 	/* Work around the buggy PDC of KittyHawk-machines */
 	switch (CPU_HVERSION) {
drivers/scsi/lpfc/lpfc_ct.c +4 -4
index b65ee57..83f53fb 100644
@@ -961,8 +961,8 @@ lpfc_fdmi_cmd(struct lpfc_hba * phba, st
 			ae = (ATTRIBUTE_ENTRY *) ((uint8_t *) rh + size);
 			ae->ad.bits.AttrType = be16_to_cpu(OS_NAME_VERSION);
 			sprintf(ae->un.OsNameVersion, "%s %s %s",
-				system_utsname.sysname, system_utsname.release,
-				system_utsname.version);
+				init_utsname()->sysname, init_utsname()->release,
+				init_utsname()->version);
 			len = strlen(ae->un.OsNameVersion);
 			len += (len & 3) ? (4 - (len & 3)) : 4;
 			ae->ad.bits.AttrLen = be16_to_cpu(FOURBYTES + len);
@@ -1080,7 +1080,7 @@ lpfc_fdmi_cmd(struct lpfc_hba * phba, st
 							  size);
 				ae->ad.bits.AttrType = be16_to_cpu(HOST_NAME);
 				sprintf(ae->un.HostName, "%s",
-					system_utsname.nodename);
+					init_utsname()->nodename);
 				len = strlen(ae->un.HostName);
 				len += (len & 3) ? (4 - (len & 3)) : 4;
 				ae->ad.bits.AttrLen =
@@ -1168,7 +1168,7 @@ lpfc_fdmi_tmo_handler(struct lpfc_hba *p
 
 	ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, FDMI_DID);
 	if (ndlp) {
-		if (system_utsname.nodename[0] != '\0') {
+		if (init_utsname()->nodename[0] != '\0') {
 			lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
 		} else {
 			mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
drivers/usb/core/hcd.c +2 -2
index fbd938d..c1255ec 100644
@@ -318,8 +318,8 @@ static int rh_string (
 
  	// id 3 == vendor description
 	} else if (id == 3) {
-		snprintf (buf, sizeof buf, "%s %s %s", system_utsname.sysname,
-			system_utsname.release, hcd->driver->description);
+		snprintf (buf, sizeof buf, "%s %s %s", init_utsname()->sysname,
+			init_utsname()->release, hcd->driver->description);
 
 	// unsupported IDs --> "protocol stall"
 	} else
drivers/usb/gadget/ether.c +1 -1
index 9c4422a..76ad9b4 100644
@@ -2242,7 +2242,7 @@ #endif
 		return -ENODEV;
 	}
 	snprintf (manufacturer, sizeof manufacturer, "%s %s/%s",
-		system_utsname.sysname, system_utsname.release,
+		init_utsname()->sysname, init_utsname()->release,
 		gadget->name);
 
 	/* If there's an RNDIS configuration, that's what Windows wants to
drivers/usb/gadget/file_storage.c +1 -1
index 6f88747..53d9581 100644
@@ -3985,7 +3985,7 @@ #endif
 	usb_gadget_set_selfpowered(gadget);
 
 	snprintf(manufacturer, sizeof manufacturer, "%s %s with %s",
-			system_utsname.sysname, system_utsname.release,
+			init_utsname()->sysname, init_utsname()->release,
 			gadget->name);
 
 	/* On a real device, serial[] would be loaded from permanent
drivers/usb/gadget/serial.c +1 -1
index b992546..a2f905b 100644
@@ -1496,7 +1496,7 @@ #endif /* CONFIG_USB_GADGET_DUALSPEED */
 		return -ENOMEM;
 
 	snprintf(manufacturer, sizeof(manufacturer), "%s %s with %s",
-		system_utsname.sysname, system_utsname.release,
+		init_utsname()->sysname, init_utsname()->release,
 		gadget->name);
 
 	memset(dev, 0, sizeof(struct gs_dev));
drivers/usb/gadget/zero.c +1 -1
index 68e3d8f..4c888bc 100644
@@ -1243,7 +1243,7 @@ #endif
 		EP_OUT_NAME, EP_IN_NAME);
 
 	snprintf (manufacturer, sizeof manufacturer, "%s %s with %s",
-		system_utsname.sysname, system_utsname.release,
+		init_utsname()->sysname, init_utsname()->release,
 		gadget->name);
 
 	return 0;
include/asm-i386/bugs.h +1 -1
index 50233e0..6cb79fe 100644
@@ -190,6 +190,6 @@ #endif
 	check_fpu();
 	check_hlt();
 	check_popad();
-	system_utsname.machine[1] = '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
+	init_utsname()->machine[1] = '0' + (boot_cpu_data.x86 > 6 ? 6 : boot_cpu_data.x86);
 	alternative_instructions(); 
 }
include/asm-sh/bugs.h +1 -1
index a6de3d0..d09933c 100644
@@ -18,7 +18,7 @@ static void __init check_bugs(void)
 {
 	extern char *get_cpu_subtype(void);
 	extern unsigned long loops_per_jiffy;
-	char *p= &system_utsname.machine[2]; /* "sh" */
+	char *p= &init_utsname()->machine[2]; /* "sh" */
 
 	cpu_data->loops_per_jiffy = loops_per_jiffy;
 
kernel/power/snapshot.c +5 -5
index 3eeedbb..1ca6f95 100644
@@ -524,7 +524,7 @@ static void init_header(struct swsusp_in
 	memset(info, 0, sizeof(struct swsusp_info));
 	info->version_code = LINUX_VERSION_CODE;
 	info->num_physpages = num_physpages;
-	memcpy(&info->uts, &system_utsname, sizeof(system_utsname));
+	memcpy(&info->uts, init_utsname(), sizeof(struct new_utsname));
 	info->cpus = num_online_cpus();
 	info->image_pages = nr_copy_pages;
 	info->pages = nr_copy_pages + nr_meta_pages + 1;
@@ -663,13 +663,13 @@ static int check_header(struct swsusp_in
 		reason = "kernel version";
 	if (info->num_physpages != num_physpages)
 		reason = "memory size";
-	if (strcmp(info->uts.sysname,system_utsname.sysname))
+	if (strcmp(info->uts.sysname,init_utsname()->sysname))
 		reason = "system type";
-	if (strcmp(info->uts.release,system_utsname.release))
+	if (strcmp(info->uts.release,init_utsname()->release))
 		reason = "kernel release";
-	if (strcmp(info->uts.version,system_utsname.version))
+	if (strcmp(info->uts.version,init_utsname()->version))
 		reason = "version";
-	if (strcmp(info->uts.machine,system_utsname.machine))
+	if (strcmp(info->uts.machine,init_utsname()->machine))
 		reason = "machine";
 	if (reason) {
 		printk(KERN_ERR "swsusp: Resume mismatch: %s\n", reason);
net/ipv4/ipconfig.c +1 -1
index b9bdf0f..4c13acb 100644
@@ -367,7 +367,7 @@ static int __init ic_defaults(void)
 	 */
 	 
 	if (!ic_host_name_set)
-		sprintf(system_utsname.nodename, "%u.%u.%u.%u", NIPQUAD(ic_myaddr));
+		sprintf(init_utsname()->nodename, "%u.%u.%u.%u", NIPQUAD(ic_myaddr));
 
 	if (root_server_addr == INADDR_NONE)
 		root_server_addr = ic_servaddr;
sound/core/info_oss.c +5 -5
index f9ce854..35662bb 100644
@@ -94,11 +94,11 @@ static void snd_sndstat_proc_read(struct
 {
 	snd_iprintf(buffer, "Sound Driver:3.8.1a-980706 (ALSA v" CONFIG_SND_VERSION " emulation code)\n");
 	snd_iprintf(buffer, "Kernel: %s %s %s %s %s\n",
-		    system_utsname.sysname,
-		    system_utsname.nodename,
-		    system_utsname.release,
-		    system_utsname.version,
-		    system_utsname.machine);
+		    init_utsname()->sysname,
+		    init_utsname()->nodename,
+		    init_utsname()->release,
+		    init_utsname()->version,
+		    init_utsname()->machine);
 	snd_iprintf(buffer, "Config options: 0\n");
 	snd_iprintf(buffer, "\nInstalled drivers: \n");
 	snd_iprintf(buffer, "Type 10: ALSA emulation\n");
Signature · 1 line
1.3.0
#2 lore raw

PATCH 1/7 uts namespaces: introduce temporary helpers

Define utsname() and init_utsname() which return &system_utsname. Users of system_utsname will be changed to use these helpers, after which system_utsname will disappear.

---

 include/linux/utsname.h |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

751c1567989ac921a1f861c05234a58c9181cfd3

include/linux/utsname.h +8 -0
index 13e1da0..8f0decf 100644
@@ -32,5 +32,13 @@ struct new_utsname {
 
 extern struct new_utsname system_utsname;
 
+static inline struct new_utsname *utsname(void) {
+	return &system_utsname;
+}
+
+static inline struct new_utsname *init_utsname(void) {
+	return &system_utsname;
+}
+
 extern struct rw_semaphore uts_sem;
 #endif
Signature · 1 line
1.3.0
#3 lore raw

PATCH 4/7 uts namespaces: implement utsname namespaces

In reply to Serge E. Hallyn

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/sched.h     |    2 ++
 include/linux/utsname.h   |   51 +++++++++++++++++++++++++++++++++++++++++----
 init/Kconfig              |    8 +++++++
 init/version.c            |   22 +++++++++++--------
 kernel/Makefile           |    1 +
 kernel/exit.c             |    2 ++
 kernel/fork.c             |   11 +++++++---
 kernel/utsname.c          |   48 ++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 131 insertions(+), 16 deletions(-)
 create mode 100644 kernel/utsname.c

73a1721f20bb13cb49bc29b7553768fc788d4d22

include/linux/init_task.h +2 -0
index 41ecbb8..21b1751 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 \
 {							\
@@ -123,6 +124,7 @@ #define INIT_TASK(tsk)	\
 	.journal_info	= NULL,						\
 	.cpu_timers	= INIT_CPU_TIMERS(tsk.cpu_timers),		\
 	.fs_excl	= ATOMIC_INIT(0),				\
+	.uts_ns		= &init_uts_ns,					\
 }
 
 
include/linux/sched.h +2 -0
index 29b7d4f..3d74d77 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,
@@ -808,6 +809,7 @@ #endif
 	struct files_struct *files;
 /* namespace */
 	struct namespace *namespace;
+	struct uts_namespace *uts_ns;
 /* signal handlers */
 	struct signal_struct *signal;
 	struct sighand_struct *sighand;
include/linux/utsname.h +47 -4

67 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 58908f9..70a69bc 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 +2 -0
index f86434d..6a46059 100644
@@ -35,6 +35,7 @@ #include <linux/mutex.h>
 #include <linux/futex.h>
 #include <linux/compat.h>
 #include <linux/pipe_fs_i.h>
+#include <linux/utsname.h>
 
 #include <asm/uaccess.h>
 #include <asm/unistd.h>
@@ -174,6 +175,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;
kernel/fork.c +8 -3
index d2fa57d..cedfd86 100644
@@ -44,6 +44,7 @@ #include <linux/profile.h>
 #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>
@@ -1064,9 +1065,11 @@ #endif
 		goto bad_fork_cleanup_mm;
 	if ((retval = copy_namespace(clone_flags, p)))
 		goto bad_fork_cleanup_keys;
+	if ((retval = copy_utsname(clone_flags, p)))
+		goto bad_fork_cleanup_namespace;
 	retval = copy_thread(0, clone_flags, stack_start, stack_size, p, regs);
 	if (retval)
-		goto bad_fork_cleanup_namespace;
+		goto bad_fork_cleanup_utsns;
 
 	p->set_child_tid = (clone_flags & CLONE_CHILD_SETTID) ? child_tidptr : NULL;
 	/*
@@ -1153,7 +1156,7 @@ #endif
 		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) {
@@ -1166,7 +1169,7 @@ #endif
 			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;
@@ -1218,6 +1221,8 @@ #endif
 	proc_fork_connector(p);
 	return p;
 
+bad_fork_cleanup_utsns:
+	exit_utsname(p);
 bad_fork_cleanup_namespace:
 	exit_namespace(p);
 bad_fork_cleanup_keys:
kernel/utsname.c new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
1.3.0
#4 lore raw

PATCH 5/7 uts namespaces: sysctl hack

Sysctl uts patch. This clearly will need to be done another way, but since sysctl itself needs to be container aware, 'the right thing' is a separate patchset.

---

 kernel/sysctl.c |   20 ++++++++++----------
 1 files changed, 10 insertions(+), 10 deletions(-)

1ead4c366dd1cd7e6ad0e4d891b34040a3b1e565

kernel/sysctl.c +10 -10
index e82726f..ab36b41 100644
@@ -233,8 +233,8 @@ static ctl_table kern_table[] = {
 	{
 		.ctl_name	= KERN_OSTYPE,
 		.procname	= "ostype",
-		.data		= system_utsname.sysname,
-		.maxlen		= sizeof(system_utsname.sysname),
+		.data		= init_uts_ns.name.sysname,
+		.maxlen		= sizeof(init_uts_ns.name.sysname),
 		.mode		= 0444,
 		.proc_handler	= &proc_doutsstring,
 		.strategy	= &sysctl_string,
@@ -242,8 +242,8 @@ static ctl_table kern_table[] = {
 	{
 		.ctl_name	= KERN_OSRELEASE,
 		.procname	= "osrelease",
-		.data		= system_utsname.release,
-		.maxlen		= sizeof(system_utsname.release),
+		.data		= init_uts_ns.name.release,
+		.maxlen		= sizeof(init_uts_ns.name.release),
 		.mode		= 0444,
 		.proc_handler	= &proc_doutsstring,
 		.strategy	= &sysctl_string,
@@ -251,8 +251,8 @@ static ctl_table kern_table[] = {
 	{
 		.ctl_name	= KERN_VERSION,
 		.procname	= "version",
-		.data		= system_utsname.version,
-		.maxlen		= sizeof(system_utsname.version),
+		.data		= init_uts_ns.name.version,
+		.maxlen		= sizeof(init_uts_ns.name.version),
 		.mode		= 0444,
 		.proc_handler	= &proc_doutsstring,
 		.strategy	= &sysctl_string,
@@ -260,8 +260,8 @@ static ctl_table kern_table[] = {
 	{
 		.ctl_name	= KERN_NODENAME,
 		.procname	= "hostname",
-		.data		= system_utsname.nodename,
-		.maxlen		= sizeof(system_utsname.nodename),
+		.data		= init_uts_ns.name.nodename,
+		.maxlen		= sizeof(init_uts_ns.name.nodename),
 		.mode		= 0644,
 		.proc_handler	= &proc_doutsstring,
 		.strategy	= &sysctl_string,
@@ -269,8 +269,8 @@ static ctl_table kern_table[] = {
 	{
 		.ctl_name	= KERN_DOMAINNAME,
 		.procname	= "domainname",
-		.data		= system_utsname.domainname,
-		.maxlen		= sizeof(system_utsname.domainname),
+		.data		= init_uts_ns.name.domainname,
+		.maxlen		= sizeof(init_uts_ns.name.domainname),
 		.mode		= 0644,
 		.proc_handler	= &proc_doutsstring,
 		.strategy	= &sysctl_string,
Signature · 1 line
1.3.0
#5 lore raw

PATCH 6/7 uts namespaces: remove system_utsname

The system_utsname isn't needed now that kernel/sysctl.c is fixed. Nuke it.

---

 include/linux/utsname.h |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)

a3dec7d619ca222d5260022c1f1f72fb61d26efc

include/linux/utsname.h +0 -2
index a28e956..d58a406 100644
@@ -81,7 +81,5 @@ static inline struct new_utsname *init_u
 	return &init_uts_ns.name;
 }
 
-#define system_utsname init_uts_ns.name
-
 extern struct rw_semaphore uts_sem;
 #endif
Signature · 1 line
1.3.0
#6 lore raw

PATCH 7/7 uts namespaces: Implement CLONE_NEWUTS flag

Implement a CLONE_NEWUTS flag, and use it at clone and sys_unshare.

---

 include/linux/sched.h   |    1 +
 include/linux/utsname.h |    7 ++++++
 kernel/fork.c           |   13 ++++++++++--
 kernel/utsname.c        |   53 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 72 insertions(+), 2 deletions(-)

f785920e68ae2482ff76df39d6be5335bbfcc511

include/linux/sched.h +1 -0
index 3d74d77..7f4af71 100644
@@ -62,6 +62,7 @@ #define CLONE_DETACHED		0x00400000	/* Un
 #define CLONE_UNTRACED		0x00800000	/* set if the tracing process can't force CLONE_PTRACE on this clone */
 #define CLONE_CHILD_SETTID	0x01000000	/* set the TID in the child */
 #define CLONE_STOPPED		0x02000000	/* Start in stopped state */
+#define CLONE_NEWUTS		0x04000000	/* New utsname group? */
 
 /*
  * List of flags we want to share for kernel threads,
include/linux/utsname.h +7 -0
index d58a406..caecec7 100644
@@ -40,6 +40,8 @@ struct uts_namespace {
 extern struct uts_namespace init_uts_ns;
 
 #ifdef CONFIG_UTS_NS
+extern int unshare_utsname(unsigned long unshare_flags,
+				struct uts_namespace **new_uts);
 extern int copy_utsname(int flags, struct task_struct *tsk);
 extern void free_uts_ns(struct kref *kref);
 
@@ -70,6 +72,11 @@ static inline void put_uts_ns(struct uts
 static inline void exit_utsname(struct task_struct *p)
 {
 }
+static inline int unshare_utsname(unsigned long unshare_flags,
+			struct uts_namespace **new_uts)
+{
+	return -EINVAL;
+}
 #endif
 
 static inline struct new_utsname *utsname(void)
kernel/fork.c +11 -2
index cedfd86..c52c274 100644
@@ -1566,13 +1566,14 @@ asmlinkage long sys_unshare(unsigned lon
 	struct mm_struct *mm, *new_mm = NULL, *active_mm = NULL;
 	struct files_struct *fd, *new_fd = NULL;
 	struct sem_undo_list *new_ulist = NULL;
+	struct uts_namespace *new_uts = NULL;
 
 	check_unshare_flags(&unshare_flags);
 
 	/* Return -EINVAL for all unsupported flags */
 	err = -EINVAL;
 	if (unshare_flags & ~(CLONE_THREAD|CLONE_FS|CLONE_NEWNS|CLONE_SIGHAND|
-				CLONE_VM|CLONE_FILES|CLONE_SYSVSEM))
+				CLONE_VM|CLONE_FILES|CLONE_SYSVSEM|CLONE_NEWUTS))
 		goto bad_unshare_out;
 
 	if ((err = unshare_thread(unshare_flags)))
@@ -1589,8 +1590,11 @@ asmlinkage long sys_unshare(unsigned lon
 		goto bad_unshare_cleanup_vm;
 	if ((err = unshare_semundo(unshare_flags, &new_ulist)))
 		goto bad_unshare_cleanup_fd;
+	if ((err = unshare_utsname(unshare_flags, &new_uts)))
+		goto bad_unshare_cleanup_fd;
 
-	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist) {
+	if (new_fs || new_ns || new_sigh || new_mm || new_fd || new_ulist ||
+				new_uts) {
 
 		task_lock(current);
 
@@ -1627,6 +1631,11 @@ asmlinkage long sys_unshare(unsigned lon
 			new_fd = fd;
 		}
 
+		if (new_uts) {
+			put_uts_ns(current->uts_ns);
+			current->uts_ns = new_uts;
+		}
+
 		task_unlock(current);
 	}
 
kernel/utsname.c +53 -0

71 lines not on this page · raw message

Signature · 1 line
1.3.0
#7 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

kernel/utsname.c static inline void get_uts_ns(struct uts · line 38

Quoted 11 lines · Serge E. Hallyn
kernel/utsname.c +11 -0
+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;
+}

Very small nit...

Would this memcpy be more appropriate as a strncpy()?

kernel/utsname.c static inline void get_uts_ns(struct uts · line 56

Quoted 13 lines
kernel/utsname.c +13 -0
+int unshare_utsname(unsigned long unshare_flags, struct uts_namespace **new_uts)
+{
+	if (unshare_flags & CLONE_NEWUTS) {
+		if (!capable(CAP_SYS_ADMIN))
+			return -EPERM;
+
+		*new_uts = clone_uts_ns(current->uts_ns);
+		if (!*new_uts)
+			return -ENOMEM;
+	}
+
+	return 0;
+}

Would it be a bit nicer to use the ERR_PTR() mechanism here instead of the double-pointer bit?

I've always liked those a bit better because there's no hiding the fact of what is actually a return value from a function.

-- Dave

#8 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 34 lines · Dave Hansen

kernel/utsname.c static inline void get_uts_ns(struct uts · line 38

Quoted 11 lines · Serge E. Hallyn
kernel/utsname.c +11 -0
+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;
+}

Very small nit...

Would this memcpy be more appropriate as a strncpy()?

kernel/utsname.c static inline void get_uts_ns(struct uts · line 56

Quoted 13 lines
kernel/utsname.c +13 -0
+int unshare_utsname(unsigned long unshare_flags, struct uts_namespace **new_uts)
+{
+	if (unshare_flags & CLONE_NEWUTS) {
+		if (!capable(CAP_SYS_ADMIN))
+			return -EPERM;
+
+		*new_uts = clone_uts_ns(current->uts_ns);
+		if (!*new_uts)
+			return -ENOMEM;
+	}
+
+	return 0;
+}

Would it be a bit nicer to use the ERR_PTR() mechanism here instead of the double-pointer bit?

Quoted 2 lines

I've always liked those a bit better because there's no hiding the fact of what is actually a return value from a function.

I agree. I was (grudgingly) copying the style from the other helpers in fs/fork.c. Then I had to pull it out so it could cleanly return -ENOMEM if !CONFIG_UTS, but I expect CONFIG_UTS to be yanked, and this fn to be returned to fs/fork.c...

Might be worth a separate patch to change over all those helpers in fork.c? (I think they were all brought in along with the sys_unshare syscall)

Agreed on all your other points, thanks.

-serge

#9 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 3 lines · Serge E. Hallyn

Might be worth a separate patch to change over all those helpers in fork.c? (I think they were all brought in along with the sys_unshare syscall)

I'd be a little scared to touch good, working code, but it couldn't hurt to see the patch.

-- Dave

#10 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 7 lines · Dave Hansen
Quoted 3 lines · Serge E. Hallyn

Might be worth a separate patch to change over all those helpers in fork.c? (I think they were all brought in along with the sys_unshare syscall)

I'd be a little scared to touch good, working code, but it couldn't hurt to see the patch.

Hmm, well the following untested patch was just to see the end results.
Summary: it ends up quite a bit uglier :-(

I think I like it better as is.

thanks,
-serge

Subject: [PATCH] fs/fork.c: unshare cleanup

Switch some of the unshare patch to more kernel conformant style.

---

 kernel/fork.c |  102 ++++++++++++++++++++++++++++++++++++---------------------
 1 files changed, 64 insertions(+), 38 deletions(-)

c30251d8442cfee2ada7dfd6c46159cf44011213

kernel/fork.c +64 -38
index d2fa57d..42753a4 100644
@@ -1450,86 +1450,92 @@ static int unshare_thread(unsigned long 
 /*
  * Unshare the filesystem structure if it is being shared
  */
-static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
+static struct fs_struct * unshare_fs(unsigned long flags)
 {
 	struct fs_struct *fs = current->fs;
+	struct fs_struct *new_fs = NULL;
 
-	if ((unshare_flags & CLONE_FS) &&
+	if ((flags & CLONE_FS) &&
 	    (fs && atomic_read(&fs->count) > 1)) {
-		*new_fsp = __copy_fs_struct(current->fs);
-		if (!*new_fsp)
-			return -ENOMEM;
+		new_fs = __copy_fs_struct(current->fs);
+		if (!new_fs)
+			new_fs = ERR_PTR(-ENOMEM);
 	}
 
-	return 0;
+	return new_fs;
 }
 
 /*
  * Unshare the namespace structure if it is being shared
  */
-static int unshare_namespace(unsigned long unshare_flags, struct namespace **new_nsp, struct fs_struct *new_fs)
+static struct namespace *unshare_namespace(unsigned long flags,
+		struct fs_struct *new_fs)
 {
 	struct namespace *ns = current->namespace;
+	struct namespace *new_ns = NULL;
 
-	if ((unshare_flags & CLONE_NEWNS) &&
+	if ((flags & CLONE_NEWNS) &&
 	    (ns && atomic_read(&ns->count) > 1)) {
-		if (!capable(CAP_SYS_ADMIN))
-			return -EPERM;
+		if (!capable(CAP_SYS_ADMIN)) {
+			return ERR_PTR(-EPERM);
 
-		*new_nsp = dup_namespace(current, new_fs ? new_fs : current->fs);
+		*new_ns = dup_namespace(current, new_fs ? new_fs : current->fs);
 		if (!*new_nsp)
-			return -ENOMEM;
+			return ERR_PTR(-ENOMEM);
 	}
 
-	return 0;
+	return new_ns;
 }
 
 /*
  * Unsharing of sighand for tasks created with CLONE_SIGHAND is not
  * supported yet
  */
-static int unshare_sighand(unsigned long unshare_flags, struct sighand_struct **new_sighp)
+static struct sighand_struct *unshare_sighand(unsigned long flags);
 {
 	struct sighand_struct *sigh = current->sighand;
+	struct sighand_struct *new_sigh = NULL;
 
-	if ((unshare_flags & CLONE_SIGHAND) &&
+	if ((flags & CLONE_SIGHAND) &&
 	    (sigh && atomic_read(&sigh->count) > 1))
-		return -EINVAL;
-	else
-		return 0;
+		return ERR_PTR(-EINVAL);
+
+	return new_sigh;
 }
 
 /*
  * Unshare vm if it is being shared
  */
-static int unshare_vm(unsigned long unshare_flags, struct mm_struct **new_mmp)
+static mm_struct *unshare_vm(unsigned long flags)
 {
 	struct mm_struct *mm = current->mm;
+	struct mm_struct *new_mm = NULL;
 
-	if ((unshare_flags & CLONE_VM) &&
+	if ((flags & CLONE_VM) &&
 	    (mm && atomic_read(&mm->mm_users) > 1)) {
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 	}
 
-	return 0;
+	return new_mm;
 }
 
 /*
  * Unshare file descriptor table if it is being shared
  */
-static int unshare_fd(unsigned long unshare_flags, struct files_struct **new_fdp)
+static struct files_struct *unshare_fd(unsigned long flags)
 {
 	struct files_struct *fd = current->files;
+	struct files_struct *new_fd = NULL;
 	int error = 0;
 
-	if ((unshare_flags & CLONE_FILES) &&
+	if ((flags & CLONE_FILES) &&
 	    (fd && atomic_read(&fd->count) > 1)) {
-		*new_fdp = dup_fd(fd, &error);
-		if (!*new_fdp)
-			return error;
+		new_fd = dup_fd(fd, &error);
+		if (!new_fd)
+			return ERR_PTR(error);
 	}
 
-	return 0;
+	return new_fd;
 }
 
 /*
@@ -1572,16 +1578,36 @@ asmlinkage long sys_unshare(unsigned lon
 
 	if ((err = unshare_thread(unshare_flags)))
 		goto bad_unshare_out;
-	if ((err = unshare_fs(unshare_flags, &new_fs)))
+
+	new_fs = unshare_fs(unshare_flags);
+	if (IS_ERR(new_fs)) {
+		err = PTR_ERR(new_fs);
 		goto bad_unshare_cleanup_thread;
-	if ((err = unshare_namespace(unshare_flags, &new_ns, new_fs)))
+	}
+
+	new_ns = unshare_namespace(unshare_flags, &new_ns);
+	if (IS_ERR(new_ns)) {
+		err = PTR_ERR(new_ns);
 		goto bad_unshare_cleanup_fs;
-	if ((err = unshare_sighand(unshare_flags, &new_sigh)))
+	}
+
+	new_sigh = unshare_sighand(unshare_flags);
+	if (IS_ERR(new_sigh)) {
+		err = PTR_ERR(new_sigh);
 		goto bad_unshare_cleanup_ns;
-	if ((err = unshare_vm(unshare_flags, &new_mm)))
+	}
+	new_mm = unshare_vm(unshare_flags);
+	if (IS_ERR(new_mm)) {
+		err = PTR_ERR(new_mm);
 		goto bad_unshare_cleanup_sigh;
-	if ((err = unshare_fd(unshare_flags, &new_fd)))
+	}
+
+	new_fd = unshare_fd(unshare_flags);
+	if (IS_ERR(new_fd)) {
+		err = PTR_ERR(new_fd);
 		goto bad_unshare_cleanup_vm;
+	}
+
 	if ((err = unshare_semundo(unshare_flags, &new_ulist)))
 		goto bad_unshare_cleanup_fd;
 
@@ -1626,24 +1652,24 @@ asmlinkage long sys_unshare(unsigned lon
 	}
 
 bad_unshare_cleanup_fd:
-	if (new_fd)
+	if (new_fd && !IS_ERR(new_fd))
 		put_files_struct(new_fd);
 
 bad_unshare_cleanup_vm:
-	if (new_mm)
+	if (new_mm && !IS_ERR(new_mm))
 		mmput(new_mm);
 
 bad_unshare_cleanup_sigh:
-	if (new_sigh)
+	if (new_sigh && !IS_ERR(new_sigh))
 		if (atomic_dec_and_test(&new_sigh->count))
 			kmem_cache_free(sighand_cachep, new_sigh);
 
 bad_unshare_cleanup_ns:
-	if (new_ns)
+	if (new_ns && !IS_ERR(new_ns))
 		put_namespace(new_ns);
 
 bad_unshare_cleanup_fs:
-	if (new_fs)
+	if (new_fs && !IS_ERR(new_fs)))
 		put_fs_struct(new_fs);
 
 bad_unshare_cleanup_thread:
Signature · 1 line
1.3.0
#11 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

In reply to Dave Hansen
Quoted 15 lines · Dave Hansen

kernel/utsname.c static inline void get_uts_ns(struct uts · line 38

Quoted 11 lines · Serge E. Hallyn
kernel/utsname.c +11 -0
+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;
+}

Very small nit...

Quoted 1 line

Would this memcpy be more appropriate as a strncpy()?

Nope. It is several strings. Although a different field name for the old utsname structure might be called for to keep people from getting confused.

Eric

#12 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

In reply to Serge E. Hallyn
Quoted 1 line · Serge E. Hallyn

Implement a CLONE_NEWUTS flag, and use it at clone and sys_unshare.

I still think it's a design mistake to add zillions of pointers to task_struct for every possible kernel object. Going through a proxy datastructure to merge common cases would be much better.

-Andi

#13 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 7 lines · Andi Kleen
Quoted 1 line · Serge E. Hallyn

Implement a CLONE_NEWUTS flag, and use it at clone and sys_unshare.

I still think it's a design mistake to add zillions of pointers to task_struct for every possible kernel object. Going through a proxy datastructure to merge common cases would be much better.

The design point is not every kernel object. The target is one per namespace. Or more usefully one per logical chunk of the kernel.

The UTS namespace is by far the smallest of these pieces.

The kernel networking stack is probably the largest.

At last count there were about 7 of these, enough so that the few remaining clone bits would be sufficient.

Do you disagree that to be able to implement this properly we need to take small steps?

Are there any semantic differences between a clone bit and what you are proposing?

If it is just an internal implementation detail do you have a clear suggestion on how to implement this? Possibly illustrated by the thread flags that are already in this situation, and more likely to always share everything.

Except for reducing reference counting I really don't see where we could have a marked improvement. I also don't see us closing the door to that kind of implementation at this point, but instead taking the simple path.

Eric

#14 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 4 lines · Eric W. Biederman
Quoted 2 lines · Andi Kleen

"Serge E. Hallyn" <[email protected]> writes:

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

Implement a CLONE_NEWUTS flag, and use it at clone and sys_unshare.

I still think it's a design mistake to add zillions of pointers to task_struct for every possible kernel object. Going through a proxy datastructure to merge common cases would be much better.

The design point is not every kernel object. The target is one per namespace. Or more usefully one per logical chunk of the kernel.

Which are likely tens or even hundreds if you go through all the source. Even tens would bloat task_struct far too much.

Quoted 6 lines

The UTS namespace is by far the smallest of these pieces.

The kernel networking stack is probably the largest.

At last count there were about 7 of these, enough so that the few remaining clone bits would be sufficient.

7 additional bits will probably not be enough. I still don't quite understand why you want individual bits for everything. Why not group them into logical pieces?

If you really want individual bits you'll likely need to think about a clone2() call with more flags soon.

Quoted 3 lines

Do you disagree that to be able to implement this properly we need to take small steps?

No, but at least the basic infrastructure for expansion should be added first.

Quoted 2 lines

Are there any semantic differences between a clone bit and what you are proposing?

No just internals.

Quoted 4 lines

If it is just an internal implementation detail do you have a clear suggestion on how to implement this? Possibly illustrated by the thread flags that are already in this situation, and more likely to always share everything.

Have a proxy structure which has pointers to the many name spaces and a bit mask for "namespace X is different". This structure would be reference counted. task_struct has a single pointer to it.

On clone check the clone flags against the bit mask. If there is any difference allocate a new structure and clone the name spaces into it. If no difference just use the old data structure after increasing its reference count.

Possible name "nsproxy".

Quoted 4 lines

Except for reducing reference counting I really don't see where we could have a marked improvement. I also don't see us closing the door to that kind of implementation at this point, but instead taking the simple path.

With many name spaces you would have smaller task_struct, less cache foot print, better cache use of task_struct because slab cache colouring will still work etc.

-Andi

#15 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 9 lines · Andi Kleen
Quoted 7 lines · Eric W. Biederman
Quoted 5 lines · Andi Kleen
Quoted 1 line · Serge E. Hallyn

Implement a CLONE_NEWUTS flag, and use it at clone and sys_unshare.

I still think it's a design mistake to add zillions of pointers to

task_struct

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

for every possible kernel object. Going through a proxy datastructure to merge common cases would be much better.

The design point is not every kernel object. The target is one per namespace. Or more usefully one per logical chunk of the kernel.

Which are likely tens or even hundreds if you go through all the source. Even tens would bloat task_struct far too much.

We don't have that many places where we put global names in the linux api. Yes there are several and it is painful, but we are nowhere near as high as you expect.

Quoted 10 lines
Quoted 6 lines

The UTS namespace is by far the smallest of these pieces.

The kernel networking stack is probably the largest.

At last count there were about 7 of these, enough so that the few remaining clone bits would be sufficient.

7 additional bits will probably not be enough. I still don't quite understand why you want individual bits for everything. Why not group them into logical pieces?

Each bit currently maps to one logical piece, that is why I expect to have enough bits.

Quoted 2 lines

If you really want individual bits you'll likely need to think about a clone2() call with more flags soon.

Being short on bits should keep us thinking about keeping things in logical chunks.

Quoted 10 lines
Quoted 2 lines

Do you disagree that to be able to implement this properly we need to take small steps?

No, but at least the basic infrastructure for expansion should be added first.

Quoted 2 lines

Are there any semantic differences between a clone bit and what you are proposing?

No just internals.

Good that means we can still optimize this.

Quoted 9 lines
Quoted 4 lines

If it is just an internal implementation detail do you have a clear suggestion on how to implement this? Possibly illustrated by the thread flags that are already in this situation, and more likely to always share everything.

Have a proxy structure which has pointers to the many name spaces and a bit mask for "namespace X is different". This structure would be reference counted. task_struct has a single pointer to it.

Quoted 6 lines

On clone check the clone flags against the bit mask. If there is any difference allocate a new structure and clone the name spaces into it. If no difference just use the old data structure after increasing its reference count.

Possible name "nsproxy".

Sounds reasonable, and I have nothing against it.
I simply think at this point where we are still struggling to get the simplest namespace merged and working correctly that is a premature optimization.

Quoted 8 lines
Quoted 4 lines

Except for reducing reference counting I really don't see where we could have a marked improvement. I also don't see us closing the door to that kind of implementation at this point, but instead taking the simple path.

With many name spaces you would have smaller task_struct, less cache foot print, better cache use of task_struct because slab cache colouring will still work etc.

Makes sense. I have no problem against that as an optimization, and it is firmly on the todo list as something to try. Right now with only 2 non-thread clone flags I believe it will obfuscate the code more than help performance.

Eric

#16 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

In reply to Andi Kleen
Quoted 4 lines · Andi Kleen

On Tuesday 02 May 2006 10:03, Eric W. Biederman wrote:
7 additional bits will probably not be enough. I still don't quite understand why you want individual bits for everything. Why not group them into logical pieces?

I wouldn't be surprised if it makes sense to combine some of them. For instance, perhaps utsname and networking?

Quoted 2 lines

Have a proxy structure which has pointers to the many name spaces and a bit mask for "namespace X is different".

different from what?

Oh, you mean in case we want to allow cloning a namespace outside of fork *without* cloning the nsproxy struct?

Quoted 2 lines

This structure would be reference
counted. task_struct has a single pointer to it.

If it is reference counted, that implies it is shared between some processes. But namespace pointers themselves are shared between some of these nsproxy's. The lifetime mgmt here is one reason I haven't tried a patch to do this.

Still, like Eric, I'm fine with trying that approach. It just doesn't seem like we can draw any meaningful conclusions with just one namespace pointer, and adding a separate reference counted object around the utsname pointer would seem to just make the code harder to review.

Quoted 3 lines

With many name spaces you would have smaller task_struct, less cache foot print, better cache use of task_struct because slab cache colouring will still work etc.

I suppose we could run some performance tests with some dummy namespace pointers? 9 void *'s directly in the task struct, and the same inside a refcounted container struct. The results might add some urgency to implementing the struct nsproxy.

-serge

#17 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 8 lines · Serge E. Hallyn
Quoted 4 lines · Andi Kleen

On Tuesday 02 May 2006 10:03, Eric W. Biederman wrote:
7 additional bits will probably not be enough. I still don't quite understand why you want individual bits for everything. Why not group them into logical pieces?

I wouldn't be surprised if it makes sense to combine some of them. For instance, perhaps utsname and networking?

I frankly would just combine everything new.

Quoted 11 lines
Quoted 3 lines

Have a proxy structure which has pointers to the many name spaces and a bit mask for "namespace X is different".

different from what?

From the parent.

Oh, you mean in case we want to allow cloning a namespace outside of fork *without* cloning the nsproxy struct?

Basically every time any name space changes you need a new nsproxy.

Quoted 8 lines
Quoted 3 lines

This structure would be reference
counted. task_struct has a single pointer to it.

If it is reference counted, that implies it is shared between some processes. But namespace pointers themselves are shared between some of these nsproxy's. The lifetime mgmt here is one reason I haven't tried a patch to do this.

The livetime management is no different from having individual pointers.

Quoted 8 lines
Quoted 3 lines

With many name spaces you would have smaller task_struct, less cache foot print, better cache use of task_struct because slab cache colouring will still work etc.

I suppose we could run some performance tests with some dummy namespace pointers? 9 void *'s directly in the task struct, and the same inside a refcounted container struct. The results might add some urgency to implementing the struct nsproxy.

Not sure you'll notice too much difference on the beginning. I am just the opinion memory/cache bloat needs to be attacked at the root, not when it's too late.

-Andi

#18 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 8 lines · Andi Kleen
Quoted 5 lines · Serge E. Hallyn
Quoted 2 lines · Andi Kleen

Have a proxy structure which has pointers to the many name spaces and a bit mask for "namespace X is different".

different from what?

From the parent.

...

Quoted 4 lines
Quoted 2 lines

Oh, you mean in case we want to allow cloning a namespace outside of fork *without* cloning the nsproxy struct?

Basically every time any name space changes you need a new nsproxy.

But, either the nsproxy is shared between tasks and you need to copy youself a new one as soon as any ns changes, or it is not shared, and you don't need that info at all (just make the change in the nsproxy immediately)

What am I missing?

Should we talk about this on irc someplace? Perhaps drag in Eric as well?

Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

This structure would be reference
counted. task_struct has a single pointer to it.

If it is reference counted, that implies it is shared between some processes. But namespace pointers themselves are shared between some of these nsproxy's. The lifetime mgmt here is one reason I haven't tried a patch to do this.

The livetime management is no different from having individual pointers.

That's true if we have one nsproxy per process or thread, which I didn't think was the case. Are you saying not to share nsproxy's among processes which share all namespaces?

Quoted 10 lines
Quoted 8 lines
Quoted 3 lines

With many name spaces you would have smaller task_struct, less cache foot print, better cache use of task_struct because slab cache colouring will still work etc.

I suppose we could run some performance tests with some dummy namespace pointers? 9 void *'s directly in the task struct, and the same inside a refcounted container struct. The results might add some urgency to implementing the struct nsproxy.

Not sure you'll notice too much difference on the beginning. I am just

9 void*'s is probably more than we'll need, though, so it's not "the
beginning". Eric previously mentioned uts, sysvipc, net, pid, and uid,
to which we might add proc, sysctl, and signals, though those are probably just implied through the others.

What others do you see us needing?

If the number were more likely to be 50, then in the above experiment use 50 instead - the point was to see the performance implications without implementing the namespaces first.

Anyway I guess I'll go ahead and queue up some tests.

Quoted 2 lines

the opinion memory/cache bloat needs to be attacked at the root, not when it's too late.

-serge

#19 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 18 lines · Serge E. Hallyn
Quoted 11 lines · Andi Kleen
Quoted 8 lines · Serge E. Hallyn
Quoted 3 lines

With many name spaces you would have smaller task_struct, less cache foot print, better cache use of task_struct because slab cache colouring will still work etc.

I suppose we could run some performance tests with some dummy namespace pointers? 9 void *'s directly in the task struct, and the same inside a refcounted container struct. The results might add some urgency to implementing the struct nsproxy.

Not sure you'll notice too much difference on the beginning. I am just

9 void*'s is probably more than we'll need, though, so it's not "the
beginning". Eric previously mentioned uts, sysvipc, net, pid, and uid,
to which we might add proc, sysctl, and signals, though those are probably just implied through the others.

Quoted 7 lines

What others do you see us needing?

If the number were more likely to be 50, then in the above experiment use 50 instead - the point was to see the performance implications without implementing the namespaces first.

Anyway I guess I'll go ahead and queue up some tests.

Though of course one reason those tests won't be very meaningful is that the void*'s won't be being dereferenced, so we won't be accounting for the performance hit of the double dereference and resulting cache hits...

-serge

#20 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

In reply to Serge E. Hallyn
Quoted 22 lines · Serge E. Hallyn
Quoted 8 lines · Andi Kleen
Quoted 5 lines · Serge E. Hallyn
Quoted 2 lines · Andi Kleen

Have a proxy structure which has pointers to the many name spaces and a bit mask for "namespace X is different".

different from what?

From the parent.

...

Quoted 4 lines
Quoted 2 lines

Oh, you mean in case we want to allow cloning a namespace outside of fork *without* cloning the nsproxy struct?

Basically every time any name space changes you need a new nsproxy.

But, either the nsproxy is shared between tasks and you need to copy youself a new one as soon as any ns changes, or it is not shared, and you don't need that info at all (just make the change in the nsproxy immediately)

Quoted 4 lines

What am I missing?

Should we talk about this on irc someplace? Perhaps drag in Eric as well?

good idea, feel free to use #vserver (irc.oftc.net) for that

Quoted 23 lines
Quoted 9 lines
Quoted 7 lines
Quoted 2 lines

This structure would be reference
counted. task_struct has a single pointer to it.

If it is reference counted, that implies it is shared between some processes. But namespace pointers themselves are shared between some of these nsproxy's. The lifetime mgmt here is one reason I haven't tried a patch to do this.

The livetime management is no different from having individual pointers.

That's true if we have one nsproxy per process or thread, which I didn't think was the case. Are you saying not to share nsproxy's among processes which share all namespaces?

Quoted 9 lines
Quoted 8 lines
Quoted 3 lines

With many name spaces you would have smaller task_struct, less cache foot print, better cache use of task_struct because slab cache colouring will still work etc.

I suppose we could run some performance tests with some dummy namespace pointers? 9 void *'s directly in the task struct, and the same inside a refcounted container struct. The results might add some urgency to implementing the struct nsproxy.

Quoted 8 lines
Quoted 1 line

Not sure you'll notice too much difference on the beginning. I am just

9 void*'s is probably more than we'll need, though, so it's not "the
beginning". Eric previously mentioned uts, sysvipc, net, pid, and uid,
to which we might add proc, sysctl, and signals, though those are probably just implied through the others.

What others do you see us needing?

the 'container', as well as accounting and resource limits but they are not required in the beginning either

Quoted 5 lines

If the number were more likely to be 50, then in the above experiment use 50 instead - the point was to see the performance implications without implementing the namespaces first.

Anyway I guess I'll go ahead and queue up some tests.

good!

best,
Herbert

Quoted 4 lines
Quoted 2 lines

the opinion memory/cache bloat needs to be attacked at the root, not when it's too late.

-serge

#21 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 5 lines · Herbert Poetzl
Quoted 2 lines · Serge E. Hallyn

Should we talk about this on irc someplace? Perhaps drag in Eric as well?

good idea, feel free to use #vserver (irc.oftc.net) for that

Moves a bit too fast for me to be able to keep up, but I'll try to hang out there more than I have been :)

Quoted 3 lines
Quoted 1 line

Anyway I guess I'll go ahead and queue up some tests.

good!

As I later mentioned, this won't necessary give honest picture of performance implications, since some namespaces might need to be frequently referenced, in which case the extra indirection from task_struct->container->nsstruct may give a big hit.

But perhaps I can use the utsname ns on top of the experimental container patch to test that aspect.

thanks,
-serge

#22 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

In reply to Serge E. Hallyn
Quoted 3 lines

But, either the nsproxy is shared between tasks and you need to copy youself a new one as soon as any ns changes

That would be the case. But it is only shared between tasks where all the name spaces are the same.

Quoted 3 lines

, or it is not shared, and
you don't need that info at all (just make the change in the nsproxy immediately)

Don't follow you here.

Basically the goal is to have a minimum number of nsproxies in the system without having to maintain a global hash table. So instead you assume that name space changes are infrequent. In the common case of clone without a name space change you just share the nsproxy of the parent. If there is a name space change of any kind you get a new one.

This won't get the absolute minimum number of nsproxies, but should be reasonably good without too much effort.

-Andi

Quoted 1 line
#23 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 6 lines · Andi Kleen
Quoted 3 lines

But, either the nsproxy is shared between tasks and you need to copy youself a new one as soon as any ns changes

That would be the case. But it is only shared between tasks where all the name spaces are the same.

Ok, that is how I was thinking.

Quoted 6 lines
Quoted 3 lines

, or it is not shared, and
you don't need that info at all (just make the change in the nsproxy immediately)

Don't follow you here.

Quoted 8 lines

Basically the goal is to have a minimum number of nsproxies in the system without having to maintain a global hash table. So instead you assume that name space changes are infrequent. In the common case of clone without a name space change you just share the nsproxy of the parent. If there is a name space change of any kind you get a new one.

This won't get the absolute minimum number of nsproxies, but should be reasonably good without too much effort.

Ok. Then I maintain that the bitmap of changed namespaces seems unnecessary. Since you're likely sharing an nsproxy with your parent process, when you clone a new namespace you just want to immediately get a new nsproxy pointing to the new namespaces.

Anyway this seems simple enough to just code up. Simpler than continuing to talk about it :)

-serge

#24 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

Quoted 3 lines · Serge E. Hallyn

Ok. Then I maintain that the bitmap of changed namespaces seems unnecessary.

I didn't spell it out, but it's obviously to optimize cache footprint of clone(). I expect nsproxy to be eventually more than a cacheline and with a bitmap test you can avoid checking it all.

-Andi

#25 lore raw

Re: [PATCH 7/7] uts namespaces: Implement CLONE_NEWUTS flag

In reply to Serge E. Hallyn
Quoted 7 lines · Serge E. Hallyn

Ok. Then I maintain that the bitmap of changed namespaces seems unnecessary. Since you're likely sharing an nsproxy with your parent process, when you clone a new namespace you just want to immediately get a new nsproxy pointing to the new namespaces.

Anyway this seems simple enough to just code up. Simpler than continuing to talk about it :)

For testing please include both uts and the filesystem namespace in nsproxy.

That should give you at least one namespace that is frequently used.

Eric

#26 lore raw

cover uts namespaces: Introduction

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.

Changes since last submission:
As per Eric's suggestion, switched several uses of init_utsname
to (per-process namespace) utsname().
Implemented UTS namespace cloning through clone and unshare.

-serge