From patchwork Mon Oct 19 07:42:56 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: 11844483 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 28C06157C for ; Mon, 19 Oct 2020 14:36:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F09E1222E7 for ; Mon, 19 Oct 2020 14:36:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="IdPJyVvt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729533AbgJSOgq (ORCPT ); Mon, 19 Oct 2020 10:36:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728311AbgJSOgp (ORCPT ); Mon, 19 Oct 2020 10:36:45 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7AB5C0613CE for ; Mon, 19 Oct 2020 07:36:45 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id a17so5427654pju.1 for ; Mon, 19 Oct 2020 07:36:45 -0700 (PDT) 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=UoHJ3+c7Lf/38s7wa4B7r00P0zN1yzUQ11Dcaas1jcA=; b=IdPJyVvtXXTtbZhidBu/MjHofIzMbijn1TNMA7/J2uXyXPaEvNrn9Fqzi5mshwdijE TzI3GwphJ5VfV/+0LebFO2tHyG3dyBnAQkqGSa0kMj4ZObLt+0zLuZLbbLqK/Cu7OCpV vVYOZzS2aPZXs9CDhjQlUxBJmuGvWUXh4TtSQ= 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=UoHJ3+c7Lf/38s7wa4B7r00P0zN1yzUQ11Dcaas1jcA=; b=GxcHliXXgAb26rjG+AWi70t31yENS/O+0sJUoGjsUswk6woelDaFjw08Av/rX/n9oA 89oofODLG2h7lRdwYGDUZ3aZf2B7KKkuBFb0ChEq+NFDpkf+VuCgGaQepRh9QmWUItDQ aJP/7HkIWWkVE1QbXVXrhK2XSMFqtZRnkI1/PT9XYj3FOxx7XIe+fZjHFUE6GdXBB9+n o7QQKhg5vBMy541PYYdHq+A45T0FLAud2RJlkfMEhcIzNuWlr021/TLKldmU2rg3K8gy nJiuUL9gjotxxWZAdDHq9GWzIg3CYmm2yziEFDeiROKBEJI+CKVNLkMaqQ71qiMB3O96 VbDw== X-Gm-Message-State: AOAM533VDuXS0euAxmVOCzy53xKmm3Ce4atY2hhYi3a+lgoWIB/drp/t jUfoVuIhv8aRJrnjAJSZHerQFw== X-Google-Smtp-Source: ABdhPJxJTHTWuBPPKZfRmbNisYnsTQhfguxC9/ZUkbp3EwnAfwfRjg4TM+UBtI1hYJks2iLdlGaB8w== X-Received: by 2002:a17:90a:4b4e:: with SMTP id o14mr90782pjl.216.1603118205179; Mon, 19 Oct 2020 07:36:45 -0700 (PDT) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id kb15sm53377pjb.17.2020.10.19.07.36.42 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 19 Oct 2020 07:36:44 -0700 (PDT) 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: [RFC v2 01/18] cgroup: Added cgroup_get_from_kernfs_id Date: Mon, 19 Oct 2020 13:12:56 +0530 Message-Id: <1603093393-12875-2-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1603093393-12875-1-git-send-email-muneendra.kumar@broadcom.com> References: <1603093393-12875-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 Signed-off-by: Muneendra Acked-by: Tejun Heo --- v2: New patch --- include/linux/cgroup.h | 6 ++++++ kernel/cgroup/cgroup.c | 25 +++++++++++++++++++++++++ 2 files changed, 31 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..f34ca94b04c0 100644 --- a/kernel/cgroup/cgroup.c +++ b/kernel/cgroup/cgroup.c @@ -5803,6 +5803,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