Lines Matching refs:kobj
28 const void *kobject_namespace(struct kobject *kobj) in kobject_namespace() argument
30 const struct kobj_ns_type_operations *ns_ops = kobj_ns_ops(kobj); in kobject_namespace()
35 return kobj->ktype->namespace(kobj); in kobject_namespace()
48 void kobject_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid) in kobject_get_ownership() argument
53 if (kobj->ktype->get_ownership) in kobject_get_ownership()
54 kobj->ktype->get_ownership(kobj, uid, gid); in kobject_get_ownership()
66 static int populate_dir(struct kobject *kobj) in populate_dir() argument
68 struct kobj_type *t = get_ktype(kobj); in populate_dir()
75 error = sysfs_create_file(kobj, attr); in populate_dir()
83 static int create_dir(struct kobject *kobj) in create_dir() argument
85 const struct kobj_type *ktype = get_ktype(kobj); in create_dir()
89 error = sysfs_create_dir_ns(kobj, kobject_namespace(kobj)); in create_dir()
93 error = populate_dir(kobj); in create_dir()
95 sysfs_remove_dir(kobj); in create_dir()
100 error = sysfs_create_groups(kobj, ktype->default_groups); in create_dir()
102 sysfs_remove_dir(kobj); in create_dir()
111 sysfs_get(kobj->sd); in create_dir()
117 ops = kobj_child_ns_ops(kobj); in create_dir()
123 sysfs_enable_ns(kobj->sd); in create_dir()
129 static int get_kobj_path_length(struct kobject *kobj) in get_kobj_path_length() argument
132 struct kobject *parent = kobj; in get_kobj_path_length()
147 static void fill_kobj_path(struct kobject *kobj, char *path, int length) in fill_kobj_path() argument
152 for (parent = kobj; parent; parent = parent->parent) { in fill_kobj_path()
160 pr_debug("kobject: '%s' (%p): %s: path = '%s'\n", kobject_name(kobj), in fill_kobj_path()
161 kobj, __func__, path); in fill_kobj_path()
171 char *kobject_get_path(struct kobject *kobj, gfp_t gfp_mask) in kobject_get_path() argument
176 len = get_kobj_path_length(kobj); in kobject_get_path()
182 fill_kobj_path(kobj, path, len); in kobject_get_path()
189 static void kobj_kset_join(struct kobject *kobj) in kobj_kset_join() argument
191 if (!kobj->kset) in kobj_kset_join()
194 kset_get(kobj->kset); in kobj_kset_join()
195 spin_lock(&kobj->kset->list_lock); in kobj_kset_join()
196 list_add_tail(&kobj->entry, &kobj->kset->list); in kobj_kset_join()
197 spin_unlock(&kobj->kset->list_lock); in kobj_kset_join()
201 static void kobj_kset_leave(struct kobject *kobj) in kobj_kset_leave() argument
203 if (!kobj->kset) in kobj_kset_leave()
206 spin_lock(&kobj->kset->list_lock); in kobj_kset_leave()
207 list_del_init(&kobj->entry); in kobj_kset_leave()
208 spin_unlock(&kobj->kset->list_lock); in kobj_kset_leave()
209 kset_put(kobj->kset); in kobj_kset_leave()
212 static void kobject_init_internal(struct kobject *kobj) in kobject_init_internal() argument
214 if (!kobj) in kobject_init_internal()
216 kref_init(&kobj->kref); in kobject_init_internal()
217 INIT_LIST_HEAD(&kobj->entry); in kobject_init_internal()
218 kobj->state_in_sysfs = 0; in kobject_init_internal()
219 kobj->state_add_uevent_sent = 0; in kobject_init_internal()
220 kobj->state_remove_uevent_sent = 0; in kobject_init_internal()
221 kobj->state_initialized = 1; in kobject_init_internal()
225 static int kobject_add_internal(struct kobject *kobj) in kobject_add_internal() argument
230 if (!kobj) in kobject_add_internal()
233 if (!kobj->name || !kobj->name[0]) { in kobject_add_internal()
236 kobj); in kobject_add_internal()
240 parent = kobject_get(kobj->parent); in kobject_add_internal()
243 if (kobj->kset) { in kobject_add_internal()
245 parent = kobject_get(&kobj->kset->kobj); in kobject_add_internal()
246 kobj_kset_join(kobj); in kobject_add_internal()
247 kobj->parent = parent; in kobject_add_internal()
251 kobject_name(kobj), kobj, __func__, in kobject_add_internal()
253 kobj->kset ? kobject_name(&kobj->kset->kobj) : "<NULL>"); in kobject_add_internal()
255 error = create_dir(kobj); in kobject_add_internal()
257 kobj_kset_leave(kobj); in kobject_add_internal()
259 kobj->parent = NULL; in kobject_add_internal()
264 __func__, kobject_name(kobj)); in kobject_add_internal()
267 __func__, kobject_name(kobj), error, in kobject_add_internal()
270 kobj->state_in_sysfs = 1; in kobject_add_internal()
281 int kobject_set_name_vargs(struct kobject *kobj, const char *fmt, in kobject_set_name_vargs() argument
286 if (kobj->name && !fmt) in kobject_set_name_vargs()
309 kfree_const(kobj->name); in kobject_set_name_vargs()
310 kobj->name = s; in kobject_set_name_vargs()
324 int kobject_set_name(struct kobject *kobj, const char *fmt, ...) in kobject_set_name() argument
330 retval = kobject_set_name_vargs(kobj, fmt, vargs); in kobject_set_name()
349 void kobject_init(struct kobject *kobj, struct kobj_type *ktype) in kobject_init() argument
353 if (!kobj) { in kobject_init()
361 if (kobj->state_initialized) { in kobject_init()
364 kobj); in kobject_init()
368 kobject_init_internal(kobj); in kobject_init()
369 kobj->ktype = ktype; in kobject_init()
373 pr_err("kobject (%p): %s\n", kobj, err_str); in kobject_init()
378 static __printf(3, 0) int kobject_add_varg(struct kobject *kobj, in kobject_add_varg() argument
384 retval = kobject_set_name_vargs(kobj, fmt, vargs); in kobject_add_varg()
389 kobj->parent = parent; in kobject_add_varg()
390 return kobject_add_internal(kobj); in kobject_add_varg()
426 int kobject_add(struct kobject *kobj, struct kobject *parent, in kobject_add() argument
432 if (!kobj) in kobject_add()
435 if (!kobj->state_initialized) { in kobject_add()
437 kobject_name(kobj), kobj); in kobject_add()
442 retval = kobject_add_varg(kobj, parent, fmt, args); in kobject_add()
464 int kobject_init_and_add(struct kobject *kobj, struct kobj_type *ktype, in kobject_init_and_add() argument
470 kobject_init(kobj, ktype); in kobject_init_and_add()
473 retval = kobject_add_varg(kobj, parent, fmt, args); in kobject_init_and_add()
490 int kobject_rename(struct kobject *kobj, const char *new_name) in kobject_rename() argument
498 kobj = kobject_get(kobj); in kobject_rename()
499 if (!kobj) in kobject_rename()
501 if (!kobj->parent) { in kobject_rename()
502 kobject_put(kobj); in kobject_rename()
506 devpath = kobject_get_path(kobj, GFP_KERNEL); in kobject_rename()
526 error = sysfs_rename_dir_ns(kobj, new_name, kobject_namespace(kobj)); in kobject_rename()
531 dup_name = kobj->name; in kobject_rename()
532 kobj->name = name; in kobject_rename()
537 kobject_uevent_env(kobj, KOBJ_MOVE, envp); in kobject_rename()
543 kobject_put(kobj); in kobject_rename()
554 int kobject_move(struct kobject *kobj, struct kobject *new_parent) in kobject_move() argument
562 kobj = kobject_get(kobj); in kobject_move()
563 if (!kobj) in kobject_move()
567 if (kobj->kset) in kobject_move()
568 new_parent = kobject_get(&kobj->kset->kobj); in kobject_move()
572 devpath = kobject_get_path(kobj, GFP_KERNEL); in kobject_move()
585 error = sysfs_move_dir_ns(kobj, new_parent, kobject_namespace(kobj)); in kobject_move()
588 old_parent = kobj->parent; in kobject_move()
589 kobj->parent = new_parent; in kobject_move()
592 kobject_uevent_env(kobj, KOBJ_MOVE, envp); in kobject_move()
595 kobject_put(kobj); in kobject_move()
609 void kobject_del(struct kobject *kobj) in kobject_del() argument
614 if (!kobj) in kobject_del()
617 sd = kobj->sd; in kobject_del()
618 ktype = get_ktype(kobj); in kobject_del()
621 sysfs_remove_groups(kobj, ktype->default_groups); in kobject_del()
623 sysfs_remove_dir(kobj); in kobject_del()
626 kobj->state_in_sysfs = 0; in kobject_del()
627 kobj_kset_leave(kobj); in kobject_del()
628 kobject_put(kobj->parent); in kobject_del()
629 kobj->parent = NULL; in kobject_del()
637 struct kobject *kobject_get(struct kobject *kobj) in kobject_get() argument
639 if (kobj) { in kobject_get()
640 if (!kobj->state_initialized) in kobject_get()
643 kobject_name(kobj), kobj); in kobject_get()
644 kref_get(&kobj->kref); in kobject_get()
646 return kobj; in kobject_get()
650 struct kobject * __must_check kobject_get_unless_zero(struct kobject *kobj) in kobject_get_unless_zero() argument
652 if (!kobj) in kobject_get_unless_zero()
654 if (!kref_get_unless_zero(&kobj->kref)) in kobject_get_unless_zero()
655 kobj = NULL; in kobject_get_unless_zero()
656 return kobj; in kobject_get_unless_zero()
664 static void kobject_cleanup(struct kobject *kobj) in kobject_cleanup() argument
666 struct kobj_type *t = get_ktype(kobj); in kobject_cleanup()
667 const char *name = kobj->name; in kobject_cleanup()
670 kobject_name(kobj), kobj, __func__, kobj->parent); in kobject_cleanup()
674 kobject_name(kobj), kobj); in kobject_cleanup()
677 if (kobj->state_add_uevent_sent && !kobj->state_remove_uevent_sent) { in kobject_cleanup()
679 kobject_name(kobj), kobj); in kobject_cleanup()
680 kobject_uevent(kobj, KOBJ_REMOVE); in kobject_cleanup()
684 if (kobj->state_in_sysfs) { in kobject_cleanup()
686 kobject_name(kobj), kobj); in kobject_cleanup()
687 kobject_del(kobj); in kobject_cleanup()
692 kobject_name(kobj), kobj); in kobject_cleanup()
693 t->release(kobj); in kobject_cleanup()
713 struct kobject *kobj = container_of(kref, struct kobject, kref); in kobject_release() local
717 kobject_name(kobj), kobj, __func__, kobj->parent, delay); in kobject_release()
718 INIT_DELAYED_WORK(&kobj->release, kobject_delayed_cleanup); in kobject_release()
720 schedule_delayed_work(&kobj->release, delay); in kobject_release()
722 kobject_cleanup(kobj); in kobject_release()
732 void kobject_put(struct kobject *kobj) in kobject_put() argument
734 if (kobj) { in kobject_put()
735 if (!kobj->state_initialized) in kobject_put()
738 kobject_name(kobj), kobj); in kobject_put()
739 kref_put(&kobj->kref, kobject_release); in kobject_put()
744 static void dynamic_kobj_release(struct kobject *kobj) in dynamic_kobj_release() argument
746 pr_debug("kobject: (%p): %s\n", kobj, __func__); in dynamic_kobj_release()
747 kfree(kobj); in dynamic_kobj_release()
768 struct kobject *kobj; in kobject_create() local
770 kobj = kzalloc(sizeof(*kobj), GFP_KERNEL); in kobject_create()
771 if (!kobj) in kobject_create()
774 kobject_init(kobj, &dynamic_kobj_ktype); in kobject_create()
775 return kobj; in kobject_create()
793 struct kobject *kobj; in kobject_create_and_add() local
796 kobj = kobject_create(); in kobject_create_and_add()
797 if (!kobj) in kobject_create_and_add()
800 retval = kobject_add(kobj, parent, "%s", name); in kobject_create_and_add()
803 kobject_put(kobj); in kobject_create_and_add()
804 kobj = NULL; in kobject_create_and_add()
806 return kobj; in kobject_create_and_add()
816 kobject_init_internal(&k->kobj); in kset_init()
822 static ssize_t kobj_attr_show(struct kobject *kobj, struct attribute *attr, in kobj_attr_show() argument
830 ret = kattr->show(kobj, kattr, buf); in kobj_attr_show()
834 static ssize_t kobj_attr_store(struct kobject *kobj, struct attribute *attr, in kobj_attr_store() argument
842 ret = kattr->store(kobj, kattr, buf, count); in kobj_attr_store()
864 err = kobject_add_internal(&k->kobj); in kset_register()
867 kobject_uevent(&k->kobj, KOBJ_ADD); in kset_register()
880 kobject_del(&k->kobj); in kset_unregister()
881 kobject_put(&k->kobj); in kset_unregister()
913 static void kset_release(struct kobject *kobj) in kset_release() argument
915 struct kset *kset = container_of(kobj, struct kset, kobj); in kset_release()
917 kobject_name(kobj), kobj, __func__); in kset_release()
921 static void kset_get_ownership(struct kobject *kobj, kuid_t *uid, kgid_t *gid) in kset_get_ownership() argument
923 if (kobj->parent) in kset_get_ownership()
924 kobject_get_ownership(kobj->parent, uid, gid); in kset_get_ownership()
958 retval = kobject_set_name(&kset->kobj, "%s", name); in kset_create()
964 kset->kobj.parent = parent_kobj; in kset_create()
971 kset->kobj.ktype = &kset_ktype; in kset_create()
972 kset->kobj.kset = NULL; in kset_create()
1063 const struct kobj_ns_type_operations *kobj_ns_ops(struct kobject *kobj) in kobj_ns_ops() argument
1065 return kobj_child_ns_ops(kobj->parent); in kobj_ns_ops()