cgroup: use rculist ops for cgroup->children
authorTejun Heo <tj@kernel.org>
Fri, 9 Nov 2012 17:12:29 +0000 (09:12 -0800)
committerTejun Heo <tj@kernel.org>
Fri, 9 Nov 2012 17:12:29 +0000 (09:12 -0800)
Use RCU safe list operations for cgroup->children.  This will be used
to implement cgroup children / descendant walking which can be used by
controllers.

Note that cgroup_create() now puts a new cgroup at the end of the
->children list instead of head.  This isn't strictly necessary but is
done so that the iteration order is more conventional.

Signed-off-by: Tejun Heo <tj@kernel.org>
Reviewed-by: Michal Hocko <mhocko@suse.cz>
Reviewed-by: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Acked-by: Li Zefan <lizefan@huawei.com>
include/linux/cgroup.h
kernel/cgroup.c

index b4421221111dd6390a6766a7824338ebc0b13d7b..90c33ebdd6bc8a66f02a10c18026052d0ad3aff4 100644 (file)
@@ -12,6 +12,7 @@
 #include <linux/cpumask.h>
 #include <linux/nodemask.h>
 #include <linux/rcupdate.h>
+#include <linux/rculist.h>
 #include <linux/cgroupstats.h>
 #include <linux/prio_heap.h>
 #include <linux/rwsem.h>
index 26f2edbaf4f51a1a65f09b6df22f57bdf6e9f6d9..2ed5968a04e774f230d26f5a5d8e3750f3001ab6 100644 (file)
@@ -1650,7 +1650,6 @@ static struct dentry *cgroup_mount(struct file_system_type *fs_type,
 
                free_cg_links(&tmp_cg_links);
 
-               BUG_ON(!list_empty(&root_cgrp->sibling));
                BUG_ON(!list_empty(&root_cgrp->children));
                BUG_ON(root->number_of_cgroups != 1);
 
@@ -1699,7 +1698,6 @@ static void cgroup_kill_sb(struct super_block *sb) {
 
        BUG_ON(root->number_of_cgroups != 1);
        BUG_ON(!list_empty(&cgrp->children));
-       BUG_ON(!list_empty(&cgrp->sibling));
 
        mutex_lock(&cgroup_mutex);
        mutex_lock(&cgroup_root_mutex);
@@ -4052,7 +4050,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
                }
        }
 
-       list_add(&cgrp->sibling, &cgrp->parent->children);
+       list_add_tail_rcu(&cgrp->sibling, &cgrp->parent->children);
        root->number_of_cgroups++;
 
        err = cgroup_create_dir(cgrp, dentry, mode);
@@ -4083,7 +4081,7 @@ static long cgroup_create(struct cgroup *parent, struct dentry *dentry,
 
  err_remove:
 
-       list_del(&cgrp->sibling);
+       list_del_rcu(&cgrp->sibling);
        root->number_of_cgroups--;
 
  err_destroy:
@@ -4209,7 +4207,7 @@ static int cgroup_rmdir(struct inode *unused_dir, struct dentry *dentry)
        raw_spin_unlock(&release_list_lock);
 
        /* delete this cgroup from parent->children */
-       list_del_init(&cgrp->sibling);
+       list_del_rcu(&cgrp->sibling);
 
        list_del_init(&cgrp->allcg_node);