diff options
Diffstat (limited to 'fs/sysfs/group.c')
-rw-r--r-- | fs/sysfs/group.c | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/fs/sysfs/group.c b/fs/sysfs/group.c index 1898a10e38ce..7177532b8f7b 100644 --- a/fs/sysfs/group.c +++ b/fs/sysfs/group.c | |||
@@ -26,7 +26,7 @@ static void remove_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, | |||
26 | 26 | ||
27 | if (grp->attrs) | 27 | if (grp->attrs) |
28 | for (attr = grp->attrs; *attr; attr++) | 28 | for (attr = grp->attrs; *attr; attr++) |
29 | sysfs_hash_and_remove(dir_sd, (*attr)->name, NULL); | 29 | kernfs_remove_by_name(dir_sd, (*attr)->name); |
30 | if (grp->bin_attrs) | 30 | if (grp->bin_attrs) |
31 | for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) | 31 | for (bin_attr = grp->bin_attrs; *bin_attr; bin_attr++) |
32 | sysfs_remove_bin_file(kobj, *bin_attr); | 32 | sysfs_remove_bin_file(kobj, *bin_attr); |
@@ -49,15 +49,13 @@ static int create_files(struct sysfs_dirent *dir_sd, struct kobject *kobj, | |||
49 | * re-adding (if required) the file. | 49 | * re-adding (if required) the file. |
50 | */ | 50 | */ |
51 | if (update) | 51 | if (update) |
52 | sysfs_hash_and_remove(dir_sd, (*attr)->name, | 52 | kernfs_remove_by_name(dir_sd, (*attr)->name); |
53 | NULL); | ||
54 | if (grp->is_visible) { | 53 | if (grp->is_visible) { |
55 | mode = grp->is_visible(kobj, *attr, i); | 54 | mode = grp->is_visible(kobj, *attr, i); |
56 | if (!mode) | 55 | if (!mode) |
57 | continue; | 56 | continue; |
58 | } | 57 | } |
59 | error = sysfs_add_file_mode_ns(dir_sd, *attr, | 58 | error = sysfs_add_file_mode_ns(dir_sd, *attr, false, |
60 | SYSFS_KOBJ_ATTR, | ||
61 | (*attr)->mode | mode, | 59 | (*attr)->mode | mode, |
62 | NULL); | 60 | NULL); |
63 | if (unlikely(error)) | 61 | if (unlikely(error)) |
@@ -102,18 +100,21 @@ static int internal_create_group(struct kobject *kobj, int update, | |||
102 | return -EINVAL; | 100 | return -EINVAL; |
103 | } | 101 | } |
104 | if (grp->name) { | 102 | if (grp->name) { |
105 | error = sysfs_create_subdir(kobj, grp->name, &sd); | 103 | sd = kernfs_create_dir(kobj->sd, grp->name, kobj); |
106 | if (error) | 104 | if (IS_ERR(sd)) { |
107 | return error; | 105 | if (PTR_ERR(sd) == -EEXIST) |
106 | sysfs_warn_dup(kobj->sd, grp->name); | ||
107 | return PTR_ERR(sd); | ||
108 | } | ||
108 | } else | 109 | } else |
109 | sd = kobj->sd; | 110 | sd = kobj->sd; |
110 | sysfs_get(sd); | 111 | kernfs_get(sd); |
111 | error = create_files(sd, kobj, grp, update); | 112 | error = create_files(sd, kobj, grp, update); |
112 | if (error) { | 113 | if (error) { |
113 | if (grp->name) | 114 | if (grp->name) |
114 | sysfs_remove(sd); | 115 | kernfs_remove(sd); |
115 | } | 116 | } |
116 | sysfs_put(sd); | 117 | kernfs_put(sd); |
117 | return error; | 118 | return error; |
118 | } | 119 | } |
119 | 120 | ||
@@ -207,21 +208,23 @@ void sysfs_remove_group(struct kobject *kobj, | |||
207 | struct sysfs_dirent *sd; | 208 | struct sysfs_dirent *sd; |
208 | 209 | ||
209 | if (grp->name) { | 210 | if (grp->name) { |
210 | sd = sysfs_get_dirent(dir_sd, grp->name); | 211 | sd = kernfs_find_and_get(dir_sd, grp->name); |
211 | if (!sd) { | 212 | if (!sd) { |
212 | WARN(!sd, KERN_WARNING | 213 | WARN(!sd, KERN_WARNING |
213 | "sysfs group %p not found for kobject '%s'\n", | 214 | "sysfs group %p not found for kobject '%s'\n", |
214 | grp, kobject_name(kobj)); | 215 | grp, kobject_name(kobj)); |
215 | return; | 216 | return; |
216 | } | 217 | } |
217 | } else | 218 | } else { |
218 | sd = sysfs_get(dir_sd); | 219 | sd = dir_sd; |
220 | kernfs_get(sd); | ||
221 | } | ||
219 | 222 | ||
220 | remove_files(sd, kobj, grp); | 223 | remove_files(sd, kobj, grp); |
221 | if (grp->name) | 224 | if (grp->name) |
222 | sysfs_remove(sd); | 225 | kernfs_remove(sd); |
223 | 226 | ||
224 | sysfs_put(sd); | 227 | kernfs_put(sd); |
225 | } | 228 | } |
226 | EXPORT_SYMBOL_GPL(sysfs_remove_group); | 229 | EXPORT_SYMBOL_GPL(sysfs_remove_group); |
227 | 230 | ||
@@ -262,17 +265,17 @@ int sysfs_merge_group(struct kobject *kobj, | |||
262 | struct attribute *const *attr; | 265 | struct attribute *const *attr; |
263 | int i; | 266 | int i; |
264 | 267 | ||
265 | dir_sd = sysfs_get_dirent(kobj->sd, grp->name); | 268 | dir_sd = kernfs_find_and_get(kobj->sd, grp->name); |
266 | if (!dir_sd) | 269 | if (!dir_sd) |
267 | return -ENOENT; | 270 | return -ENOENT; |
268 | 271 | ||
269 | for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) | 272 | for ((i = 0, attr = grp->attrs); *attr && !error; (++i, ++attr)) |
270 | error = sysfs_add_file(dir_sd, *attr, SYSFS_KOBJ_ATTR); | 273 | error = sysfs_add_file(dir_sd, *attr, false); |
271 | if (error) { | 274 | if (error) { |
272 | while (--i >= 0) | 275 | while (--i >= 0) |
273 | sysfs_hash_and_remove(dir_sd, (*--attr)->name, NULL); | 276 | kernfs_remove_by_name(dir_sd, (*--attr)->name); |
274 | } | 277 | } |
275 | sysfs_put(dir_sd); | 278 | kernfs_put(dir_sd); |
276 | 279 | ||
277 | return error; | 280 | return error; |
278 | } | 281 | } |
@@ -289,11 +292,11 @@ void sysfs_unmerge_group(struct kobject *kobj, | |||
289 | struct sysfs_dirent *dir_sd; | 292 | struct sysfs_dirent *dir_sd; |
290 | struct attribute *const *attr; | 293 | struct attribute *const *attr; |
291 | 294 | ||
292 | dir_sd = sysfs_get_dirent(kobj->sd, grp->name); | 295 | dir_sd = kernfs_find_and_get(kobj->sd, grp->name); |
293 | if (dir_sd) { | 296 | if (dir_sd) { |
294 | for (attr = grp->attrs; *attr; ++attr) | 297 | for (attr = grp->attrs; *attr; ++attr) |
295 | sysfs_hash_and_remove(dir_sd, (*attr)->name, NULL); | 298 | kernfs_remove_by_name(dir_sd, (*attr)->name); |
296 | sysfs_put(dir_sd); | 299 | kernfs_put(dir_sd); |
297 | } | 300 | } |
298 | } | 301 | } |
299 | EXPORT_SYMBOL_GPL(sysfs_unmerge_group); | 302 | EXPORT_SYMBOL_GPL(sysfs_unmerge_group); |
@@ -311,12 +314,12 @@ int sysfs_add_link_to_group(struct kobject *kobj, const char *group_name, | |||
311 | struct sysfs_dirent *dir_sd; | 314 | struct sysfs_dirent *dir_sd; |
312 | int error = 0; | 315 | int error = 0; |
313 | 316 | ||
314 | dir_sd = sysfs_get_dirent(kobj->sd, group_name); | 317 | dir_sd = kernfs_find_and_get(kobj->sd, group_name); |
315 | if (!dir_sd) | 318 | if (!dir_sd) |
316 | return -ENOENT; | 319 | return -ENOENT; |
317 | 320 | ||
318 | error = sysfs_create_link_sd(dir_sd, target, link_name); | 321 | error = sysfs_create_link_sd(dir_sd, target, link_name); |
319 | sysfs_put(dir_sd); | 322 | kernfs_put(dir_sd); |
320 | 323 | ||
321 | return error; | 324 | return error; |
322 | } | 325 | } |
@@ -333,10 +336,10 @@ void sysfs_remove_link_from_group(struct kobject *kobj, const char *group_name, | |||
333 | { | 336 | { |
334 | struct sysfs_dirent *dir_sd; | 337 | struct sysfs_dirent *dir_sd; |
335 | 338 | ||
336 | dir_sd = sysfs_get_dirent(kobj->sd, group_name); | 339 | dir_sd = kernfs_find_and_get(kobj->sd, group_name); |
337 | if (dir_sd) { | 340 | if (dir_sd) { |
338 | sysfs_hash_and_remove(dir_sd, link_name, NULL); | 341 | kernfs_remove_by_name(dir_sd, link_name); |
339 | sysfs_put(dir_sd); | 342 | kernfs_put(dir_sd); |
340 | } | 343 | } |
341 | } | 344 | } |
342 | EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); | 345 | EXPORT_SYMBOL_GPL(sysfs_remove_link_from_group); |