Lines Matching refs:a
13 place. Dealing with kobjects requires understanding a few different types,
15 easier, we'll take a multi-pass approach, starting with vague terms and
19 - A kobject is an object of type struct kobject. Kobjects have a name
20 and a reference count. A kobject also has a parent pointer (allowing
21 objects to be arranged into hierarchies), a specific type, and,
22 usually, a representation in the sysfs virtual filesystem.
32 - A ktype is the type of object that embeds a kobject. Every structure
33 that embeds a kobject needs a corresponding ktype. The ktype controls
36 - A kset is a group of kobjects. These kobjects can be of the same ktype
42 When you see a sysfs directory full of other directories, generally each
43 of those directories corresponds to a kobject in the same kset.
51 It is rare for kernel code to create a standalone kobject, with one major
53 a larger, domain-specific object. To this end, kobjects will be found
55 object-oriented terms, kobjects can be seen as a top-level, abstract class
56 from which other classes are derived. A kobject implements a set of
67 So, for example, the UIO code in drivers/uio/uio.c has a structure that
68 defines the memory region associated with a uio device:
75 If you have a struct uio_map structure, finding its embedded kobject is
76 just a matter of using the kobj member. Code that works with kobjects will
77 often have the opposite problem, however: given a struct kobject pointer,
90 The return value from container_of() is a pointer to the corresponding
91 container type. So, for example, a pointer "kp" to a struct kobject
92 embedded *within* a struct uio_map could be converted to a pointer to the
97 For convenience, programmers often define a simple macro for "back-casting"
108 where the macro argument "map" is a pointer to the struct kobject in
116 Code which creates a kobject must, of course, initialize that object. Some
117 of the internal fields are setup with a (mandatory) call to kobject_init():
121 The ktype is required for a kobject to be created properly, as every kobject
128 properly. If the kobject is to be associated with a specific kset,
129 kobj->kset must be assigned before calling kobject_add(). If a kset is
130 associated with a kobject, then the parent for the kobject can be set to
140 kobject_rename does not perform any locking or have a solid notion of
144 There is a function called kobject_set_name() but that is legacy cruft and
153 There is a helper function to both initialize and add the kobject to the
165 After a kobject has been registered with the kobject core, you need to
166 announce to the world that it has been created. This can be done with a
184 One of the key functions of a kobject is to serve as a reference counter
187 The low-level functions for manipulating a kobject's reference counts are:
195 When a reference is released, the call to kobject_put() will decrement the
198 need to do a kobject_put() eventually to release that reference.
202 the kernel will contain a run-time check for kobjects that are created
205 If all that you want to use a kobject for is to provide a reference counter
206 for your structure, please use the struct kref instead; a kobject would be
213 Sometimes all that a developer wants is a way to create a simple directory
216 exception where a single kobject should be created. To create such an
221 This function will create a kobject and place it in sysfs in the location
229 Both types of attributes used here, with a kobject that has been created
234 implementation of a simple kobject and attributes.
240 One important thing still missing from the discussion is what happens to a
243 would be little point in using a kobject in the first place. Even
245 in as other portions of the kernel can get a reference on any kobject that
248 The end result is that a structure protected by a kobject cannot be freed
259 This notification is done through a kobject's release() method. Usually
260 such a method has a form like:
270 One important point cannot be overstated: every kobject must have a
271 release() method, and the kobject must persist (in a consistent state)
273 flawed. Note that the kernel will warn you if you forget to provide a
279 must NOT be changed within this callback. Otherwise there will be a memory
294 This structure is used to describe a particular type of kobject (or, more
296 kobj_type structure; a pointer to that structure must be specified when you
299 The release field in struct kobj_type is, of course, a pointer to the
304 The default_attrs pointer is a list of default attributes that will be
310 A kset is merely a collection of kobjects that want to be associated with
316 - It serves as a bag containing a group of objects. A kset can be used by
319 - A kset is also a subdirectory in sysfs, where the associated kobjects
320 with the kset can show up. Every kset contains a kobject which can be
331 A kset keeps its children in a standard kernel linked list. Kobjects point
333 the kobjects belonging to a kset have that kset (or, strictly, its embedded
336 As a kset contains a kobject within it, it should always be dynamically
337 created and never declared statically or on the stack. To create a new
350 An example of using a kset can be seen in the
353 If a kset wishes to control the uevent operations of the kobjects
364 The filter function allows a kset to prevent a uevent from being emitted to
365 userspace for a specific kobject. If the function returns 0, the uevent
375 One might ask how, exactly, a kobject is added to a kset, given that no
377 that this task is handled by kobject_add(). When a kobject is passed to
381 If the kobject belonging to a kset has no parent kobject set, it will be
382 added to the kset's directory. Not all members of a kset do necessarily
390 After a kobject has been registered with the kobject core successfully, it
393 all of the memory allocated by this kobject. If a KOBJ_ADD uevent has been
394 sent for the object, a corresponding KOBJ_REMOVE uevent will be sent, and
397 If you need to do a two-stage delete of the kobject (say you are not
401 the object is still the same. At a later time call kobject_put() to finish
405 circular references are constructed. It is valid in some cases, that a
406 parent objects references a child. Circular references _must_ be broken
407 with an explicit call to kobject_del(), so that a release functions will be
413 For a more complete example of using ksets and kobjects properly, see the