[PATCH 1/2] pid_ns: move destroy_pid_namespace() into workqueue context

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Oleg Nesterov
Date: Sunday, June 20, 2010 - 11:06 am

A separate patch to simplify the review of the next change.

Move destroy_pid_namespace() into workqueue context. This allows us to do
mntput() from free_pid_ns() paths, see the next patch.

Add the new member, "struct work_struct destroy" into struct pid_namespace
and change free_pid_ns() to call destroy_pid_namespace() via schedule_work().

The patch looks a bit complicated because it also moves copy_pid_ns() up.

Signed-off-by: Oleg Nesterov <oleg@redhat.com>
---

 include/linux/pid_namespace.h |    1 +
 kernel/pid_namespace.c        |   25 +++++++++++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)

--- 35-rc3/include/linux/pid_namespace.h~PNS_5_DESTROY_FROM_WQ	2009-04-06 00:03:41.000000000 +0200
+++ 35-rc3/include/linux/pid_namespace.h	2010-06-20 17:47:05.000000000 +0200
@@ -24,6 +24,7 @@ struct pid_namespace {
 	struct kmem_cache *pid_cachep;
 	unsigned int level;
 	struct pid_namespace *parent;
+	struct work_struct destroy;
 #ifdef CONFIG_PROC_FS
 	struct vfsmount *proc_mnt;
 #endif
--- 35-rc3/kernel/pid_namespace.c~PNS_5_DESTROY_FROM_WQ	2010-06-19 19:21:42.000000000 +0200
+++ 35-rc3/kernel/pid_namespace.c	2010-06-20 18:36:00.000000000 +0200
@@ -114,6 +114,16 @@ out:
 	return ERR_PTR(err);
 }
 
+struct pid_namespace *copy_pid_ns(unsigned long flags,
+					struct pid_namespace *old_ns)
+{
+	if (!(flags & CLONE_NEWPID))
+		return get_pid_ns(old_ns);
+	if (flags & (CLONE_THREAD|CLONE_PARENT))
+		return ERR_PTR(-EINVAL);
+	return create_pid_namespace(old_ns);
+}
+
 static void destroy_pid_namespace(struct pid_namespace *ns)
 {
 	int i;
@@ -123,13 +133,11 @@ static void destroy_pid_namespace(struct
 	kmem_cache_free(pid_ns_cachep, ns);
 }
 
-struct pid_namespace *copy_pid_ns(unsigned long flags, struct pid_namespace *old_ns)
+static void destroy_pid_namespace_work(struct work_struct *work)
 {
-	if (!(flags & CLONE_NEWPID))
-		return get_pid_ns(old_ns);
-	if (flags & (CLONE_THREAD|CLONE_PARENT))
-		return ERR_PTR(-EINVAL);
-	return create_pid_namespace(old_ns);
+	struct pid_namespace *ns =
+			container_of(work, struct pid_namespace, destroy);
+	destroy_pid_namespace(ns);
 }
 
 void free_pid_ns(struct kref *kref)
@@ -137,9 +145,10 @@ void free_pid_ns(struct kref *kref)
 	struct pid_namespace *ns, *parent;
 
 	ns = container_of(kref, struct pid_namespace, kref);
-
 	parent = ns->parent;
-	destroy_pid_namespace(ns);
+
+	INIT_WORK(&ns->destroy, destroy_pid_namespace_work);
+	schedule_work(&ns->destroy);
 
 	if (parent != NULL)
 		put_pid_ns(parent);

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 0/4] pid_ns_prepare_proc/unshare cleanups, Oleg Nesterov, (Sat Jun 19, 12:08 pm)
[PATCH 2/4] procfs: kill the global proc_mnt variable, Oleg Nesterov, (Sat Jun 19, 12:10 pm)
[PATCH 0/6] Unshare support for the pid namespace., Eric W. Biederman, (Sun Jun 20, 1:42 am)
[PATCH 1/6] pid: Remove the child_reaper special case in ..., Eric W. Biederman, (Sun Jun 20, 1:44 am)
[PATCH 2/6] pidns: Call pid_ns_prepare_proc from create_pi ..., Eric W. Biederman, (Sun Jun 20, 1:45 am)
[PATCH 3/6] procfs: kill the global proc_mnt variable, Eric W. Biederman, (Sun Jun 20, 1:45 am)
[PATCH 4/6] pidns: Don't allow new pids after the namespac ..., Eric W. Biederman, (Sun Jun 20, 1:47 am)
[PATCH 5/6] pidns: Use task_active_pid_ns where appropriate, Eric W. Biederman, (Sun Jun 20, 1:48 am)
[PATCH 6/6] pidns: Support unsharing the pid namespace., Eric W. Biederman, (Sun Jun 20, 1:49 am)
Re: [PATCH 0/6] Unshare support for the pid namespace., Oleg Nesterov, (Sun Jun 20, 11:03 am)
[PATCH 0/2] pid_ns_release_proc() fixes, Oleg Nesterov, (Sun Jun 20, 11:05 am)
[PATCH 1/2] pid_ns: move destroy_pid_namespace() into work ..., Oleg Nesterov, (Sun Jun 20, 11:06 am)
Re: [PATCH 0/6] Unshare support for the pid namespace., Eric W. Biederman, (Sun Jun 20, 2:00 pm)
Re: [PATCH 0/6] Unshare support for the pid namespace., Oleg Nesterov, (Sun Jun 20, 2:48 pm)
Re: [PATCH 0/6] Unshare support for the pid namespace., Oleg Nesterov, (Sun Jun 20, 2:56 pm)
Re: [PATCH 6/6] pidns: Support unsharing the pid namespace., Eric W. Biederman, (Sun Jun 20, 6:53 pm)
Re: [PATCH 1/1] pid_ns: move pid_ns_release_proc() from pr ..., Sukadev Bhattiprolu, (Wed Jun 23, 11:36 pm)
Re: [PATCH 1/1] pid_ns: move pid_ns_release_proc() from pr ..., Eric W. Biederman, (Thu Jun 24, 12:06 am)
Re: [RESEND PATCH] pid_ns: Fix proc_flush_task() accessing ..., Sukadev Bhattiprolu, (Fri Jun 25, 11:37 am)
Re: [RESEND PATCH] pid_ns: Fix proc_flush_task() accessing ..., Sukadev Bhattiprolu, (Fri Jun 25, 2:26 pm)
Re: [RESEND PATCH] pid_ns: Fix proc_flush_task() accessing ..., Sukadev Bhattiprolu, (Fri Jun 25, 3:07 pm)
[PATCH 01/24] pidns: Remove races by stopping the caching ..., Eric W. Biederman, (Fri Jul 9, 8:58 am)
Re: [PATCH 01/24] pidns: Remove races by stopping the cach ..., Eric W. Biederman, (Sun Jul 11, 7:25 am)
[PATCH] pidns: Fix wait for zombies to be reaped in zap_pi ..., Eric W. Biederman, (Mon Jul 12, 11:09 am)
Re: [PATCH] pidns: Fix wait for zombies to be reaped in za ..., Eric W. Biederman, (Tue Jul 13, 6:47 pm)
Re: [PATCH] pidns: Fix wait for zombies to be reaped in za ..., Sukadev Bhattiprolu, (Wed Jul 14, 1:53 pm)
Re: [PATCH] pidns: Fix wait for zombies to be reaped in za ..., Eric W. Biederman, (Wed Jul 14, 2:35 pm)
Re: [PATCH] pidns: Fix wait for zombies to be reaped in za ..., Sukadev Bhattiprolu, (Sat Oct 30, 12:07 am)