From patchwork Tue Dec 22 00:11:43 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar X-Patchwork-Id: 346841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.2 required=3.0 tests=BAYES_00, DATE_IN_PAST_06_12, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A01CC433E9 for ; Tue, 22 Dec 2020 07:05:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 360A223331 for ; Tue, 22 Dec 2020 07:05:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725937AbgLVHFi (ORCPT ); Tue, 22 Dec 2020 02:05:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725911AbgLVHFi (ORCPT ); Tue, 22 Dec 2020 02:05:38 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E23E8C06179C for ; Mon, 21 Dec 2020 23:04:57 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id 11so7924322pfu.4 for ; Mon, 21 Dec 2020 23:04:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=mime-version:from:to:cc:subject:date:message-id:in-reply-to :references; bh=15GGdAOB8va5BAcDFncR6MtogFFWqcOamX79gD8p5F8=; b=IPyIDoMBlU1GQK1d2wT3Iye9sNsW1rowLhwgDbTu4jYb53psz7LLmeWy42XLkyd7a4 Ch7X5bAnUJgWbFJU7gFfWWO1TyON4p1Hw2s3ufkaYEi3dX9SKMcxj2s2JykLhqDjAmUk yrZ93fb9IWnHahbUJxNAPb+LoyEVZAhBPbCJw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :in-reply-to:references; bh=15GGdAOB8va5BAcDFncR6MtogFFWqcOamX79gD8p5F8=; b=rgpNawlTWYwheNRVcNSPjZHYVIFlwQfSUGj06gbym5qooz6jsXTJx/YwndRmk6xAoj +bD7+ZGsplBgCJvQrEsghM+8qNe15Uu2s0k9oC1ZEGZKtGf4wLrHwddKyO1MPgdj/2p6 yqmmMWLLR/WA5veKBQpXWL2Lxl2XNHbvIkl7dr1Qp2C9W47ow06mPmzaz2c4bmmU+9H0 O1a+m285lmFGEUxw5WtlvZQpenn9d8v+YeTNAiX0TlbWPtZ+pAluWPc2H8m0Hc6Kedx6 ypNXpuOvsjhclIVgt8YourmT3UTEEg+f5/qfd/19O8qkjuQoUPlhJ7l67SzRl1PM0ciC ArKQ== MIME-Version: 1.0 X-Gm-Message-State: AOAM533eIk6OAnJq6PITvjABO1FiaYqophX3nJ+Ob1C/tQqIqmRhWDpK woUDz96AGFtLPtGKq4KQ6qQyg1G+nNynwZT7Uex0lwc7xpCZbGaHjI4O6cxFSuUdqjKfY+/s8MV G+HNjfKJjOAzN X-Google-Smtp-Source: ABdhPJwPLynoDMfABcnpVKcK76wZ4PpY0WUYczDLDsZhuQKbNqarRfIHR4Oy+TTa0S0r+qdaidyn+A== X-Received: by 2002:a62:6c2:0:b029:19e:b63a:91e9 with SMTP id 185-20020a6206c20000b029019eb63a91e9mr18582302pfg.79.1608620697242; Mon, 21 Dec 2020 23:04:57 -0800 (PST) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id t9sm12466082pgh.41.2020.12.21.23.04.53 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Dec 2020 23:04:56 -0800 (PST) From: Muneendra To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, tj@kernel.org, linux-nvme@lists.infradead.org, hare@suse.de Cc: jsmart2021@gmail.com, emilne@redhat.com, mkumar@redhat.com, pbonzini@redhat.com, Muneendra Subject: [PATCH v6 01/16] cgroup: Added cgroup_get_from_id Date: Tue, 22 Dec 2020 05:41:43 +0530 Message-Id: <1608595918-21954-2-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1608595918-21954-1-git-send-email-muneendra.kumar@broadcom.com> References: <1608595918-21954-1-git-send-email-muneendra.kumar@broadcom.com> Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org Added a new function cgroup_get_from_id to retrieve the cgroup associated with cgroup id. Exported the same as this can be used by blk-cgorup.c Added function declaration of cgroup_get_from_id in cgorup.h This patch also exported the function cgroup_get_e_css as this is getting used in blk-cgroup.h Signed-off-by: Muneendra --- v6: No change v5: renamed the function cgroup_get_from_kernfs_id to cgroup_get_from_id v4: No change v3: Exported the cgroup_get_e_css v2: New patch --- include/linux/cgroup.h | 6 ++++++ kernel/cgroup/cgroup.c | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index 618838c48313..da31b14db198 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h @@ -696,6 +696,7 @@ static inline void cgroup_kthread_ready(void) } void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen); +struct cgroup *cgroup_get_from_id(u64 id); #else /* !CONFIG_CGROUPS */ struct cgroup_subsys_state; @@ -743,6 +744,11 @@ static inline bool task_under_cgroup_hierarchy(struct task_struct *task, static inline void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) {} + +static struct cgroup *cgroup_get_from_id(u64 id) +{ + return NULL; +} #endif /* !CONFIG_CGROUPS */ #ifdef CONFIG_CGROUPS diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index e41c21819ba0..34ebfbeba098 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -580,6 +580,7 @@ struct cgroup_subsys_state *cgroup_get_e_css(struct cgroup *cgrp, rcu_read_unlock(); return css; } +EXPORT_SYMBOL_GPL(cgroup_get_e_css); static void cgroup_get_live(struct cgroup *cgrp) { @@ -5805,6 +5806,31 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) kernfs_put(kn); } +/* + * cgroup_get_from_id : get the cgroup associated with cgroup id + * @id: cgroup id + * On success it returns the cgrp on failure it returns NULL + */ +struct cgroup *cgroup_get_from_id(u64 id) +{ + struct kernfs_node *kn; + struct cgroup *cgrp = NULL; + + mutex_lock(&cgroup_mutex); + kn = kernfs_find_and_get_node_by_id(cgrp_dfl_root.kf_root, id); + if (!kn) + goto out_unlock; + + cgrp = kn->priv; + if (cgroup_is_dead(cgrp) || !cgroup_tryget(cgrp)) + cgrp = NULL; + kernfs_put(kn); +out_unlock: + mutex_unlock(&cgroup_mutex); + return cgrp; +} +EXPORT_SYMBOL_GPL(cgroup_get_from_id); + /* * proc_cgroup_show() * - Print task's cgroup paths into seq_file, one line for each hierarchy