Datasheet

Mauerer runc01.tex V2 - 09/04/2008 4:13pm Page 24
Chapter 1: Introduction and Overview
Table 1-1: Standard Methods for Processing
kobject
s
Function Meaning
kobject_get
,
kobject_put
Increments or decrements the reference counter of a
kobject
kobject_(un)register
Registers or removes
obj
from a hierarchy (the object is added to the
existing set (if any) of the parent element; a corresponding entry is cre-
ated in the
sysfs
filesystem).
kobject_init
Initializes a
kobject
; that is, it sets the reference counter to its initial
value and initializes the list elements of the object.
kobect_add
Initializes a kernel object and makes it visible in sysfs
kobject_cleanup
Releases the allocated resources when a
kobject
(and therefore the
embedding object) is no longer needed
Encapsulation of the single value in a structure was chosen to prevent direct manipulation of the value.
kref_init
must always be used for initialization. If an object is in use,
kref_get
must be invoked
beforehand to increment the reference counter.
kref_put
decrements the counter when the object is no
longer used.
Sets of Objects
In many cases, it is necessary to group different kernel objects into a set for instance, the set of all
character devices or the set of all PCI-based devices. The data structure provided for this purpose is
defined as follows:
<kobject.h>
struct kset {
struct kobj_type * ktype;
struct list_head list;
...
struct kobject kobj;
struct kset_uevent_ops * uevent_ops;
};
Interestingly, the
kset
serves as the first example for the use of kernel objects. Since the management
structure for sets is nothing other than a kernel object, it can be managed via the previously discussed
struct kobj
. Indeed, an instance is embedded via
kobj
. It has nothing to do with the
kobject
s collected
in the set, but only serves to manage the properties of the
kset
object itself.
The other members have the following meaning:
ktype
points to a further object that generalizes the behavior of the
kset
.
list
is used to build a list of all kernel objects that are a member of the set.
uevent_ops
provides several function pointers to methods that relay information about the state
of the set to userland. This mechanism is used by the core of the driver model, for instance, to
format messages that inform about the addition of new devices.
24