public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Sam Vilain <sam.vilain@catalyst.net.nz>
To: ebiederm@xmission.com (Eric W. Biederman)
Cc: linux-kernel@vger.kernel.org,
	"Serge E. Hallyn" <serue@us.ibm.com>,
	herbert@13thfloor.at, dev@sw.ru, devel@openvz.org,
	sam@vilain.net, xemul@sw.ru, Dave Hansen <haveblue@us.ibm.com>,
	Andrew Morton <akpm@osdl.org>, Cedric Le Goater <clg@fr.ibm.com>,
	Alan Cox <alan@lxorguk.ukuu.org.uk>
Subject: [PATCH 3/3] proc: make UTS-related sysctls utsns aware
Date: Tue, 23 May 2006 13:23:01 +1200	[thread overview]
Message-ID: <20060523012301.13531.12776.stgit@localhost.localdomain> (raw)
In-Reply-To: <20060523012300.13531.96685.stgit@localhost.localdomain>

From: Sam Vilain <sam.vilain@catalyst.net.nz>

Add a new function proc_do_utsns_string, that derives the pointer
into the uts_namespace->name structure, currently based on the
filename of the dentry in /proc, and calls _proc_do_string()
---
RFC only - not tested yet.  builds, though.

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

diff --git a/kernel/sysctl.c b/kernel/sysctl.c
index cf053fc..37dc17f 100644
--- a/kernel/sysctl.c
+++ b/kernel/sysctl.c
@@ -141,8 +141,13 @@ #endif
 
 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
 		       ctl_table *, void **);
+#ifndef CONFIG_UTS_NS
 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
 		  void __user *buffer, size_t *lenp, loff_t *ppos);
+#else
+static int proc_do_utsns_string(ctl_table *table, int write, struct file *filp,
+		  void __user *buffer, size_t *lenp, loff_t *ppos);
+#endif
 
 static ctl_table root_table[];
 static struct ctl_table_header root_table_header =
@@ -238,6 +243,7 @@ #endif
 };
 
 static ctl_table kern_table[] = {
+#ifndef CONFIG_UTS_NS
 	{
 		.ctl_name	= KERN_OSTYPE,
 		.procname	= "ostype",
@@ -283,6 +289,54 @@ static ctl_table kern_table[] = {
 		.proc_handler	= &proc_do_uts_string,
 		.strategy	= &sysctl_string,
 	},
+#else  /* !CONFIG_UTS_NS */
+	{
+		.ctl_name	= KERN_OSTYPE,
+		.procname	= "ostype",
+		.data		= NULL,
+		/* could maybe use __NEW_UTS_LEN here? */
+		.maxlen		= sizeof(current->nsproxy->uts_ns->name.sysname),
+		.mode		= 0444,
+		.proc_handler	= &proc_do_utsns_string,
+		.strategy	= &sysctl_string,
+	},
+	{
+		.ctl_name	= KERN_OSRELEASE,
+		.procname	= "osrelease",
+		.data		= NULL,
+		.maxlen		= sizeof(current->nsproxy->uts_ns->name.release),
+		.mode		= 0444,
+		.proc_handler	= &proc_do_utsns_string,
+		.strategy	= &sysctl_string,
+	},
+	{
+		.ctl_name	= KERN_VERSION,
+		.procname	= "version",
+		.data		= NULL,
+		.maxlen		= sizeof(current->nsproxy->uts_ns->name.version),
+		.mode		= 0444,
+		.proc_handler	= &proc_do_utsns_string,
+		.strategy	= &sysctl_string,
+	},
+	{
+		.ctl_name	= KERN_NODENAME,
+		.procname	= "hostname",
+		.data		= NULL,
+		.maxlen		= sizeof(current->nsproxy->uts_ns->name.nodename),
+		.mode		= 0644,
+		.proc_handler	= &proc_do_utsns_string,
+		.strategy	= &sysctl_string,
+	},
+	{
+		.ctl_name	= KERN_DOMAINNAME,
+		.procname	= "domainname",
+		.data		= NULL,
+		.maxlen		= sizeof(current->nsproxy->uts_ns->name.domainname),
+		.mode		= 0644,
+		.proc_handler	= &proc_do_utsns_string,
+		.strategy	= &sysctl_string,
+	},
+#endif /* !CONFIG_UTS_NS */
 	{
 		.ctl_name	= KERN_PANIC,
 		.procname	= "panic",
@@ -1684,6 +1738,7 @@ int proc_dostring(ctl_table *table, int 
  *	to observe. Should this be in kernel/sys.c ????
  */
  
+#ifndef CONFIG_UTS_NS
 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
 		  void __user *buffer, size_t *lenp, loff_t *ppos)
 {
@@ -1700,6 +1755,55 @@ static int proc_do_uts_string(ctl_table 
 	}
 	return r;
 }
+#else /* !CONFIG_UTS_NS */
+static int proc_do_utsns_string(ctl_table *table, int write, struct file *filp,
+		  void __user *buffer, size_t *lenp, loff_t *ppos)
+{
+	int r;
+	struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
+	char* which;
+
+	/* map the filename to the pointer.  perhaps it would be better
+	   to put struct offset pointers in table->data ? */
+	switch (filp->f_dentry->d_name.name[3]) {
+		case 'y':  /* ostYpe */
+			which = uts_ns->name.sysname;
+			break;
+		case 't':  /* hosTname */
+			which = uts_ns->name.nodename;
+			break;
+		case 'e':  /* osrElease */
+			which = uts_ns->name.release;
+			break;
+		case 's':  /* verSion */
+			which = uts_ns->name.version;
+			break;
+		case 'x':  /* XXX - unreachable */
+			which = uts_ns->name.machine;
+			break;
+		case 'a':  /* domAinname */
+			which = uts_ns->name.domainname;
+			break;
+		default:
+			printk("procfs: impossible uts part '%s'",
+			       (char*)filp->f_dentry->d_name.name);
+			r = -EINVAL;
+			goto out;
+	}
+
+	if (!write) {
+		down_read(&uts_sem);
+		r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
+		up_read(&uts_sem);
+	} else {
+		down_write(&uts_sem);
+		r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
+		up_write(&uts_sem);
+	}
+ out:
+	return r;
+}
+#endif /* !CONFIG_UTS_NS */
 
 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
 				 int *valp,


  reply	other threads:[~2006-05-23  1:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-23  1:23 [PATCH 1/3] proc: sysctl: rename proc_doutsstring to proc_do_uts_string Sam Vilain
2006-05-23  1:23 ` Sam Vilain [this message]
2006-05-24 15:54   ` [PATCH 3/3] proc: make UTS-related sysctls utsns aware Andrew Morton
2006-05-25  3:51     ` Sam Vilain
2006-05-24 18:02   ` Dave Hansen
2006-05-25  4:01     ` Sam Vilain
2006-05-23  1:23 ` [PATCH 2/3] proc: sysctl: add _proc_do_string helper Sam Vilain

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20060523012301.13531.12776.stgit@localhost.localdomain \
    --to=sam.vilain@catalyst.net.nz \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=clg@fr.ibm.com \
    --cc=dev@sw.ru \
    --cc=devel@openvz.org \
    --cc=ebiederm@xmission.com \
    --cc=haveblue@us.ibm.com \
    --cc=herbert@13thfloor.at \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sam@vilain.net \
    --cc=serue@us.ibm.com \
    --cc=xemul@sw.ru \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox