From: Gowrishankar M <gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: Containers
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>
Cc: Dave <dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>,
Eric <ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org>,
Sukadev
<sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>,
Balbir <balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Subject: [PATCH 1/5] pid: add new iterative macros to list processes in a namespace
Date: Thu, 18 Dec 2008 22:12:29 +0530 [thread overview]
Message-ID: <1229618553-6348-2-git-send-email-gowrishankar.m@linux.vnet.ibm.com> (raw)
In-Reply-To: <1229618553-6348-1-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
From: Gowrishankar M <gomuthuk-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Below patch addresses a common solution for any place where a process
should be checked if it is associated to caller namespace. At present,
we use 'task_pid_vnr(t) > 0' to further proceed with task 't' in current
namespace.
To avoid applying this check in every userspace code related to PID namespace,
this patch provides two new iterative macros;for_each_process_in_ns and
do_each_thread_in_ns.
Signed-off-by: Gowrishankar M <gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
include/linux/pid.h | 1 +
include/linux/sched.h | 12 ++++++++++++
kernel/pid.c | 17 +++++++++++++++++
3 files changed, 30 insertions(+), 0 deletions(-)
diff --git a/include/linux/pid.h b/include/linux/pid.h
index d7e98ff..1c6b24f 100644
--- a/include/linux/pid.h
+++ b/include/linux/pid.h
@@ -117,6 +117,7 @@ extern struct pid *find_vpid(int nr);
*/
extern struct pid *find_get_pid(int nr);
extern struct pid *find_ge_pid(int nr, struct pid_namespace *);
+extern struct pid *find_ge_tgid(int nr, struct pid_namespace *);
int next_pidmap(struct pid_namespace *pid_ns, int last);
extern struct pid *alloc_pid(struct pid_namespace *ns);
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 2e46189..bdd9f0d 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1919,16 +1919,28 @@ static inline unsigned long wait_task_inactive(struct task_struct *p,
#define next_task(p) list_entry(rcu_dereference((p)->tasks.next), struct task_struct, tasks)
+#define next_task_in_ns(p, ns) \
+ pid_task(find_ge_tgid(task_pid_nr_ns(p, ns) + 1, ns), PIDTYPE_PID)
+
#define for_each_process(p) \
for (p = &init_task ; (p = next_task(p)) != &init_task ; )
+#define for_each_process_in_ns(p, ns) \
+ for (p = find_task_by_pid_ns(1, ns) ; p != NULL ; \
+ p = next_task_in_ns(p, ns))
+
/*
* Careful: do_each_thread/while_each_thread is a double loop so
* 'break' will not work as expected - use goto instead.
+ * same applies to do_each_thread_in_ns.
*/
#define do_each_thread(g, t) \
for (g = t = &init_task ; (g = t = next_task(g)) != &init_task ; ) do
+#define do_each_thread_in_ns(g, t, ns) \
+ for (g = t = find_task_by_pid_ns(1, ns) ; g != NULL ; \
+ (g = t = next_task_in_ns(g, ns))) do
+
#define while_each_thread(g, t) \
while ((t = next_thread(t)) != g)
diff --git a/kernel/pid.c b/kernel/pid.c
index 064e76a..15f707a 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -493,6 +493,23 @@ struct pid *find_ge_pid(int nr, struct pid_namespace *ns)
return pid;
}
+struct pid *find_ge_tgid(int nr, struct pid_namespace *ns)
+{
+ struct pid *pid;
+ struct task_struct *task;
+
+retry:
+ pid = find_ge_pid(nr, ns);
+ if (pid) {
+ task = pid_task(pid, PIDTYPE_PID);
+ if (!task || !has_group_leader_pid(task)) {
+ nr += 1;
+ goto retry;
+ }
+ }
+ return pid;
+}
+
/*
* The pid hash table is scaled according to the amount of memory in the
* machine. From a minimum of 16 slots up to 4096 slots at one gigabyte or
--
1.5.5.1
next prev parent reply other threads:[~2008-12-18 16:42 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-12-18 16:42 pid: improved namespaced iteration over processes list (v2) Gowrishankar M
[not found] ` <1229618553-6348-1-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-12-18 16:42 ` Gowrishankar M [this message]
[not found] ` <1229618553-6348-2-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-12-18 17:45 ` [PATCH 1/5] pid: add new iterative macros to list processes in a namespace Eric W. Biederman
2008-12-18 16:42 ` [PATCH 2/5] pid: use namespaced iteration on processes while using sysrq Gowrishankar M
[not found] ` <1229618553-6348-3-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-12-18 16:58 ` Dave Hansen
2008-12-18 17:12 ` Serge E. Hallyn
2008-12-18 17:31 ` Eric W. Biederman
2008-12-18 16:42 ` [PATCH 3/5] pid: use namespaced iteration on processes while setting capability Gowrishankar M
[not found] ` <1229618553-6348-4-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-12-18 17:04 ` Serge E. Hallyn
2008-12-18 17:35 ` Eric W. Biederman
2008-12-18 16:42 ` [PATCH 4/5] pid: use namespaced iteration on processes while sending signal to all Gowrishankar M
[not found] ` <1229618553-6348-5-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-12-18 17:04 ` Serge E. Hallyn
2008-12-18 17:10 ` Dave Hansen
2008-12-18 17:32 ` Serge E. Hallyn
2008-12-18 16:42 ` [PATCH 5/5] pid: use namespaced iteration on processes while managing priority Gowrishankar M
[not found] ` <1229618553-6348-6-git-send-email-gowrishankar.m-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2008-12-18 17:05 ` Serge E. Hallyn
[not found] ` <20081218170509.GC13188-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-12-18 17:46 ` Eric W. Biederman
2008-12-18 17:38 ` Eric W. Biederman
[not found] ` <m1d4fp8ju3.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-12-18 18:13 ` Serge E. Hallyn
[not found] ` <20081218181317.GA14409-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2008-12-18 18:54 ` Eric W. Biederman
[not found] ` <m1wsdx71r7.fsf-B27657KtZYmhTnVgQlOflh2eb7JE58TQ@public.gmane.org>
2008-12-18 19:23 ` Serge E. Hallyn
2008-12-19 4:30 ` Matt Helsley
2008-12-19 4:37 ` Matt Helsley
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=1229618553-6348-2-git-send-email-gowrishankar.m@linux.vnet.ibm.com \
--to=gowrishankar.m-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=balbir-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=dave-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org \
--cc=ebiederm-aS9lmoZGLiVWk0Htik3J/w@public.gmane.org \
--cc=sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@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