linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
To: peterhuewe@gmx.de, tpmdd-devel@lists.sourceforge.net,
	linux-kernel@vger.kernel.org
Cc: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Tejun Heo <tj@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Al Viro <viro@zeniv.linux.org.uk>,
	Jianyu Zhan <nasa4836@gmail.com>,
	Rasmus Villemoes <linux@rasmusvillemoes.dk>,
	"Eric W. Biederman" <ebiederm@xmission.com>,
	Andrzej Hajda <a.hajda@samsung.com>,
	Simon Wunderlich <sw@simonwunderlich.de>,
	NeilBrown <neilb@suse.de>, Guenter Roeck <linux@roeck-us.net>
Subject: [PATCH v3 1/2] sysfs: added sysfs_link_entry_to_kobj()
Date: Wed, 22 Apr 2015 21:54:16 +0300	[thread overview]
Message-ID: <1429728857-6372-2-git-send-email-jarkko.sakkinen@linux.intel.com> (raw)
In-Reply-To: <1429728857-6372-1-git-send-email-jarkko.sakkinen@linux.intel.com>

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 <jarkko.sakkinen@linux.intel.com>
---
 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)
 {
-- 
2.1.4


  reply	other threads:[~2015-04-22 18:56 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-22 18:54 [PATCH v3 0/2] Enable PPI sysfs interface for TPM 2.0 Jarkko Sakkinen
2015-04-22 18:54 ` Jarkko Sakkinen [this message]
2015-04-22 18:54 ` [PATCH v3 2/2] tpm: move the PPI attributes to character device directory Jarkko Sakkinen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1429728857-6372-2-git-send-email-jarkko.sakkinen@linux.intel.com \
    --to=jarkko.sakkinen@linux.intel.com \
    --cc=a.hajda@samsung.com \
    --cc=akpm@linux-foundation.org \
    --cc=ebiederm@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=linux@roeck-us.net \
    --cc=nasa4836@gmail.com \
    --cc=neilb@suse.de \
    --cc=peterhuewe@gmx.de \
    --cc=sw@simonwunderlich.de \
    --cc=tj@kernel.org \
    --cc=tpmdd-devel@lists.sourceforge.net \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).