diff options
| author | Paul Mackerras <paulus@samba.org> | 2007-04-29 22:38:01 -0400 |
|---|---|---|
| committer | Paul Mackerras <paulus@samba.org> | 2007-04-29 22:38:01 -0400 |
| commit | 49e1900d4cc2e7bcecb681fe60f0990bec2dcce8 (patch) | |
| tree | 253801ebf57e0a23856a2c7be129c2c178f62fdf /lib/kobject.c | |
| parent | 34f6d749c0a328817d5e36274e53121c1db734dc (diff) | |
| parent | b9099ff63c75216d6ca10bce5a1abcd9293c27e6 (diff) | |
Merge branch 'linux-2.6' into for-2.6.22
Diffstat (limited to 'lib/kobject.c')
| -rw-r--r-- | lib/kobject.c | 62 |
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); | |||
| 311 | int kobject_rename(struct kobject * kobj, const char *new_name) | 312 | int 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 | |||
| 349 | out: | ||
| 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 | */ |
| 497 | struct kobject *kobject_add_dir(struct kobject *parent, const char *name) | 529 | struct 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 | */ | ||
| 564 | struct 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 | ||
| 614 | void subsystem_init(struct subsystem * s) | 660 | void 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 | ||
| 629 | int subsystem_register(struct subsystem * s) | 673 | int subsystem_register(struct subsystem * s) |
