From patchwork Wed Apr 22 18:54:16 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jarkko Sakkinen X-Patchwork-Id: 6257501 Return-Path: X-Original-To: patchwork-tpmdd-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 8AD1C9F1C4 for ; Wed, 22 Apr 2015 18:56:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5B85120328 for ; Wed, 22 Apr 2015 18:56:14 +0000 (UTC) Received: from lists.sourceforge.net (lists.sourceforge.net [216.34.181.88]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 527B1202D1 for ; Wed, 22 Apr 2015 18:56:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=sfs-ml-2.v29.ch3.sourceforge.com) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Ykzoi-0008Nm-O8; Wed, 22 Apr 2015 18:56:12 +0000 Received: from sog-mx-4.v43.ch3.sourceforge.com ([172.29.43.194] helo=mx.sourceforge.net) by sfs-ml-2.v29.ch3.sourceforge.com with esmtp (Exim 4.76) (envelope-from ) id 1Ykzoi-0008Nf-B0 for tpmdd-devel@lists.sourceforge.net; Wed, 22 Apr 2015 18:56:12 +0000 X-ACL-Warn: Received: from mga01.intel.com ([192.55.52.88]) by sog-mx-4.v43.ch3.sourceforge.com with esmtp (Exim 4.76) id 1Ykzoh-0004qy-3w for tpmdd-devel@lists.sourceforge.net; Wed, 22 Apr 2015 18:56:12 +0000 Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 22 Apr 2015 11:56:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.11,625,1422950400"; d="scan'208";a="560198974" Received: from pmullee-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.27.110]) by orsmga003.jf.intel.com with ESMTP; 22 Apr 2015 11:55:57 -0700 From: Jarkko Sakkinen To: peterhuewe@gmx.de, tpmdd-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org Date: Wed, 22 Apr 2015 21:54:16 +0300 Message-Id: <1429728857-6372-2-git-send-email-jarkko.sakkinen@linux.intel.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1429728857-6372-1-git-send-email-jarkko.sakkinen@linux.intel.com> References: <1429728857-6372-1-git-send-email-jarkko.sakkinen@linux.intel.com> X-Spam-Score: -0.0 (/) X-Headers-End: 1Ykzoh-0004qy-3w Cc: Simon Wunderlich , NeilBrown , Greg Kroah-Hartman , Rasmus Villemoes , Jianyu Zhan , Andrzej Hajda , Al Viro , Tejun Heo , Andrew Morton , Guenter Roeck , "Eric W. Biederman" Subject: [tpmdd-devel] [PATCH v3 1/2] sysfs: added sysfs_link_entry_to_kobj() X-BeenThere: tpmdd-devel@lists.sourceforge.net X-Mailman-Version: 2.1.9 Precedence: list List-Id: Tpm Device Driver maintainance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: tpmdd-devel-bounces@lists.sourceforge.net X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, HK_RANDOM_ENVFROM, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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/kernfs/dir.c | 1 + fs/sysfs/group.c | 42 ++++++++++++++++++++++++++++++++++++++++++ include/linux/sysfs.h | 8 ++++++++ 3 files changed, 51 insertions(+) diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c index 6acc964..749cea3 100644 --- a/fs/kernfs/dir.c +++ b/fs/kernfs/dir.c @@ -1225,6 +1225,7 @@ int kernfs_remove_by_name_ns(struct kernfs_node *parent, const char *name, else return -ENOENT; } +EXPORT_SYMBOL_GPL(kernfs_remove_by_name_ns); /** * kernfs_rename_ns - move and rename a kernfs_node 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..f2be044 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,12 @@ static inline void sysfs_remove_link_from_group(struct kobject *kobj, { } +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) {