Commit aac1f7f9 authored by Jiri Olsa's avatar Jiri Olsa Committed by Ingo Molnar

sysfs: Add sysfs_update_groups function

Adding sysfs_update_groups function to update
multiple groups.

  sysfs_update_groups - given a directory kobject, create a bunch of attribute groups
  @kobj:      The kobject to update the group on
  @groups:    The attribute groups to update, NULL terminated

This function update a bunch of attribute groups.  If an error occurs when
updating a group, all previously updated groups will be removed together
with already existing (not updated) attributes.
Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20190512155518.21468-2-jolsa@kernel.orgSigned-off-by: default avatarIngo Molnar <mingo@kernel.org>
parent 6e86d3db
...@@ -175,20 +175,7 @@ int sysfs_create_group(struct kobject *kobj, ...@@ -175,20 +175,7 @@ int sysfs_create_group(struct kobject *kobj,
} }
EXPORT_SYMBOL_GPL(sysfs_create_group); EXPORT_SYMBOL_GPL(sysfs_create_group);
/** static int internal_create_groups(struct kobject *kobj, int update,
* sysfs_create_groups - given a directory kobject, create a bunch of attribute groups
* @kobj: The kobject to create the group on
* @groups: The attribute groups to create, NULL terminated
*
* This function creates a bunch of attribute groups. If an error occurs when
* creating a group, all previously created groups will be removed, unwinding
* everything back to the original state when this function was called.
* It will explicitly warn and error if any of the attribute files being
* created already exist.
*
* Returns 0 on success or error code from sysfs_create_group on failure.
*/
int sysfs_create_groups(struct kobject *kobj,
const struct attribute_group **groups) const struct attribute_group **groups)
{ {
int error = 0; int error = 0;
...@@ -198,7 +185,7 @@ int sysfs_create_groups(struct kobject *kobj, ...@@ -198,7 +185,7 @@ int sysfs_create_groups(struct kobject *kobj,
return 0; return 0;
for (i = 0; groups[i]; i++) { for (i = 0; groups[i]; i++) {
error = sysfs_create_group(kobj, groups[i]); error = internal_create_group(kobj, update, groups[i]);
if (error) { if (error) {
while (--i >= 0) while (--i >= 0)
sysfs_remove_group(kobj, groups[i]); sysfs_remove_group(kobj, groups[i]);
...@@ -207,8 +194,45 @@ int sysfs_create_groups(struct kobject *kobj, ...@@ -207,8 +194,45 @@ int sysfs_create_groups(struct kobject *kobj,
} }
return error; return error;
} }
/**
* sysfs_create_groups - given a directory kobject, create a bunch of attribute groups
* @kobj: The kobject to create the group on
* @groups: The attribute groups to create, NULL terminated
*
* This function creates a bunch of attribute groups. If an error occurs when
* creating a group, all previously created groups will be removed, unwinding
* everything back to the original state when this function was called.
* It will explicitly warn and error if any of the attribute files being
* created already exist.
*
* Returns 0 on success or error code from sysfs_create_group on failure.
*/
int sysfs_create_groups(struct kobject *kobj,
const struct attribute_group **groups)
{
return internal_create_groups(kobj, 0, groups);
}
EXPORT_SYMBOL_GPL(sysfs_create_groups); EXPORT_SYMBOL_GPL(sysfs_create_groups);
/**
* sysfs_update_groups - given a directory kobject, create a bunch of attribute groups
* @kobj: The kobject to update the group on
* @groups: The attribute groups to update, NULL terminated
*
* This function update a bunch of attribute groups. If an error occurs when
* updating a group, all previously updated groups will be removed together
* with already existing (not updated) attributes.
*
* Returns 0 on success or error code from sysfs_update_group on failure.
*/
int sysfs_update_groups(struct kobject *kobj,
const struct attribute_group **groups)
{
return internal_create_groups(kobj, 1, groups);
}
EXPORT_SYMBOL_GPL(sysfs_update_groups);
/** /**
* sysfs_update_group - given a directory kobject, update an attribute group * sysfs_update_group - given a directory kobject, update an attribute group
* @kobj: The kobject to update the group on * @kobj: The kobject to update the group on
......
...@@ -268,6 +268,8 @@ int __must_check sysfs_create_group(struct kobject *kobj, ...@@ -268,6 +268,8 @@ int __must_check sysfs_create_group(struct kobject *kobj,
const struct attribute_group *grp); const struct attribute_group *grp);
int __must_check sysfs_create_groups(struct kobject *kobj, int __must_check sysfs_create_groups(struct kobject *kobj,
const struct attribute_group **groups); const struct attribute_group **groups);
int __must_check sysfs_update_groups(struct kobject *kobj,
const struct attribute_group **groups);
int sysfs_update_group(struct kobject *kobj, int sysfs_update_group(struct kobject *kobj,
const struct attribute_group *grp); const struct attribute_group *grp);
void sysfs_remove_group(struct kobject *kobj, void sysfs_remove_group(struct kobject *kobj,
...@@ -433,6 +435,12 @@ static inline int sysfs_create_groups(struct kobject *kobj, ...@@ -433,6 +435,12 @@ static inline int sysfs_create_groups(struct kobject *kobj,
return 0; return 0;
} }
static inline int sysfs_update_groups(struct kobject *kobj,
const struct attribute_group **groups)
{
return 0;
}
static inline int sysfs_update_group(struct kobject *kobj, static inline int sysfs_update_group(struct kobject *kobj,
const struct attribute_group *grp) const struct attribute_group *grp)
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment