summaryrefslogtreecommitdiff
path: root/fs/sysfs/file.c
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2013-11-28 14:54:30 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-11-29 17:55:10 -0800
commitccf73cf336dc55bc52748205dee998d2fd4a8808 (patch)
tree8e3a3b9891e6b9d4804299cd23110c91d8f8016e /fs/sysfs/file.c
parent517e64f57883bd63c5a4ab8b3d0d3ed68c55d0cf (diff)
sysfs, kernfs: introduce kernfs[_find_and]_get() and kernfs_put()
Introduce kernfs interface for finding, getting and putting sysfs_dirents. * sysfs_find_dirent() is renamed to kernfs_find_ns() and lockdep assertion for sysfs_mutex is added. * sysfs_get_dirent_ns() is renamed to kernfs_find_and_get(). * Macro inline dancing around __sysfs_get/put() are removed and kernfs_get/put() are made proper functions implemented in fs/sysfs/dir.c. While the conversions are mostly equivalent, there's one difference - kernfs_get() doesn't return the input param as its return value. This change is intentional. While passing through the input increases writability in some areas, it is unnecessary and has been shown to cause confusion regarding how the last ref is handled. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/sysfs/file.c')
-rw-r--r--fs/sysfs/file.c41
1 files changed, 23 insertions, 18 deletions
diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
index e4eca285b390..7f0a79fa2ed8 100644
--- a/fs/sysfs/file.c
+++ b/fs/sysfs/file.c
@@ -881,19 +881,19 @@ void sysfs_notify(struct kobject *k, const char *dir, const char *attr)
struct sysfs_dirent *sd = k->sd, *tmp;
if (sd && dir)
- sd = sysfs_get_dirent(sd, dir);
+ sd = kernfs_find_and_get(sd, dir);
else
- sysfs_get(sd);
+ kernfs_get(sd);
if (sd && attr) {
- tmp = sysfs_get_dirent(sd, attr);
- sysfs_put(sd);
+ tmp = kernfs_find_and_get(sd, attr);
+ kernfs_put(sd);
sd = tmp;
}
if (sd) {
kernfs_notify(sd);
- sysfs_put(sd);
+ kernfs_put(sd);
}
}
EXPORT_SYMBOL_GPL(sysfs_notify);
@@ -1052,7 +1052,7 @@ struct sysfs_dirent *kernfs_create_file_ns_key(struct sysfs_dirent *parent,
sysfs_addrm_finish(&acxt);
if (rc) {
- sysfs_put(sd);
+ kernfs_put(sd);
return ERR_PTR(rc);
}
return sd;
@@ -1106,16 +1106,18 @@ int sysfs_add_file_to_group(struct kobject *kobj,
struct sysfs_dirent *dir_sd;
int error;
- if (group)
- dir_sd = sysfs_get_dirent(kobj->sd, group);
- else
- dir_sd = sysfs_get(kobj->sd);
+ if (group) {
+ dir_sd = kernfs_find_and_get(kobj->sd, group);
+ } else {
+ dir_sd = kobj->sd;
+ kernfs_get(dir_sd);
+ }
if (!dir_sd)
return -ENOENT;
error = sysfs_add_file(dir_sd, attr, false);
- sysfs_put(dir_sd);
+ kernfs_put(dir_sd);
return error;
}
@@ -1135,7 +1137,7 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
struct iattr newattrs;
int rc;
- sd = sysfs_get_dirent(kobj->sd, attr->name);
+ sd = kernfs_find_and_get(kobj->sd, attr->name);
if (!sd)
return -ENOENT;
@@ -1144,7 +1146,7 @@ int sysfs_chmod_file(struct kobject *kobj, const struct attribute *attr,
rc = kernfs_setattr(sd, &newattrs);
- sysfs_put(sd);
+ kernfs_put(sd);
return rc;
}
EXPORT_SYMBOL_GPL(sysfs_chmod_file);
@@ -1185,13 +1187,16 @@ void sysfs_remove_file_from_group(struct kobject *kobj,
{
struct sysfs_dirent *dir_sd;
- if (group)
- dir_sd = sysfs_get_dirent(kobj->sd, group);
- else
- dir_sd = sysfs_get(kobj->sd);
+ if (group) {
+ dir_sd = kernfs_find_and_get(kobj->sd, group);
+ } else {
+ dir_sd = kobj->sd;
+ kernfs_get(dir_sd);
+ }
+
if (dir_sd) {
kernfs_remove_by_name(dir_sd, attr->name);
- sysfs_put(dir_sd);
+ kernfs_put(dir_sd);
}
}
EXPORT_SYMBOL_GPL(sysfs_remove_file_from_group);