From patchwork Mon Nov 9 04:23:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar X-Patchwork-Id: 321795 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=-11.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_PATCH,MAILING_LIST_MULTI, MIME_HEADER_CTYPE_ONLY,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, T_TVD_MIME_NO_HEADERS,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 2E5CBC2D0A3 for ; Mon, 9 Nov 2020 11:17:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE79120897 for ; Mon, 9 Nov 2020 11:17:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="bys6JMDg" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729399AbgKILRc (ORCPT ); Mon, 9 Nov 2020 06:17:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727774AbgKILRa (ORCPT ); Mon, 9 Nov 2020 06:17:30 -0500 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84B96C0613CF for ; Mon, 9 Nov 2020 03:17:30 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id c66so2136340pfa.4 for ; Mon, 09 Nov 2020 03:17:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bYaqDyHlUOGibR7tX3hHCoOSVm1gaUK15169GGLsr6o=; b=bys6JMDgvlSlg6km/faITtL0+PGteN2C0zS3eg4Y24KOB4gIiYEQG5/yUnx4J0bVJ1 2f/e87dbVTux92JiJ9Nbl5Qso7CEh0q9NcbnZchV/xFauNIHXoBZVjordIazGO8bj2sG t3JxfL2Ga+iSmfhDokgLoB9UrqLbZmGfxxLoo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bYaqDyHlUOGibR7tX3hHCoOSVm1gaUK15169GGLsr6o=; b=I0RAgf0fjgANdPqZGC9ELzQZPJVuloQdlC/k0upJv6Vc8tZqvmyrbJbOluWY7afbD0 rWbnrDbQLJ5LVPxsWhDupa+zVsuhPayJGqHAFUYNAnVAB19bUKGfQkcOt0+D9W3CCVa6 lkKi9TakMV4vzVCZxDCve1x49qEGSv8Rh2vxDDuYJxGspH+98IsNCQsqrUvrns0HA8Kn QMOBhb5hxFYuE4XCQopDI+BXrebKasAKF7IMy/qG4hoJSq+tqSkfp5NVfImAmnVz/QRR 3GZVr+7G/vWw2se9CiNFPBtFqFZotwhh+C+W2raIF5onrVnPIqJXyocoCPj9F5NJtBpv nUXw== X-Gm-Message-State: AOAM533msd1YYzyWDJGRLpZydwc7olM93bI+wgwiFmSqeAQT3PX2ZIfn C/mSCpiOEgKVYZlJ4Vt+p9jA5g== X-Google-Smtp-Source: ABdhPJwWUEgPyCdgMOJLastt8Q8dPEQ5cCal+j3gGAoHpcak4z3S4xrigxKUtcyNFoqXHfdMNCPlzw== X-Received: by 2002:a05:6a00:88d:b029:164:5a00:29b8 with SMTP id q13-20020a056a00088db02901645a0029b8mr13935521pfj.10.1604920649995; Mon, 09 Nov 2020 03:17:29 -0800 (PST) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id k9sm10889364pfp.68.2020.11.09.03.17.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Nov 2020 03:17:29 -0800 (PST) From: Muneendra To: linux-block@vger.kernel.org, linux-scsi@vger.kernel.org, tj@kernel.org, linux-nvme@lists.infradead.org Cc: jsmart2021@gmail.com, emilne@redhat.com, mkumar@redhat.com, pbonzini@redhat.com, Muneendra Subject: [PATCH v4 01/19] cgroup: Added cgroup_get_from_kernfs_id Date: Mon, 9 Nov 2020 09:53:47 +0530 Message-Id: <1604895845-2587-2-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1604895845-2587-1-git-send-email-muneendra.kumar@broadcom.com> References: <1604895845-2587-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_kernfs_id to retrieve the cgroup associated with cgroup id. It takes cgroupid as an argument and returns cgrp and on failure it returns NULL. Exported the same as this can be used by blk-cgorup.c Added function declaration of cgroup_get_from_kernfs_id in cgorup.h Exported the cgroup_get_e_css Signed-off-by: Muneendra Reviewed-by: Hannes Reinecke --- 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..1741f02a41d6 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_kernfs_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_kernfs_id(u64 id) +{ + return NULL; +} #endif /* !CONFIG_CGROUPS */ #ifdef CONFIG_CGROUPS diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c index dd247747ec14..53046deeb9ca 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) { @@ -5803,6 +5804,31 @@ void cgroup_path_from_kernfs_id(u64 id, char *buf, size_t buflen) kernfs_put(kn); } +/* + * cgroup_get_from_kernfs_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_kernfs_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_kernfs_id); + /* * proc_cgroup_show() * - Print task's cgroup paths into seq_file, one line for each hierarchy