kobjects, ktypes, ksets π
λλ°μ΄μ€ νΈλ¦¬λ₯Ό μ΄ν΄λ³΄λ€ kobject
μ λν λ΄μ©μ΄ μΈκΈλκΈ° μμνλ€. λ¨μν κ°μ²΄κ° μλλΌ νΉμν λͺ©μ μΌλ‘ μ¬μ©λ κ²μ΄λΌ μμλμ΄ κ΄λ ¨ λ΄μ©μ μ°Ύμ보μλ€.
61 struct kobject {
62 const char *name;
63 struct list_head entry;
64 struct kobject *parent;
65 struct kset *kset;
66 struct kobj_type *ktype;
67 struct kernfs_node *sd;
68 struct kref kref;
69 #ifdef CONFIG_DEBUG_KOBJECT_RELEASE
70 struct delayed_work release;
71 #endif
72 unsigned int state_initialized:1;
73 unsigned int state_in_sysfs:1;
74 unsigned int state_add_uevent_sent:1;
75 unsigned int state_remove_uevent_sent:1;
76 unsigned int uevent_suppress:1;
77 };
컀λ λ¬Έμ(https://www.kernel.org/doc/Documentation/kobject.txt)μ λ°λ₯΄λ©΄ kobjects
μ λλΆμ΄ ksets
, ktypes
μ λν΄ μλμ κ°μ΄ κΈ°μ νκ³ μλ€.
A kobject is an object of type struct kobject. Kobjects have a name and a reference count. A kobject also has a parent pointer (allowing objects to be arranged into hierarchies), a specific type, and, usually, a representation in the sysfs virtual filesystem.
Kobjects are generally not interesting on their own; instead, they are usually embedded within some other structure which contains the stuff the code is really interested in
A ktype is the type of object that embeds a kobject. Every structure that embeds a kobject needs a corresponding ktype. The ktype controls what happens to the kobject when it is created and destroyed.
A kset is a group of kobjects. These kobjects can be of the same ktype or belong to different ktypes. The kset is the basic container type for collections of kobjects. Ksets contain their own kobjects, but you can safely ignore that implementation detail as the kset core code handles this kobject automatically.
Kobjectλ μ΄λ¦κ³Ό μ°Έμ‘°νμλ₯Ό κ°μ§κ³ μλ κ°μ²΄λ‘μ μκΈ° μμ μ λν΄ κ΄μ¬μ κ°μ§λ κ²μ΄ μλλΌ λ€λ₯Έ ꡬ쑰체μ embedded λμ΄ κ΄λ ¨ μ½λμμ νμλ‘ νλ λ΄μ©λ€μ μ μ₯νλ μ©λλ‘ μ¬μ©νλ€. kobjects μ체λ κ³μΈ΅ κ΅¬μ‘°λ‘ κ΅¬μ±ν μ μλλ‘ λΆλͺ¨ ν¬μΈν°λ₯Ό κ°μ§λ©° νΉμ μ νμ΄λ sysfs λ±μλ μ¬μ©λλ€.
ktypeμ kobjectμ λν λλ©μΈ(μ μμ)μ΄λΌ μκ°νλ©΄ μ΄ν΄νκΈ° μ½λ€. μλ‘ λ€λ₯Έ κ°λ€λ‘ ꡬμ±ν μ μλ λλ©μΈμ κ·Έ κ°μ λν νμ μμ€ν μΌλ‘ ꡬμ±ν μ μμΌλ©° μ΄λ¬ν νμ μμ€ν μ λν κ°λ μ΄ μ¬κΈ°μλ κ·Έλλ‘ λ¬»μ΄λλ κ²μ λ€μ΄λ°μ ν΅ν΄ λ¨λ²μ μ μ μλ€.
ksetμ kobject, μ¦ λ¨μν μ§ν©μ΄λ€. λλ¬Έμ μλ‘ λ€λ₯Έ ktypeλ€μ κ°μ§κ³ μμ μλ μκ³ λͺ¨λ κ°μ ktypeλ€λ‘ ꡬμ±ν μλ μλ€.
μ 리νλ©΄, kobjects, ksets, ktypes λ€μ μ΄μ©νμ¬ μ»€λ λ΄μμ κ°μ²΄λ₯Ό μ΄μ©ν μμ νμ μμ€ν μ΄λΌ μκ°ν μ μλ€. Functional Programming μμ μκΈ°νλ νμ μμ€ν μ μ΄ν΄νκ³ μλ€λ©΄ κ°λ μ μΌλ‘ λ¨λ²μ μ΄ν΄κ° κ°λ₯ν κ²μ΄λΌ μκ°λλ€. κ°λ μ μΌλ‘ νμ μμ€ν μ ꡬμ±νκ³ μ΄λ₯Ό sysfs μ κ°μ νμΌ μμ€ν μ μ μ©νμ¬, ν΄λΉ μλΈμμ€ν (?)μ΄ κ°μ§ μ μλ λ°μ΄ν°λ€μ λν νμ μμ€ν μ μΆμννμ¬ μΌκ΄μ± μκ² κ΅¬ννκΈ° μν΄ κ³ λ―Όν νμ λ€μ μΏλ³Ό μ μλ€.
μλ©΄ μμλ‘, λͺ¨λ₯΄λ κ² μ λ§ λ§λ€.