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()
238 __func__, kobject_name(kobj)); in kobject_add_internal()
241 __func__, kobject_name(kobj), error, in kobject_add_internal()
244 kobj->state_in_sysfs = 1; in kobject_add_internal()
255 int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, in kobject_set_name_vargs() argument
260 if (kobj->name && !fmt) in kobject_set_name_vargs()
283 kfree_const(kobj->name); in kobject_set_name_vargs()
284 kobj->name = s; in kobject_set_name_vargs()
298 int kobject_set_name(struct kobject *kobj, const char *fmt, ...) in kobject_set_name() argument
304 retval = kobject_set_name_vargs(kobj, fmt, vargs); in kobject_set_name()
323 void kobject_init(struct kobject *kobj, struct kobj_type *ktype) in kobject_init() argument
327 if (!kobj) { in kobject_init()
335 if (kobj->state_initialized) { in kobject_init()
338 "object, something is seriously wrong.\n", kobj); in kobject_init()
342 kobject_init_internal(kobj); in kobject_init()
343 kobj->ktype = ktype; in kobject_init()
347 printk(KERN_ERR "kobject (%p): %s\n", kobj, err_str); in kobject_init()
352 static __printf(3, 0) int kobject_add_varg(struct kobject *kobj, in kobject_add_varg() argument
358 retval = kobject_set_name_vargs(kobj, fmt, vargs); in kobject_add_varg()
363 kobj->parent = parent; in kobject_add_varg()
364 return kobject_add_internal(kobj); in kobject_add_varg()
392 int kobject_add(struct kobject *kobj, struct kobject *parent, in kobject_add() argument
398 if (!kobj) in kobject_add()
401 if (!kobj->state_initialized) { in kobject_add()
404 kobject_name(kobj), kobj); in kobject_add()
409 retval = kobject_add_varg(kobj, parent, fmt, args); in kobject_add()
427 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, in kobject_init_and_add() argument
433 kobject_init(kobj, ktype); in kobject_init_and_add()
436 retval = kobject_add_varg(kobj, parent, fmt, args); in kobject_init_and_add()
453 int kobject_rename(struct kobject *kobj, const char *new_name) in kobject_rename() argument
461 kobj = kobject_get(kobj); in kobject_rename()
462 if (!kobj) in kobject_rename()
464 if (!kobj->parent) in kobject_rename()
467 devpath = kobject_get_path(kobj, GFP_KERNEL); in kobject_rename()
487 error = sysfs_rename_dir_ns(kobj, new_name, kobject_namespace(kobj)); in kobject_rename()
492 dup_name = kobj->name; in kobject_rename()
493 kobj->name = name; in kobject_rename()
498 kobject_uevent_env(kobj, KOBJ_MOVE, envp); in kobject_rename()
504 kobject_put(kobj); in kobject_rename()
515 int kobject_move(struct kobject *kobj, struct kobject *new_parent) in kobject_move() argument
523 kobj = kobject_get(kobj); in kobject_move()
524 if (!kobj) in kobject_move()
528 if (kobj->kset) in kobject_move()
529 new_parent = kobject_get(&kobj->kset->kobj); in kobject_move()
533 devpath = kobject_get_path(kobj, GFP_KERNEL); in kobject_move()
546 error = sysfs_move_dir_ns(kobj, new_parent, kobject_namespace(kobj)); in kobject_move()
549 old_parent = kobj->parent; in kobject_move()
550 kobj->parent = new_parent; in kobject_move()
553 kobject_uevent_env(kobj, KOBJ_MOVE, envp); in kobject_move()
556 kobject_put(kobj); in kobject_move()
567 void kobject_del(struct kobject *kobj) in kobject_del() argument
571 if (!kobj) in kobject_del()
574 sd = kobj->sd; in kobject_del()
575 sysfs_remove_dir(kobj); in kobject_del()
578 kobj->state_in_sysfs = 0; in kobject_del()
579 kobj_kset_leave(kobj); in kobject_del()
580 kobject_put(kobj->parent); in kobject_del()
581 kobj->parent = NULL; in kobject_del()
589 struct kobject *kobject_get(struct kobject *kobj) in kobject_get() argument
591 if (kobj) { in kobject_get()
592 if (!kobj->state_initialized) in kobject_get()
595 "called.\n", kobject_name(kobj), kobj); in kobject_get()
596 kref_get(&kobj->kref); in kobject_get()
598 return kobj; in kobject_get()
602 struct kobject * __must_check kobject_get_unless_zero(struct kobject *kobj) in kobject_get_unless_zero() argument
604 if (!kobj) in kobject_get_unless_zero()
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()
616 static void kobject_cleanup(struct kobject *kobj) in kobject_cleanup() argument
618 struct kobj_type *t = get_ktype(kobj); in kobject_cleanup()
619 const char *name = kobj->name; in kobject_cleanup()
622 kobject_name(kobj), kobj, __func__, kobj->parent); in kobject_cleanup()
627 kobject_name(kobj), kobj); in kobject_cleanup()
630 if (kobj->state_add_uevent_sent && !kobj->state_remove_uevent_sent) { in kobject_cleanup()
632 kobject_name(kobj), kobj); in kobject_cleanup()
633 kobject_uevent(kobj, KOBJ_REMOVE); in kobject_cleanup()
637 if (kobj->state_in_sysfs) { in kobject_cleanup()
639 kobject_name(kobj), kobj); in kobject_cleanup()
640 kobject_del(kobj); in kobject_cleanup()
645 kobject_name(kobj), kobj); in kobject_cleanup()
646 t->release(kobj); in kobject_cleanup()
666 struct kobject *kobj = container_of(kref, struct kobject, kref); in kobject_release() local
670 kobject_name(kobj), kobj, __func__, kobj->parent, delay); in kobject_release()
671 INIT_DELAYED_WORK(&kobj->release, kobject_delayed_cleanup); in kobject_release()
673 schedule_delayed_work(&kobj->release, delay); in kobject_release()
675 kobject_cleanup(kobj); in kobject_release()
685 void kobject_put(struct kobject *kobj) in kobject_put() argument
687 if (kobj) { in kobject_put()
688 if (!kobj->state_initialized) in kobject_put()
691 "called.\n", kobject_name(kobj), kobj); in kobject_put()
692 kref_put(&kobj->kref, kobject_release); in kobject_put()
697 static void dynamic_kobj_release(struct kobject *kobj) in dynamic_kobj_release() argument
699 pr_debug("kobject: (%p): %s\n", kobj, __func__); in dynamic_kobj_release()
700 kfree(kobj); in dynamic_kobj_release()
721 struct kobject *kobj; in kobject_create() local
723 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); in kobject_create()
724 if (!kobj) in kobject_create()
727 kobject_init(kobj, &dynamic_kobj_ktype); in kobject_create()
728 return kobj; in kobject_create()
746 struct kobject *kobj; in kobject_create_and_add() local
749 kobj = kobject_create(); in kobject_create_and_add()
750 if (!kobj) in kobject_create_and_add()
753 retval = kobject_add(kobj, parent, "%s", name); in kobject_create_and_add()
757 kobject_put(kobj); in kobject_create_and_add()
758 kobj = NULL; in kobject_create_and_add()
760 return kobj; in kobject_create_and_add()
770 kobject_init_internal(&k->kobj); in kset_init()
776 static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr, in kobj_attr_show() argument
784 ret = kattr->show(kobj, kattr, buf); in kobj_attr_show()
788 static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr, in kobj_attr_store() argument
796 ret = kattr->store(kobj, kattr, buf, count); in kobj_attr_store()
818 err = kobject_add_internal(&k->kobj); in kset_register()
821 kobject_uevent(&k->kobj, KOBJ_ADD); in kset_register()
834 kobject_del(&k->kobj); in kset_unregister()
835 kobject_put(&k->kobj); in kset_unregister()
866 static void kset_release(struct kobject *kobj) in kset_release() argument
868 struct kset *kset = container_of(kobj, struct kset, kobj); in kset_release()
870 kobject_name(kobj), kobj, __func__); in kset_release()
904 retval = kobject_set_name(&kset->kobj, "%s", name); in kset_create()
910 kset->kobj.parent = parent_kobj; in kset_create()
917 kset->kobj.ktype = &kset_ktype; in kset_create()
918 kset->kobj.kset = NULL; in kset_create()
1009 const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj) in kobj_ns_ops() argument
1011 return kobj_child_ns_ops(kobj->parent); in kobj_ns_ops()