All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	"Kristen C. Accardi" <kristen.c.accardi@intel.com>,
	Len Brown <lenb@kernel.org>
Subject: [Update][PATCH 4/5] sysfs: Functions for adding/removing symlinks to/from attribute groups
Date: Wed, 23 Jan 2013 19:00:54 +0100	[thread overview]
Message-ID: <1511541.AH8DLsNQJH@vostro.rjw.lan> (raw)
In-Reply-To: <1551140.kO91IOVbjI@vostro.rjw.lan>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

The most convenient way to expose ACPI power resources lists of a
device is to put symbolic links to sysfs directories representing
those resources into special attribute groups in the device's sysfs
directory.  For this purpose, it is necessary to be able to add
symbolic links to attribute groups.

For this reason, add sysfs helper functions for adding/removing
symbolic links to/from attribute groups, sysfs_add_link_to_group()
and sysfs_remove_link_from_group(), respectively.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 fs/sysfs/group.c      |   42 ++++++++++++++++++++++++++++++++++++++++++
 fs/sysfs/symlink.c    |   45 ++++++++++++++++++++++++++++++++-------------
 fs/sysfs/sysfs.h      |    2 ++
 include/linux/sysfs.h |    4 ++++
 4 files changed, 80 insertions(+), 13 deletions(-)

Index: linux-pm/fs/sysfs/group.c
===================================================================
--- linux-pm.orig/fs/sysfs/group.c
+++ linux-pm/fs/sysfs/group.c
@@ -205,6 +205,48 @@ void sysfs_unmerge_group(struct kobject
 }
 EXPORT_SYMBOL_GPL(sysfs_unmerge_group);
 
+/**
+ * sysfs_add_link_to_group - add a symlink to an attribute group.
+ * @kobj:	The kobject containing the group.
+ * @group_name:	The name of the group.
+ * @target:	The target kobject of the symlink to create.
+ * @link_name:	The name of the symlink to create.
+ */
+int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name,
+			    struct kobject *target, const char *link_name)
+{
+	struct sysfs_dirent *dir_sd;
+	int error = 0;
+
+	dir_sd = sysfs_get_dirent(kobj->sd, NULL, group_name);
+	if (!dir_sd)
+		return -ENOENT;
+
+	error = sysfs_create_link_sd(dir_sd, target, link_name);
+	sysfs_put(dir_sd);
+
+	return error;
+}
+EXPORT_SYMBOL_GPL(sysfs_add_link_to_group);
+
+/**
+ * sysfs_remove_link_from_group - remove a symlink from an attribute group.
+ * @kobj:	The kobject containing the group.
+ * @group_name:	The name of the group.
+ * @link_name:	The name of the symlink to remove.
+ */
+void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name,
+				  const char *link_name)
+{
+	struct sysfs_dirent *dir_sd;
+
+	dir_sd = sysfs_get_dirent(kobj->sd, NULL, group_name);
+	if (dir_sd) {
+		sysfs_hash_and_remove(dir_sd, NULL, link_name);
+		sysfs_put(dir_sd);
+	}
+}
+EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group);
 
 EXPORT_SYMBOL_GPL(sysfs_create_group);
 EXPORT_SYMBOL_GPL(sysfs_update_group);
Index: linux-pm/fs/sysfs/symlink.c
===================================================================
--- linux-pm.orig/fs/sysfs/symlink.c
+++ linux-pm/fs/sysfs/symlink.c
@@ -21,26 +21,17 @@
 
 #include "sysfs.h"
 
-static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
-				const char *name, int warn)
+static int sysfs_do_create_link_sd(struct sysfs_dirent *parent_sd,
+				   struct kobject *target,
+				   const char *name, int warn)
 {
-	struct sysfs_dirent *parent_sd = NULL;
 	struct sysfs_dirent *target_sd = NULL;
 	struct sysfs_dirent *sd = NULL;
 	struct sysfs_addrm_cxt acxt;
 	enum kobj_ns_type ns_type;
 	int error;
 
-	BUG_ON(!name);
-
-	if (!kobj)
-		parent_sd = &sysfs_root;
-	else
-		parent_sd = kobj->sd;
-
-	error = -EFAULT;
-	if (!parent_sd)
-		goto out_put;
+	BUG_ON(!name || !parent_sd);
 
 	/* target->sd can go away beneath us but is protected with
 	 * sysfs_assoc_lock.  Fetch target_sd from it.
@@ -96,6 +87,34 @@ static int sysfs_do_create_link(struct k
 }
 
 /**
+ *	sysfs_create_link_sd - create symlink to a given object.
+ *	@sd:		directory we're creating the link in.
+ *	@target:	object we're pointing to.
+ *	@name:		name of the symlink.
+ */
+int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target,
+			 const char *name)
+{
+	return sysfs_do_create_link_sd(sd, target, name, 1);
+}
+
+static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target,
+				const char *name, int warn)
+{
+	struct sysfs_dirent *parent_sd = NULL;
+
+	if (!kobj)
+		parent_sd = &sysfs_root;
+	else
+		parent_sd = kobj->sd;
+
+	if (!parent_sd)
+		return -EFAULT;
+
+	return sysfs_do_create_link_sd(parent_sd, target, name, warn);
+}
+
+/**
  *	sysfs_create_link - create symlink between two objects.
  *	@kobj:	object whose directory we're creating the link in.
  *	@target:	object we're pointing to.
Index: linux-pm/include/linux/sysfs.h
===================================================================
--- linux-pm.orig/include/linux/sysfs.h
+++ linux-pm/include/linux/sysfs.h
@@ -181,6 +181,10 @@ int sysfs_merge_group(struct kobject *ko
 		       const struct attribute_group *grp);
 void sysfs_unmerge_group(struct kobject *kobj,
 		       const struct attribute_group *grp);
+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);
 
 void sysfs_notify(struct kobject *kobj, const char *dir, const char *attr);
 void sysfs_notify_dirent(struct sysfs_dirent *sd);
Index: linux-pm/fs/sysfs/sysfs.h
===================================================================
--- linux-pm.orig/fs/sysfs/sysfs.h
+++ linux-pm/fs/sysfs/sysfs.h
@@ -240,3 +240,5 @@ void unmap_bin_file(struct sysfs_dirent
  * symlink.c
  */
 extern const struct inode_operations sysfs_symlink_inode_operations;
+int sysfs_create_link_sd(struct sysfs_dirent *sd, struct kobject *target,
+			 const char *name);

  parent reply	other threads:[~2013-01-23 18:00 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-20 14:51 [RFC][PATCH 0/3] ACPI / PM: Export power resources information to user space Rafael J. Wysocki
2013-01-20 14:53 ` [RFC][PATCH 1/3] ACPI / PM: Expose reference count values of ACPI power resources Rafael J. Wysocki
2013-01-20 14:54 ` [RFC][PATCH 2/3] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-20 14:57 ` [RFC][PATCH 3/3] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-20 23:37 ` [RFC][PATCH 0/3] ACPI / PM: Export power resources information " Greg Kroah-Hartman
2013-01-21  0:11   ` Rafael J. Wysocki
2013-01-21  0:48 ` [RFC][Update][PATCH " Rafael J. Wysocki
2013-01-21  0:50   ` [RFC][Update][PATCH 1/3] ACPI / PM: Expose reference count values of ACPI power resources Rafael J. Wysocki
2013-01-21  0:51   ` [RFC][Update][PATCH 2/3] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-21  0:53   ` [RFC][Update][PATCH 3/3] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-21 13:03   ` [RFC][Update 2][PATCH 0/4] ACPI / PM: Export power information " Rafael J. Wysocki
2013-01-21 13:04     ` [RFC][Update 2][PATCH 1/4] ACPI / PM: Export power states of ACPI devices via sysfs Rafael J. Wysocki
2013-01-21 20:53       ` Greg Kroah-Hartman
2013-01-21 22:27         ` Rafael J. Wysocki
2013-01-21 22:26           ` Greg Kroah-Hartman
2013-01-21 22:59             ` Rafael J. Wysocki
2013-01-21 23:08               ` Greg Kroah-Hartman
2013-01-22  0:48                 ` Rafael J. Wysocki
2013-01-21 13:05     ` [RFC][Update 2][PATCH 2/4] ACPI / PM: Expose reference count values of ACPI power resources Rafael J. Wysocki
2013-01-21 20:53       ` Greg Kroah-Hartman
2013-01-21 22:35         ` Rafael J. Wysocki
2013-01-21 22:33           ` Greg Kroah-Hartman
2013-01-21 13:06     ` [RFC][Update 2][PATCH 3/4] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-21 20:58       ` Greg Kroah-Hartman
2013-01-21 22:41         ` Rafael J. Wysocki
2013-01-21 22:38           ` Greg Kroah-Hartman
2013-01-21 13:08     ` [RFC][Update 2][PATCH 4/4] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-21 20:58       ` Greg Kroah-Hartman
2013-01-21 22:42         ` Rafael J. Wysocki
2013-01-22  2:15     ` [PATCH 0/4] ACPI / PM: Export power information " Rafael J. Wysocki
2013-01-22  2:25       ` [PATCH 1/4] ACPI / PM: Expose power states of ACPI devices " Rafael J. Wysocki
2013-01-22 23:42         ` Greg Kroah-Hartman
2013-01-22 23:47         ` Greg Kroah-Hartman
2013-01-23  0:01           ` Rafael J. Wysocki
2013-01-22 23:58             ` Greg Kroah-Hartman
2013-01-22  2:26       ` [PATCH 2/4] ACPI / PM: Expose current status of ACPI power resources Rafael J. Wysocki
2013-01-22 23:49         ` Greg Kroah-Hartman
2013-01-22  2:27       ` [PATCH 3/4] sysfs: Functions for adding/removing symlinks to/from attribute groups Rafael J. Wysocki
2013-01-22 23:51         ` Greg Kroah-Hartman
2013-01-23  0:03           ` Rafael J. Wysocki
2013-01-22  2:28       ` [PATCH 4/4] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-22 23:56         ` Greg Kroah-Hartman
2013-01-23  0:08           ` Rafael J. Wysocki
2013-01-23  0:17             ` Rafael J. Wysocki
2013-01-23  0:28               ` Rafael J. Wysocki
2013-01-23  1:05                 ` Greg Kroah-Hartman
2013-01-23 14:01                   ` Rafael J. Wysocki
2013-01-23  1:03               ` Greg Kroah-Hartman
2013-01-23 14:00                 ` Rafael J. Wysocki
2013-01-23 17:56       ` [Update][PATCH 0/5] ACPI / PM: Export power information " Rafael J. Wysocki
2013-01-23 17:58         ` [Update][PATCH 1/5] ACPI / scan: Prevent device add uevents from racing with " Rafael J. Wysocki
2013-01-24  0:33           ` Greg Kroah-Hartman
2013-01-23 17:59         ` [Update][PATCH 2/5] ACPI / PM: Expose power states of ACPI devices to " Rafael J. Wysocki
2013-01-23 18:00         ` [Update][PATCH 3/5] ACPI / PM: Expose current status of ACPI power resources Rafael J. Wysocki
2013-01-23 18:00         ` Rafael J. Wysocki [this message]
2013-01-24  0:33           ` [Update][PATCH 4/5] sysfs: Functions for adding/removing symlinks to/from attribute groups Greg Kroah-Hartman
2013-01-25 20:13           ` [patch] sysfs: Fix build when sysfs is disabled David Rientjes
2013-01-25 20:42             ` Greg Kroah-Hartman
2013-01-25 20:53               ` Rafael J. Wysocki
2013-01-25 20:52             ` Rafael J. Wysocki
2013-01-25 21:34               ` David Rientjes
2013-01-23 18:01         ` [Update][PATCH 5/5] ACPI / PM: Expose lists of device power resources to user space Rafael J. Wysocki
2013-01-24  0:34           ` Greg Kroah-Hartman
2013-01-24  0:34         ` [Update][PATCH 0/5] ACPI / PM: Export power information " Greg Kroah-Hartman
2013-01-24 12:34           ` Rafael J. Wysocki

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=1511541.AH8DLsNQJH@vostro.rjw.lan \
    --to=rjw@sisk.pl \
    --cc=gregkh@linuxfoundation.org \
    --cc=kristen.c.accardi@intel.com \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.