From patchwork Thu Jul 6 21:52:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ross Zwisler X-Patchwork-Id: 9829053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D6D4E602BD for ; Thu, 6 Jul 2017 21:52:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C85EA27DCD for ; Thu, 6 Jul 2017 21:52:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD07B2842E; Thu, 6 Jul 2017 21:52:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from ml01.01.org (ml01.01.org [198.145.21.10]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 63BB227DCD for ; Thu, 6 Jul 2017 21:52:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 465BC21CC5371; Thu, 6 Jul 2017 14:51:09 -0700 (PDT) X-Original-To: linux-nvdimm@lists.01.org Delivered-To: linux-nvdimm@lists.01.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id CA16A21C9E7C0 for ; Thu, 6 Jul 2017 14:51:07 -0700 (PDT) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Jul 2017 14:52:48 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.40,319,1496127600"; d="scan'208";a="989770605" Received: from theros.lm.intel.com ([10.232.112.77]) by orsmga003.jf.intel.com with ESMTP; 06 Jul 2017 14:52:47 -0700 From: Ross Zwisler To: linux-kernel@vger.kernel.org Subject: [RFC v2 4/5] sysfs: add sysfs_add_group_link() Date: Thu, 6 Jul 2017 15:52:32 -0600 Message-Id: <20170706215233.11329-5-ross.zwisler@linux.intel.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170706215233.11329-1-ross.zwisler@linux.intel.com> References: <20170706215233.11329-1-ross.zwisler@linux.intel.com> MIME-Version: 1.0 X-BeenThere: linux-nvdimm@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: "Linux-nvdimm developer list." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "Box, David E" , Dave Hansen , "Zheng, Lv" , linux-nvdimm@lists.01.org, "Rafael J. Wysocki" , "Anaczkowski, Lukasz" , "Moore, Robert" , linux-acpi@vger.kernel.org, "Odzioba, Lukasz" , "Schmauss, Erik" , Len Brown , Jerome Glisse , devel@acpica.org, "Kogut, Jaroslaw" , linux-mm@kvack.org, Greg Kroah-Hartman , "Nachimuthu, Murugasamy" , "Rafael J. Wysocki" , "Lahtinen, Joonas" , Andrew Morton , Tim Chen Errors-To: linux-nvdimm-bounces@lists.01.org Sender: "Linux-nvdimm" X-Virus-Scanned: ClamAV using ClamSMTP The current __compat_only_sysfs_link_entry_to_kobj() code allows us to create symbolic links in sysfs to groups or attributes. Something like: /sys/.../entry1/groupA -> /sys/.../entry2/groupA This patch extends this functionality with a new sysfs_add_group_link() call that allows the link to have a different name than the group or attribute, so: /sys/.../entry1/link_name -> /sys/.../entry2/groupA __compat_only_sysfs_link_entry_to_kobj() now just calls sysfs_add_group_link(), passing in the same name for both the group/attribute and for the link name. This is needed by the ACPI HMAT enabling work because we want to have a group of performance attributes that live in a memory target. This group represents the performance between a memory target and its local inititator. In the target the attribute group is named "local_init": # tree mem_tgt2/local_init/ mem_tgt2/local_init/ ├── mem_init0 -> ../../mem_init0 ├── mem_tgt2 -> ../../mem_tgt2 ├── read_bw_MBps ├── read_lat_nsec ├── write_bw_MBps └── write_lat_nsec We then want to link to this attribute group from the initiator, but change the name of the link to "mem_tgtX" since we're now looking at it from the initiator's perspective, and because a given initiator can have multiple local memory targets: # ls -l mem_init0/mem_tgt2 lrwxrwxrwx. 1 root root 0 Jul 5 14:38 mem_init0/mem_tgt2 -> ../mem_tgt2/local_init Signed-off-by: Ross Zwisler --- fs/sysfs/group.c | 30 +++++++++++++++++++++++------- include/linux/sysfs.h | 2 ++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index ac2de0e..19db57c8 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -367,15 +367,15 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); /** - * __compat_only_sysfs_link_entry_to_kobj - add a symlink to a kobject pointing - * to a group or an attribute + * sysfs_add_group_link - add a symlink to a kobject pointing to a group or + * an attribute * @kobj: The kobject containing the group. * @target_kobj: The target kobject. * @target_name: The name of the target group or attribute. + * @link_name: The name of the link to the target group or attribute. */ -int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, - struct kobject *target_kobj, - const char *target_name) +int sysfs_add_group_link(struct kobject *kobj, struct kobject *target_kobj, + const char *target_name, const char *link_name) { struct kernfs_node *target; struct kernfs_node *entry; @@ -400,12 +400,28 @@ int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, return -ENOENT; } - link = kernfs_create_link(kobj->sd, target_name, entry); + link = kernfs_create_link(kobj->sd, link_name, entry); if (IS_ERR(link) && PTR_ERR(link) == -EEXIST) - sysfs_warn_dup(kobj->sd, target_name); + sysfs_warn_dup(kobj->sd, link_name); kernfs_put(entry); kernfs_put(target); return IS_ERR(link) ? PTR_ERR(link) : 0; } +EXPORT_SYMBOL_GPL(sysfs_add_group_link); + +/** + * __compat_only_sysfs_link_entry_to_kobj - add a symlink to a kobject pointing + * to a group or an attribute + * @kobj: The kobject containing the group. + * @target_kobj: The target kobject. + * @target_name: The name of the target group or attribute. + */ +int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, + struct kobject *target_kobj, + const char *target_name) +{ + return sysfs_add_group_link(kobj, target_kobj, target_name, + target_name); +} EXPORT_SYMBOL_GPL(__compat_only_sysfs_link_entry_to_kobj); diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index c6f0f0d..865f499 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -278,6 +278,8 @@ int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, struct kobject *target, const char *link_name); void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, const char *link_name); +int sysfs_add_group_link(struct kobject *kobj, struct kobject *target_kobj, + const char *target_name, const char *link_name); int __compat_only_sysfs_link_entry_to_kobj(struct kobject *kobj, struct kobject *target_kobj, const char *target_name);