Lines Matching refs:kobj

30 const void *kobject_namespace(struct kobject *kobj)  in kobject_namespace()  argument
32 const struct kobj_ns_type_operations *ns_ops = kobj_ns_ops(kobj); in kobject_namespace()
37 return kobj->ktype->namespace(kobj); in kobject_namespace()
49 static int populate_dir(struct kobject *kobj) in populate_dir() argument
51 struct kobj_type *t = get_ktype(kobj); in populate_dir()
58 error = sysfs_create_file(kobj, attr); in populate_dir()
66 static int create_dir(struct kobject *kobj) in create_dir() argument
71 error = sysfs_create_dir_ns(kobj, kobject_namespace(kobj)); in create_dir()
75 error = populate_dir(kobj); in create_dir()
77 sysfs_remove_dir(kobj); in create_dir()
85 sysfs_get(kobj->sd); in create_dir()
91 ops = kobj_child_ns_ops(kobj); in create_dir()
97 sysfs_enable_ns(kobj->sd); in create_dir()
103 static int get_kobj_path_length(struct kobject *kobj) in get_kobj_path_length() argument
106 struct kobject *parent = kobj; in get_kobj_path_length()
121 static void fill_kobj_path(struct kobject *kobj, char *path, int length) in fill_kobj_path() argument
126 for (parent = kobj; parent; parent = parent->parent) { in fill_kobj_path()
134 pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj), in fill_kobj_path()
135 kobj, __func__, path); in fill_kobj_path()
146 char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask) in kobject_get_path() argument
151 len = get_kobj_path_length(kobj); in kobject_get_path()
157 fill_kobj_path(kobj, path, len); in kobject_get_path()
164 static void kobj_kset_join(struct kobject *kobj) in kobj_kset_join() argument
166 if (!kobj->kset) in kobj_kset_join()
169 kset_get(kobj->kset); in kobj_kset_join()
170 spin_lock(&kobj->kset->list_lock); in kobj_kset_join()
171 list_add_tail(&kobj->entry, &kobj->kset->list); in kobj_kset_join()
172 spin_unlock(&kobj->kset->list_lock); in kobj_kset_join()
176 static void kobj_kset_leave(struct kobject *kobj) in kobj_kset_leave() argument
178 if (!kobj->kset) in kobj_kset_leave()
181 spin_lock(&kobj->kset->list_lock); in kobj_kset_leave()
182 list_del_init(&kobj->entry); in kobj_kset_leave()
183 spin_unlock(&kobj->kset->list_lock); in kobj_kset_leave()
184 kset_put(kobj->kset); in kobj_kset_leave()
187 static void kobject_init_internal(struct kobject *kobj) in kobject_init_internal() argument
189 if (!kobj) in kobject_init_internal()
191 kref_init(&kobj->kref); in kobject_init_internal()
192 INIT_LIST_HEAD(&kobj->entry); in kobject_init_internal()
193 kobj->state_in_sysfs = 0; in kobject_init_internal()
194 kobj->state_add_uevent_sent = 0; in kobject_init_internal()
195 kobj->state_remove_uevent_sent = 0; in kobject_init_internal()
196 kobj->state_initialized = 1; in kobject_init_internal()
200 static int kobject_add_internal(struct kobject *kobj) in kobject_add_internal() argument
205 if (!kobj) in kobject_add_internal()
208 if (!kobj->name || !kobj->name[0]) { in kobject_add_internal()
210 "name!\n", kobj); in kobject_add_internal()
214 parent = kobject_get(kobj->parent); in kobject_add_internal()
217 if (kobj->kset) { in kobject_add_internal()
219 parent = kobject_get(&kobj->kset->kobj); in kobject_add_internal()
220 kobj_kset_join(kobj); in kobject_add_internal()
221 kobj->parent = parent; in kobject_add_internal()
225 kobject_name(kobj), kobj, __func__, in kobject_add_internal()
227 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>"); in kobject_add_internal()
229 error = create_dir(kobj); in kobject_add_internal()
231 kobj_kset_leave(kobj); in kobject_add_internal()
233 kobj->parent = NULL; in kobject_add_internal()
240 __func__, kobject_name(kobj)); in kobject_add_internal()
243 __func__, kobject_name(kobj), error, in kobject_add_internal()
246 kobj->state_in_sysfs = 1; in kobject_add_internal()
257 int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, in kobject_set_name_vargs() argument
262 if (kobj->name && !fmt) in kobject_set_name_vargs()
285 kfree_const(kobj->name); in kobject_set_name_vargs()
286 kobj->name = s; in kobject_set_name_vargs()
300 int kobject_set_name(struct kobject *kobj, const char *fmt, ...) in kobject_set_name() argument
306 retval = kobject_set_name_vargs(kobj, fmt, vargs); in kobject_set_name()
325 void kobject_init(struct kobject *kobj, struct kobj_type *ktype) in kobject_init() argument
329 if (!kobj) { in kobject_init()
337 if (kobj->state_initialized) { in kobject_init()
340 "object, something is seriously wrong.\n", kobj); in kobject_init()
344 kobject_init_internal(kobj); in kobject_init()
345 kobj->ktype = ktype; in kobject_init()
349 printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str); in kobject_init()
354 static __printf(3, 0) int kobject_add_varg(struct kobject *kobj, in kobject_add_varg() argument
360 retval = kobject_set_name_vargs(kobj, fmt, vargs); in kobject_add_varg()
365 kobj->parent = parent; in kobject_add_varg()
366 return kobject_add_internal(kobj); in kobject_add_varg()
394 int kobject_add(struct kobject *kobj, struct kobject *parent, in kobject_add() argument
400 if (!kobj) in kobject_add()
403 if (!kobj->state_initialized) { in kobject_add()
406 kobject_name(kobj), kobj); in kobject_add()
411 retval = kobject_add_varg(kobj, parent, fmt, args); in kobject_add()
429 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, in kobject_init_and_add() argument
435 kobject_init(kobj, ktype); in kobject_init_and_add()
438 retval = kobject_add_varg(kobj, parent, fmt, args); in kobject_init_and_add()
455 int kobject_rename(struct kobject *kobj, const char *new_name) in kobject_rename() argument
463 kobj = kobject_get(kobj); in kobject_rename()
464 if (!kobj) in kobject_rename()
466 if (!kobj->parent) in kobject_rename()
469 devpath = kobject_get_path(kobj, GFP_KERNEL); in kobject_rename()
489 error = sysfs_rename_dir_ns(kobj, new_name, kobject_namespace(kobj)); in kobject_rename()
494 dup_name = kobj->name; in kobject_rename()
495 kobj->name = name; in kobject_rename()
500 kobject_uevent_env(kobj, KOBJ_MOVE, envp); in kobject_rename()
506 kobject_put(kobj); in kobject_rename()
517 int kobject_move(struct kobject *kobj, struct kobject *new_parent) in kobject_move() argument
525 kobj = kobject_get(kobj); in kobject_move()
526 if (!kobj) in kobject_move()
530 if (kobj->kset) in kobject_move()
531 new_parent = kobject_get(&kobj->kset->kobj); in kobject_move()
535 devpath = kobject_get_path(kobj, GFP_KERNEL); in kobject_move()
548 error = sysfs_move_dir_ns(kobj, new_parent, kobject_namespace(kobj)); in kobject_move()
551 old_parent = kobj->parent; in kobject_move()
552 kobj->parent = new_parent; in kobject_move()
555 kobject_uevent_env(kobj, KOBJ_MOVE, envp); in kobject_move()
558 kobject_put(kobj); in kobject_move()
569 void kobject_del(struct kobject *kobj) in kobject_del() argument
573 if (!kobj) in kobject_del()
576 sd = kobj->sd; in kobject_del()
577 sysfs_remove_dir(kobj); in kobject_del()
580 kobj->state_in_sysfs = 0; in kobject_del()
581 kobj_kset_leave(kobj); in kobject_del()
582 kobject_put(kobj->parent); in kobject_del()
583 kobj->parent = NULL; in kobject_del()
591 struct kobject *kobject_get(struct kobject *kobj) in kobject_get() argument
593 if (kobj) { in kobject_get()
594 if (!kobj->state_initialized) in kobject_get()
597 "called.\n", kobject_name(kobj), kobj); in kobject_get()
598 kref_get(&kobj->kref); in kobject_get()
600 return kobj; in kobject_get()
604 static struct kobject * __must_check kobject_get_unless_zero(struct kobject *kobj) in kobject_get_unless_zero() argument
606 if (!kref_get_unless_zero(&kobj->kref)) in kobject_get_unless_zero()
607 kobj = NULL; in kobject_get_unless_zero()
608 return kobj; in kobject_get_unless_zero()
615 static void kobject_cleanup(struct kobject *kobj) in kobject_cleanup() argument
617 struct kobj_type *t = get_ktype(kobj); in kobject_cleanup()
618 const char *name = kobj->name; in kobject_cleanup()
621 kobject_name(kobj), kobj, __func__, kobj->parent); in kobject_cleanup()
626 kobject_name(kobj), kobj); in kobject_cleanup()
629 if (kobj->state_add_uevent_sent && !kobj->state_remove_uevent_sent) { in kobject_cleanup()
631 kobject_name(kobj), kobj); in kobject_cleanup()
632 kobject_uevent(kobj, KOBJ_REMOVE); in kobject_cleanup()
636 if (kobj->state_in_sysfs) { in kobject_cleanup()
638 kobject_name(kobj), kobj); in kobject_cleanup()
639 kobject_del(kobj); in kobject_cleanup()
644 kobject_name(kobj), kobj); in kobject_cleanup()
645 t->release(kobj); in kobject_cleanup()
665 struct kobject *kobj = container_of(kref, struct kobject, kref); in kobject_release() local
669 kobject_name(kobj), kobj, __func__, kobj->parent, delay); in kobject_release()
670 INIT_DELAYED_WORK(&kobj->release, kobject_delayed_cleanup); in kobject_release()
672 schedule_delayed_work(&kobj->release, delay); in kobject_release()
674 kobject_cleanup(kobj); in kobject_release()
684 void kobject_put(struct kobject *kobj) in kobject_put() argument
686 if (kobj) { in kobject_put()
687 if (!kobj->state_initialized) in kobject_put()
690 "called.\n", kobject_name(kobj), kobj); in kobject_put()
691 kref_put(&kobj->kref, kobject_release); in kobject_put()
696 static void dynamic_kobj_release(struct kobject *kobj) in dynamic_kobj_release() argument
698 pr_debug("kobject: (%p): %s\n", kobj, __func__); in dynamic_kobj_release()
699 kfree(kobj); in dynamic_kobj_release()
720 struct kobject *kobj; in kobject_create() local
722 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); in kobject_create()
723 if (!kobj) in kobject_create()
726 kobject_init(kobj, &dynamic_kobj_ktype); in kobject_create()
727 return kobj; in kobject_create()
745 struct kobject *kobj; in kobject_create_and_add() local
748 kobj = kobject_create(); in kobject_create_and_add()
749 if (!kobj) in kobject_create_and_add()
752 retval = kobject_add(kobj, parent, "%s", name); in kobject_create_and_add()
756 kobject_put(kobj); in kobject_create_and_add()
757 kobj = NULL; in kobject_create_and_add()
759 return kobj; in kobject_create_and_add()
769 kobject_init_internal(&k->kobj); in kset_init()
775 static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr, in kobj_attr_show() argument
783 ret = kattr->show(kobj, kattr, buf); in kobj_attr_show()
787 static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr, in kobj_attr_store() argument
795 ret = kattr->store(kobj, kattr, buf, count); in kobj_attr_store()
817 err = kobject_add_internal(&k->kobj); in kset_register()
820 kobject_uevent(&k->kobj, KOBJ_ADD); in kset_register()
833 kobject_del(&k->kobj); in kset_unregister()
834 kobject_put(&k->kobj); in kset_unregister()
865 static void kset_release(struct kobject *kobj) in kset_release() argument
867 struct kset *kset = container_of(kobj, struct kset, kobj); in kset_release()
869 kobject_name(kobj), kobj, __func__); in kset_release()
903 retval = kobject_set_name(&kset->kobj, "%s", name); in kset_create()
909 kset->kobj.parent = parent_kobj; in kset_create()
916 kset->kobj.ktype = &kset_ktype; in kset_create()
917 kset->kobj.kset = NULL; in kset_create()
1008 const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj) in kobj_ns_ops() argument
1010 return kobj_child_ns_ops(kobj->parent); in kobj_ns_ops()