@@ -83,6 +83,7 @@ struct cgroup_subsys_state *css_tryget_online_from_dir(struct dentry *dentry,
struct cgroup *cgroup_get_from_path(const char *path);
+bool cgroup_match_groups(struct task_struct *, struct task_struct *);
int cgroup_attach_task_all(struct task_struct *from, struct task_struct *);
int cgroup_transfer_tasks(struct cgroup *to, struct cgroup *from);
@@ -2745,6 +2745,42 @@ out_unlock_threadgroup:
}
/**
+ * cgroup_match_groups - check if tsk1 and tsk2 belong to same cgroups
+ * in all hierarchies
+ */
+bool cgroup_match_groups(struct task_struct *tsk1, struct task_struct *tsk2)
+{
+ struct cgroup_root *root;
+ bool result = true;
+
+ mutex_lock(&cgroup_mutex);
+ for_each_root(root) {
+ struct cgroup *cg_tsk1;
+ struct cgroup *cg_tsk2;
+
+ if (root == &cgrp_dfl_root)
+ continue;
+
+ if (!root->subsys_mask)
+ continue;
+
+ spin_lock_bh(&css_set_lock);
+ cg_tsk1 = task_cgroup_from_root(tsk1, root);
+ cg_tsk2 = task_cgroup_from_root(tsk2, root);
+ spin_unlock_bh(&css_set_lock);
+
+ if (cg_tsk1 != cg_tsk2) {
+ result = false;
+ break;
+ }
+ }
+ mutex_unlock(&cgroup_mutex);
+
+ return result;
+}
+EXPORT_SYMBOL_GPL(cgroup_match_groups);
+
+/**
* cgroup_attach_task_all - attach task 'tsk' to all cgroups of task 'from'
* @from: attach to all cgroups of a given task
* @tsk: the task to be attached
This function takes two tasks and iterates through all hierarchies to check if they belong to the same cgroups. It ignores the check for default hierarchies or for hierarchies with no subsystems attached. Signed-off-by: Bandan Das <bsd@redhat.com> --- include/linux/cgroup.h | 1 + kernel/cgroup.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)