From: ebiederm@xmission.com (Eric W. Biederman)
To: Hubertus Franke <frankeh@watson.ibm.com>
Cc: linux-kernel@vger.kernel.org, vserver@list.linux-vserver.org,
Herbert Poetzl <herbert@13thfloor.at>,
"Serge E. Hallyn" <serue@us.ibm.com>,
Alan Cox <alan@lxorguk.ukuu.org.uk>,
Dave Hansen <haveblue@us.ibm.com>,
Arjan van de Ven <arjan@infradead.org>,
Suleiman Souhlal <ssouhlal@FreeBSD.org>,
Cedric Le Goater <clg@fr.ibm.com>,
Kyle Moffett <mrmacman_g4@mac.com>, Kirill Korotaev <dev@sw.ru>,
Greg <gkurz@fr.ibm.com>, Linus Torvalds <torvalds@osdl.org>,
Andrew Morton <akpm@osdl.org>, Greg KH <greg@kroah.com>,
Rik van Riel <riel@redhat.com>,
Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>,
Andrey Savochkin <saw@sawoct.com>,
Kirill Korotaev <dev@openvz.org>, Andi Kleen <ak@suse.de>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Jeff Garzik <jgarzik@pobox.com>,
Trond Myklebust <trond.myklebust@fys.uio.no>,
Jes Sorensen <jes@sgi.com>
Subject: Re: [RFC][PATCH 0/20] Multiple instances of the process id namespace
Date: Mon, 06 Feb 2006 14:56:42 -0700 [thread overview]
Message-ID: <m13biwi21x.fsf@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <43E7BA78.6030501@watson.ibm.com> (Hubertus Franke's message of "Mon, 06 Feb 2006 16:07:04 -0500")
Hubertus Franke <frankeh@watson.ibm.com> writes:
> Eric W. Biederman wrote:
>> Hubertus Franke <frankeh@watson.ibm.com> writes:
>>
>>
>>>find_task_by_pid( pid ) { return find_task_pidspace_by_pid ( current->pspace,
>>>pid ); }
>>>
>>>and then only deal with the exceptional cases using find_task_pidspace_by_pid
>>>when the pidspace is different..
>> That is a possibility. However I want to break some eggs so that the
>> users are updated appropriately. It is only by a strenuous act of
>> will that I don't change the type of pid,tgid,pgrp,session.
>> The size of the changes is much less important than being clear.
>> So for I want find_task_by_pid to be an absolute interface.
>>
>
> Fair enough, valid answers .. I checked the patch and it would only take
> 19/33 instances out .. so not the end of the world.
>
>>
>>>> Does the use of clone to create a new namespace instance look
>>>> like the sane approach?
>>>>
>>>
>>>At he surface it looks OK .. how does this work in a multi-threaded
>>>process which does cloen ( CLONE_NPSPACE ) ?
>>>We discussed at some point that exec is the right place to do it,
>>>but what I get is that because this is the container_init task
>>>we are OK !
>>>A bit clarification would help here ...
>> Well the parent doesn't much matter. But the child must have a fresh
>> start on all the groups of processes. As all other groupings known by
>> a pid are per pspace, so they can't cross that line.
>>
>
> Now, on which kernel does this compile/work ?
2.6.latest plus a few patches I have already sent off to Andrew.
> Do you have a "helper" program you can share that starts/exec's an
> app under a new container (uhmm, namespace). No point for us to
> actually write that..
Ok here is my little helper/tester program. Not beautiful but
it should work.
Eric
/* gcc -Wall -O2 -g chpid.c -o chpid */
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE_EXTENDED
#define _SVID_SOURCE
#define _GNU_SOURCE
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#include <sys/wait.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/mount.h>
#include <sys/vfs.h>
#include <fcntl.h>
#include <unistd.h>
#include <sched.h>
#include <stdarg.h>
#include <dirent.h>
#ifndef MNT_FORCE
#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
#endif /* MNT_FORCE */
#ifndef MNT_DETACH
#define MNT_DETACH 0x00000002 /* Just detach from the tree */
#endif /* MNT_DETACH */
#ifndef MNT_EXPIRE
#define MNT_EXPIRE 0x00000004 /* Mark for expiry */
#endif /* MNT_EXPIRE */
#ifndef MS_MOVE
#define MS_MOVE 8192
#endif
#ifndef MS_REC
#define MS_REC 16384
#endif
#ifndef CLONE_NPSPACE
#define CLONE_NPSPACE 0x04000000 /* New process space */
#endif
#ifndef PROC_SUPER_MAGIC
#define PROC_SUPER_MAGIC 0x9fa0
#endif /* PROC_SUPER_MAGIC */
struct user_desc;
static pid_t raw_clone(int flags, void *child_stack,
int *parent_tidptr, struct user_desc *newtls, int *child_tidptr)
{
return syscall(__NR_clone, flags, child_stack, parent_tidptr, newtls, child_tidptr);
}
static int raw_pivot_root(const char *new_root, const char *old_root)
{
return syscall(__NR_pivot_root, new_root, old_root);
}
static void (*my_exit)(int status) = exit;
static void die(char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vfprintf(stderr, fmt, ap);
va_end(ap);
fflush(stderr);
fflush(stdout);
my_exit(1);
}
static void *xmalloc(size_t size)
{
void *ptr;
ptr = malloc(size);
if (!ptr) die("malloc of %d bytes failed: %s\n", size, strerror(errno));
return ptr;
}
int main(int argc, char **argv, char **envp)
{
pid_t pid;
int status;
struct rlimit rlim;
int clone_flags;
char **cmd_argv, *shell_argv[2];
char *root = "/", *old = "/mnt";
int i;
int tty, tty_force;
tty = 0;
tty_force = 0;
clone_flags = CLONE_NPSPACE | SIGCHLD;
for (i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
if (strcmp(argv[i], "--") == 0) {
break;
}
else if (((argc - i) >= 2) && (strcmp(argv[i], "-r") == 0)) {
clone_flags |= CLONE_NEWNS;
root = argv[i + 1];
i++;
}
else if (((argc - i) >= 2) && (strcmp(argv[i], "-o") == 0)) {
old = argv[i + 1];
i++;
}
else if (strcmp(argv[i], "-n") == 0) {
clone_flags |= CLONE_NEWNS;
}
else if (strcmp(argv[i], "--tty") == 0) {
tty = 1;
}
else if (strcmp(argv[i], "--tty-force") == 0) {
tty = 1; tty_force = 1;
}
else {
die("Bad argument %s\n", argv[i]);
}
}
cmd_argv = argv + i;
if (cmd_argv[0] == NULL) {
cmd_argv = shell_argv;
shell_argv[0] = getenv("SHELL");
shell_argv[1] = NULL;
}
if (cmd_argv[0] == NULL) {
die("No command specified\n");
}
#if 1
fprintf(stderr, "cmd_argv: %s\n", cmd_argv[0]);
#endif
if (root[0] != '/') {
die("root path: '%s' not absolute\n", root);
}
if (old[0] != '/') {
die("old path: '%s' not absolute\n", old);
}
pid = raw_clone(clone_flags, NULL, NULL, NULL, NULL);
if (pid < 0) {
fprintf(stderr, "clone_failed: pid: %d %d:%s\n",
pid, errno, strerror(errno));
exit(2);
}
if (pid == 0) {
/* In the child */
int result;
my_exit = _exit;
/* FIXME allocate a process inside for controlling the new process space */
fprintf(stderr, "pid: %d, ppid: %d pgrp: %d sid: %d\n",
getpid(), getppid(), getpgid(0), getsid(0));
/* If CLONE_NPSPACE isn't implemented exit */
if (getpid() != 1)
die("CLONE_NPSPACE not implemented\n");
if (clone_flags & CLONE_NEWNS) {
struct statfs stfs;
if (strcmp(root, "/") != 0) {
char put_old[PATH_MAX];
result = snprintf(put_old, sizeof(put_old), "%s%s", root, old);
if (result >= sizeof(put_old))
die("path name to long\n");
if (result < 0)
die("snprintf failed: %d:%s\n",
errno, strerror(errno));
/* Ensure I have a mount point at the directory I want to export */
result = mount(root, root, NULL, MS_BIND | MS_REC, NULL);
if (result < 0)
die("bind of '%s' failed: %d:%s\n",
root, errno, strerror(errno));
/* Switch the mount points */
result = raw_pivot_root(root, put_old);
if (result < 0)
die("pivot_root('%s', '%s') failed: %d:%s\n",
root, put_old, errno, strerror(errno));
/* Unmount all of the old mounts */
result = umount2(old, MNT_DETACH);
if (result < 0)
die("umount2 of '%s' failed: %d:%s\n",
put_old, errno, strerror(errno));
}
result = statfs("/proc", &stfs);
if ((result == 0) && (stfs.f_type == PROC_SUPER_MAGIC)) {
/* Unmount and remount proc so it reflects the new pid space */
result = umount2("/proc", 0);
if (result < 0)
die("umount failed: %d:%s\n", errno, strerror(errno));
result = mount("proc", "/proc", "proc", 0, NULL);
if (result < 0)
die("mount failed: %d:%s\n",
errno, strerror(errno));
}
}
if (tty) {
pid_t sid, pgrp;
sid = setsid();
if (sid < 0)
die("setsid failed: %d:%s\n",
errno, strerror(errno));
fprintf(stderr, "pid: %d, ppid: %d pgrp: %d sid: %d\n",
getpid(), getppid(), getpgid(0), getsid(0));
result = ioctl(STDIN_FILENO, TIOCSCTTY, tty_force);
if (result < 0)
die("tiocsctty failed: %d:%s\n",
errno, strerror(errno));
pgrp = tcgetpgrp(STDIN_FILENO);
fprintf(stderr, "pgrp: %d\n", pgrp);
fprintf(stderr, "pid: %d, ppid: %d pgrp: %d sid: %d\n",
getpid(), getppid(), getpgid(0), getsid(0));
}
result = execve(cmd_argv[0], cmd_argv, envp);
die("execve of %s failed: %d:%s\n",
cmd_argv[0], errno, strerror(errno));
}
/* In the parent */
fprintf(stderr, "child pid: %d\n", pid);
pid = waitpid(pid, &status, 0);
fprintf(stderr, "pid: %d exited status: %d\n",
pid, status);
if (pid < 0) {
fprintf(stderr, "waitpid failed: %d %s\n",
errno, strerror(errno));
exit(9);
}
if (pid == 0) {
fprintf(stderr, "waitpid returned no pid!\n");
exit(10);
}
if (WIFEXITED(status)) {
fprintf(stderr, "pid: %d exited: %d\n",
pid, WEXITSTATUS(status));
}
if (WIFSIGNALED(status)) {
fprintf(stderr, "pid: %d exited with a uncaught signal: %d %s\n",
pid, WTERMSIG(status), strsignal(WTERMSIG(status)));
}
if (WIFSTOPPED(status)) {
fprintf(stderr, "pid: %d stopped with signal: %d\n",
pid, WSTOPSIG(status));
}
return 0;
}
next prev parent reply other threads:[~2006-02-06 22:00 UTC|newest]
Thread overview: 78+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-02-06 19:19 Eric W. Biederman
2006-02-06 19:22 ` [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id) Eric W. Biederman
2006-02-06 19:27 ` [RFC][PATCH 02/20] pspace: The parent process id of pid 1 is always 0 Eric W. Biederman
2006-02-06 19:29 ` [RFC][PATCH 03/20] pid: Introduce a generic helper to test for init Eric W. Biederman
2006-02-06 19:34 ` [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace Eric W. Biederman
2006-02-06 19:36 ` [RFC][PATCH 05/20] sched: Fixup the scheduler syscalls to deal with pspaces Eric W. Biederman
2006-02-06 19:39 ` [RFC][PATCH 06/20] cad_pid: Fixup the cad_pid users to assume it is in the initial process id namespace Eric W. Biederman
2006-02-06 19:41 ` [RFC][PATCH 07/20] tty: Update the tty layer to work with pspaces Eric W. Biederman
2006-02-06 19:44 ` [RFC][PATCH 08/20] vt: Update the virtual console to handle pspaces Eric W. Biederman
2006-02-06 19:46 ` [RFC][PATCH 09/20] ptrace: Update ptrace " Eric W. Biederman
2006-02-06 19:49 ` [RFC][PATCH 10/20] capabilities: Update the capabilities code to " Eric W. Biederman
2006-02-06 19:51 ` [RFC][PATCH 11/20] ioprio: Update ioprio " Eric W. Biederman
2006-02-06 19:54 ` [RFC][PATCH 12/20] fcntl: Update fcntl to work with pspaces Eric W. Biederman
2006-02-06 19:57 ` [RFC][PATCH 13/20] kthread: Update kthread " Eric W. Biederman
2006-02-06 19:59 ` [RFC][PATCH 14/20] mm: Update vmscan " Eric W. Biederman
2006-02-06 20:00 ` [RFC][PATCH 15/20] posix-timers: Update posix timers " Eric W. Biederman
2006-02-06 20:02 ` [PATCH 16/20] nfs: Don't use pids to track the lockd server process Eric W. Biederman
2006-02-06 20:03 ` [RFC][PATCH 17/20] usb: Fixup usb so it works with pspaces Eric W. Biederman
2006-02-06 20:05 ` [RFC][PATCH 18/20] posix-mqueue: Make mqueues work with pspspaces Eric W. Biederman
2006-02-06 20:07 ` [RFC][PATCH 19/20] pspace: Upcate the pid_max sysctl to work in a per pspace fashion Eric W. Biederman
2006-02-06 20:12 ` [RFC][PATCH 20/20] proc: Update /proc to support multiple pid spaces Eric W. Biederman
2006-02-10 20:40 ` Kirill Korotaev
2006-02-11 10:10 ` Eric W. Biederman
2006-02-06 20:41 ` [RFC][PATCH 17/20] usb: Fixup usb so it works with pspaces Serge E. Hallyn
2006-02-06 20:53 ` Eric W. Biederman
2006-02-07 16:41 ` [RFC][PATCH 04/20] pspace: Allow multiple instaces of the process id namespace William Lee Irwin III
2006-02-07 17:05 ` Eric W. Biederman
2006-02-10 20:30 ` Kirill Korotaev
2006-02-11 9:42 ` Eric W. Biederman
2006-02-11 10:11 ` Eric W. Biederman
2006-02-11 10:43 ` Eric W. Biederman
2006-02-13 8:53 ` Kirill Korotaev
2006-02-13 16:40 ` Dave Hansen
2006-02-11 11:03 ` Eric W. Biederman
2006-02-13 9:02 ` Kirill Korotaev
2006-02-13 21:31 ` Serge E. Hallyn
2006-02-13 23:41 ` Eric W. Biederman
2006-02-11 11:57 ` Eric W. Biederman
2006-02-13 9:22 ` Kirill Korotaev
2006-02-13 17:02 ` Serge E. Hallyn
2006-02-14 5:59 ` Eric W. Biederman
2006-02-14 5:54 ` Eric W. Biederman
2006-02-14 18:45 ` Dave Hansen
2006-02-15 12:07 ` Kirill Korotaev
2006-02-15 13:31 ` Herbert Poetzl
2006-02-16 13:44 ` Serge E. Hallyn
2006-02-20 9:27 ` Kirill Korotaev
2006-02-20 17:04 ` Herbert Poetzl
2006-02-21 16:29 ` Kirill Korotaev
2006-02-21 23:23 ` Herbert Poetzl
2006-02-20 11:29 ` Kirill Korotaev
2006-02-20 12:34 ` Herbert Poetzl
2006-02-20 14:11 ` Kirill Korotaev
2006-02-20 15:08 ` Herbert Poetzl
2006-03-01 22:06 ` Cedric Le Goater
2006-02-15 18:40 ` Eric W. Biederman
2006-02-06 19:56 ` [RFC][PATCH 03/20] pid: Introduce a generic helper to test for init Dave Hansen
2006-02-06 20:22 ` Eric W. Biederman
2006-02-07 15:08 ` Geert Uytterhoeven
2006-02-07 15:17 ` Eric W. Biederman
2006-02-06 19:54 ` [RFC][PATCH 01/20] pid: Intoduce the concept of a wid (wait id) Serge E. Hallyn
2006-02-06 20:23 ` Eric W. Biederman
2006-02-07 17:39 ` Jeff Dike
2006-02-07 18:32 ` Eric W. Biederman
2006-02-10 18:51 ` Kirill Korotaev
2006-02-11 9:25 ` Eric W. Biederman
2006-02-13 8:43 ` Kirill Korotaev
2006-02-14 0:04 ` Eric W. Biederman
2006-02-06 20:40 ` [RFC][PATCH 0/20] Multiple instances of the process id namespace Hubertus Franke
2006-02-06 20:51 ` Eric W. Biederman
2006-02-06 21:07 ` Hubertus Franke
2006-02-06 21:56 ` Eric W. Biederman [this message]
2006-02-07 0:48 ` Dave Hansen
2006-02-07 5:14 ` Eric W. Biederman
2006-02-07 9:33 ` Andi Kleen
2006-02-08 4:19 ` Randy.Dunlap
2006-02-08 4:28 ` Eric W. Biederman
2006-02-08 4:51 ` Randy.Dunlap
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=m13biwi21x.fsf@ebiederm.dsl.xmission.com \
--to=ebiederm@xmission.com \
--cc=ak@suse.de \
--cc=akpm@osdl.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arjan@infradead.org \
--cc=benh@kernel.crashing.org \
--cc=clg@fr.ibm.com \
--cc=dev@openvz.org \
--cc=dev@sw.ru \
--cc=frankeh@watson.ibm.com \
--cc=gkurz@fr.ibm.com \
--cc=greg@kroah.com \
--cc=haveblue@us.ibm.com \
--cc=herbert@13thfloor.at \
--cc=jes@sgi.com \
--cc=jgarzik@pobox.com \
--cc=kuznet@ms2.inr.ac.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=mrmacman_g4@mac.com \
--cc=riel@redhat.com \
--cc=saw@sawoct.com \
--cc=serue@us.ibm.com \
--cc=ssouhlal@FreeBSD.org \
--cc=torvalds@osdl.org \
--cc=trond.myklebust@fys.uio.no \
--cc=vserver@list.linux-vserver.org \
/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
Powered by JetHome