I have a driver that provides services for a hypervisor that my company is
creating. The hypervisor can send notifications to the driver via interrupts.
I want to send a message to user space whenever the driver receives one of the
interrupts. The messages don't have any payload.
Should I be creating kobjects and using kobject_uevent(..., KOBJ_CHANGE) to send
these messages? I want to take advantage of the standard (hotplug?) user-space
interface for this sort of thing, so that I don't need to have a custom-written
daemon running that waits on blocking ioctl calls.
--
Timur Tabi
Linux kernel developer at Freescale
On Tue, Oct 21, 2008 at 10:54 AM, Timur Tabi <[email protected]> wrote:
> I have a driver that provides services for a hypervisor that my company is
> creating. The hypervisor can send notifications to the driver via interrupts.
> I want to send a message to user space whenever the driver receives one of the
> interrupts. The messages don't have any payload.
>
> Should I be creating kobjects and using kobject_uevent(..., KOBJ_CHANGE) to send
> these messages? I want to take advantage of the standard (hotplug?) user-space
> interface for this sort of thing, so that I don't need to have a custom-written
> daemon running that waits on blocking ioctl calls.
>
I really like the sysfs_notify() approach that Neil Brown has put
together for delivering md-raid events. Now with 2.6.28 you will be
able do this from an atomic context with sysfs_notify_dirent() [1].
--
Dan
[1] http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commitdiff;h=f1282c84
Dan Williams wrote:
> I really like the sysfs_notify() approach that Neil Brown has put
> together for delivering md-raid events.
Is there any documentation for sysfs_notify? It doesn't appear to do anything
whenever I call it.
> Now with 2.6.28 you will be
> able do this from an atomic context with sysfs_notify_dirent() [1].
That sounds like something I could use.
Kumar, can you update the repository I'm using to include sysfs_notify_dirent()?
--
Timur Tabi
Linux kernel developer at Freescale
On Tue, Oct 21, 2008 at 12:43 PM, Timur Tabi <[email protected]> wrote:
> Dan Williams wrote:
>
>> I really like the sysfs_notify() approach that Neil Brown has put
>> together for delivering md-raid events.
>
> Is there any documentation for sysfs_notify? It doesn't appear to do anything
> whenever I call it.
>
It simply allows you to write an event loop in userspace using a sysfs
attribute file descriptor. Pseudo-example:
fd = open("/sys/block/md0/md/array_state");
do {
read(buf, fd, len);
act_on_message(buf);
select(...); /* wait for next sysfs_notify event */
lseek(fd, 0, SEEK_SET); /* seek back so we can read the new state */
} while (1);
Dan Williams wrote:
> fd = open("/sys/block/md0/md/array_state");
> do {
> read(buf, fd, len);
> act_on_message(buf);
> select(...); /* wait for next sysfs_notify event */
> lseek(fd, 0, SEEK_SET); /* seek back so we can read the new state */
> } while (1);
I meant from the kernel side. I added a call to sysfs_notify(), and I didn't
see any sysfs entries being created, so I presume I need to set up sysfs before
I call sysfs_notify(), but I can't figure out what that setup is.
--
Timur Tabi
Linux kernel developer at Freescale
On Tue, Oct 21, 2008 at 1:23 PM, Timur Tabi <[email protected]> wrote:
> Dan Williams wrote:
>
>> fd = open("/sys/block/md0/md/array_state");
>> do {
>> read(buf, fd, len);
>> act_on_message(buf);
>> select(...); /* wait for next sysfs_notify event */
>> lseek(fd, 0, SEEK_SET); /* seek back so we can read the new state */
>> } while (1);
>
> I meant from the kernel side. I added a call to sysfs_notify(), and I didn't
> see any sysfs entries being created, so I presume I need to set up sysfs before
> I call sysfs_notify(), but I can't figure out what that setup is.
>
sysfs_notify() will not create any files it only operates on
pre-existing attributes created via kobject_{init_and_}add(). See:
http://lxr.linux.no/linux+v2.6.27/drivers/md/md.c#L3473
http://lxr.linux.no/linux+v2.6.27/drivers/md/md.c#L3761