From: Cornelia Huck <cornelia.huck@de.ibm.com>
To: Greg KH <greg@kroah.com>
Cc: linux-kernel@vger.kernel.org, Kay Sievers <kay.sievers@vrfy.org>,
Alan Stern <stern@rowland.harvard.edu>,
Jonathan Corbet <corbet@lwn.net>,
Randy Dunlap <randy.dunlap@oracle.com>
Subject: Re: [RFC] New kobject/kset/ktype documentation and example code
Date: Wed, 28 Nov 2007 12:45:45 +0100 [thread overview]
Message-ID: <20071128124545.39ae8070@gondolin.boeblingen.de.ibm.com> (raw)
In-Reply-To: <20071127230252.GB10038@kroah.com>
On Tue, 27 Nov 2007 15:02:52 -0800,
Greg KH <greg@kroah.com> wrote:
>
> ksets
>
> A kset is merely a collection of kobjects that want to be associated with
> each other. There is no restriction that they be of the same ktype, but be
> very careful if they are not.
>
> A kset serves these functions:
>
> - It serves as a bag containing a group of objects. A kset can be used by
> the kernel to track "all block devices" or "all PCI device drivers."
>
> - A kset is also a subdirectory in sysfs, where the associated kobjects
> with the kset can show up.
Perhaps better wording:
A kset is also represented via a subdirectory in sysfs, under which the
kobjects associated with the kset can show up.
> Every kset contains a kobject which can be
> set up to be the parent of other kobjects; in this way the device model
> hierarchy is constructed.
>
> - Ksets can support the "hotplugging" of kobjects and influence how
> uevent events are reported to user space.
>
> - A kset can provide a set of default attributes that all kobjects that
> belong to it automatically inherit and have created whenever a kobject
> is registered belonging to the kset.
Hm, the default attributes are provided by the ktype?
>
> In object-oriented terms, "kset" is the top-level container class; ksets
> contain their own kobject, but that kobject is managed by the kset code and
> should not be manipulated by any other user.
>
> A kset keeps its children in a standard kernel linked list. Kobjects point
> back to their containing kset via their kset field. In almost all cases,
> the contained kobjects also have a pointer to the kset (or, strictly, its
> embedded kobject) in their parent field.
>
> As a kset contains a kobject within it, it should always be dynamically
> created and never declared statically or on the stack. To create a new
> kset use:
> struct kset *kset_create_and_register(char *name,
> struct kset_uevent_ops *u,
> struct kobject *parent);
>
> When you are finished with the kset, call:
> void kset_unregister(struct kset *kset);
> to destroy it.
Maybe also mention kset_get()/kset_put() here? kset_unregister() will
only destroy the kset if the caller holds the last reference to it.
>
> An example of using a kset can be seen in the
> samples/kobject/kset-example.c file in the kernel tree.
>
> If a kset wishes to control the uevent operations of the kobjects
> associated with it, it can use the struct kset_uevent_ops to handle it:
>
> 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,
> struct kobj_uevent_env *env);
> };
>
>
> The filter function allows a kset to prevent a uevent from being emitted to
> userspace for a specific kobject. If the function returns 0, the uevent
> will not be emitted.
>
> The name function will be called to override the default name of the kset
> that the uevent sends to userspace. By default, the name will be the same
> as the kset itself, but this function, if present, can override that name.
>
> The uevent function will be called when the uevent is about to be sent to
> userspace to allow more environment variables to be added to the uevent.
It may be helpful to mention which uevents are by default created by
the kobject core (KOBJ_ADD, KOBJ_DEL, KOBJ_MOVE).
>
> One might ask how, exactly, a kobject is added to a kset, given that no
> functions which perform that function have been presented. The answer is
> that this task is handled by kobject_add(). When a kobject is passed to
> kobject_add(), its kset member should point to the kset to which the
> kobject will belong. kobject_add() will handle the rest. There is currently
> no other way to add a kobject to a kset without directly messing with the
> list pointers.
>
>
> Kobject initialization again
>
> Now that we have covered all of that stuff, we can talk in detail about how
> a kobject should be prepared for its existence in the kernel. Here are all
> of the struct kobject fields which must be initialized somehow:
>
> - k_name - the name of the object. This fields should always be
> initialized with kobject_set_name(), or specified in the original call
> to kobject_create_and_register().
>
> - refcount is the kobject's reference count; it is initialized by kobject_init()
There is no field called "refcount"; the embedded struct kref kref is
initialized by kobject_init().
>
> - parent is the kobject's parent in whatever hierarchy it belongs to. It
> can be set explicitly by the creator. If parent is NULL when
> kobject_add() is called, it will be set to the kobject of the containing
> kset.
>
> - kset is a pointer to the kset which will contain this kobject; it should
> be set prior to calling kobject_init().
>
> - ktype is the type of the kobject; it should be set prior to calling
> kobject_init().
>
> Often, much of the initialization of a kobject is handled by the layer that
> manages the containing kset. See the sample/kobject/kset-example.c for how
> this is usually handled.
Do we also want to mention kobject_rename() and kobject_move(), or are
those functions so esoteric that most people don't want to know about
them?
next prev parent reply other threads:[~2007-11-28 11:46 UTC|newest]
Thread overview: 77+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-27 23:02 Greg KH
2007-11-27 23:03 ` [RFC] sample kobject implementation Greg KH
2007-11-27 23:04 ` [RFC] Sample kset/ktype/kobject implementation Greg KH
2007-11-28 16:35 ` Cornelia Huck
2007-11-29 6:11 ` Greg KH
2007-11-29 9:39 ` Cornelia Huck
2007-11-29 20:39 ` Greg KH
2007-11-29 22:11 ` Alan Stern
2007-11-30 5:07 ` Dave Young
2007-11-30 5:57 ` Dave Young
2007-11-30 14:51 ` Alan Stern
2007-11-30 6:41 ` Greg KH
2007-11-27 23:10 ` [RFC] New kobject/kset/ktype documentation and example code Kyle McMartin
2007-11-27 23:29 ` Greg KH
2007-11-27 23:21 ` Frans Pop
2007-11-28 3:50 ` Jonathan Corbet
2007-11-29 5:46 ` Greg KH
2007-11-28 9:01 ` Cornelia Huck
2007-11-28 12:35 ` Kay Sievers
2007-11-28 15:52 ` Cornelia Huck
2007-11-28 16:03 ` Kay Sievers
2007-11-28 16:09 ` Cornelia Huck
2007-11-28 17:06 ` Greg KH
2007-11-28 19:18 ` Alan Stern
2007-11-29 10:12 ` Cornelia Huck
2007-11-29 15:47 ` Alan Stern
2007-11-29 16:28 ` Cornelia Huck
2007-11-29 16:55 ` Alan Stern
2007-11-29 17:52 ` Cornelia Huck
2007-11-29 5:59 ` Greg KH
2007-11-28 11:45 ` Cornelia Huck [this message]
2007-11-28 12:23 ` Kay Sievers
2007-11-28 15:48 ` Cornelia Huck
2007-11-28 15:57 ` Kay Sievers
2007-11-28 16:12 ` Cornelia Huck
2007-11-28 16:36 ` Kay Sievers
2007-11-28 16:51 ` Cornelia Huck
2007-11-28 17:00 ` Kay Sievers
2007-11-29 6:08 ` Greg KH
2007-11-29 7:50 ` Kay Sievers
2007-11-29 9:35 ` Cornelia Huck
2007-11-29 10:53 ` Kay Sievers
2007-11-29 6:02 ` Greg KH
2007-11-29 6:04 ` Greg KH
2007-11-29 9:41 ` Cornelia Huck
2007-11-28 19:03 ` Alan Stern
2007-11-28 19:28 ` Kay Sievers
2007-11-28 19:36 ` Alan Stern
2007-11-28 19:46 ` Kay Sievers
2007-11-28 20:42 ` [PATCH] kobject: make sure kobj->ktype is set before kobject_init Alan Stern
2007-11-28 20:52 ` Kay Sievers
2007-11-28 21:45 ` Greg KH
2007-11-28 22:00 ` Alan Stern
2007-11-28 22:38 ` Greg KH
2007-11-29 10:05 ` Cornelia Huck
2007-11-29 10:59 ` Kay Sievers
2007-11-29 11:48 ` Cornelia Huck
2007-11-29 15:54 ` Alan Stern
2007-11-29 16:04 ` Kay Sievers
2007-11-29 16:21 ` Cornelia Huck
2007-11-29 21:53 ` kobject_init rewrite Greg KH
2007-11-29 21:54 ` Greg KH
2007-11-30 9:31 ` Cornelia Huck
2007-11-29 22:16 ` Alan Stern
2007-11-29 22:24 ` Greg KH
2007-11-29 17:06 ` [PATCH] kobject: make sure kobj->ktype is set before kobject_init Alan Stern
2007-11-29 17:17 ` Kay Sievers
2007-11-29 18:04 ` Alan Stern
2007-11-29 18:33 ` Kay Sievers
2007-11-29 19:05 ` Alan Stern
2007-11-29 19:51 ` Kay Sievers
2007-11-29 20:09 ` Alan Stern
2007-11-29 20:19 ` Kay Sievers
2007-11-29 20:26 ` Kay Sievers
2007-11-30 9:30 ` Cornelia Huck
2007-11-29 6:18 ` [RFC] New kobject/kset/ktype documentation and example code Greg KH
2007-11-29 15:42 ` Alan Stern
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20071128124545.39ae8070@gondolin.boeblingen.de.ibm.com \
--to=cornelia.huck@de.ibm.com \
--cc=corbet@lwn.net \
--cc=greg@kroah.com \
--cc=kay.sievers@vrfy.org \
--cc=linux-kernel@vger.kernel.org \
--cc=randy.dunlap@oracle.com \
--cc=stern@rowland.harvard.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®