From: "Serge E. Hallyn" <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
To: Linux Containers <containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.org>
Subject: [PATCH 2/2] sys_restore: set the pid number
Date: Fri, 25 Jul 2008 17:59:35 -0500 [thread overview]
Message-ID: <20080725225935.GB28764@us.ibm.com> (raw)
In-Reply-To: <20080725225655.GA28276-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
Set the pid number for a restored task. This is purely a toy, as it
only sets the pidnr in the lowest level pid namespace.
Signed-off-by: Serge Hallyn <serue-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
---
kernel/fork.c | 5 +++++
kernel/pid.c | 19 +++++++++++++++++++
2 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/kernel/fork.c b/kernel/fork.c
index 0e43f69..41c46d2 100644
--- a/kernel/fork.c
+++ b/kernel/fork.c
@@ -1685,6 +1685,8 @@ int unshare_files(struct files_struct **displaced)
char buf[CKPT_SIZE];
char exe_filename[PAGE_SIZE];
+extern int choose_pidmap(struct pid *pid, int new);
+
/*
* userspace will already have made us a new pidns
*/
@@ -1717,6 +1719,9 @@ long do_restore(unsigned int fd,
if (nr_scanned != 2)
return -EINVAL;
+ ret = choose_pidmap(task_pid(current), pid);
+ if (!ret)
+ return -EAGAIN;
ret = do_execve(exe_filename, argv, envp, regs);
out:
diff --git a/kernel/pid.c b/kernel/pid.c
index 30bd5d4..88a5e2a 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -122,6 +122,25 @@ static void free_pidmap(struct upid *upid)
atomic_inc(&map->nr_free);
}
+int choose_pidmap(struct pid *pid, int new)
+{
+ struct pidmap *map;
+ int level = pid->level;
+ struct upid *upid = &pid->numbers[level];
+ struct pid_namespace *pid_ns = upid->ns;
+ int old = upid->nr;
+
+ map = &pid_ns->pidmap[new/BITS_PER_PAGE];
+ if (!test_and_set_bit(new, map->page)) {
+ map = &pid_ns->pidmap[old/BITS_PER_PAGE];
+ clear_bit(old, map->page);
+ upid->nr = new;
+ return 1;
+ }
+
+ return 0;
+}
+
static int alloc_pidmap(struct pid_namespace *pid_ns)
{
int i, offset, max_scan, pid, last = pid_ns->last_pid;
--
1.5.4.3
next prev parent reply other threads:[~2008-07-25 22:59 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-07-25 22:56 [PATCH 0/2] sys_restore prototype Serge E. Hallyn
[not found] ` <20080725225655.GA28276-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-25 22:58 ` [PATCH 1/2] introduce sys_restore Serge E. Hallyn
2008-07-25 22:59 ` Serge E. Hallyn [this message]
[not found] ` <20080725225935.GB28764-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-07-27 2:33 ` [Devel] [PATCH 2/2] sys_restore: set the pid number Pavel Emelyanov
[not found] ` <488BDE7D.7090602-GEFAQzZX7r8dnm+yROfE0A@public.gmane.org>
2008-07-29 18:31 ` Serge E. Hallyn
2008-07-28 22:00 ` [PATCH 0/2] sys_restore prototype Eric W. Biederman
[not found] ` <m1sktthdp3.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-07-29 18:27 ` Serge E. Hallyn
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=20080725225935.GB28764@us.ibm.com \
--to=serue-r/jw6+rmf7hqt0dzr+alfa@public.gmane.org \
--cc=containers-qjLDD68F18O7TbgM5vRIOg@public.gmane.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