summary refs log tree commit diff
path: root/fs/kernfs
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-01-13 14:43:11 -0800
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2014-01-13 14:43:11 -0800
commit87da149343c8c93f6984c0f4b9da7651709624f7 (patch)
tree47e2f102a0dd40ae822a8b7c470da07f3a1b9081 /fs/kernfs
parent0890147fe09ff7e8275a162b1ab76ab5e3158c6d (diff)
downloadlinux-87da149343c8c93f6984c0f4b9da7651709624f7.tar.gz
Revert "kernfs: replace kernfs_node->u.completion with kernfs_root->deactivate_waitq"
This reverts commit ea1c472dfeada211a0100daa7976e8e8e779b858.

Tejun writes:
        I'm sorry but can you please revert the whole series?
        get_active() waiting while a node is deactivated has potential
        to lead to deadlock and that deactivate/reactivate interface is
        something fundamentally flawed and that cgroup will have to work
        with the remove_self() like everybody else.  IOW, I think the
        first posting was correct.

Cc: Tejun Heo <tj@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/kernfs')
-rw-r--r--fs/kernfs/dir.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
index ed62de6cdf8f..510b5062ef30 100644
--- a/fs/kernfs/dir.c
+++ b/fs/kernfs/dir.c
@@ -8,7 +8,6 @@
  * This file is released under the GPLv2.
  */
 
-#include <linux/sched.h>
 #include <linux/fs.h>
 #include <linux/namei.h>
 #include <linux/idr.h>
@@ -152,7 +151,6 @@ struct kernfs_node *kernfs_get_active(struct kernfs_node *kn)
  */
 void kernfs_put_active(struct kernfs_node *kn)
 {
-	struct kernfs_root *root = kernfs_root(kn);
 	int v;
 
 	if (unlikely(!kn))
@@ -164,7 +162,11 @@ void kernfs_put_active(struct kernfs_node *kn)
 	if (likely(v != KN_DEACTIVATED_BIAS))
 		return;
 
-	wake_up_all(&root->deactivate_waitq);
+	/*
+	 * atomic_dec_return() is a mb(), we'll always see the updated
+	 * kn->u.completion.
+	 */
+	complete(kn->u.completion);
 }
 
 /**
@@ -175,22 +177,26 @@ void kernfs_put_active(struct kernfs_node *kn)
  */
 static void kernfs_deactivate(struct kernfs_node *kn)
 {
-	struct kernfs_root *root = kernfs_root(kn);
+	DECLARE_COMPLETION_ONSTACK(wait);
+	int v;
 
 	BUG_ON(!(kn->flags & KERNFS_REMOVED));
 
 	if (!(kernfs_type(kn) & KERNFS_ACTIVE_REF))
 		return;
 
-	rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_);
+	kn->u.completion = (void *)&wait;
 
-	atomic_add(KN_DEACTIVATED_BIAS, &kn->active);
+	rwsem_acquire(&kn->dep_map, 0, 0, _RET_IP_);
+	/* atomic_add_return() is a mb(), put_active() will always see
+	 * the updated kn->u.completion.
+	 */
+	v = atomic_add_return(KN_DEACTIVATED_BIAS, &kn->active);
 
-	if (atomic_read(&kn->active) != KN_DEACTIVATED_BIAS)
+	if (v != KN_DEACTIVATED_BIAS) {
 		lock_contended(&kn->dep_map, _RET_IP_);
-
-	wait_event(root->deactivate_waitq,
-		   atomic_read(&kn->active) == KN_DEACTIVATED_BIAS);
+		wait_for_completion(&wait);
+	}
 
 	lock_acquired(&kn->dep_map, _RET_IP_);
 	rwsem_release(&kn->dep_map, 1, _RET_IP_);
@@ -607,7 +613,6 @@ struct kernfs_root *kernfs_create_root(struct kernfs_dir_ops *kdops, void *priv)
 
 	root->dir_ops = kdops;
 	root->kn = kn;
-	init_waitqueue_head(&root->deactivate_waitq);
 
 	return root;
 }