aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kobject.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/kobject.c')
-rw-r--r--lib/kobject.c62
1 files changed, 53 insertions, 9 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 057921c5945a..cecf2fbede3e 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -157,7 +157,7 @@ static void unlink(struct kobject * kobj)
157} 157}
158 158
159/** 159/**
160 * kobject_add - add an object to the hierarchy. 160 * kobject_shadow_add - add an object to the hierarchy.
161 * @kobj: object. 161 * @kobj: object.
162 * @shadow_parent: sysfs directory to add to. 162 * @shadow_parent: sysfs directory to add to.
163 */ 163 */
@@ -174,6 +174,7 @@ int kobject_shadow_add(struct kobject * kobj, struct dentry *shadow_parent)
174 if (!*kobj->k_name) { 174 if (!*kobj->k_name) {
175 pr_debug("kobject attempted to be registered with no name!\n"); 175 pr_debug("kobject attempted to be registered with no name!\n");
176 WARN_ON(1); 176 WARN_ON(1);
177 kobject_put(kobj);
177 return -EINVAL; 178 return -EINVAL;
178 } 179 }
179 parent = kobject_get(kobj->parent); 180 parent = kobject_get(kobj->parent);
@@ -190,8 +191,8 @@ int kobject_shadow_add(struct kobject * kobj, struct dentry *shadow_parent)
190 191
191 list_add_tail(&kobj->entry,&kobj->kset->list); 192 list_add_tail(&kobj->entry,&kobj->kset->list);
192 spin_unlock(&kobj->kset->list_lock); 193 spin_unlock(&kobj->kset->list_lock);
194 kobj->parent = parent;
193 } 195 }
194 kobj->parent = parent;
195 196
196 error = create_dir(kobj, shadow_parent); 197 error = create_dir(kobj, shadow_parent);
197 if (error) { 198 if (error) {
@@ -311,13 +312,43 @@ EXPORT_SYMBOL(kobject_set_name);
311int kobject_rename(struct kobject * kobj, const char *new_name) 312int kobject_rename(struct kobject * kobj, const char *new_name)
312{ 313{
313 int error = 0; 314 int error = 0;
315 const char *devpath = NULL;
316 char *devpath_string = NULL;
317 char *envp[2];
314 318
315 kobj = kobject_get(kobj); 319 kobj = kobject_get(kobj);
316 if (!kobj) 320 if (!kobj)
317 return -EINVAL; 321 return -EINVAL;
318 if (!kobj->parent) 322 if (!kobj->parent)
319 return -EINVAL; 323 return -EINVAL;
324
325 devpath = kobject_get_path(kobj, GFP_KERNEL);
326 if (!devpath) {
327 error = -ENOMEM;
328 goto out;
329 }
330 devpath_string = kmalloc(strlen(devpath) + 15, GFP_KERNEL);
331 if (!devpath_string) {
332 error = -ENOMEM;
333 goto out;
334 }
335 sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
336 envp[0] = devpath_string;
337 envp[1] = NULL;
338 /* Note : if we want to send the new name alone, not the full path,
339 * we could probably use kobject_name(kobj); */
340
320 error = sysfs_rename_dir(kobj, kobj->parent->dentry, new_name); 341 error = sysfs_rename_dir(kobj, kobj->parent->dentry, new_name);
342
343 /* This function is mostly/only used for network interface.
344 * Some hotplug package track interfaces by their name and
345 * therefore want to know when the name is changed by the user. */
346 if (!error)
347 kobject_uevent_env(kobj, KOBJ_MOVE, envp);
348
349out:
350 kfree(devpath_string);
351 kfree(devpath);
321 kobject_put(kobj); 352 kobject_put(kobj);
322 353
323 return error; 354 return error;
@@ -488,13 +519,15 @@ static struct kobj_type dir_ktype = {
488}; 519};
489 520
490/** 521/**
491 * kobject_add_dir - add sub directory of object. 522 * kobject_kset_add_dir - add sub directory of object.
523 * @kset: kset the directory is belongs to.
492 * @parent: object in which a directory is created. 524 * @parent: object in which a directory is created.
493 * @name: directory name. 525 * @name: directory name.
494 * 526 *
495 * Add a plain directory object as child of given object. 527 * Add a plain directory object as child of given object.
496 */ 528 */
497struct kobject *kobject_add_dir(struct kobject *parent, const char *name) 529struct kobject *kobject_kset_add_dir(struct kset *kset,
530 struct kobject *parent, const char *name)
498{ 531{
499 struct kobject *k; 532 struct kobject *k;
500 int ret; 533 int ret;
@@ -506,13 +539,14 @@ struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
506 if (!k) 539 if (!k)
507 return NULL; 540 return NULL;
508 541
542 k->kset = kset;
509 k->parent = parent; 543 k->parent = parent;
510 k->ktype = &dir_ktype; 544 k->ktype = &dir_ktype;
511 kobject_set_name(k, name); 545 kobject_set_name(k, name);
512 ret = kobject_register(k); 546 ret = kobject_register(k);
513 if (ret < 0) { 547 if (ret < 0) {
514 printk(KERN_WARNING "kobject_add_dir: " 548 printk(KERN_WARNING "%s: kobject_register error: %d\n",
515 "kobject_register error: %d\n", ret); 549 __func__, ret);
516 kobject_del(k); 550 kobject_del(k);
517 return NULL; 551 return NULL;
518 } 552 }
@@ -521,6 +555,18 @@ struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
521} 555}
522 556
523/** 557/**
558 * kobject_add_dir - add sub directory of object.
559 * @parent: object in which a directory is created.
560 * @name: directory name.
561 *
562 * Add a plain directory object as child of given object.
563 */
564struct kobject *kobject_add_dir(struct kobject *parent, const char *name)
565{
566 return kobject_kset_add_dir(NULL, parent, name);
567}
568
569/**
524 * kset_init - initialize a kset for use 570 * kset_init - initialize a kset for use
525 * @k: kset 571 * @k: kset
526 */ 572 */
@@ -613,7 +659,6 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name)
613 659
614void subsystem_init(struct subsystem * s) 660void subsystem_init(struct subsystem * s)
615{ 661{
616 init_rwsem(&s->rwsem);
617 kset_init(&s->kset); 662 kset_init(&s->kset);
618} 663}
619 664
@@ -622,8 +667,7 @@ void subsystem_init(struct subsystem * s)
622 * @s: the subsystem we're registering. 667 * @s: the subsystem we're registering.
623 * 668 *
624 * Once we register the subsystem, we want to make sure that 669 * Once we register the subsystem, we want to make sure that
625 * the kset points back to this subsystem for correct usage of 670 * the kset points back to this subsystem.
626 * the rwsem.
627 */ 671 */
628 672
629int subsystem_register(struct subsystem * s) 673int subsystem_register(struct subsystem * s)