Commit b4f5f93b authored by Lu Jialin's avatar Lu Jialin Committed by yanhaitao
Browse files

cgroup: factor out __cgroup_get_from_id() for cgroup v1

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: default avatarLu Jialin <lujialin4@huawei.com>
Signed-off-by: default avatarchenridong <chenridong@huawei.com>
parent 6d225089
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -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
+1 −0
Original line number Diff line number Diff line
@@ -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 */

+24 −6
Original line number Diff line number Diff line
@@ -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;
@@ -6203,17 +6203,18 @@ 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 the cgroup associated with cgroup root and id
 * @root: hierarchy root
 * @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);

@@ -6234,7 +6235,13 @@ struct cgroup *cgroup_get_from_id(u64 id)
	if (!cgrp)
		return ERR_PTR(-ENOENT);

	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 +6249,17 @@ struct cgroup *cgroup_get_from_id(u64 id)

	return cgrp;
}

/*
 * cgroup_get_from_id : get the cgroup at dfl hierarchy 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)
{
	return __cgroup_get_from_id(&cgrp_dfl_root, id);
}
EXPORT_SYMBOL_GPL(cgroup_get_from_id);

/*