Best method for sending messages to user space?
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.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 10 lines · Timur Tabi
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
Quoted 2 lines · Dan Williams
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.
Quoted 2 lines
Now with 2.6.28 you will be
able do this from an atomic context withsysfs_notify_dirent()[1].
That sounds like something I could use.
Kumar, can you update the repository I'm using to include sysfs_notify_dirent()?
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 8 lines · Timur Tabi
Quoted 2 lines · Dan Williams
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);Quoted 7 lines · Dan Williams
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.
Signature · 2 lines
Timur Tabi Linux kernel developer at Freescale
Quoted 10 lines · Timur Tabi
Quoted 7 lines · Dan Williams
fd =
open("/sys/block/md0/md/array_state");
do {
read(buf, fd, len);
act_on_message(buf);
select(...); /* wait for nextsysfs_notifyevent */lseek(fd, 0, SEEK_SET); /* seek back so we can read the new state */
} while (1);
Quoted 4 lines
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 callsysfs_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