From patchwork Tue Nov 3 07:18:05 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Muneendra Kumar X-Patchwork-Id: 315363 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 93581C388F9 for ; Tue, 3 Nov 2020 14:12:59 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3E9BC22243 for ; Tue, 3 Nov 2020 14:12:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=broadcom.com header.i=@broadcom.com header.b="ONFaDRvi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729634AbgKCOM5 (ORCPT ); Tue, 3 Nov 2020 09:12:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729248AbgKCOLt (ORCPT ); Tue, 3 Nov 2020 09:11:49 -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 2E2CEC0613D1 for ; Tue, 3 Nov 2020 06:11:49 -0800 (PST) Received: by mail-pf1-x444.google.com with SMTP id y14so14271253pfp.13 for ; Tue, 03 Nov 2020 06:11:49 -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=EUMy7Zq/F/BENdHKHHaH6mRJFyN2oA04ziP7UtBR00k=; b=ONFaDRviNEWYSgCY4HnBIyGtLVZQQdfI+TaXP4O3j+snSYKij4RX3+eD2qhMXWAcFg E9tc1h5zBvupQ9forIImlWCuwXi8om4V9O2vqLmSexZ6eRmNEBx77bNd2pw9q5nVFW+2 iGXy0FJacZyBTeIyOPMKk0EPDLA78JuttTCtc= 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=EUMy7Zq/F/BENdHKHHaH6mRJFyN2oA04ziP7UtBR00k=; b=AhVlhVjOKeYREsfmcIrR8c6mwtbDCU2dMGYIj0OtJDwAxGXu7kmzeciYTn7xd/JeBU DHxQI9qJjRNdGScahRC5ujvOdMlg0baDC5NamlfXoazLK396JL96Odj4XrQKVpXTtbgq 1CxbMX0WdqRdshXcj1ZwEt/POhQmOKQKlwPSBLi14YuQ3M9PunAEyIq4n9xk5Vo5tRqN ZoS3ESY2LW8CCkgewoK7/TKGhnV8f8o4XBYRJDhsFefOmllhjZfIFRGIO1ksLUJCl25/ qFHN2Q0jxI62Q5phiKiFDwVKA7agj+P+QgtUWImjO7cdhQo0PCO8m+9/k26pP6Itge/G LjbA== X-Gm-Message-State: AOAM533KfTvh1ody/cIBGfEzruNh/lKwPcOb4VhyV7lIGbFj9tBmVTBE io9DDrWDG+L3zYoUhVOYh+6R/A== X-Google-Smtp-Source: ABdhPJyNsgeo5p08Ruv90PKkCbLlOxm3tADTSwlYgWNXT5vkuvTn15rdwfPhu0UM2M870V2pz0/F6g== X-Received: by 2002:a17:90a:6c61:: with SMTP id x88mr4197999pjj.13.1604412708631; Tue, 03 Nov 2020 06:11:48 -0800 (PST) Received: from localhost.localdomain ([192.19.234.250]) by smtp.gmail.com with ESMTPSA id t19sm3596691pgv.37.2020.11.03.06.11.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Nov 2020 06:11:47 -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 v3 01/19] cgroup: Added cgroup_get_from_kernfs_id Date: Tue, 3 Nov 2020 12:48:05 +0530 Message-Id: <1604387903-20006-2-git-send-email-muneendra.kumar@broadcom.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1604387903-20006-1-git-send-email-muneendra.kumar@broadcom.com> References: <1604387903-20006-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 Acked-by: Tejun Heo --- 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