| Age | Commit message (Collapse) | Author |
|
kobject: change name() method in kset_hotplug_ops return const char *
since users shoudl not try to modify returned data.
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
|
|
kobject: make kobject's name const char * since users should not
attempt to change it (except by calling kobject_rename).
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
|
|
Do this instead of using the rwsem of a subsys.
Smaller, faster, and I'm trying to get rid of the rwsem in the subsys.
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
|
|
include/linux/kobject.h: In function `to_kset':
include/linux/kobject.h:116: warning: implicit declaration of function `container_of'
Signed-off-by: Manish Lachwani <mlachwani@mvista.com>
Cc: Greg KH <greg@kroah.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
|
|
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
Add a (non-inlined) add_hotplug_env_var() function to <linux/kobject.h>
and lib/kobject.c. There's a lot of boilerplate code involved in
setting environment variables in a hotplug method, so we should have a
convenience function to consolidate it (and avoid subtle bugs).
Signed-off-by: Roland Dreier <roland@topspin.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
This prevents any potential typos from happening.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
Implemetation of userspace events through a netlink socket. The kernel events
layer provides the functionality to raise an event from a given kobject
represented by its sysfs-path and a signal string to describe the type of
event.
Currently, kobject additions and removals are signalized to userspace by forking
the /sbin/hotplug helper. This patch moves this special case of userspace-event
out of the kobject core to the new kobject_uevent implementation. This makes it
possible to send all hotplug messages also through the new netlink transport.
Possible new users of the kernel userspace functionality are filesystem
mount events (block device claim/release) or simple device state transitions
(cpu overheating).
To send an event, the user needs to pass the kobject, a optional
sysfs-attribute and the signal string to the following function:
kobject_uevent(const char *signal,
struct kobject *kobj,
struct attribute *attr)
Example:
kobject_uevent("overheating", &cpu->kobj, NULL);
The message itself is sent over multicast netlink socket, which makes
it possible for userspace to listen with multiple applications for the same
messages.
Signed-off-by: Robert Love <rml@novell.com>
Signed-off-by: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
Thanks to Kay Sievers for pointing this out.
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
o /sys/kernel/hotplug_seqnum exports the current number
o lib/kobject.c's sequence_num is renamed to hotplug_seqnum and
exported by include/linux/kobject.h
o the source file ksysfs.c in kernel/ creates on init the
sybsystem "/sys/kernel/" in sysfs
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
Both work, but the latter can cause warnings in user space
from compilers that don't like using undefined identifiers
in preprocessor expressions (quite reasonable).
Pointed out by Randy Dunlap.
|
|
Both gcc and sparse will speed up tokenization by noticing
when a header file is protected by the standard preprocessor
#ifndef .. #endif exclusion.
However, that requires that the headers actually _use_ that
standard exclusion. Some did their own little broken dance.
|
|
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
Add a new kobject helper, kobject_get_path(), which is the greatest
function ever.
Signed-Off-By: Robert Love <rml@ximian.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
|
|
o The following patch cleans up sysfs_rename_dir(). It now checks the
return code of kobject_set_name() and propagates the error code to its
callers. Because of this there are changes in the following two APIs. Both
return int instead of void.
int sysfs_rename_dir(struct kobject * kobj, const char *new_name)
int kobject_rename(struct kobject * kobj, char *new_name)
|
|
subsystem name
|
|
make kobject hotplug mechanism public so that others may call it.
|
|
Add ->k_name pointer which points to the name for a kobject. By default, this
points to ->name (the static name array).
Users of kobjects may use the helper function kobject_set_name() (and are
encouraged to do so in all cases). This function will determined whether or
not the name is short enough to fit in ->name. If so, great.
Otherwise, a dyanamic string is allocated and the name is stored there.
->k_name will point to that, and will be freed when the kobject is released.
kobject_set_name() may take a format string, like:
kobject_set_name(kobj,"%s%d",base_name,id);
and will behave as expected (will put in ->name, unless it's too long, in
which case a new string will be allocated and it will be stored in there).
|
|
Based on a patch written by Dan Aloni <da-x@gmx.net>
|
|
Shorthand macro for initializing only the name of an embedded kset in an
object.
|
|
- Make it very explicit that supplying an object desctructor is imperative
if using the interface for object reference counting.
- Add GPL statement to the source files.
- Add GFL (http://www.fsf.org/licenses/fdl.html) statement to documentation.
|
|
has bus ID's that are longer than 16 bytes.
Noted by Ben Collins, who also signed up to fix up some broken
strncpy() users. Sucker!
|
|
This only happens if a kobject belongs to a subsystem that has specified
a set of hotplug operations.
Based on work done by Kevin Fleming <kpfleming@cox.net>
|
|
Check whether kset is NULL or not before doing container_of().
From Dominik Brodowski
|
|
From Louis Zhang.
|
|
- Fixup subsys_sysfs_ops along the way.
|
|
- Remove @count and @off from the show() and store() methods.
|
|
The operation is simple:
- Take read lock for kset.
- Iterate over kset->list.
- Compare name to each kobject's name.
- Return kobject if found.
|
|
The kobject core no longer references a subsystem directly through a kobject,
instead using the kobject's dominant kset to reference the subsystem. The
registrants of kobjects have been fixed up.
To aid in this process, a few helpers were introdcuced:
- kobj_set_kset_s(obj,subsys)
- kset_set_kset_s(obj,subsys)
- subsys_set_kset(obj,subsys)
that set the kset ptr of embedded kobjects for objects that have different
embedded types. See include/linux/kobject.h for more description and usage.
struct subsystem::kobj is also removed, relying solely on a subsystem's
embedded kset for hierarchy information. Since this requires modification
of the subsystem declarations, a helper macro has been defined:
decl_subsys(name,type)
which initializes the name and ktype fields of the subsystem's embedded
kset. All the subsystem declarations have been fixed up.
|
|
struct kset is what struct subsystem should have originally been called. It
is a set of kobjects, and nothing more, with a much less confusing name than
'subsystem.'
struct kset contains an embedded kobject, making it possible to represent it
in the object hierarchy, and sysfs. This also provides a means for objects
to easily express a list of subordinate objects.
struct subsystem still exists, and contains an rwsem, which its subordinate
ksets use to protect their lists.
An arbitrary number of ksets may belong to a subsystem. A ksets specifies
the subsystem it belongs to via its ->subsys field.
struct subsystem also contains a default kset, which may be used without
having to define a separate kset.
The objects that defined subordinate subsystems (bus and class drivers) have
been converted to use subordinate ksets instead.
Note that the usage of ksets is flexible.
- ksets may contain a list of objects of any type, not just kobjects.
- The objects registered with a kset do not have to be registered.
- ksets themselves do not have to be registered. One can be used by
simply calling kset_init().
- ksets do not need a name if they are not registered.
- Note however that locking must be done manually in these cases.
|
|
This is the first step in morphing struct subsystem into something meaningful.
A subsystem is defined simply as a list of kobjects of a certain type, which
is far too generic. A subsystem should be representative of a large entity
of code (i.e. a subsystem of the kernel), not just a simple list.
This changeset:
- Creates struct kobj_type, a descriptor of the type a kobject is embedded
in.
- Extracts the fields that are specific to a particular object type from
struct subsystem and puts them in struct kobj_type, which are
- the object's release method.
- the sysfs operations for the object type.
- the default attributes of the object type.
- Adds ptr to struct kobject to point to its type descriptor.
- Converts the existing subsystem definitions to define struct kobj_type.
struct kobj_type's are not registered, as they do not have any explicit
representation in the object hierarchy, nor do they have any fields that
need runtime initialization.
A kobject's ktype should be set when it is registered, like its subsystem.
Note this obviates the need for defining a struct subsystem when an object
type does not need to be kept in a global list.
|
|
|
|
- check if subsystem is NULL during subsys_get().
- Don't increment parent's reference count before we check if we have a
valid kobject during kobject_add()
- Do kobject_add() in subsys_register(), instead of kobject_register(),
since we've already done kobject_init().
|
|
This is really handy for subsystems that have any attributes they want
to export, esp. if they have just a few, since they don't have to define
all of the infrastructure for creating and tearing down the attributes
for the high level type that they are.
- define struct subsys_attribute for declaring attributes of subsystems
themselves.
- define subsys_create_file() and subsys_remove_file().
- define subsys_sysfs_ops for forwarding sysfs reads and writes to the
subsystem attribute callbacks.
- Set the sysfs_ops to be the subsystem ones if the kobject doesn't belong
to a subsystem itself (meaning that it is a subsystem).
|
|
The interface should now be more sane and protect against races better.
kobject_register() was split into two helpers: kobject_init() and kobject_add().
It calls both consecutively, though both are also exposed for use by users
that want to use the objects w/o adding them to the object hierarchy.
kobject_unregister() was made simply a wrapper for kobject_del() and
kobject_put(), which are both also exposed. The guts of kobject_put() was
moved into kobject_cleanup(), which it calls when the reference count hits
0. (This was done for clarity).
The infrastructure now takes a lot in kobject_get() and kobject_put() when
checking and modifying the objects' reference counts. This was an obvious
one that hsould have been fixed long ago.
kobject_add() increments the refcount of the object, which is decremented
when kobject_del() is called. This guarantees that the object's memory
cannot be freed if it has been added to the hierarchy, and kobject_del()
has not been called on it.
kobject_init() is now the function that increments the refcount on the
object's subsystem, which is decremented only after its release() method
has been called for the object in kobject_cleanup().
The documentation has been updated to reflect these changes.
|
|
- Define a device subsystem and register it on startup.
- Fill it in with fields converted from driverfs-style fields.
- Convert device_{create,remove}_file() to create files in sysfs.
- Add default device attributes to device subsystem.
- Make sure devices get proper kobject familial pointers and that the kobjects
are registered.
|
|
registration.
struct subsystem may now contain a pointer to a NULL-terminated array of
default attributes to be exported when an object is registered with the subsystem.
kobject registration will check the return values of the directory creation and
the creation of each file, and handle it appropriately.
The documentation has also been updated.
|
|
Previously, sysfs read() and write() calls looked for sysfs_ops in the struct
sysfs_dir, in the kobject. Since objects belong to a subsystem, and is a member
of a group of like devices, the sysfs_ops have been moved to struct subsystem,
and are referenced from there.
The only remaining member of struct sysfs_dir is the dentry of the object's
directory. That is moved out of the dir struct and directly into struct kobject.
That saves us 4 bytes/object.
All of the sysfs functions that referenced the struct have been changed to just
reference the dentry.
|
|
A struct subsystem is basically a collection of objects of a certain type,
and some callbacks to operate on objects of that type.
subsystems contain embedded kobjects themselves, and have a similar set of
library routines that kobjects do, which are mostly just wrappers for the
correlating kobject routines.
kobjects are inserted in depth-first order into their subsystem's list of
objects. Orphan kobjects are also given foster parents that point to their
subsystem. This provides a bit more rigidity in the hierarchy, and disallows
any orphan kobjects.
When an object is unregistered, it is removed from its subsystem's list. When
the objects' refcount hits 0, the subsystem's ->release() callback is called.
Documentation describing the objects and the interfaces has also been added.
|
|
This works on obviating the need for a separate data type to describe a sysfs
directory (which was renamed from struct driver_dir_entry to struct sysfs_dir).
All sysfs creation and removal functions now take a struct kobject, instead
of a struct sysfs_dir. This kobject is embedded in ->d_fsdata of the directory.
sysfs_create_dir() takes only 1 parameter now: the object that we're creating
the directory for. The parent dentry is derived by looking at the object's
parent.
sysfs_create_file() takes the object as the first parameter, and the attribute
as the second, which makes more sense from an API perspective.
sysfs_remove_file() now takes an attribute as a second parameter, to be
consistent with the creation function.
sysfs_remove_link() is created, which is basically the old sysfs_remove_file().
(symlinks don't have an attribute associated with them; only a name, which was
prohibiting the previous change).
open() and close() look for a kobject now, and do refcounting directly on the
object. Because of that, we don't need the ->open() and ->close() callbacks
in struct sysfs_ops, so they've been removed.
read() and write() also now look for a kobject now.
The comments have been updated, too.
|
|
structures.
This is not meant to be fancy; just something simple for which we can
control the refcount and other common functionality using common code.
The basic operations for registration and reference count manipulation are
included.
|