diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/kobject.c | 62 | ||||
| -rw-r--r-- | lib/kobject_uevent.c | 26 | ||||
| -rw-r--r-- | lib/kref.c | 2 |
3 files changed, 67 insertions, 23 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) |
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 82fc1794b691..12e311dc664c 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c | |||
| @@ -42,10 +42,6 @@ static char *action_to_string(enum kobject_action action) | |||
| 42 | return "remove"; | 42 | return "remove"; |
| 43 | case KOBJ_CHANGE: | 43 | case KOBJ_CHANGE: |
| 44 | return "change"; | 44 | return "change"; |
| 45 | case KOBJ_MOUNT: | ||
| 46 | return "mount"; | ||
| 47 | case KOBJ_UMOUNT: | ||
| 48 | return "umount"; | ||
| 49 | case KOBJ_OFFLINE: | 45 | case KOBJ_OFFLINE: |
| 50 | return "offline"; | 46 | return "offline"; |
| 51 | case KOBJ_ONLINE: | 47 | case KOBJ_ONLINE: |
| @@ -95,10 +91,8 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, | |||
| 95 | 91 | ||
| 96 | /* search the kset we belong to */ | 92 | /* search the kset we belong to */ |
| 97 | top_kobj = kobj; | 93 | top_kobj = kobj; |
| 98 | if (!top_kobj->kset && top_kobj->parent) { | 94 | while (!top_kobj->kset && top_kobj->parent) { |
| 99 | do { | 95 | top_kobj = top_kobj->parent; |
| 100 | top_kobj = top_kobj->parent; | ||
| 101 | } while (!top_kobj->kset && top_kobj->parent); | ||
| 102 | } | 96 | } |
| 103 | if (!top_kobj->kset) { | 97 | if (!top_kobj->kset) { |
| 104 | pr_debug("kobject attempted to send uevent without kset!\n"); | 98 | pr_debug("kobject attempted to send uevent without kset!\n"); |
| @@ -115,6 +109,16 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, | |||
| 115 | return 0; | 109 | return 0; |
| 116 | } | 110 | } |
| 117 | 111 | ||
| 112 | /* originating subsystem */ | ||
| 113 | if (uevent_ops && uevent_ops->name) | ||
| 114 | subsystem = uevent_ops->name(kset, kobj); | ||
| 115 | else | ||
| 116 | subsystem = kobject_name(&kset->kobj); | ||
| 117 | if (!subsystem) { | ||
| 118 | pr_debug("unset subsytem caused the event to drop!\n"); | ||
| 119 | return 0; | ||
| 120 | } | ||
| 121 | |||
| 118 | /* environment index */ | 122 | /* environment index */ |
| 119 | envp = kzalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL); | 123 | envp = kzalloc(NUM_ENVP * sizeof (char *), GFP_KERNEL); |
| 120 | if (!envp) | 124 | if (!envp) |
| @@ -134,12 +138,6 @@ int kobject_uevent_env(struct kobject *kobj, enum kobject_action action, | |||
| 134 | goto exit; | 138 | goto exit; |
| 135 | } | 139 | } |
| 136 | 140 | ||
| 137 | /* originating subsystem */ | ||
| 138 | if (uevent_ops && uevent_ops->name) | ||
| 139 | subsystem = uevent_ops->name(kset, kobj); | ||
| 140 | else | ||
| 141 | subsystem = kobject_name(&kset->kobj); | ||
| 142 | |||
| 143 | /* event environemnt for helper process only */ | 141 | /* event environemnt for helper process only */ |
| 144 | envp[i++] = "HOME=/"; | 142 | envp[i++] = "HOME=/"; |
| 145 | envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; | 143 | envp[i++] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin"; |
diff --git a/lib/kref.c b/lib/kref.c index 0d07cc31c818..a6dc3ec328e0 100644 --- a/lib/kref.c +++ b/lib/kref.c | |||
| @@ -21,6 +21,7 @@ | |||
| 21 | void kref_init(struct kref *kref) | 21 | void kref_init(struct kref *kref) |
| 22 | { | 22 | { |
| 23 | atomic_set(&kref->refcount,1); | 23 | atomic_set(&kref->refcount,1); |
| 24 | smp_mb(); | ||
| 24 | } | 25 | } |
| 25 | 26 | ||
| 26 | /** | 27 | /** |
| @@ -31,6 +32,7 @@ void kref_get(struct kref *kref) | |||
| 31 | { | 32 | { |
| 32 | WARN_ON(!atomic_read(&kref->refcount)); | 33 | WARN_ON(!atomic_read(&kref->refcount)); |
| 33 | atomic_inc(&kref->refcount); | 34 | atomic_inc(&kref->refcount); |
| 35 | smp_mb__after_atomic_inc(); | ||
| 34 | } | 36 | } |
| 35 | 37 | ||
| 36 | /** | 38 | /** |
