From patchwork Mon Aug 29 11:46:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sargun Dhillon X-Patchwork-Id: 9303677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 33C33607F0 for ; Mon, 29 Aug 2016 11:46:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2541D2878B for ; Mon, 29 Aug 2016 11:46:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19D7228823; Mon, 29 Aug 2016 11:46:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9679D2878B for ; Mon, 29 Aug 2016 11:46:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932914AbcH2LqN (ORCPT ); Mon, 29 Aug 2016 07:46:13 -0400 Received: from mail-it0-f54.google.com ([209.85.214.54]:34717 "EHLO mail-it0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932900AbcH2LqM (ORCPT ); Mon, 29 Aug 2016 07:46:12 -0400 Received: by mail-it0-f54.google.com with SMTP id e63so16021323ith.1 for ; Mon, 29 Aug 2016 04:46:11 -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=w+gIwX5HH79oqKbqc860XJSFF19qxoex+1tXYt+p3a8=; b=sEr6AJcDvbkcfD5C5O9r8TS3hKpHlKeQWhoOLUJpF+5pKDKH1SZfnSGgF8nyI3Ci2P ex/GIYDszeuWBs+F62ai8x+cC1lyCL0W2EFtMfkRVBTE49L0AQNgV0mMW4z8GHzQSSNd 9M4VHUUdb90UV3XQXOylyk0oae3+soqw+kAOg= 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=w+gIwX5HH79oqKbqc860XJSFF19qxoex+1tXYt+p3a8=; b=OIKIci54hS8LrG87iORN19rd5GrFFzzm54U8ZYa9sC7IVfq7KHugRHx+SV1hSrM9kX WR6aHlNSm7Omsp0y1Jct97Fx6UVpvAIg5ljjaXWujV2M8d1+IbClvSju5Pu0Typ5ppI3 hb+K+zPB8gWnZFOX9zzfM8ZNv0PV83HrwYhUnim0EHoS1vI+a/1ym58tPLF2P22RiGfa iNnXi9KPUSn88vp1yxkEsM2YOcIMCWpQMw7ithalUO7cJwJl08NrsTJag5XYuFQms4sR v+bS01YT/QvmJ9Cc7qeU7FlGc58A7I8JVYLSjJn4uCXvV7ZNZ919UGZ19b0wn/9wqrFr yZrw== X-Gm-Message-State: AE9vXwOmZJE86hjuJJq9A6lQIq+t26C0PmMZtl6pj+qXi9gTkdm2ZPqQgbnCBI7XWu7MZQ== X-Received: by 10.36.127.87 with SMTP id r84mr8488931itc.4.1472471171273; Mon, 29 Aug 2016 04:46:11 -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 b133sm6005965iti.21.2016.08.29.04.46.10 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Mon, 29 Aug 2016 04:46:11 -0700 (PDT) Date: Mon, 29 Aug 2016 04:46:09 -0700 From: Sargun Dhillon To: netdev@vger.kernel.org Cc: cgroups@vger.kernel.org, linux-security-module@vger.kernel.org, daniel@iogearbox.net, ast@fb.com Subject: [net-next RFC v2 2/9] cgroups: move helper cgroup_parent to cgroup.h Message-ID: <20160829114608.GA20848@ircssh.c.rugged-nimbus-611.internal> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: X-Virus-Scanned: ClamAV using ClamSMTP This patch moves cgroup_parent into cgroup.h as a static inline helper function so that others can use it. Although this pattern is easy to implement, having it in one place simplifies the creation of new cgroup controllers. Signed-off-by: Sargun Dhillon --- include/linux/cgroup.h | 16 ++++++++++++++++ kernel/cgroup.c | 9 --------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index a4414a1..b84eb6e 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -571,6 +571,22 @@ static inline void pr_cont_cgroup_path(struct cgroup *cgrp) pr_cont_kernfs_path(cgrp->kn); } +/** + * cgroup_parent - Get the parent of a specific cgroup + * @cgrp: target cgroup + * + * If the cgroup does not have a parent (top level), then this function + * returns NULL. Otherwise, it'll return a pointer to te the parent cgroup. + */ +static inline struct cgroup *cgroup_parent(struct cgroup *cgrp) +{ + struct cgroup_subsys_state *parent_css = cgrp->self.parent; + + if (parent_css) + return container_of(parent_css, struct cgroup, self); + return NULL; +} + #else /* !CONFIG_CGROUPS */ struct cgroup_subsys_state; diff --git a/kernel/cgroup.c b/kernel/cgroup.c index d1c51b7..1ec1a4e 100644 --- a/kernel/cgroup.c +++ b/kernel/cgroup.c @@ -358,15 +358,6 @@ static void cgroup_idr_remove(struct idr *idr, int id) spin_unlock_bh(&cgroup_idr_lock); } -static struct cgroup *cgroup_parent(struct cgroup *cgrp) -{ - struct cgroup_subsys_state *parent_css = cgrp->self.parent; - - if (parent_css) - return container_of(parent_css, struct cgroup, self); - return NULL; -} - /* subsystems visibly enabled on a cgroup */ static u16 cgroup_control(struct cgroup *cgrp) {