Re: [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API

2012-07-28 Thread Bryan Wu
On Fri, Jul 27, 2012 at 11:52 PM, Greg KH  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 
>> ---
>>  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 
Kernel Developer+86.186-168-78255 Mobile
Canonical Ltd.  www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API

2012-07-28 Thread Bryan Wu
On Fri, Jul 27, 2012 at 11:52 PM, Greg KH gre...@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...@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...@canonical.com
Kernel Developer+86.186-168-78255 Mobile
Canonical Ltd.  www.canonical.com
Ubuntu - Linux for human beings | www.ubuntu.com
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API

2012-07-27 Thread Greg KH
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 
> ---
>  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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API

2012-07-27 Thread Greg KH
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...@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
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API

2012-07-26 Thread Bryan Wu
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 
---
 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

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH 1/3] sysfs: introduce a sysfs_create_file_uevent new API

2012-07-26 Thread Bryan Wu
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...@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

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/