diff options
author | Dmitry Torokhov <dtor@insightbb.com> | 2007-05-01 00:24:54 -0400 |
---|---|---|
committer | Dmitry Torokhov <dtor@insightbb.com> | 2007-05-01 00:24:54 -0400 |
commit | bc95f3669f5e6f63cf0b84fe4922c3c6dd4aa775 (patch) | |
tree | 427fcf2a7287c16d4b5aa6cbf494d59579a6a8b1 /lib/kobject.c | |
parent | 3d29cdff999c37b3876082278a8134a0642a02cd (diff) | |
parent | dc87c3985e9b442c60994308a96f887579addc39 (diff) |
Merge master.kernel.org:/pub/scm/linux/kernel/git/torvalds/linux-2.6
Conflicts:
drivers/usb/input/Makefile
drivers/usb/input/gtco.c
Diffstat (limited to 'lib/kobject.c')
-rw-r--r-- | lib/kobject.c | 67 |
1 files changed, 57 insertions, 10 deletions
diff --git a/lib/kobject.c b/lib/kobject.c index 2782f49e906e..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 | */ |
@@ -171,9 +171,10 @@ int kobject_shadow_add(struct kobject * kobj, struct dentry *shadow_parent) | |||
171 | return -ENOENT; | 171 | return -ENOENT; |
172 | if (!kobj->k_name) | 172 | if (!kobj->k_name) |
173 | kobj->k_name = kobj->name; | 173 | kobj->k_name = kobj->name; |
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; |
@@ -326,6 +357,7 @@ int kobject_rename(struct kobject * kobj, const char *new_name) | |||
326 | /** | 357 | /** |
327 | * kobject_rename - change the name of an object | 358 | * kobject_rename - change the name of an object |
328 | * @kobj: object in question. | 359 | * @kobj: object in question. |
360 | * @new_parent: object's new parent | ||
329 | * @new_name: object's new name | 361 | * @new_name: object's new name |
330 | */ | 362 | */ |
331 | 363 | ||
@@ -384,9 +416,11 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent) | |||
384 | goto out; | 416 | goto out; |
385 | old_parent = kobj->parent; | 417 | old_parent = kobj->parent; |
386 | kobj->parent = new_parent; | 418 | kobj->parent = new_parent; |
419 | new_parent = NULL; | ||
387 | kobject_put(old_parent); | 420 | kobject_put(old_parent); |
388 | kobject_uevent_env(kobj, KOBJ_MOVE, envp); | 421 | kobject_uevent_env(kobj, KOBJ_MOVE, envp); |
389 | out: | 422 | out: |
423 | kobject_put(new_parent); | ||
390 | kobject_put(kobj); | 424 | kobject_put(kobj); |
391 | kfree(devpath_string); | 425 | kfree(devpath_string); |
392 | kfree(devpath); | 426 | kfree(devpath); |
@@ -485,13 +519,15 @@ static struct kobj_type dir_ktype = { | |||
485 | }; | 519 | }; |
486 | 520 | ||
487 | /** | 521 | /** |
488 | * 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. | ||
489 | * @parent: object in which a directory is created. | 524 | * @parent: object in which a directory is created. |
490 | * @name: directory name. | 525 | * @name: directory name. |
491 | * | 526 | * |
492 | * Add a plain directory object as child of given object. | 527 | * Add a plain directory object as child of given object. |
493 | */ | 528 | */ |
494 | 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) | ||
495 | { | 531 | { |
496 | struct kobject *k; | 532 | struct kobject *k; |
497 | int ret; | 533 | int ret; |
@@ -503,13 +539,14 @@ struct kobject *kobject_add_dir(struct kobject *parent, const char *name) | |||
503 | if (!k) | 539 | if (!k) |
504 | return NULL; | 540 | return NULL; |
505 | 541 | ||
542 | k->kset = kset; | ||
506 | k->parent = parent; | 543 | k->parent = parent; |
507 | k->ktype = &dir_ktype; | 544 | k->ktype = &dir_ktype; |
508 | kobject_set_name(k, name); | 545 | kobject_set_name(k, name); |
509 | ret = kobject_register(k); | 546 | ret = kobject_register(k); |
510 | if (ret < 0) { | 547 | if (ret < 0) { |
511 | printk(KERN_WARNING "kobject_add_dir: " | 548 | printk(KERN_WARNING "%s: kobject_register error: %d\n", |
512 | "kobject_register error: %d\n", ret); | 549 | __func__, ret); |
513 | kobject_del(k); | 550 | kobject_del(k); |
514 | return NULL; | 551 | return NULL; |
515 | } | 552 | } |
@@ -518,6 +555,18 @@ struct kobject *kobject_add_dir(struct kobject *parent, const char *name) | |||
518 | } | 555 | } |
519 | 556 | ||
520 | /** | 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 | /** | ||
521 | * kset_init - initialize a kset for use | 570 | * kset_init - initialize a kset for use |
522 | * @k: kset | 571 | * @k: kset |
523 | */ | 572 | */ |
@@ -610,7 +659,6 @@ struct kobject * kset_find_obj(struct kset * kset, const char * name) | |||
610 | 659 | ||
611 | void subsystem_init(struct subsystem * s) | 660 | void subsystem_init(struct subsystem * s) |
612 | { | 661 | { |
613 | init_rwsem(&s->rwsem); | ||
614 | kset_init(&s->kset); | 662 | kset_init(&s->kset); |
615 | } | 663 | } |
616 | 664 | ||
@@ -619,8 +667,7 @@ void subsystem_init(struct subsystem * s) | |||
619 | * @s: the subsystem we're registering. | 667 | * @s: the subsystem we're registering. |
620 | * | 668 | * |
621 | * Once we register the subsystem, we want to make sure that | 669 | * Once we register the subsystem, we want to make sure that |
622 | * the kset points back to this subsystem for correct usage of | 670 | * the kset points back to this subsystem. |
623 | * the rwsem. | ||
624 | */ | 671 | */ |
625 | 672 | ||
626 | int subsystem_register(struct subsystem * s) | 673 | int subsystem_register(struct subsystem * s) |