diff options
author | Cornelia Huck <cornelia.huck@de.ibm.com> | 2007-07-27 07:41:10 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2007-07-30 17:25:13 -0400 |
commit | f285ea058001ef534f9e53a21aad42c2952bbad5 (patch) | |
tree | d3e4df63f49fc10c599d9fd123812ac297c226ce | |
parent | a56156489dbdc60ac39a77b8a988d375b2f273a0 (diff) |
kobject: update documentation
Update kobject documentation:
- Update structure definitions.
- Remove documentation of removed struct subsystem.
(First shot, uevent_ops probably need some documentation as well.)
Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | Documentation/kobject.txt | 178 |
1 files changed, 59 insertions, 119 deletions
diff --git a/Documentation/kobject.txt b/Documentation/kobject.txt index e44855513b3d..8ee49ee7c963 100644 --- a/Documentation/kobject.txt +++ b/Documentation/kobject.txt | |||
@@ -27,7 +27,6 @@ in detail, and briefly here: | |||
27 | - kobjects a simple object. | 27 | - kobjects a simple object. |
28 | - kset a set of objects of a certain type. | 28 | - kset a set of objects of a certain type. |
29 | - ktype a set of helpers for objects of a common type. | 29 | - ktype a set of helpers for objects of a common type. |
30 | - subsystem a controlling object for a number of ksets. | ||
31 | 30 | ||
32 | 31 | ||
33 | The kobject infrastructure maintains a close relationship with the | 32 | The kobject infrastructure maintains a close relationship with the |
@@ -54,13 +53,15 @@ embedded in larger data structures and replace fields they duplicate. | |||
54 | 1.2 Definition | 53 | 1.2 Definition |
55 | 54 | ||
56 | struct kobject { | 55 | struct kobject { |
56 | const char * k_name; | ||
57 | char name[KOBJ_NAME_LEN]; | 57 | char name[KOBJ_NAME_LEN]; |
58 | atomic_t refcount; | 58 | struct kref kref; |
59 | struct list_head entry; | 59 | struct list_head entry; |
60 | struct kobject * parent; | 60 | struct kobject * parent; |
61 | struct kset * kset; | 61 | struct kset * kset; |
62 | struct kobj_type * ktype; | 62 | struct kobj_type * ktype; |
63 | struct dentry * dentry; | 63 | struct sysfs_dirent * sd; |
64 | wait_queue_head_t poll; | ||
64 | }; | 65 | }; |
65 | 66 | ||
66 | void kobject_init(struct kobject *); | 67 | void kobject_init(struct kobject *); |
@@ -137,8 +138,7 @@ If a kobject does not have a parent when it is registered, its parent | |||
137 | becomes its dominant kset. | 138 | becomes its dominant kset. |
138 | 139 | ||
139 | If a kobject does not have a parent nor a dominant kset, its directory | 140 | If a kobject does not have a parent nor a dominant kset, its directory |
140 | is created at the top-level of the sysfs partition. This should only | 141 | is created at the top-level of the sysfs partition. |
141 | happen for kobjects that are embedded in a struct subsystem. | ||
142 | 142 | ||
143 | 143 | ||
144 | 144 | ||
@@ -150,10 +150,10 @@ A kset is a set of kobjects that are embedded in the same type. | |||
150 | 150 | ||
151 | 151 | ||
152 | struct kset { | 152 | struct kset { |
153 | struct subsystem * subsys; | ||
154 | struct kobj_type * ktype; | 153 | struct kobj_type * ktype; |
155 | struct list_head list; | 154 | struct list_head list; |
156 | struct kobject kobj; | 155 | struct kobject kobj; |
156 | struct kset_uevent_ops * uevent_ops; | ||
157 | }; | 157 | }; |
158 | 158 | ||
159 | 159 | ||
@@ -169,8 +169,7 @@ struct kobject * kset_find_obj(struct kset *, char *); | |||
169 | 169 | ||
170 | 170 | ||
171 | The type that the kobjects are embedded in is described by the ktype | 171 | The type that the kobjects are embedded in is described by the ktype |
172 | pointer. The subsystem that the kobject belongs to is pointed to by the | 172 | pointer. |
173 | subsys pointer. | ||
174 | 173 | ||
175 | A kset contains a kobject itself, meaning that it may be registered in | 174 | A kset contains a kobject itself, meaning that it may be registered in |
176 | the kobject hierarchy and exported via sysfs. More importantly, the | 175 | the kobject hierarchy and exported via sysfs. More importantly, the |
@@ -209,6 +208,58 @@ the hierarchy. | |||
209 | kset_find_obj() may be used to locate a kobject with a particular | 208 | kset_find_obj() may be used to locate a kobject with a particular |
210 | name. The kobject, if found, is returned. | 209 | name. The kobject, if found, is returned. |
211 | 210 | ||
211 | There are also some helper functions which names point to the formerly | ||
212 | existing "struct subsystem", whose functions have been taken over by | ||
213 | ksets. | ||
214 | |||
215 | |||
216 | decl_subsys(name,type,uevent_ops) | ||
217 | |||
218 | Declares a kset named '<name>_subsys' of type <type> with | ||
219 | uevent_ops <uevent_ops>. For example, | ||
220 | |||
221 | decl_subsys(devices, &ktype_device, &device_uevent_ops); | ||
222 | |||
223 | is equivalent to doing: | ||
224 | |||
225 | struct kset devices_subsys = { | ||
226 | .kobj = { | ||
227 | .name = "devices", | ||
228 | }, | ||
229 | .ktype = &ktype_devices, | ||
230 | .uevent_ops = &device_uevent_ops, | ||
231 | }; | ||
232 | |||
233 | |||
234 | The objects that are registered with a subsystem that use the | ||
235 | subsystem's default list must have their kset ptr set properly. These | ||
236 | objects may have embedded kobjects or ksets. The | ||
237 | following helpers make setting the kset easier: | ||
238 | |||
239 | |||
240 | kobj_set_kset_s(obj,subsys) | ||
241 | |||
242 | - Assumes that obj->kobj exists, and is a struct kobject. | ||
243 | - Sets the kset of that kobject to the kset <subsys>. | ||
244 | |||
245 | |||
246 | kset_set_kset_s(obj,subsys) | ||
247 | |||
248 | - Assumes that obj->kset exists, and is a struct kset. | ||
249 | - Sets the kset of the embedded kobject to the kset <subsys>. | ||
250 | |||
251 | subsys_set_kset(obj,subsys) | ||
252 | |||
253 | - Assumes obj->subsys exists, and is a struct subsystem. | ||
254 | - Sets obj->subsys.kset.kobj.kset to the subsystem's embedded kset. | ||
255 | |||
256 | void subsystem_init(struct kset *s); | ||
257 | int subsystem_register(struct kset *s); | ||
258 | void subsystem_unregister(struct kset *s); | ||
259 | struct kset *subsys_get(struct kset *s); | ||
260 | void kset_put(struct kset *s); | ||
261 | |||
262 | These are just wrappers around the respective kset_* functions. | ||
212 | 263 | ||
213 | 2.3 sysfs | 264 | 2.3 sysfs |
214 | 265 | ||
@@ -254,114 +305,3 @@ Instances of struct kobj_type are not registered; only referenced by | |||
254 | the kset. A kobj_type may be referenced by an arbitrary number of | 305 | the kset. A kobj_type may be referenced by an arbitrary number of |
255 | ksets, as there may be disparate sets of identical objects. | 306 | ksets, as there may be disparate sets of identical objects. |
256 | 307 | ||
257 | |||
258 | |||
259 | 4. subsystems | ||
260 | |||
261 | 4.1 Description | ||
262 | |||
263 | A subsystem represents a significant entity of code that maintains an | ||
264 | arbitrary number of sets of objects of various types. Since the number | ||
265 | of ksets and the type of objects they contain are variable, a | ||
266 | generic representation of a subsystem is minimal. | ||
267 | |||
268 | |||
269 | struct subsystem { | ||
270 | struct kset kset; | ||
271 | struct rw_semaphore rwsem; | ||
272 | }; | ||
273 | |||
274 | int subsystem_register(struct subsystem *); | ||
275 | void subsystem_unregister(struct subsystem *); | ||
276 | |||
277 | struct subsystem * subsys_get(struct subsystem * s); | ||
278 | void subsys_put(struct subsystem * s); | ||
279 | |||
280 | |||
281 | A subsystem contains an embedded kset so: | ||
282 | |||
283 | - It can be represented in the object hierarchy via the kset's | ||
284 | embedded kobject. | ||
285 | |||
286 | - It can maintain a default list of objects of one type. | ||
287 | |||
288 | Additional ksets may attach to the subsystem simply by referencing the | ||
289 | subsystem before they are registered. (This one-way reference means | ||
290 | that there is no way to determine the ksets that are attached to the | ||
291 | subsystem.) | ||
292 | |||
293 | All ksets that are attached to a subsystem share the subsystem's R/W | ||
294 | semaphore. | ||
295 | |||
296 | |||
297 | 4.2 subsystem Programming Interface. | ||
298 | |||
299 | The subsystem programming interface is simple and does not offer the | ||
300 | flexibility that the kset and kobject programming interfaces do. They | ||
301 | may be registered and unregistered, as well as reference counted. Each | ||
302 | call forwards the calls to their embedded ksets (which forward the | ||
303 | calls to their embedded kobjects). | ||
304 | |||
305 | |||
306 | 4.3 Helpers | ||
307 | |||
308 | A number of macros are available to make dealing with subsystems and | ||
309 | their embedded objects easier. | ||
310 | |||
311 | |||
312 | decl_subsys(name,type) | ||
313 | |||
314 | Declares a subsystem named '<name>_subsys', with an embedded kset of | ||
315 | type <type>. For example, | ||
316 | |||
317 | decl_subsys(devices,&ktype_devices); | ||
318 | |||
319 | is equivalent to doing: | ||
320 | |||
321 | struct subsystem device_subsys = { | ||
322 | .kset = { | ||
323 | .kobj = { | ||
324 | .name = "devices", | ||
325 | }, | ||
326 | .ktype = &ktype_devices, | ||
327 | } | ||
328 | }; | ||
329 | |||
330 | |||
331 | The objects that are registered with a subsystem that use the | ||
332 | subsystem's default list must have their kset ptr set properly. These | ||
333 | objects may have embedded kobjects, ksets, or other subsystems. The | ||
334 | following helpers make setting the kset easier: | ||
335 | |||
336 | |||
337 | kobj_set_kset_s(obj,subsys) | ||
338 | |||
339 | - Assumes that obj->kobj exists, and is a struct kobject. | ||
340 | - Sets the kset of that kobject to the subsystem's embedded kset. | ||
341 | |||
342 | |||
343 | kset_set_kset_s(obj,subsys) | ||
344 | |||
345 | - Assumes that obj->kset exists, and is a struct kset. | ||
346 | - Sets the kset of the embedded kobject to the subsystem's | ||
347 | embedded kset. | ||
348 | |||
349 | subsys_set_kset(obj,subsys) | ||
350 | |||
351 | - Assumes obj->subsys exists, and is a struct subsystem. | ||
352 | - Sets obj->subsys.kset.kobj.kset to the subsystem's embedded kset. | ||
353 | |||
354 | |||
355 | 4.4 sysfs | ||
356 | |||
357 | subsystems are represented in sysfs via their embedded kobjects. They | ||
358 | follow the same rules as previously mentioned with no exceptions. They | ||
359 | typically receive a top-level directory in sysfs, except when their | ||
360 | embedded kobject is part of another kset, or the parent of the | ||
361 | embedded kobject is explicitly set. | ||
362 | |||
363 | Note that the subsystem's embedded kset must be 'attached' to the | ||
364 | subsystem itself in order to use its rwsem. This is done after | ||
365 | kset_add() has been called. (Not before, because kset_add() uses its | ||
366 | subsystem for a default parent if it doesn't already have one). | ||
367 | |||