不太清楚历史,标题优化下
标题就行: cgroup: unify cgroup_get_from_id
On 2023/12/9 18:36, chenridong wrote:
hulk inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I8LY4S
drop cgroup1_get_from_id, unify cgroup_get_from_id
理论上这里要写清楚,想我不了解历史就知道为什么要统一了
Signed-off-by: chenridong chenridong@huawei.com
include/linux/cgroup.h | 4 +-- kernel/cgroup/cgroup.c | 60 +++++++++++------------------------------- mm/memcontrol.c | 2 +- 3 files changed, 18 insertions(+), 48 deletions(-)
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index b98d63d8f1cc..41b19d2107fe 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -633,9 +633,7 @@ static inline void cgroup_kthread_ready(void) }
void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen); -#ifdef CONFIG_CGROUP_V1_WRITEBACK -struct cgroup *cgroup1_get_from_id(struct cgroup_root *root, u64 id); -#endif +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 6645e60773f6..3f5ddeb916ef 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -6186,17 +6186,26 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) }
/*
- cgroup_get_from_id : get the cgroup associated with cgroup id
+* cgroup_get_from_id:get cgrp_dfl_root's cgroup with 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);
+/*
*/
- __cgroup_get_from_id : get the cgroup associated with cgroup id
- @id: cgroup id
- 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);
@@ -6217,7 +6226,9 @@ struct cgroup *cgroup_get_from_id(u64 id) if (!cgrp) return ERR_PTR(-ENOENT);
- root_cgrp = current_cgns_cgroup_dfl();
- 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);
@@ -6225,7 +6236,7 @@ struct cgroup *cgroup_get_from_id(u64 id)
return cgrp; } -EXPORT_SYMBOL_GPL(cgroup_get_from_id); +EXPORT_SYMBOL_GPL(__cgroup_get_from_id);
/*
- proc_cgroup_show()
@@ -6305,45 +6316,6 @@ int proc_cgroup_show(struct seq_file *m, struct pid_namespace *ns, return retval; }
-#ifdef CONFIG_CGROUP_V1_WRITEBACK -struct cgroup *cgroup1_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(root->kf_root, id);
- if (!kn)
return ERR_PTR(-ENOENT);
- if (kernfs_type(kn) != KERNFS_DIR) {
kernfs_put(kn);
return ERR_PTR(-ENOENT);
- }
- rcu_read_lock();
- cgrp = rcu_dereference(*(void __rcu __force **)&kn->priv);
- if (cgrp && !cgroup_tryget(cgrp))
cgrp = NULL;
- rcu_read_unlock();
- kernfs_put(kn);
- if (!cgrp)
return ERR_PTR(-ENOENT);
- 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);
- }
- return cgrp;
-} -#endif
- /**
- cgroup_fork - initialize cgroup related fields during copy_process()
- @child: pointer to task_struct of forking parent process.
diff --git a/mm/memcontrol.c b/mm/memcontrol.c index b832e67b3002..cb1f927ce5a6 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -5064,7 +5064,7 @@ static ssize_t wb_blkio_write(struct kernfs_open_file *of, char *buf,
mutex_lock(&cgroup_mutex); root = blkcg_root_css->cgroup->root;
- blk_cgroup = cgroup1_get_from_id(root, cgrp_id);
- blk_cgroup = __cgroup_get_from_id(root, cgrp_id); if (IS_ERR(blk_cgroup)) { mutex_unlock(&cgroup_mutex); return -EINVAL;