From patchwork Mon Jul 13 04:07:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bandan Das X-Patchwork-Id: 6773901 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 369F7C05AC for ; Mon, 13 Jul 2015 04:10:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4CDF720584 for ; Mon, 13 Jul 2015 04:10:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F963204E0 for ; Mon, 13 Jul 2015 04:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751469AbbGMEJA (ORCPT ); Mon, 13 Jul 2015 00:09:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51172 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751438AbbGMEI7 (ORCPT ); Mon, 13 Jul 2015 00:08:59 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 3C96A8E761; Mon, 13 Jul 2015 04:08:59 +0000 (UTC) Received: from aqua.redhat.com (ovpn-113-42.phx2.redhat.com [10.3.113.42]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6D482Fo014431; Mon, 13 Jul 2015 00:08:58 -0400 From: Bandan Das To: kvm@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, mst@redhat.com, Eyal Moscovici , Razya Ladelsky , cgroups@vger.kernel.org, jasowang@redhat.com Subject: [RFC PATCH 3/4] cgroup: Introduce a function to compare cgroups Date: Mon, 13 Jul 2015 00:07:34 -0400 Message-Id: <1436760455-5686-4-git-send-email-bsd@redhat.com> In-Reply-To: <1436760455-5686-1-git-send-email-bsd@redhat.com> References: <1436760455-5686-1-git-send-email-bsd@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. This function will be used by the next patch to add rudimentary cgroup support with vhost workers. Signed-off-by: Bandan Das --- include/linux/cgroup.h | 1 + kernel/cgroup.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index b9cb94c..606fb5b 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -933,6 +933,7 @@ void css_task_iter_start(struct cgroup_subsys_state *css, struct task_struct *css_task_iter_next(struct css_task_iter *it); void css_task_iter_end(struct css_task_iter *it); +int cgroup_match_groups(struct task_struct *tsk1, struct task_struct *tsk2); 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 469dd54..ba4121e 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -2465,6 +2465,46 @@ out_unlock_cgroup: } /** + * cgroup_match_groups - check if tsk1 and tsk2 belong to + * same cgroups in all hierarchies + * Returns 0 on success + */ +int cgroup_match_groups(struct task_struct *tsk1, struct task_struct *tsk2) +{ + struct cgroup_root *root; + int retval = 0; + + WARN_ON(!tsk1 || !tsk2); + + mutex_lock(&cgroup_mutex); + for_each_root(root) { + struct cgroup *cg_tsk1; + struct cgroup *cg_tsk2; + + /* Default hierarchy */ + if (root == &cgrp_dfl_root) + continue; + /* No subsystems attached */ + if (!root->subsys_mask) + continue; + + down_read(&css_set_rwsem); + cg_tsk1 = task_cgroup_from_root(tsk1, root); + cg_tsk2 = task_cgroup_from_root(tsk2, root); + up_read(&css_set_rwsem); + + if (cg_tsk1 != cg_tsk2) { + retval = 1; + break; + } + } + mutex_unlock(&cgroup_mutex); + + return retval; +} +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