From patchwork Wed Dec 16 05:29:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar M X-Patchwork-Id: 11977417 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,URIBL_BLOCKED,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 B11ECC0018C for ; Wed, 16 Dec 2020 12:23:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4E5D4230FA for ; Wed, 16 Dec 2020 12:23:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725891AbgLPMXb (ORCPT ); Wed, 16 Dec 2020 07:23:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48882 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725385AbgLPMXb (ORCPT ); Wed, 16 Dec 2020 07:23:31 -0500 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22562C0617A6 for ; Wed, 16 Dec 2020 04:22:51 -0800 (PST) Received: by mail-pg1-x533.google.com with SMTP id c22so2099507pgg.13 for ; Wed, 16 Dec 2020 04:22:51 -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=XydzqVCIfvQOdz6sh1D78ve4Odu9PhRS+RbZjruU+y0=; b=Ljx5/y1WmwqufwBGtalwHHnyjg8OiaXIcPpXFOvStWFEe+KqfVZ3YOO6IOhjvuqeqJ T6qVbeF2sFWpqtvT/C7VIJJze0Ly+MO4qRDdqdAukMUH/Y95nFIJ1Ft8u3Imu3uijQZx IgKcIBT4cPfr4z0c98TGZpzQgogADq7aSmwa4= 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=XydzqVCIfvQOdz6sh1D78ve4Odu9PhRS+RbZjruU+y0=; b=FSrlIDpyKUiz3USJj+IjTKbmSb/jjvcr0p6uS1GMx60thChOHZEaO+Ulp5EmEmjV0F Q+bMvXxUmb5jLN0Cnx+v/IhJTP5Q78UlHWenHf0ncwB2TEWUFcUeo8xIy9qd5jVir5/Z LF2zaHGVLuXrotiPKe5V3ZII97X+JEcOWIoaRnpNyIPf/UaUe/mFbF6OhX1E/jYDf9NO 3lQaP/GyTbpE6hHeQQrJvUSA/k0I86gYm73ojRIXQB6+mQTwKq+4HOW92xMRp3kODGd/ R9vYH1cdnqLafxTTBp2dJizDXRpYSo8kD5YeMX8Z4mdbvuqq1VePVsWcuWX9jvo6Q4Dq LIcw== MIME-Version: 1.0 X-Gm-Message-State: AOAM531Y1yE8bYuqfTe6s5Y2NeluRtHftWdMXo+fS0ryr4mmJb5qZcuL uBdjxOzr7nfZMXkrHzdz43zkXIopylJVQy4au1Y3eARCILCc87HE06c54w65+kK7+m/hxbbucMe 7ZAkpP3PfwcoeE9wfU2DoLKk= X-Google-Smtp-Source: ABdhPJwbLrQTS3ScEIvote8nd17uCJZURZtOX20Ej/Cj2v79zmUPlKpWHBQJ+FmN/lBghLWX8vKybA== X-Received: by 2002:a63:da4f:: with SMTP id l15mr6405369pgj.22.1608121370565; Wed, 16 Dec 2020 04:22:50 -0800 (PST) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id s7sm2477296pfh.207.2020.12.16.04.22.47 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Dec 2020 04:22:49 -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 v5 01/16] cgroup: Added cgroup_get_from_id Date: Wed, 16 Dec 2020 10:59:31 +0530 Message-Id: <1608096586-21656-2-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1608096586-21656-1-git-send-email-muneendra.kumar@broadcom.com> References: <1608096586-21656-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 --- 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