[Vserver] [RFC][PATCH 8/9] proc interface to tsk->container_id

From: Dave Hansen <haveblue_at_us.ibm.com>
Date: Mon 24 Oct 2005 - 17:21:30 BST
Message-Id: <20051024162130.49BACD6B@localhost>

We allow setting this for now, but it's mostly just for debugging
at this point.

---
 linux-2.6.14-rc5-dave/fs/proc/base.c        |   56 ++++++++++++++++++++++++++++
 linux-2.6.14-rc5-dave/include/linux/sched.h |    1 
 2 files changed, 57 insertions(+)
diff -puN fs/proc/base.c~C3-proc-interface-to-container_id fs/proc/base.c
--- linux-2.6.14-rc5/fs/proc/base.c~C3-proc-interface-to-container_id	2005-10-24 17:55:41.000000000 +0200
+++ linux-2.6.14-rc5-dave/fs/proc/base.c	2005-10-24 17:55:41.000000000 +0200
@@ -165,9 +165,11 @@ enum pid_directory_inos {
 	PROC_TID_OOM_SCORE,
 	PROC_TID_OOM_ADJUST,
 	PROC_TID_CHILD_CONTAINER_ID,
+	PROC_TID_CHILD_CONTAINER_ID,
 	PROC_TGID_CHILD_CONTAINER_ID,
 	PROC_TGID_VPID,
 	PROC_TID_VPID,
+	PROC_CONTAINER_ID,
 
 	/* Add new entries before this */
 	PROC_TID_FD_DIR = 0x8000,	/* 0x8000-0xffff */
@@ -266,6 +268,7 @@ static struct pid_entry tid_base_stuff[]
 	E(PROC_TID_OOM_ADJUST, "oom_adj", S_IFREG|S_IRUGO|S_IWUSR),
 	E(PROC_TID_CHILD_CONTAINER_ID, "child_container_id", S_IFREG|S_IRUGO|S_IWUSR),
 	E(PROC_TID_VPID,       "vpid", S_IFREG|S_IRUGO|S_IWUSR),
+	E(PROC_CONTAINER_ID, "container_id", S_IFREG|S_IRUGO|S_IWUSR),
 #ifdef CONFIG_AUDITSYSCALL
 	E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
@@ -1019,6 +1022,56 @@ static struct file_operations proc_vpid_
 	.write		= proc_vpid_write,
 };
 
+static ssize_t proc_container_id_read(struct file *file, char __user *buf,
+				size_t count, loff_t *ppos)
+{
+	struct task_struct *task = proc_task(file->f_dentry->d_inode);
+	char buffer[8];
+	size_t len;
+	int container_id = task->container_id;
+	loff_t __ppos = *ppos;
+
+	len = sprintf(buffer, "%i\n", container_id);
+	if (__ppos >= len)
+		return 0;
+	if (count > len-__ppos)
+		count = len-__ppos;
+	if (copy_to_user(buf, buffer + __ppos, count))
+		return -EFAULT;
+	*ppos = __ppos + count;
+	return count;
+}
+
+static ssize_t proc_container_id_write(struct file *file, const char __user *buf,
+				size_t count, loff_t *ppos)
+{
+	struct task_struct *task = proc_task(file->f_dentry->d_inode);
+	char buffer[8], *end;
+	int container_id;
+
+	if (!capable(CAP_SYS_RESOURCE))
+		return -EPERM;
+	memset(buffer, 0, 8);
+	if (count > 6)
+		count = 6;
+	if (copy_from_user(buffer, buf, count))
+		return -EFAULT;
+	container_id = simple_strtol(buffer, &end, 0);
+	if (container_id < 0 || container_id > MAX_CONTAINER_ID)
+		return -EINVAL;
+	if (*end == '\n')
+		end++;
+	task->container_id = container_id;
+	if (end - buffer == 0)
+		return -EIO;
+	return end - buffer;
+}
+
+static struct file_operations proc_container_id_operations = {
+	.read		= proc_container_id_read,
+	.write		= proc_container_id_write,
+};
+
 static struct inode_operations proc_mem_inode_operations = {
 	.permission	= proc_permission,
 };
@@ -1865,6 +1918,9 @@ static struct dentry *proc_pident_lookup
 		case PROC_TGID_VPID:
 			inode->i_fop = &proc_vpid_operations;
 			break;
+		case PROC_CONTAINER_ID:
+			inode->i_fop = &proc_container_id_operations;
+			break;
 #ifdef CONFIG_AUDITSYSCALL
 		case PROC_TID_LOGINUID:
 		case PROC_TGID_LOGINUID:
diff -puN include/linux/sched.h~C3-proc-interface-to-container_id include/linux/sched.h
--- linux-2.6.14-rc5/include/linux/sched.h~C3-proc-interface-to-container_id	2005-10-24 17:55:41.000000000 +0200
+++ linux-2.6.14-rc5-dave/include/linux/sched.h	2005-10-24 17:55:41.000000000 +0200
@@ -729,6 +729,7 @@ struct task_struct {
 #define MAX_CONTAINER_ID 1024
 	int child_container_id;
 	int vpid;
+	int container_id;
 	struct group_info *group_info;
 	kernel_cap_t   cap_effective, cap_inheritable, cap_permitted;
 	unsigned keep_capabilities:1;
_
_______________________________________________
Vserver mailing list
Vserver@list.linux-vserver.org
http://list.linux-vserver.org/mailman/listinfo/vserver
Received on Mon Oct 24 17:27:12 2005
[Next/Previous Months] [Main vserver Project Homepage] [Howto Subscribe/Unsubscribe] [Paul Sladen's vserver stuff]
Generated on Mon 24 Oct 2005 - 17:27:17 BST by hypermail 2.1.8