Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752682AbbFVRZy (ORCPT ); Mon, 22 Jun 2015 13:25:54 -0400 Received: from mga14.intel.com ([192.55.52.115]:11134 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752154AbbFVRZT (ORCPT ); Mon, 22 Jun 2015 13:25:19 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.13,660,1427785200"; d="scan'208";a="512471126" From: Jarkko Sakkinen To: tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Cc: peterhuewe@gmx.de, gregkh@linuxfoundation.org, jgunthorpe@obsidianresearch.com, Jarkko Sakkinen , Vivien Didelot , Guenter Roeck , Tejun Heo , NeilBrown Subject: [PATCH v7 1/3] sysfs: added sysfs_link_entry_to_kobj() Date: Mon, 22 Jun 2015 20:24:50 +0300 Message-Id: <1434993894-5911-2-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1434993894-5911-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1434993894-5911-1-git-send-email-jarkko.sakkinen@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3008 Lines: 93 Added a new function sysfs_link_group_to_kobj() that adds a symlink from attribute or group to a kobject. Exported kernfs_remove_by_name_ns in order to provide a way to remove such symlinks. Signed-off-by: Jarkko Sakkinen --- fs/sysfs/group.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/linux/sysfs.h | 9 +++++++++ 2 files changed, 51 insertions(+) diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index b400c04..5c72996 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c @@ -352,3 +352,45 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, } } EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); + +/** + * 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 sysfs_link_entry_to_kobj(struct kobject *kobj, struct kobject *target_kobj, + const char *target_name) +{ + struct kernfs_node *target; + struct kernfs_node *entry; + struct kernfs_node *link; + + /* + * We don't own @target_kobj and it may be removed at any time. + * Synchronize using sysfs_symlink_target_lock. See sysfs_remove_dir() + * for details. + */ + spin_lock(&sysfs_symlink_target_lock); + target = target_kobj->sd; + if (target) + kernfs_get(target); + spin_unlock(&sysfs_symlink_target_lock); + if (!target) + return -ENOENT; + + entry = kernfs_find_and_get(target_kobj->sd, target_name); + if (!entry) { + kernfs_put(target); + return -ENOENT; + } + + link = kernfs_create_link(kobj->sd, target_name, entry); + if (IS_ERR(link) && PTR_ERR(link) == -EEXIST) + sysfs_warn_dup(kobj->sd, target_name); + + kernfs_put(entry); + kernfs_put(target); + return IS_ERR(link) ? PTR_ERR(link) : 0; +} +EXPORT_SYMBOL_GPL(sysfs_link_entry_to_kobj); diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h index 99382c0..bfdf5c7 100644 --- a/include/linux/sysfs.h +++ b/include/linux/sysfs.h @@ -264,6 +264,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_link_entry_to_kobj(struct kobject *kobj, struct kobject *target_kobj, + const char *target_name); void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr); @@ -436,6 +438,13 @@ static inline void sysfs_remove_link_from_group(struct kobject *kobj, { } +static inline int sysfs_link_entry_to_kobj(struct kobject *kobj, + struct kobject *target_kobj, + const char *target_name) +{ + return 0; +} + static inline void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr) { -- 2.1.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in Please read the FAQ at http://www.tux.org/lkml/