From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755701Ab3G2HIq (ORCPT ); Mon, 29 Jul 2013 03:08:46 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:53220 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755674Ab3G2HIn (ORCPT ); Mon, 29 Jul 2013 03:08:43 -0400 Message-ID: <51F614DF.9010508@huawei.com> Date: Mon, 29 Jul 2013 15:08:15 +0800 From: Li Zefan User-Agent: Mozilla/5.0 (Windows NT 6.1; rv:17.0) Gecko/20130620 Thunderbird/17.0.7 MIME-Version: 1.0 To: Tejun Heo CC: Andrew Morton , Glauber Costa , KAMEZAWA Hiroyuki , Michal Hocko , Johannes Weiner , LKML , Cgroups , Subject: [PATCH v3 3/8] cgroup: implement cgroup_from_id() References: <51F614B2.6010503@huawei.com> In-Reply-To: <51F614B2.6010503@huawei.com> Content-Type: text/plain; charset="GB2312" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.135.68.215] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This will be used as a replacement for css_lookup(). There's a difference with cgroup id and css id. cgroup id starts with 0, while css id starts with 1. Signed-off-by: Li Zefan Reviewed-by: Michal Hocko --- include/linux/cgroup.h | 2 ++ kernel/cgroup.c | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 8c107e9..e8eb361 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -553,6 +553,8 @@ int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id, int cgroup_task_count(const struct cgroup *cgrp); +struct cgroup *cgroup_from_id(struct cgroup_subsys *ss, int id); + /* * Control Group taskset, used to pass around set of tasks to cgroup_subsys * methods. diff --git a/kernel/cgroup.c b/kernel/cgroup.c index b7c7c68..dc4a749 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -5536,6 +5536,22 @@ struct cgroup_subsys_state *cgroup_css_from_dir(struct file *f, int id) return css ? css : ERR_PTR(-ENOENT); } +/** + * cgroup_from_id - lookup cgroup by id + * @ss: cgroup subsys to be looked into + * @id: the cgroup id + * + * Returns the cgroup if there's valid one with @id, otherwise returns NULL. + * Should be called under rcu_readlock(). + */ +struct cgroup *cgroup_from_id(struct cgroup_subsys *ss, int id) +{ + rcu_lockdep_assert(rcu_read_lock_held(), + "cgroup_from_id() needs rcu_read_lock()" + " protection"); + return idr_find(&ss->root->cgroup_idr, id); +} + #ifdef CONFIG_CGROUP_DEBUG static struct cgroup_subsys_state *debug_css_alloc(struct cgroup *cgrp) { -- 1.8.0.2