From patchwork Fri Aug 12 15:56:40 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 658694 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3s9qJH2F0Kz9stY for ; Sat, 13 Aug 2016 01:56:47 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=sargun.me header.i=@sargun.me header.b=aY6FIQDZ; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752707AbcHLP4o (ORCPT ); Fri, 12 Aug 2016 11:56:44 -0400 Received: from mail-it0-f52.google.com ([209.85.214.52]:36757 "EHLO mail-it0-f52.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752535AbcHLP4n (ORCPT ); Fri, 12 Aug 2016 11:56:43 -0400 Received: by mail-it0-f52.google.com with SMTP id x130so15081494ite.1 for ; Fri, 12 Aug 2016 08:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sargun.me; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=eu7K4hUxMpw1mixmwskopOqnpJa1LQRlB9Ebu7O1zUA=; b=aY6FIQDZRh24hldyu6TovTLOOSUOsvWSPKZn0scjEbizsgeRcNcar3xLv33+Hy3Pbi umKdyjUp4a0rSF44Qbt/H81ZhJ7jL7uHHTeeKKh2ZFLHnIIfVA8+auRwInJafXhqSWpR 3JbTyXnDhsWyJeIQfsJJweMFtqfBQ4iR9e2mk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=eu7K4hUxMpw1mixmwskopOqnpJa1LQRlB9Ebu7O1zUA=; b=jlA50rUeKE886KOgRDvwACnQCtAjmmVrmuEMYBQpVnQp2YXyAHMsrPbilNVz86C6PO zwlJH4PRscjQDiHyy3ULH48WaA6OBLxqAE1DBNFoAu1rREZywrytGIr6gyzY9H6vRVsT L2c1ITE17qT4BUV0jNkFaYaccOpHuN6giu63VNZC6WDL6E+7XeEoAcGKm1vgmQrVwY8s LG1KxB1QUYxRZEUyKfwWBEhNG7qAWFQ7AIN4+13VW5mjCAm7zo7C8nR70cw8YFaXrNhd JdMBU3TEL37sjmUTEMNwV4fHjeoAJPjKrkD+UkhM+TDI5XLoUM9F16PG5FoSSE9PeBjN JBMw== X-Gm-Message-State: AEkoouvqiaUBOABiAtqZZRnOr8TXY7MFjplVNR8A/zvSfE8UlC1kW3zItxuuUMD6iDG1Aw== X-Received: by 10.36.133.213 with SMTP id r204mr4197615itd.50.1471017402329; Fri, 12 Aug 2016 08:56:42 -0700 (PDT) Received: from ircssh.c.rugged-nimbus-611.internal (55.145.251.23.bc.googleusercontent.com. [23.251.145.55]) by smtp.gmail.com with ESMTPSA id k99sm3695265iod.25.2016.08.12.08.56.42 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 12 Aug 2016 08:56:42 -0700 (PDT) Date: Fri, 12 Aug 2016 08:56:40 -0700 From: Sargun Dhillon To: netdev@vger.kernel.org Cc: alexei.starovoitov@gmail.com, daniel@iogearbox.net, tj@kernel.org Subject: [PATCH net-next v5 1/3] cgroup: Add task_under_cgroup_hierarchy cgroup inline function to headers Message-ID: <20160812155638.GA12880@ircssh.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This commit adds an inline function to cgroup.h to check whether a given task is under a given cgroup hierarchy. This is to avoid having to put ifdefs in .c files to gate access to cgroups. When cgroups are disabled this always returns true. Signed-off-by: Sargun Dhillon Cc: Alexei Starovoitov Cc: Daniel Borkmann Cc: Tejun Heo Acked-by: Tejun Heo --- include/linux/cgroup.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 984f73b..a4414a1 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -497,6 +497,23 @@ static inline bool cgroup_is_descendant(struct cgroup *cgrp, return cgrp->ancestor_ids[ancestor->level] == ancestor->id; } +/** + * task_under_cgroup_hierarchy - test task's membership of cgroup ancestry + * @task: the task to be tested + * @ancestor: possible ancestor of @task's cgroup + * + * Tests whether @task's default cgroup hierarchy is a descendant of @ancestor. + * It follows all the same rules as cgroup_is_descendant, and only applies + * to the default hierarchy. + */ +static inline bool task_under_cgroup_hierarchy(struct task_struct *task, + struct cgroup *ancestor) +{ + struct css_set *cset = task_css_set(task); + + return cgroup_is_descendant(cset->dfl_cgrp, ancestor); +} + /* no synchronization, the result can only be used as a hint */ static inline bool cgroup_is_populated(struct cgroup *cgrp) { @@ -557,6 +574,7 @@ static inline void pr_cont_cgroup_path(struct cgroup *cgrp) #else /* !CONFIG_CGROUPS */ struct cgroup_subsys_state; +struct cgroup; static inline void css_put(struct cgroup_subsys_state *css) {} static inline int cgroup_attach_task_all(struct task_struct *from, @@ -574,6 +592,11 @@ static inline void cgroup_free(struct task_struct *p) {} static inline int cgroup_init_early(void) { return 0; } static inline int cgroup_init(void) { return 0; } +static inline bool task_under_cgroup_hierarchy(struct task_struct *task, + struct cgroup *ancestor) +{ + return true; +} #endif /* !CONFIG_CGROUPS */ /*