* [PATCH 0/3] add new API to sysfs and device core code
@ 2012-07-27 4:02 Bryan Wu
2012-07-27 4:02 ` [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API Bryan Wu
` (3 more replies)
0 siblings, 4 replies; 8+ messages in thread
From: Bryan Wu @ 2012-07-27 4:02 UTC (permalink / raw)
To: gregkh, ccross, hmh, rpurdie, linux-kernel, linux-leds
Send out a uevent when create file in sysfs, which is required by userspace
application such udev in Android
Bryan Wu (3):
sysfs: introduce a sysfs_create_file_uevent new API
drivers: add a new device_create_file_uevent API
ledtrig-timer: convert to use device_create_file_uevent API
drivers/base/core.c | 19 +++++++++++++++++++
drivers/leds/ledtrig-timer.c | 6 ++++--
fs/sysfs/file.c | 28 ++++++++++++++++++++++++++++
include/linux/device.h | 4 ++++
include/linux/sysfs.h | 13 +++++++++++++
5 files changed, 68 insertions(+), 2 deletions(-)
--
1.7.11.1
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API
2012-07-27 4:02 [PATCH 0/3] add new API to sysfs and device core code Bryan Wu
@ 2012-07-27 4:02 ` Bryan Wu
2012-07-27 15:52 ` Greg KH
2012-07-27 4:02 ` [PATCH 2/3] drivers: add a new device_create_file_uevent API Bryan Wu
` (2 subsequent siblings)
3 siblings, 1 reply; 8+ messages in thread
From: Bryan Wu @ 2012-07-27 4:02 UTC (permalink / raw)
To: gregkh, ccross, hmh, rpurdie, linux-kernel, linux-leds
Send a uevent notification whenever a new sysfs file is created to allow
userspace processes such as udev to modify permissions on the new files.
This new API function helps to do this.
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
fs/sysfs/file.c | 28 ++++++++++++++++++++++++++++
include/linux/sysfs.h | 13 +++++++++++++
2 files changed, 41 insertions(+)
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index 00012e3..5a22d13 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -576,6 +576,34 @@ int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
}
+/**
+ * sysfs_create_file_uevent - create an attribute file for an object
+ and send a uevent to userspace.
+ * @kobj: object we're creating for.
+ * @attr: attribute descriptor.
+ * @desc: description about the uevent.
+ * @action: kobject uevent action type.
+ */
+
+int sysfs_create_file_uevent(struct kobject *kobj, const struct attribute *attr,
+ const char *desc, enum kobject_action action)
+{
+ int err = 0;
+ char *envp[2];
+
+ BUG_ON(!kobj || !kobj->sd || !attr || !desc);
+
+ err = sysfs_add_file(kobj->sd, attr, SYSFS_KOBJ_ATTR);
+
+ if (desc) {
+ envp[0] = desc;
+ envp[1] = NULL;
+ kobject_uevent_env(kobj, action, envp);
+ }
+
+ return err;
+}
+
int sysfs_create_files(struct kobject *kobj, const struct attribute **ptr)
{
int err = 0;
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 381f06d..0054d41 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -22,6 +22,7 @@
struct kobject;
struct module;
enum kobj_ns_type;
+enum kobject_action;
struct attribute {
const char *name;
@@ -142,6 +143,10 @@ int __must_check sysfs_move_dir(struct kobject *kobj,
int __must_check sysfs_create_file(struct kobject *kobj,
const struct attribute *attr);
+int __must_check sysfs_create_file_uevent(struct kobject * kobj,
+ const struct attribute * attr,
+ const char * desc,
+ enum kobject_action action);
int __must_check sysfs_create_files(struct kobject *kobj,
const struct attribute **attr);
int __must_check sysfs_chmod_file(struct kobject *kobj,
@@ -226,6 +231,14 @@ static inline int sysfs_create_file(struct kobject *kobj,
return 0;
}
+static inline int sysfs_create_file_uevent(struct kobject * kobj,
+ const struct attribute * attr,
+ const char *desc,
+ enum kobject_action action)
+{
+ return 0;
+}
+
static inline int sysfs_create_files(struct kobject *kobj,
const struct attribute **attr)
{
--
1.7.11.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 2/3] drivers: add a new device_create_file_uevent API
2012-07-27 4:02 [PATCH 0/3] add new API to sysfs and device core code Bryan Wu
2012-07-27 4:02 ` [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API Bryan Wu
@ 2012-07-27 4:02 ` Bryan Wu
2012-07-27 4:02 ` [PATCH 3/3] ledtrig-timer: convert to use " Bryan Wu
2012-07-27 15:50 ` [PATCH 0/3] add new API to sysfs and device core code Greg KH
3 siblings, 0 replies; 8+ messages in thread
From: Bryan Wu @ 2012-07-27 4:02 UTC (permalink / raw)
To: gregkh, ccross, hmh, rpurdie, linux-kernel, linux-leds
This will use sysfs_create_file_uevent to create a sysfs file and send out
a uevent to userspace application such as udev.
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
drivers/base/core.c | 19 +++++++++++++++++++
include/linux/device.h | 4 ++++
2 files changed, 23 insertions(+)
diff --git a/drivers/base/core.c b/drivers/base/core.c
index 346be8b..62fd266 100644
--- a/drivers/base/core.c
+++ b/drivers/base/core.c
@@ -538,6 +538,25 @@ int device_create_file(struct device *dev,
}
/**
+ * device_create_file_uevent - create sysfs attribute file for device
+ * and send a uevent to userspace.
+ * @dev: device.
+ * @attr: device attribute descriptor.
+ * @desc: description about the uevent.
+ * @action: kobject uevent action type.
+ */
+int device_create_file_uevent(struct device *dev,
+ const struct device_attribute *attr,
+ const char *desc,
+ enum kobject_action action)
+{
+ int error = 0;
+ if (dev)
+ error = sysfs_create_file_uevent(&dev->kobj, &attr->attr,
+ desc, action);
+ return error;
+}
+/**
* device_remove_file - remove sysfs attribute file.
* @dev: device.
* @attr: device attribute descriptor.
diff --git a/include/linux/device.h b/include/linux/device.h
index 6de9415..d1545f3 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -510,6 +510,10 @@ ssize_t device_store_int(struct device *dev, struct device_attribute *attr,
extern int device_create_file(struct device *device,
const struct device_attribute *entry);
+extern int device_create_file_uevent(struct device *dev,
+ const struct device_attribute *attr,
+ const char *desc,
+ enum kobject_action action);
extern void device_remove_file(struct device *dev,
const struct device_attribute *attr);
extern int __must_check device_create_bin_file(struct device *dev,
--
1.7.11.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [PATCH 3/3] ledtrig-timer: convert to use device_create_file_uevent API
2012-07-27 4:02 [PATCH 0/3] add new API to sysfs and device core code Bryan Wu
2012-07-27 4:02 ` [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API Bryan Wu
2012-07-27 4:02 ` [PATCH 2/3] drivers: add a new device_create_file_uevent API Bryan Wu
@ 2012-07-27 4:02 ` Bryan Wu
2012-07-27 15:50 ` [PATCH 0/3] add new API to sysfs and device core code Greg KH
3 siblings, 0 replies; 8+ messages in thread
From: Bryan Wu @ 2012-07-27 4:02 UTC (permalink / raw)
To: gregkh, ccross, hmh, rpurdie, linux-kernel, linux-leds
To send KOBJ_CHANGE uevent to userspace which is required by Android
Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
---
drivers/leds/ledtrig-timer.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/drivers/leds/ledtrig-timer.c b/drivers/leds/ledtrig-timer.c
index 9010f7a..d8b6296 100644
--- a/drivers/leds/ledtrig-timer.c
+++ b/drivers/leds/ledtrig-timer.c
@@ -78,10 +78,12 @@ static void timer_trig_activate(struct led_classdev *led_cdev)
led_cdev->trigger_data = NULL;
- rc = device_create_file(led_cdev->dev, &dev_attr_delay_on);
+ rc = device_create_file_uevent(led_cdev->dev, &dev_attr_delay_on,
+ "TRIGGER=timer", KOBJ_CHANGE);
if (rc)
return;
- rc = device_create_file(led_cdev->dev, &dev_attr_delay_off);
+ rc = device_create_file_uevent(led_cdev->dev, &dev_attr_delay_off,
+ "TRIGGER=timer", KOBJ_CHANGE);
if (rc)
goto err_out_delayon;
--
1.7.11.1
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] add new API to sysfs and device core code
2012-07-27 4:02 [PATCH 0/3] add new API to sysfs and device core code Bryan Wu
` (2 preceding siblings ...)
2012-07-27 4:02 ` [PATCH 3/3] ledtrig-timer: convert to use " Bryan Wu
@ 2012-07-27 15:50 ` Greg KH
2012-07-27 19:38 ` Colin Cross
3 siblings, 1 reply; 8+ messages in thread
From: Greg KH @ 2012-07-27 15:50 UTC (permalink / raw)
To: Bryan Wu; +Cc: ccross, hmh, rpurdie, linux-kernel, linux-leds
On Fri, Jul 27, 2012 at 12:02:40PM +0800, Bryan Wu wrote:
> Send out a uevent when create file in sysfs, which is required by userspace
> application such udev in Android
There is no such thing as "udev in Android" the last time I looked.
Has this changed?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API
2012-07-27 4:02 ` [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API Bryan Wu
@ 2012-07-27 15:52 ` Greg KH
2012-07-28 15:18 ` Bryan Wu
0 siblings, 1 reply; 8+ messages in thread
From: Greg KH @ 2012-07-27 15:52 UTC (permalink / raw)
To: Bryan Wu; +Cc: ccross, hmh, rpurdie, linux-kernel, linux-leds
On Fri, Jul 27, 2012 at 12:02:41PM +0800, Bryan Wu wrote:
> Send a uevent notification whenever a new sysfs file is created to allow
> userspace processes such as udev to modify permissions on the new files.
This makes no sense, why not just call kobject_uevent after creating the
file when needed? Wrapping it up in a single function call doesn't add
any benefit that I can see, can you?
>
> This new API function helps to do this.
>
> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
> ---
> fs/sysfs/file.c | 28 ++++++++++++++++++++++++++++
> include/linux/sysfs.h | 13 +++++++++++++
> 2 files changed, 41 insertions(+)
>
> diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
> index 00012e3..5a22d13 100644
> --- a/fs/sysfs/file.c
> +++ b/fs/sysfs/file.c
> @@ -576,6 +576,34 @@ int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
>
> }
>
> +/**
> + * sysfs_create_file_uevent - create an attribute file for an object
> + and send a uevent to userspace.
kerneldoc needs to be on one line for function names, right?
greg k-h
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 0/3] add new API to sysfs and device core code
2012-07-27 15:50 ` [PATCH 0/3] add new API to sysfs and device core code Greg KH
@ 2012-07-27 19:38 ` Colin Cross
0 siblings, 0 replies; 8+ messages in thread
From: Colin Cross @ 2012-07-27 19:38 UTC (permalink / raw)
To: Greg KH; +Cc: Bryan Wu, hmh, rpurdie, linux-kernel, linux-leds
On Fri, Jul 27, 2012 at 8:50 AM, Greg KH <gregkh@linuxfoundation.org> wrote:
> On Fri, Jul 27, 2012 at 12:02:40PM +0800, Bryan Wu wrote:
>> Send out a uevent when create file in sysfs, which is required by userspace
>> application such udev in Android
>
> There is no such thing as "udev in Android" the last time I looked.
>
> Has this changed?
Android does not use udev, but it does have a daemon that listens for
uevents (ueventd). I used udev in my previous examples because the
issue is not specific to Android.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API
2012-07-27 15:52 ` Greg KH
@ 2012-07-28 15:18 ` Bryan Wu
0 siblings, 0 replies; 8+ messages in thread
From: Bryan Wu @ 2012-07-28 15:18 UTC (permalink / raw)
To: Greg KH; +Cc: ccross, hmh, rpurdie, linux-kernel, linux-leds
On Fri, Jul 27, 2012 at 11:52 PM, Greg KH <gregkh@linuxfoundation.org> wrote:
> On Fri, Jul 27, 2012 at 12:02:41PM +0800, Bryan Wu wrote:
>> Send a uevent notification whenever a new sysfs file is created to allow
>> userspace processes such as udev to modify permissions on the new files.
>
> This makes no sense, why not just call kobject_uevent after creating the
> file when needed? Wrapping it up in a single function call doesn't add
> any benefit that I can see, can you?
>
I actually just want to make it benefit for further similar issue in
other subsystem, although I got this point from the email started by
Colin Cross. I agree if it is just specific to LED subsystem, we'd
better add this fixing in LED trigger core code. Maybe I worried about
too much and if you guys all ack Colin's patch, I'm going to apply it.
Thanks,
-Bryan
>>
>> This new API function helps to do this.
>>
>> Signed-off-by: Bryan Wu <bryan.wu@canonical.com>
>> ---
>> fs/sysfs/file.c | 28 ++++++++++++++++++++++++++++
>> include/linux/sysfs.h | 13 +++++++++++++
>> 2 files changed, 41 insertions(+)
>>
>> diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
>> index 00012e3..5a22d13 100644
>> --- a/fs/sysfs/file.c
>> +++ b/fs/sysfs/file.c
>> @@ -576,6 +576,34 @@ int sysfs_create_file(struct kobject * kobj, const struct attribute * attr)
>>
>> }
>>
>> +/**
>> + * sysfs_create_file_uevent - create an attribute file for an object
>> + and send a uevent to userspace.
>
> kerneldoc needs to be on one line for function names, right?
>
> greg k-h
--
Bryan Wu <bryan.wu@canonical.com>
Kernel Developer +86.186-168-78255 Mobile
Canonical Ltd. www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2012-07-28 15:18 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-27 4:02 [PATCH 0/3] add new API to sysfs and device core code Bryan Wu
2012-07-27 4:02 ` [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API Bryan Wu
2012-07-27 15:52 ` Greg KH
2012-07-28 15:18 ` Bryan Wu
2012-07-27 4:02 ` [PATCH 2/3] drivers: add a new device_create_file_uevent API Bryan Wu
2012-07-27 4:02 ` [PATCH 3/3] ledtrig-timer: convert to use " Bryan Wu
2012-07-27 15:50 ` [PATCH 0/3] add new API to sysfs and device core code Greg KH
2012-07-27 19:38 ` Colin Cross
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).