diff mbox

[v5,1/2] sysfs: added sysfs_link_entry_to_kobj()

Message ID 1430590253-29019-2-git-send-email-jarkko.sakkinen@linux.intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jarkko Sakkinen May 2, 2015, 6:10 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      | 42 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/sysfs.h |  8 ++++++++
 2 files changed, 50 insertions(+)

Comments

Greg KH May 3, 2015, 6 p.m. UTC | #1
On Sat, May 02, 2015 at 09:10:52PM +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.
> 
> Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> ---
>  fs/sysfs/group.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
>  include/linux/sysfs.h |  8 ++++++++
>  2 files changed, 50 insertions(+)

What changed from v4?  Why keep resending this?

confused,

greg k-h

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jarkko Sakkinen May 4, 2015, 6:57 a.m. UTC | #2
On Sun, 2015-05-03 at 20:00 +0200, Greg Kroah-Hartman wrote:
> On Sat, May 02, 2015 at 09:10:52PM +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.
> > 
> > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > ---
> >  fs/sysfs/group.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
> >  include/linux/sysfs.h |  8 ++++++++
> >  2 files changed, 50 insertions(+)
> 
> What changed from v4?  Why keep resending this?

Yesterday, I had by mistake --subject-prefix="PATCH v4". From
original v4 changes are enumerated in the cover letter. Sorry.

> confused,
> 
> greg k-h

/Jarkko



------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Greg KH May 4, 2015, 7:42 a.m. UTC | #3
On Mon, May 04, 2015 at 09:57:13AM +0300, Jarkko Sakkinen wrote:
> On Sun, 2015-05-03 at 20:00 +0200, Greg Kroah-Hartman wrote:
> > On Sat, May 02, 2015 at 09:10:52PM +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.
> > > 
> > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > ---
> > >  fs/sysfs/group.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
> > >  include/linux/sysfs.h |  8 ++++++++
> > >  2 files changed, 50 insertions(+)
> > 
> > What changed from v4?  Why keep resending this?
> 
> Yesterday, I had by mistake --subject-prefix="PATCH v4". From
> original v4 changes are enumerated in the cover letter. Sorry.

What cover letter?  All I got was this patch, and nothing else, no 2/2
or 0/2.

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jarkko Sakkinen May 6, 2015, 6 a.m. UTC | #4
On Mon, May 04, 2015 at 09:42:25AM +0200, Greg Kroah-Hartman wrote:
> On Mon, May 04, 2015 at 09:57:13AM +0300, Jarkko Sakkinen wrote:
> > On Sun, 2015-05-03 at 20:00 +0200, Greg Kroah-Hartman wrote:
> > > On Sat, May 02, 2015 at 09:10:52PM +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.
> > > > 
> > > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > ---
> > > >  fs/sysfs/group.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
> > > >  include/linux/sysfs.h |  8 ++++++++
> > > >  2 files changed, 50 insertions(+)
> > > 
> > > What changed from v4?  Why keep resending this?
> > 
> > Yesterday, I had by mistake --subject-prefix="PATCH v4". From
> > original v4 changes are enumerated in the cover letter. Sorry.
> 
> What cover letter?  All I got was this patch, and nothing else, no 2/2
> or 0/2.

Changes since v4:
* Removed dangling export of kernfs_remove_by_name_ns() from the first
  patch.

Changes since v3:
* Use sysfs_remove_link()

Changes since v2:
* Fixed to_tpm_chip() macro.
* Split into two patches.
* Renamed sysfs_link_group_to_kobj to sysfs_link_entry_to_kobj
* Only create the "backwards compatibility" symlink for TPM 1.x devices.

[1] https://lkml.org/lkml/2015/5/2/139

/Jarkko

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Greg KH May 10, 2015, 2:11 p.m. UTC | #5
On Wed, May 06, 2015 at 09:00:19AM +0300, Jarkko Sakkinen wrote:
> On Mon, May 04, 2015 at 09:42:25AM +0200, Greg Kroah-Hartman wrote:
> > On Mon, May 04, 2015 at 09:57:13AM +0300, Jarkko Sakkinen wrote:
> > > On Sun, 2015-05-03 at 20:00 +0200, Greg Kroah-Hartman wrote:
> > > > On Sat, May 02, 2015 at 09:10:52PM +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.
> > > > > 
> > > > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > > ---
> > > > >  fs/sysfs/group.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
> > > > >  include/linux/sysfs.h |  8 ++++++++
> > > > >  2 files changed, 50 insertions(+)
> > > > 
> > > > What changed from v4?  Why keep resending this?
> > > 
> > > Yesterday, I had by mistake --subject-prefix="PATCH v4". From
> > > original v4 changes are enumerated in the cover letter. Sorry.
> > 
> > What cover letter?  All I got was this patch, and nothing else, no 2/2
> > or 0/2.
> 
> Changes since v4:
> * Removed dangling export of kernfs_remove_by_name_ns() from the first
>   patch.
> 
> Changes since v3:
> * Use sysfs_remove_link()
> 
> Changes since v2:
> * Fixed to_tpm_chip() macro.
> * Split into two patches.
> * Renamed sysfs_link_group_to_kobj to sysfs_link_entry_to_kobj
> * Only create the "backwards compatibility" symlink for TPM 1.x devices.
> 
> [1] https://lkml.org/lkml/2015/5/2/139

I only see one patch here, please resend this whole thing correctly...

------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
Jarkko Sakkinen May 11, 2015, 8:14 a.m. UTC | #6
On Sun, May 10, 2015 at 04:11:54PM +0200, Greg Kroah-Hartman wrote:
> On Wed, May 06, 2015 at 09:00:19AM +0300, Jarkko Sakkinen wrote:
> > On Mon, May 04, 2015 at 09:42:25AM +0200, Greg Kroah-Hartman wrote:
> > > On Mon, May 04, 2015 at 09:57:13AM +0300, Jarkko Sakkinen wrote:
> > > > On Sun, 2015-05-03 at 20:00 +0200, Greg Kroah-Hartman wrote:
> > > > > On Sat, May 02, 2015 at 09:10:52PM +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.
> > > > > > 
> > > > > > Signed-off-by: Jarkko Sakkinen <jarkko.sakkinen@linux.intel.com>
> > > > > > ---
> > > > > >  fs/sysfs/group.c      | 42 ++++++++++++++++++++++++++++++++++++++++++
> > > > > >  include/linux/sysfs.h |  8 ++++++++
> > > > > >  2 files changed, 50 insertions(+)
> > > > > 
> > > > > What changed from v4?  Why keep resending this?
> > > > 
> > > > Yesterday, I had by mistake --subject-prefix="PATCH v4". From
> > > > original v4 changes are enumerated in the cover letter. Sorry.
> > > 
> > > What cover letter?  All I got was this patch, and nothing else, no 2/2
> > > or 0/2.
> > 
> > Changes since v4:
> > * Removed dangling export of kernfs_remove_by_name_ns() from the first
> >   patch.
> > 
> > Changes since v3:
> > * Use sysfs_remove_link()
> > 
> > Changes since v2:
> > * Fixed to_tpm_chip() macro.
> > * Split into two patches.
> > * Renamed sysfs_link_group_to_kobj to sysfs_link_entry_to_kobj
> > * Only create the "backwards compatibility" symlink for TPM 1.x devices.
> > 
> > [1] https://lkml.org/lkml/2015/5/2/139
> 
> I only see one patch here, please resend this whole thing correctly...

OK, now that I looked at my command history I think I messed with my
send-email command-line :( Sorry for the caused confusion. I'll resend
the patch set.

/Jarkko


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
diff mbox

Patch

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)
 {