From: Lu Jialin lujialin4@huawei.com
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8LY4S
-------------------------------
Add __cgroup_get_from_id() function to help cgroupv1 get cgroup through cgroup inode;
The patch also export cgroup_tryget_css(), which will be used later
Signed-off-by: Lu Jialin lujialin4@huawei.com Signed-off-by: chenridong chenridong@huawei.com --- include/linux/cgroup-defs.h | 2 ++ include/linux/cgroup.h | 1 + kernel/cgroup/cgroup.c | 26 +++++++++++++++++++++----- 3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/include/linux/cgroup-defs.h b/include/linux/cgroup-defs.h index 265da00a1a8b..013ea018cbd4 100644 --- a/include/linux/cgroup-defs.h +++ b/include/linux/cgroup-defs.h @@ -778,6 +778,8 @@ static inline void cgroup_threadgroup_change_end(struct task_struct *tsk) percpu_up_read(&cgroup_threadgroup_rwsem); }
+struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp, + struct cgroup_subsys *ss); #else /* CONFIG_CGROUPS */
#define CGROUP_SUBSYS_COUNT 0 diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 7fa51b600ee8..3823642a66bd 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -633,6 +633,7 @@ static inline void cgroup_kthread_ready(void) }
void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen); +struct cgroup __cgroup_get_from_id(struct cgroup_root *root, u64 id); struct cgroup *cgroup_get_from_id(u64 id); #else /* !CONFIG_CGROUPS */
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index 41b16ce99f54..0279af218528 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -3652,7 +3652,6 @@ static int cgroup_stat_show(struct seq_file *seq, void *v) return 0; }
-#ifdef CONFIG_CGROUP_SCHED /** * cgroup_tryget_css - try to get a cgroup's css for the specified subsystem * @cgrp: the cgroup of interest @@ -3661,7 +3660,7 @@ static int cgroup_stat_show(struct seq_file *seq, void *v) * Find and get @cgrp's css associated with @ss. If the css doesn't exist * or is offline, %NULL is returned. */ -static struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp, +struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp, struct cgroup_subsys *ss) { struct cgroup_subsys_state *css; @@ -3675,6 +3674,7 @@ static struct cgroup_subsys_state *cgroup_tryget_css(struct cgroup *cgrp, return css; }
+#ifdef CONFIG_CGROUP_SCHED static int cgroup_extra_stat_show(struct seq_file *seq, int ssid) { struct cgroup *cgrp = seq_css(seq)->cgroup; @@ -6208,12 +6208,12 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) * On success return the cgrp or ERR_PTR on failure * Only cgroups within current task's cgroup NS are valid. */ -struct cgroup *cgroup_get_from_id(u64 id) +struct cgroup *__cgroup_get_from_id(struct cgroup_root *root, u64 id) { struct kernfs_node *kn; struct cgroup *cgrp, *root_cgrp;
- kn = kernfs_find_and_get_node_by_id(cgrp_dfl_root.kf_root, id); + kn = kernfs_find_and_get_node_by_id(root->kf_root, id); if (!kn) return ERR_PTR(-ENOENT);
@@ -6234,7 +6234,13 @@ struct cgroup *cgroup_get_from_id(u64 id) if (!cgrp) return ERR_PTR(-ENOENT);
- root_cgrp = current_cgns_cgroup_dfl(); + if (root == &cgrp_dfl_root) + root_cgrp = current_cgns_cgroup_dfl(); + else { + spin_lock_irq(&css_set_lock); + root_cgrp = current_cgns_cgroup_from_root(root); + spin_unlock_irq(&css_set_lock); + } if (!cgroup_is_descendant(cgrp, root_cgrp)) { cgroup_put(cgrp); return ERR_PTR(-ENOENT); @@ -6242,6 +6248,16 @@ struct cgroup *cgroup_get_from_id(u64 id)
return cgrp; } +EXPORT_SYMBOL_GPL(__cgroup_get_from_id); + +/* + * cgroup_get_from_id : get the cgroup at dfl Hierarchy associated with cgroup id + * @id: cgroup id + */ +struct cgroup *cgroup_get_from_id(u64 id) +{ + return __cgroup_get_from_id(&cgrp_dfl_root, id); +} EXPORT_SYMBOL_GPL(cgroup_get_from_id);
/*