aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-11-06 20:03:42 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-11-06 21:42:15 -0500
commit0324e74534241f3f00910ec04ef67de1fe1542f4 (patch)
tree88f0b2a40a47dc0a22c0ce5e9b75a58470a56204 /lib
parent1071ec7bc2dabd0a9d12a1ae5570f4fd3ba944ca (diff)
parent0cae60f91494e34a0c5391f1455f825d5849b05f (diff)
Merge tag 'driver-core-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core
Pull driver core / sysfs patches from Greg KH: "Here's the big driver core / sysfs update for 3.13-rc1. There's lots of dev_groups updates for different subsystems, as they all get slowly migrated over to the safe versions of the attribute groups (removing userspace races with the creation of the sysfs files.) Also in here are some kobject updates, devres expansions, and the first round of Tejun's sysfs reworking to enable it to be used by other subsystems as a backend for an in-kernel filesystem. All of these have been in linux-next for a while with no reported issues" * tag 'driver-core-3.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (83 commits) sysfs: rename sysfs_assoc_lock and explain what it's about sysfs: use generic_file_llseek() for sysfs_file_operations sysfs: return correct error code on unimplemented mmap() mdio_bus: convert bus code to use dev_groups device: Make dev_WARN/dev_WARN_ONCE print device as well as driver name sysfs: separate out dup filename warning into a separate function sysfs: move sysfs_hash_and_remove() to fs/sysfs/dir.c sysfs: remove unused sysfs_get_dentry() prototype sysfs: honor bin_attr.attr.ignore_lockdep sysfs: merge sysfs_elem_bin_attr into sysfs_elem_attr devres: restore zeroing behavior of devres_alloc() sysfs: fix sysfs_write_file for bin file input: gameport: convert bus code to use dev_groups input: serio: remove bus usage of dev_attrs input: serio: use DEVICE_ATTR_RO() i2o: convert bus code to use dev_groups memstick: convert bus code to use dev_groups tifm: convert bus code to use dev_groups virtio: convert bus code to use dev_groups ipack: convert bus code to use dev_groups ...
Diffstat (limited to 'lib')
-rw-r--r--lib/kobject.c93
1 files changed, 89 insertions, 4 deletions
diff --git a/lib/kobject.c b/lib/kobject.c
index 084f7b18d0c0..7a1c203083eb 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -13,11 +13,33 @@
13 */ 13 */
14 14
15#include <linux/kobject.h> 15#include <linux/kobject.h>
16#include <linux/kobj_completion.h>
16#include <linux/string.h> 17#include <linux/string.h>
17#include <linux/export.h> 18#include <linux/export.h>
18#include <linux/stat.h> 19#include <linux/stat.h>
19#include <linux/slab.h> 20#include <linux/slab.h>
20 21
22/**
23 * kobject_namespace - return @kobj's namespace tag
24 * @kobj: kobject in question
25 *
26 * Returns namespace tag of @kobj if its parent has namespace ops enabled
27 * and thus @kobj should have a namespace tag associated with it. Returns
28 * %NULL otherwise.
29 */
30const void *kobject_namespace(struct kobject *kobj)
31{
32 const struct kobj_ns_type_operations *ns_ops = kobj_ns_ops(kobj);
33 const void *ns;
34
35 if (!ns_ops || ns_ops->type == KOBJ_NS_TYPE_NONE)
36 return NULL;
37
38 ns = kobj->ktype->namespace(kobj);
39 WARN_ON(!ns); /* @kobj in a namespace is required to have !NULL tag */
40 return ns;
41}
42
21/* 43/*
22 * populate_dir - populate directory with attributes. 44 * populate_dir - populate directory with attributes.
23 * @kobj: object we're working on. 45 * @kobj: object we're working on.
@@ -46,13 +68,21 @@ static int populate_dir(struct kobject *kobj)
46 68
47static int create_dir(struct kobject *kobj) 69static int create_dir(struct kobject *kobj)
48{ 70{
49 int error = 0; 71 int error;
50 error = sysfs_create_dir(kobj); 72
73 error = sysfs_create_dir_ns(kobj, kobject_namespace(kobj));
51 if (!error) { 74 if (!error) {
52 error = populate_dir(kobj); 75 error = populate_dir(kobj);
53 if (error) 76 if (error)
54 sysfs_remove_dir(kobj); 77 sysfs_remove_dir(kobj);
55 } 78 }
79
80 /*
81 * @kobj->sd may be deleted by an ancestor going away. Hold an
82 * extra reference so that it stays until @kobj is gone.
83 */
84 sysfs_get(kobj->sd);
85
56 return error; 86 return error;
57} 87}
58 88
@@ -428,7 +458,7 @@ int kobject_rename(struct kobject *kobj, const char *new_name)
428 goto out; 458 goto out;
429 } 459 }
430 460
431 error = sysfs_rename_dir(kobj, new_name); 461 error = sysfs_rename_dir_ns(kobj, new_name, kobject_namespace(kobj));
432 if (error) 462 if (error)
433 goto out; 463 goto out;
434 464
@@ -472,6 +502,7 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent)
472 if (kobj->kset) 502 if (kobj->kset)
473 new_parent = kobject_get(&kobj->kset->kobj); 503 new_parent = kobject_get(&kobj->kset->kobj);
474 } 504 }
505
475 /* old object path */ 506 /* old object path */
476 devpath = kobject_get_path(kobj, GFP_KERNEL); 507 devpath = kobject_get_path(kobj, GFP_KERNEL);
477 if (!devpath) { 508 if (!devpath) {
@@ -486,7 +517,7 @@ int kobject_move(struct kobject *kobj, struct kobject *new_parent)
486 sprintf(devpath_string, "DEVPATH_OLD=%s", devpath); 517 sprintf(devpath_string, "DEVPATH_OLD=%s", devpath);
487 envp[0] = devpath_string; 518 envp[0] = devpath_string;
488 envp[1] = NULL; 519 envp[1] = NULL;
489 error = sysfs_move_dir(kobj, new_parent); 520 error = sysfs_move_dir_ns(kobj, new_parent, kobject_namespace(kobj));
490 if (error) 521 if (error)
491 goto out; 522 goto out;
492 old_parent = kobj->parent; 523 old_parent = kobj->parent;
@@ -508,10 +539,15 @@ out:
508 */ 539 */
509void kobject_del(struct kobject *kobj) 540void kobject_del(struct kobject *kobj)
510{ 541{
542 struct sysfs_dirent *sd;
543
511 if (!kobj) 544 if (!kobj)
512 return; 545 return;
513 546
547 sd = kobj->sd;
514 sysfs_remove_dir(kobj); 548 sysfs_remove_dir(kobj);
549 sysfs_put(sd);
550
515 kobj->state_in_sysfs = 0; 551 kobj->state_in_sysfs = 0;
516 kobj_kset_leave(kobj); 552 kobj_kset_leave(kobj);
517 kobject_put(kobj->parent); 553 kobject_put(kobj->parent);
@@ -727,6 +763,55 @@ const struct sysfs_ops kobj_sysfs_ops = {
727}; 763};
728 764
729/** 765/**
766 * kobj_completion_init - initialize a kobj_completion object.
767 * @kc: kobj_completion
768 * @ktype: type of kobject to initialize
769 *
770 * kobj_completion structures can be embedded within structures with different
771 * lifetime rules. During the release of the enclosing object, we can
772 * wait on the release of the kobject so that we don't free it while it's
773 * still busy.
774 */
775void kobj_completion_init(struct kobj_completion *kc, struct kobj_type *ktype)
776{
777 init_completion(&kc->kc_unregister);
778 kobject_init(&kc->kc_kobj, ktype);
779}
780EXPORT_SYMBOL_GPL(kobj_completion_init);
781
782/**
783 * kobj_completion_release - release a kobj_completion object
784 * @kobj: kobject embedded in kobj_completion
785 *
786 * Used with kobject_release to notify waiters that the kobject has been
787 * released.
788 */
789void kobj_completion_release(struct kobject *kobj)
790{
791 struct kobj_completion *kc = kobj_to_kobj_completion(kobj);
792 complete(&kc->kc_unregister);
793}
794EXPORT_SYMBOL_GPL(kobj_completion_release);
795
796/**
797 * kobj_completion_del_and_wait - release the kobject and wait for it
798 * @kc: kobj_completion object to release
799 *
800 * Delete the kobject from sysfs and drop the reference count. Then wait
801 * until any other outstanding references are also dropped. This routine
802 * is only necessary once other references may have been taken on the
803 * kobject. Typically this happens when the kobject has been published
804 * to sysfs via kobject_add.
805 */
806void kobj_completion_del_and_wait(struct kobj_completion *kc)
807{
808 kobject_del(&kc->kc_kobj);
809 kobject_put(&kc->kc_kobj);
810 wait_for_completion(&kc->kc_unregister);
811}
812EXPORT_SYMBOL_GPL(kobj_completion_del_and_wait);
813
814/**
730 * kset_register - initialize and add a kset. 815 * kset_register - initialize and add a kset.
731 * @k: kset. 816 * @k: kset.
732 */ 817 */