Fix kobject documentation
Subsystems (2)
PATCH 1/1 Fix kobject documentation
Fix kobject documentation as follows.
- remove trailing spaces.
- struct device_subsys -> devices_subsys
Documentation/kobject.txt +44 -45
@@ -18,7 +18,7 @@ similar functionality. This functionalit - Object reference counting. - Maintaining lists (sets) of objects. - Object set locking. -- Userspace representation. +- Userspace representation. The infrastructure consists of a number of object types to support this functionality. Their programming interfaces are described below
@@ -26,7 +26,7 @@ in detail, and briefly here: - kobjects a simple object. - kset a set of objects of a certain type. -- ktype a set of helpers for objects of a common type. +- ktype a set of helpers for objects of a common type. - subsystem a controlling object for a number of ksets.
@@ -34,11 +34,11 @@ The kobject infrastructure maintains a c sysfs filesystem. Each kobject that is registered with the kobject core receives a directory in sysfs. Attributes about the kobject can then be exported. Please see Documentation/filesystems/sysfs.txt for -more information. +more information. The kobject infrastructure provides a flexible programming interface, and allows kobjects and ksets to be used without being registered -(i.e. with no sysfs representation). This is also described later. +(i.e. with no sysfs representation). This is also described later. 1. kobjects
@@ -49,7 +49,7 @@ and allows kobjects and ksets to be used struct kobject is a simple data type that provides a foundation for more complex object types. It provides a set of basic fields that almost all complex data types share. kobjects are intended to be -embedded in larger data structures and replace fields they duplicate. +embedded in larger data structures and replace fields they duplicate. 1.2 Definition
@@ -94,51 +94,51 @@ When a kobject is unregistered, it is re removed from the sysfs filesystem, and its reference count is decremented. List and sysfs removal happen in kobject_del(), and may be called manually. kobject_put() decrements the reference count, and may also -be called manually. +be called manually. A kobject's reference count may be incremented with kobject_get(), -which returns a valid reference to a kobject; and decremented with +which returns a valid reference to a kobject; and decremented with kobject_put(). An object's reference count may only be incremented if -it is already positive. +it is already positive. When a kobject's reference count reaches 0, the method struct kobj_type::release() (which the kobject's kset points to) is called. This allows any memory allocated for the object to be freed. -NOTE!!! +NOTE!!! It is _imperative_ that you supply a destructor for dynamically allocated kobjects to free them if you are using kobject reference counts. The reference count controls the lifetime of the object. If it goes to 0, then it is assumed that the object will -be freed and cannot be used. +be freed and cannot be used. More importantly, you must free the object there, and not immediately after an unregister call. If someone else is referencing the object (e.g. through a sysfs file), they will obtain a reference to the object, assume it's valid and operate on it. If the object is unregistered and freed in the meantime, the operation will then -reference freed memory and go boom. +reference freed memory and go boom. This can be prevented, in the simplest case, by defining a release method and freeing the object from there only. Note that this will not secure reference count/object management models that use a dual reference count or do other wacky things with the reference count -(like the networking layer). +(like the networking layer). 1.4 sysfs Each kobject receives a directory in sysfs. This directory is created -under the kobject's parent directory. +under the kobject's parent directory. If a kobject does not have a parent when it is registered, its parent -becomes its dominant kset. +becomes its dominant kset. If a kobject does not have a parent nor a dominant kset, its directory is created at the top-level of the sysfs partition. This should only -happen for kobjects that are embedded in a struct subsystem. +happen for kobjects that are embedded in a struct subsystem.
@@ -146,7 +146,7 @@ happen for kobjects that are embedded in 2.1 Description -A kset is a set of kobjects that are embedded in the same type. +A kset is a set of kobjects that are embedded in the same type. struct kset {
@@ -170,12 +170,12 @@ struct kobject * kset_find_obj(struct ks The type that the kobjects are embedded in is described by the ktype pointer. The subsystem that the kobject belongs to is pointed to by the -subsys pointer. +subsys pointer. A kset contains a kobject itself, meaning that it may be registered in the kobject hierarchy and exported via sysfs. More importantly, the kset may be embedded in a larger data type, and may be part of another -kset (of that object type). +kset (of that object type). For example, a block device is an object (struct gendisk) that is contained in a set of block devices. It may also contain a set of
@@ -189,25 +189,25 @@ following code snippet illustrates how t kset_register(&disk->kset); - The kset that the disk's embedded object belongs to is the - block_kset, and is pointed to by disk->kset.kobj.kset. + block_kset, and is pointed to by disk->kset.kobj.kset. -- The type of objects on the disk's _subordinate_ list are partitions, - and is set in disk->kset.ktype. +- The type of objects on the disk's _subordinate_ list are partitions, + and is set in disk->kset.ktype. - The kset is then registered, which handles initializing and adding - the embedded kobject to the hierarchy. + the embedded kobject to the hierarchy. -2.2 kset Programming Interface +2.2 kset Programming Interface All kset functions, except kset_find_obj(), eventually forward the calls to their embedded kobjects after performing kset-specific operations. ksets offer a similar programming model to kobjects: they may be used after they are initialized, without registering them in -the hierarchy. +the hierarchy. kset_find_obj() may be used to locate a kobject with a particular -name. The kobject, if found, is returned. +name. The kobject, if found, is returned. 2.3 sysfs
@@ -216,11 +216,11 @@ ksets are represented in sysfs when thei registered. They follow the same rules of parenting, with one exception. If a kset does not have a parent, nor is its embedded kobject part of another kset, the kset's parent becomes its dominant -subsystem. +subsystem. If the kset does not have a parent, its directory is created at the sysfs root. This should only happen when the kset registered is -embedded in a subsystem itself. +embedded in a subsystem itself. 3. struct ktype
@@ -239,10 +239,10 @@ generic object and the more complex type the object-specific fields, which include: - release: Called when the kobject's reference count reaches 0. This - should convert the object to the more complex type and free it. + should convert the object to the more complex type and free it. - sysfs_ops: Provides conversion functions for sysfs access. Please - see the sysfs documentation for more information. + see the sysfs documentation for more information. - default_attrs: Default attributes to be exported via sysfs when the object is registered.Note that the last attribute has to be
@@ -252,7 +252,7 @@ the object-specific fields, which includ Instances of struct kobj_type are not registered; only referenced by the kset. A kobj_type may be referenced by an arbitrary number of -ksets, as there may be disparate sets of identical objects. +ksets, as there may be disparate sets of identical objects.
@@ -263,7 +263,7 @@ ksets, as there may be disparate sets of A subsystem represents a significant entity of code that maintains an arbitrary number of sets of objects of various types. Since the number of ksets and the type of objects they contain are variable, a -generic representation of a subsystem is minimal. +generic representation of a subsystem is minimal. struct subsystem {
@@ -281,17 +281,17 @@ void subsys_put(struct subsystem * s); A subsystem contains an embedded kset so: - It can be represented in the object hierarchy via the kset's - embedded kobject. + embedded kobject. -- It can maintain a default list of objects of one type. +- It can maintain a default list of objects of one type. Additional ksets may attach to the subsystem simply by referencing the subsystem before they are registered. (This one-way reference means that there is no way to determine the ksets that are attached to the -subsystem.) +subsystem.) All ksets that are attached to a subsystem share the subsystem's R/W -semaphore. +semaphore. 4.2 subsystem Programming Interface.
@@ -306,45 +306,45 @@ calls to their embedded kobjects). 4.3 Helpers A number of macros are available to make dealing with subsystems and -their embedded objects easier. +their embedded objects easier. decl_subsys(name,type) Declares a subsystem named '<name>_subsys', with an embedded kset of -type <type>. For example, +type <type>. For example, decl_subsys(devices,&ktype_devices); is equivalent to doing: -struct subsystem device_subsys = { +struct subsystem devices_subsys = { .kset = { .kobj = { .name = "devices", }, .ktype = &ktype_devices, } -}; +}; The objects that are registered with a subsystem that use the subsystem's default list must have their kset ptr set properly. These objects may have embedded kobjects, ksets, or other subsystems. The -following helpers make setting the kset easier: +following helpers make setting the kset easier: kobj_set_kset_s(obj,subsys) -- Assumes that obj->kobj exists, and is a struct kobject. +- Assumes that obj->kobj exists, and is a struct kobject. - Sets the kset of that kobject to the subsystem's embedded kset. kset_set_kset_s(obj,subsys) - Assumes that obj->kset exists, and is a struct kset. -- Sets the kset of the embedded kobject to the subsystem's - embedded kset. +- Sets the kset of the embedded kobject to the subsystem's + embedded kset. subsys_set_kset(obj,subsys)
@@ -358,10 +358,9 @@ subsystems are represented in sysfs via follow the same rules as previously mentioned with no exceptions. They typically receive a top-level directory in sysfs, except when their embedded kobject is part of another kset, or the parent of the -embedded kobject is explicitly set. +embedded kobject is explicitly set. Note that the subsystem's embedded kset must be 'attached' to the subsystem itself in order to use its rwsem. This is done after kset_add() has been called. (Not before, because kset_add() uses its subsystem for a default parent if it doesn't already have one). -
Quoted 6 lines · Satoru Takeuchi
Fix kobject documentation as follows.
- remove trailing spaces.
- structdevice_subsys->devices_subsysSigned-off-by Satoru Takeuchi<[email protected]>
This is certainly a start, but kobject.txt needs more updates. For example, it still refers to the removed struct subsystem, and uevent_ops are not mentioned. Looking at kobject.h, the kerneldoc there needs some updates as well...
<Removed Patrick's e-mail address as it bounces>
Update kobject documentation:
- Update structure definitions.
- Remove documentation of removed struct subsystem.
(First shot, uevent_ops probably need some documentation as well.)
--- Documentation/kobject.txt | 178 +++++++++++++++------------------------------- 1 file changed, 59 insertions(+), 119 deletions(-)
Documentation/kobject.txt +59 -119
@@ -27,7 +27,6 @@ in detail, and briefly here: - kobjects a simple object. - kset a set of objects of a certain type. - ktype a set of helpers for objects of a common type. -- subsystem a controlling object for a number of ksets. The kobject infrastructure maintains a close relationship with the
@@ -54,13 +53,15 @@ embedded in larger data structures and r 1.2 Definition struct kobject { + const char * k_name; char name[KOBJ_NAME_LEN]; - atomic_t refcount; + struct kref kref; struct list_head entry; struct kobject * parent; struct kset * kset; struct kobj_type * ktype; - struct dentry * dentry; + struct sysfs_dirent * sd; + wait_queue_head_t poll; }; void kobject_init(struct kobject *);
@@ -137,8 +138,7 @@ If a kobject does not have a parent when becomes its dominant kset. If a kobject does not have a parent nor a dominant kset, its directory -is created at the top-level of the sysfs partition. This should only -happen for kobjects that are embedded in a struct subsystem. +is created at the top-level of the sysfs partition.
@@ -150,10 +150,10 @@ A kset is a set of kobjects that are emb struct kset { - struct subsystem * subsys; struct kobj_type * ktype; struct list_head list; struct kobject kobj; + struct kset_uevent_ops * uevent_ops; };
@@ -169,8 +169,7 @@ struct kobject * kset_find_obj(struct ks The type that the kobjects are embedded in is described by the ktype -pointer. The subsystem that the kobject belongs to is pointed to by the -subsys pointer. +pointer. A kset contains a kobject itself, meaning that it may be registered in the kobject hierarchy and exported via sysfs. More importantly, the
@@ -209,6 +208,58 @@ the hierarchy. kset_find_obj() may be used to locate a kobject with a particular name. The kobject, if found, is returned. +There are also some helper functions which names point to the formerly +existing "struct subsystem", whose functions have been taken over by +ksets. + + +decl_subsys(name,type,uevent_ops) + +Declares a kset named '<name>_subsys' of type <type> with +uevent_ops <uevent_ops>. For example, + +decl_subsys(devices, &ktype_device, &device_uevent_ops); + +is equivalent to doing: + +struct kset devices_subsys = { + .kobj = { + .name = "devices", + }, + .ktype = &ktype_devices, + .uevent_ops = &device_uevent_ops, +}; + + +The objects that are registered with a subsystem that use the +subsystem's default list must have their kset ptr set properly. These +objects may have embedded kobjects or ksets. The +following helpers make setting the kset easier: + + +kobj_set_kset_s(obj,subsys) + +- Assumes that obj->kobj exists, and is a struct kobject. +- Sets the kset of that kobject to the kset <subsys>. + + +kset_set_kset_s(obj,subsys) + +- Assumes that obj->kset exists, and is a struct kset. +- Sets the kset of the embedded kobject to the kset <subsys>. + +subsys_set_kset(obj,subsys) + +- Assumes obj->subsys exists, and is a struct subsystem. +- Sets obj->subsys.kset.kobj.kset to the subsystem's embedded kset. + +void subsystem_init(struct kset *s); +int subsystem_register(struct kset *s); +void subsystem_unregister(struct kset *s); +struct kset *subsys_get(struct kset *s); +void kset_put(struct kset *s); + +These are just wrappers around the respective kset_* functions. 2.3 sysfs
@@ -254,114 +305,3 @@ Instances of struct kobj_type are not re the kset. A kobj_type may be referenced by an arbitrary number of ksets, as there may be disparate sets of identical objects. - - -4. subsystems - -4.1 Description - -A subsystem represents a significant entity of code that maintains an -arbitrary number of sets of objects of various types. Since the number -of ksets and the type of objects they contain are variable, a -generic representation of a subsystem is minimal. - - -struct subsystem { - struct kset kset; - struct rw_semaphore rwsem; -}; - -int subsystem_register(struct subsystem *); -void subsystem_unregister(struct subsystem *); - -struct subsystem * subsys_get(struct subsystem * s); -void subsys_put(struct subsystem * s); - - -A subsystem contains an embedded kset so: - -- It can be represented in the object hierarchy via the kset's - embedded kobject. - -- It can maintain a default list of objects of one type. - -Additional ksets may attach to the subsystem simply by referencing the -subsystem before they are registered. (This one-way reference means -that there is no way to determine the ksets that are attached to the -subsystem.) - -All ksets that are attached to a subsystem share the subsystem's R/W -semaphore. - - -4.2 subsystem Programming Interface. - -The subsystem programming interface is simple and does not offer the -flexibility that the kset and kobject programming interfaces do. They -may be registered and unregistered, as well as reference counted. Each -call forwards the calls to their embedded ksets (which forward the -calls to their embedded kobjects). - - -4.3 Helpers - -A number of macros are available to make dealing with subsystems and -their embedded objects easier. - - -decl_subsys(name,type) - -Declares a subsystem named '<name>_subsys', with an embedded kset of -type <type>. For example, - -decl_subsys(devices,&ktype_devices); - -is equivalent to doing: - -struct subsystem device_subsys = { - .kset = { - .kobj = { - .name = "devices", - }, - .ktype = &ktype_devices, - } -}; - - -The objects that are registered with a subsystem that use the -subsystem's default list must have their kset ptr set properly. These -objects may have embedded kobjects, ksets, or other subsystems. The -following helpers make setting the kset easier: - - -kobj_set_kset_s(obj,subsys) - -- Assumes that obj->kobj exists, and is a struct kobject. -- Sets the kset of that kobject to the subsystem's embedded kset. - - -kset_set_kset_s(obj,subsys) - -- Assumes that obj->kset exists, and is a struct kset. -- Sets the kset of the embedded kobject to the subsystem's - embedded kset. - -subsys_set_kset(obj,subsys) - -- Assumes obj->subsys exists, and is a struct subsystem. -- Sets obj->subsys.kset.kobj.kset to the subsystem's embedded kset. - - -4.4 sysfs - -subsystems are represented in sysfs via their embedded kobjects. They -follow the same rules as previously mentioned with no exceptions. They -typically receive a top-level directory in sysfs, except when their -embedded kobject is part of another kset, or the parent of the -embedded kobject is explicitly set. - -Note that the subsystem's embedded kset must be 'attached' to the -subsystem itself in order to use its rwsem. This is done after -kset_add() has been called. (Not before, because kset_add() uses its -subsystem for a default parent if it doesn't already have one). -
Quoted 8 lines · On Fri, 27 Jul 2007 13:21:15 +0200 Cornelia Huck wrote:
Quoted 5 lines · Satoru Takeuchi
Fix kobject documentation as follows.
- remove trailing spaces.
- structdevice_subsys->devices_subsys
Quoted 6 lines
Quoted 1 line
Signed-off-by Satoru Takeuchi<[email protected]>This is certainly a start, but kobject.txt needs more updates. For example, it still refers to the removed struct subsystem, and
uevent_opsare not mentioned. Looking atkobject.h, the kerneldoc there needs some updates as well...
Here's a start at that.
---
From: Randy Dunlap <[email protected]>
Removed kernel-doc marker (/**) from struct kset -- each struct member still needs annotation.
Corrected one parameter name so that kernel-doc matches the macro.
--- include/linux/kobject.h | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-)
include/linux/kobject.h +11 -12
@@ -108,9 +108,15 @@ struct kobj_type {struct attribute ** default_attrs; }; +struct kset_uevent_ops { +int (*filter)(struct kset *kset,struct kobject *kobj); +const char *(*name)(struct kset *kset,struct kobject *kobj); +int (*uevent)(struct kset *kset,struct kobject *kobj,char **envp, +int num_envp,char *buffer,int buffer_size); +}; -/** -* kset - a set of kobjects of a specific type, belonging +/* +* struct kset - a set of kobjects of a specific type, belonging * to a specific subsystem. * * All kobjects of a kset should be embedded in an identical
@@ -126,13 +132,6 @@ struct kobj_type {* supress the event generation or add subsystem specific * variables carried with the event. */ -struct kset_uevent_ops { -int (*filter)(struct kset *kset,struct kobject *kobj); -const char *(*name)(struct kset *kset,struct kobject *kobj); -int (*uevent)(struct kset *kset,struct kobject *kobj,char **envp, -int num_envp,char *buffer,int buffer_size); -}; -struct kset {struct kobj_type * ktype;struct list_head list;
@@ -173,7 +172,7 @@ static inline struct kobj_type * get_ktyextern struct kobject *kset_find_obj (struct kset *,const char *); -/** +/* * Use this when initializing an embedded kset with no other * fields to initialize. */
@@ -198,7 +197,7 @@ extern struct kset kernel_subsys;/* The global /sys/hypervisor/ subsystem */ extern struct kset hypervisor_subsys; -/** +/* * Helpers for setting the kset of registered objects. * Often, a registered object belongs to a kset embedded in a * subsystem. These do no magic, just make the resulting code
@@ -233,7 +232,7 @@ extern struct kset hypervisor_subsys;/** * subsys_set_kset(obj,subsys) - set kset for subsystem * @obj: ptr to some object type. -* @subsys: a subsystem object (not a ptr). +* @_subsys: a subsystem object (not a ptr). * * Can be used for any object type with an embedded ->subsys. * Sets the kset of @obj's kobject to @subsys.kset. This makes