cgroup: protect cgroup_root->cgroup_idr with a spinlock
authorTejun Heo <tj@kernel.org>
Sun, 4 May 2014 19:09:13 +0000 (15:09 -0400)
committerTejun Heo <tj@kernel.org>
Sun, 4 May 2014 19:09:13 +0000 (15:09 -0400)
commit6fa4918d03c39351aef3573ac3e7958d6a5ad9b6
treea7cb887fdb9cb33f0596a9c8781940ff1a150798
parent7d699ddb2b181a2c76e5ea18b1bdf102c4bebe4b
cgroup: protect cgroup_root->cgroup_idr with a spinlock

Currently, cgroup_root->cgroup_idr is protected by cgroup_mutex, which
ends up requiring cgroup_put() to be invoked under sleepable context.
This is okay for now but is an unusual requirement and we'll soon add
css->id which will have the same problem but won't be able to simply
grab cgroup_mutex as removal will have to happen from css_release()
which can't sleep.

Introduce cgroup_idr_lock and idr_alloc/replace/remove() wrappers
which protects the idr operations with the lock and use them for
cgroup_root->cgroup_idr.  cgroup_put() no longer needs to grab
cgroup_mutex and css_from_id() is updated to always require RCU read
lock instead of either RCU read lock or cgroup_mutex, which doesn't
affect the existing users.

Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
kernel/cgroup.c