diff mbox

[tpmdd-devel,v8,1/3] sysfs: added sysfs_link_entry_to_kobj()

Message ID 1435933643-4516-2-git-send-email-jarkko.sakkinen@linux.intel.com
State Superseded
Headers show

Commit Message

Jarkko Sakkinen July 3, 2015, 2:27 p.m. UTC
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/sysfs/group.c      | 44 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/sysfs.h | 10 ++++++++++
 2 files changed, 54 insertions(+)

Comments

Greg KH Aug. 5, 2015, 8:11 p.m. UTC | #1
On Fri, Jul 03, 2015 at 05:27:18PM +0300, Jarkko Sakkinen wrote:
> 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.

This text doesn't match the function name you exported :(

> 
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
>  fs/sysfs/group.c      | 44 ++++++++++++++++++++++++++++++++++++++++++++
>  include/linux/sysfs.h | 10 ++++++++++
>  2 files changed, 54 insertions(+)
> 
> diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
> index b400c04..0fb4b6e 100644
> --- a/fs/sysfs/group.c
> +++ b/fs/sysfs/group.c
> @@ -352,3 +352,47 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
>  	}
>  }
>  EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
> +
> +/**
> + * __compat_sysfs_link_entry_to_kobj - add a symlink to a kobject pointing

Why __compat?

------------------------------------------------------------------------------
Jarkko Sakkinen Aug. 10, 2015, 8:40 a.m. UTC | #2
On Wed, Aug 05, 2015 at 01:11:23PM -0700, Greg Kroah-Hartman wrote:
> On Fri, Jul 03, 2015 at 05:27:18PM +0300, Jarkko Sakkinen wrote:
> > 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.
> 
> This text doesn't match the function name you exported :(

D'oh.

> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > ---
> >  fs/sysfs/group.c      | 44 ++++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/sysfs.h | 10 ++++++++++
> >  2 files changed, 54 insertions(+)
> > 
> > diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
> > index b400c04..0fb4b6e 100644
> > --- a/fs/sysfs/group.c
> > +++ b/fs/sysfs/group.c
> > @@ -352,3 +352,47 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
> >  	}
> >  }
> >  EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
> > +
> > +/**
> > + * __compat_sysfs_link_entry_to_kobj - add a symlink to a kobject pointing
> 
> Why __compat?

https://lkml.org/lkml/2015/7/2/455

Although, should have been '__compat_only'.

/Jarkko

------------------------------------------------------------------------------
diff mbox

Patch

diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c
index b400c04..0fb4b6e 100644
--- a/fs/sysfs/group.c
+++ b/fs/sysfs/group.c
@@ -352,3 +352,47 @@  void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
 	}
 }
 EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
+
+/**
+ * __compat_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_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(__compat_sysfs_link_entry_to_kobj);
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 99382c0..f30b663 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -264,6 +264,9 @@  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 __compat_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 +439,13 @@  static inline void sysfs_remove_link_from_group(struct kobject *kobj,
 {
 }
 
+static inline int __compat_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)
 {