Commit 36ce6dad6e3cb3f050ed41e0beac0070d2062b25
Committed by
Greg Kroah-Hartman
1 parent
0ad1d6f37c
Exists in
master
and in
7 other branches
driver core: Suppress sysfs warnings for device_rename().
driver core: Suppress sysfs warnings for device_rename(). Renaming network devices to an already existing name is not something we want sysfs to print a scary warning for, since the callers can deal with this correctly. So let's introduce sysfs_create_link_nowarn() which gets rid of the common warning. Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 5 changed files with 84 additions and 14 deletions Side-by-side Diff
drivers/base/core.c
... | ... | @@ -1345,8 +1345,9 @@ |
1345 | 1345 | if (old_class_name) { |
1346 | 1346 | new_class_name = make_class_name(dev->class->name, &dev->kobj); |
1347 | 1347 | if (new_class_name) { |
1348 | - error = sysfs_create_link(&dev->parent->kobj, | |
1349 | - &dev->kobj, new_class_name); | |
1348 | + error = sysfs_create_link_nowarn(&dev->parent->kobj, | |
1349 | + &dev->kobj, | |
1350 | + new_class_name); | |
1350 | 1351 | if (error) |
1351 | 1352 | goto out; |
1352 | 1353 | sysfs_remove_link(&dev->parent->kobj, old_class_name); |
... | ... | @@ -1354,8 +1355,8 @@ |
1354 | 1355 | } |
1355 | 1356 | #else |
1356 | 1357 | if (dev->class) { |
1357 | - error = sysfs_create_link(&dev->class->p->class_subsys.kobj, | |
1358 | - &dev->kobj, dev->bus_id); | |
1358 | + error = sysfs_create_link_nowarn(&dev->class->p->class_subsys.kobj, | |
1359 | + &dev->kobj, dev->bus_id); | |
1359 | 1360 | if (error) |
1360 | 1361 | goto out; |
1361 | 1362 | sysfs_remove_link(&dev->class->p->class_subsys.kobj, |
fs/sysfs/dir.c
... | ... | @@ -398,7 +398,7 @@ |
398 | 398 | } |
399 | 399 | |
400 | 400 | /** |
401 | - * sysfs_add_one - add sysfs_dirent to parent | |
401 | + * __sysfs_add_one - add sysfs_dirent to parent without warning | |
402 | 402 | * @acxt: addrm context to use |
403 | 403 | * @sd: sysfs_dirent to be added |
404 | 404 | * |
... | ... | @@ -417,7 +417,7 @@ |
417 | 417 | * 0 on success, -EEXIST if entry with the given name already |
418 | 418 | * exists. |
419 | 419 | */ |
420 | -int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) | |
420 | +int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) | |
421 | 421 | { |
422 | 422 | if (sysfs_find_dirent(acxt->parent_sd, sd->s_name)) |
423 | 423 | return -EEXIST; |
... | ... | @@ -432,6 +432,39 @@ |
432 | 432 | sysfs_link_sibling(sd); |
433 | 433 | |
434 | 434 | return 0; |
435 | +} | |
436 | + | |
437 | +/** | |
438 | + * sysfs_add_one - add sysfs_dirent to parent | |
439 | + * @acxt: addrm context to use | |
440 | + * @sd: sysfs_dirent to be added | |
441 | + * | |
442 | + * Get @acxt->parent_sd and set sd->s_parent to it and increment | |
443 | + * nlink of parent inode if @sd is a directory and link into the | |
444 | + * children list of the parent. | |
445 | + * | |
446 | + * This function should be called between calls to | |
447 | + * sysfs_addrm_start() and sysfs_addrm_finish() and should be | |
448 | + * passed the same @acxt as passed to sysfs_addrm_start(). | |
449 | + * | |
450 | + * LOCKING: | |
451 | + * Determined by sysfs_addrm_start(). | |
452 | + * | |
453 | + * RETURNS: | |
454 | + * 0 on success, -EEXIST if entry with the given name already | |
455 | + * exists. | |
456 | + */ | |
457 | +int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd) | |
458 | +{ | |
459 | + int ret; | |
460 | + | |
461 | + ret = __sysfs_add_one(acxt, sd); | |
462 | + if (ret == -EEXIST) { | |
463 | + printk(KERN_WARNING "sysfs: duplicate filename '%s' " | |
464 | + "can not be created\n", sd->s_name); | |
465 | + WARN_ON(1); | |
466 | + } | |
467 | + return ret; | |
435 | 468 | } |
436 | 469 | |
437 | 470 | /** |
fs/sysfs/symlink.c
... | ... | @@ -19,13 +19,8 @@ |
19 | 19 | |
20 | 20 | #include "sysfs.h" |
21 | 21 | |
22 | -/** | |
23 | - * sysfs_create_link - create symlink between two objects. | |
24 | - * @kobj: object whose directory we're creating the link in. | |
25 | - * @target: object we're pointing to. | |
26 | - * @name: name of the symlink. | |
27 | - */ | |
28 | -int sysfs_create_link(struct kobject * kobj, struct kobject * target, const char * name) | |
22 | +static int sysfs_do_create_link(struct kobject *kobj, struct kobject *target, | |
23 | + const char *name, int warn) | |
29 | 24 | { |
30 | 25 | struct sysfs_dirent *parent_sd = NULL; |
31 | 26 | struct sysfs_dirent *target_sd = NULL; |
... | ... | @@ -65,7 +60,10 @@ |
65 | 60 | target_sd = NULL; /* reference is now owned by the symlink */ |
66 | 61 | |
67 | 62 | sysfs_addrm_start(&acxt, parent_sd); |
68 | - error = sysfs_add_one(&acxt, sd); | |
63 | + if (warn) | |
64 | + error = sysfs_add_one(&acxt, sd); | |
65 | + else | |
66 | + error = __sysfs_add_one(&acxt, sd); | |
69 | 67 | sysfs_addrm_finish(&acxt); |
70 | 68 | |
71 | 69 | if (error) |
... | ... | @@ -77,6 +75,33 @@ |
77 | 75 | sysfs_put(target_sd); |
78 | 76 | sysfs_put(sd); |
79 | 77 | return error; |
78 | +} | |
79 | + | |
80 | +/** | |
81 | + * sysfs_create_link - create symlink between two objects. | |
82 | + * @kobj: object whose directory we're creating the link in. | |
83 | + * @target: object we're pointing to. | |
84 | + * @name: name of the symlink. | |
85 | + */ | |
86 | +int sysfs_create_link(struct kobject *kobj, struct kobject *target, | |
87 | + const char *name) | |
88 | +{ | |
89 | + return sysfs_do_create_link(kobj, target, name, 1); | |
90 | +} | |
91 | + | |
92 | +/** | |
93 | + * sysfs_create_link_nowarn - create symlink between two objects. | |
94 | + * @kobj: object whose directory we're creating the link in. | |
95 | + * @target: object we're pointing to. | |
96 | + * @name: name of the symlink. | |
97 | + * | |
98 | + * This function does the same as sysf_create_link(), but it | |
99 | + * doesn't warn if the link already exists. | |
100 | + */ | |
101 | +int sysfs_create_link_nowarn(struct kobject *kobj, struct kobject *target, | |
102 | + const char *name) | |
103 | +{ | |
104 | + return sysfs_do_create_link(kobj, target, name, 0); | |
80 | 105 | } |
81 | 106 | |
82 | 107 | /** |
fs/sysfs/sysfs.h
... | ... | @@ -107,6 +107,7 @@ |
107 | 107 | void sysfs_put_active_two(struct sysfs_dirent *sd); |
108 | 108 | void sysfs_addrm_start(struct sysfs_addrm_cxt *acxt, |
109 | 109 | struct sysfs_dirent *parent_sd); |
110 | +int __sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); | |
110 | 111 | int sysfs_add_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); |
111 | 112 | void sysfs_remove_one(struct sysfs_addrm_cxt *acxt, struct sysfs_dirent *sd); |
112 | 113 | void sysfs_addrm_finish(struct sysfs_addrm_cxt *acxt); |
include/linux/sysfs.h
... | ... | @@ -101,6 +101,9 @@ |
101 | 101 | |
102 | 102 | int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, |
103 | 103 | const char *name); |
104 | +int __must_check sysfs_create_link_nowarn(struct kobject *kobj, | |
105 | + struct kobject *target, | |
106 | + const char *name); | |
104 | 107 | void sysfs_remove_link(struct kobject *kobj, const char *name); |
105 | 108 | |
106 | 109 | int __must_check sysfs_create_group(struct kobject *kobj, |
... | ... | @@ -176,6 +179,13 @@ |
176 | 179 | |
177 | 180 | static inline int sysfs_create_link(struct kobject *kobj, |
178 | 181 | struct kobject *target, const char *name) |
182 | +{ | |
183 | + return 0; | |
184 | +} | |
185 | + | |
186 | +static inline int sysfs_create_link_nowarn(struct kobject *kobj, | |
187 | + struct kobject *target, | |
188 | + const char *name) | |
179 | 189 | { |
180 | 190 | return 0; |
181 | 191 | } |