[RFC PATCH 1/4] cgroup: Introduce a function to compare two tasks

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 include/linux/cgroup.h |  1 +
 kernel/cgroup.c        | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 2162dca..6b66092 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -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);
 
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index d27904c..3ffdbb4 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -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
-- 
2.5.0

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux