You might have more than one process which is restored which wants the
same pid.  A container is a group of processes which share namespace.
In this case, pid namespace.  The idea for now is that everything is
in "container 0" unless otherwise specified.

This /proc file allows a task to set the container id of any of its
children.

This is mostly a hack for now, to demonstrate what can be done.

---

 linux-2.6.14-rc5-dave/fs/proc/base.c        |   58 ++++++++++++++++++++++++++++
 linux-2.6.14-rc5-dave/include/linux/sched.h |    2 
 2 files changed, 60 insertions(+)

diff -puN fs/proc/base.c~C1-proc-interface-to-child_container_id fs/proc/base.c
--- linux-2.6.14-rc5/fs/proc/base.c~C1-proc-interface-to-child_container_id     
2005-10-24 17:55:40.000000000 +0200
+++ linux-2.6.14-rc5-dave/fs/proc/base.c        2005-10-24 17:55:40.000000000 
+0200
@@ -164,6 +164,8 @@ enum pid_directory_inos {
 #endif
        PROC_TID_OOM_SCORE,
        PROC_TID_OOM_ADJUST,
+       PROC_TID_CHILD_CONTAINER_ID,
+       PROC_TGID_CHILD_CONTAINER_ID,
 
        /* Add new entries before this */
        PROC_TID_FD_DIR = 0x8000,       /* 0x8000-0xffff */
@@ -216,6 +218,7 @@ static struct pid_entry tgid_base_stuff[
 #endif
        E(PROC_TGID_OOM_SCORE, "oom_score",S_IFREG|S_IRUGO),
        E(PROC_TGID_OOM_ADJUST,"oom_adj", S_IFREG|S_IRUGO|S_IWUSR),
+       E(PROC_TGID_CHILD_CONTAINER_ID, "child_container_id", 
S_IFREG|S_IRUGO|S_IWUSR),
 #ifdef CONFIG_AUDITSYSCALL
        E(PROC_TGID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
@@ -258,6 +261,7 @@ static struct pid_entry tid_base_stuff[]
 #endif
        E(PROC_TID_OOM_SCORE,  "oom_score",S_IFREG|S_IRUGO),
        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),
 #ifdef CONFIG_AUDITSYSCALL
        E(PROC_TID_LOGINUID, "loginuid", S_IFREG|S_IWUSR|S_IRUGO),
 #endif
@@ -910,6 +914,56 @@ static struct file_operations proc_oom_a
        .write          = oom_adjust_write,
 };
 
+static ssize_t proc_child_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 child_container_id = task->child_container_id;
+       loff_t __ppos = *ppos;
+
+       len = sprintf(buffer, "%i\n", child_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_child_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 child_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;
+       child_container_id = simple_strtol(buffer, &end, 0);
+       if (child_container_id < 0 || child_container_id > MAX_CONTAINER_ID)
+               return -EINVAL;
+       if (*end == '\n')
+               end++;
+       task->child_container_id = child_container_id;
+       if (end - buffer == 0)
+               return -EIO;
+       return end - buffer;
+}
+
+static struct file_operations proc_child_container_id_operations = {
+       .read           = proc_child_container_id_read,
+       .write          = proc_child_container_id_write,
+};
+
 static struct inode_operations proc_mem_inode_operations = {
        .permission     = proc_permission,
 };
@@ -1748,6 +1802,10 @@ static struct dentry *proc_pident_lookup
                case PROC_TGID_OOM_ADJUST:
                        inode->i_fop = &proc_oom_adjust_operations;
                        break;
+               case PROC_TID_CHILD_CONTAINER_ID:
+               case PROC_TGID_CHILD_CONTAINER_ID:
+                       inode->i_fop = &proc_child_container_id_operations;
+                       break;
 #ifdef CONFIG_AUDITSYSCALL
                case PROC_TID_LOGINUID:
                case PROC_TGID_LOGINUID:
diff -puN include/linux/sched.h~C1-proc-interface-to-child_container_id 
include/linux/sched.h
--- 
linux-2.6.14-rc5/include/linux/sched.h~C1-proc-interface-to-child_container_id  
    2005-10-24 17:55:40.000000000 +0200
+++ linux-2.6.14-rc5-dave/include/linux/sched.h 2005-10-24 17:55:40.000000000 
+0200
@@ -726,6 +726,8 @@ struct task_struct {
 /* process credentials */
        uid_t uid,euid,suid,fsuid;
        gid_t gid,egid,sgid,fsgid;
+#define MAX_CONTAINER_ID 1024
+       int child_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

Reply via email to