ACPI: export acpi events via generic netlink
Subsystems (4)
PATCH 1/1 ACPI: export acpi events via generic netlink
From: Zhang Rui <[email protected]>
Export ACPI events via Generic Netlink.
An "acpi_event" genetlink family message is sent
when an ACPI event is generated.
Note: The behavior of how ACPI event works nowadays is not changed.
Use genetlink to export ACPI event instead of /proc/acpi/event someday, but not now.
This patch only adds the function of sending genetlink messages when an ACPI event is generated.
Attachment is a simple user space utility which can be used to receive acpi event notifications via netlink.
Thanks to Jamal for his great help.
--- drivers/acpi/bus.c | 4 + drivers/acpi/event.c | 166 +++++++++++++++++++++++++++++++++++++++++++++--- include/acpi/acpi_bus.h | 3 3 files changed, 165 insertions(+), 8 deletions(-)
drivers/acpi/bus.c +4 -0
@@ -292,6 +292,10 @@if (!device)return -EINVAL ; +if (acpi_bus_generate_genetlink_event (device, type, data)) + printk(KERN_WARNING PREFIX +"Failed to generate an ACPI event via genetlink!\n" ); +/* drop event on the floor if no one's listening */ if (!event_is_open)return 0 ;
drivers/acpi/event.c +159 -7
195 lines not on this page · raw message
include/acpi/acpi_bus.h +2 -1
@@ -321,7 +321,8 @@ };extern struct kset acpi_subsys; - +extern int acpi_bus_generate_genetlink_event (struct acpi_device *device, +u8 type,int data);/* * External Functions */
Quoted 5 lines · Zhang Rui
drivers/acpi/event.c +5
-0+/* attributes of acpi_genl_family */ +enum { +ACPI_GENL_ATTR_UNSPEC , +ACPI_GENL_ATTR_EVENT ,/* ACPI event info needed by user space */ + __ACPI_GENL_ATTR_MAX,
drivers/acpi/event.c line 133
Quoted 10 lines
drivers/acpi/event.c +10
-0+}; +#define ACPI_GENL_ATTR_MAX (__ACPI_GENL_ATTR_MAX - 1) + +/* commands supported by the acpi_genl_family */ +enum { +ACPI_GENL_CMD_UNSPEC , +ACPI_GENL_CMD_EVENT ,/* kernel->user notifications for ACPI events */ + __ACPI_GENL_CMD_MAX, +}; +#define ACPI_GENL_CMD_MAX (__ACPI_GENL_CMD_MAX - 1)
Shouldn't you put these into some header file instead of copying them into your userspace tool?
drivers/acpi/event.c line 136
Quoted 2 lines
drivers/acpi/event.c +2
-0+#define ACPI_GENL_NAME "acpi_event" +#define ACPI_GENL_VERSION 0x01
and maybe those too?
Quoted 5 lines
drivers/acpi/event.c +5
-0+/* .doit: standard command callback */ +static int acpi_genl_cmd_event (struct sk_buff *skb,struct genl_info *info) +{ +struct acpi_genl_event *event = info->userhdr; +
drivers/acpi/event.c line 159
Quoted 10 lines
drivers/acpi/event.c +10
-0+if (!event) +ACPI_DEBUG_PRINT ((ACPI_DB_WARN ,"ACPI event: NULL\n" )); + +return 0 ; +} + +static struct genl_ops acpi_event_genl_ops = { + .cmd =ACPI_GENL_CMD_EVENT , + .doit = acpi_genl_cmd_event, +};
This I don't understand, why would userspace ever send events to the kernel? I think you should just leave this out completely.
drivers/acpi/event.c line 218
Quoted 2 lines
drivers/acpi/event.c +2
-0+ result = +genlmsg_multicast (skb,0 , acpi_event_genl_family.id,GFP_ATOMIC );
If my patches are merged you should now register a multicast group.
Here's how I do it in nl80211 now:
| static struct genl_multicast_group nl80211_config_mcgrp = {
| .name = "config",
| };during init:
| err = genl_register_mc_group(&nl80211_fam, &nl80211_config_mcgrp); | if (err) | goto err_out;
for sending the message:
| genlmsg_multicast(msg, 0, nl80211_config_mcgrp.id, GFP_KERNEL);
(I suppose you want GFP_ATOMIC for a reason)
In userspace you query the new multicast group attribute(s) [but let's see what Jamal wants me to change there first] and bind to that group using
| int group = ...;
| setsockopt(s, 270 /*SOL_NETLINK*/, NETLINK_ADD_MEMBERSHIP, &group, sizeof(group));.
johannes
Len Brown
reviewerThanks for including the demo program, Rui, it works for me (tm).
Applied -- with the incremental patch below, which I think is correct because the only caller is bus.c, which is part of the base kernel, not a module. Modules will call acpi_bus_generate_event(), not acpi_bus_generate_genetlink_event() directly.
thanks,
-Len
commit b563d6f30d937510e02541930b1558d0f5759413
Author: Len Brown <[email protected]> Date: Tue Jul 3 15:32:23 2007 -0400
ACPI: netlink: remove unnecessary EXPORT_SYMBOL
drivers/acpi/event.c +0 -2
@@ -221,7 +221,6 @@ int acpi_bus_generate_genetlink_event(struct acpi_device *device, "Failed to send a Genetlink message!\n"));return 0 ; } -EXPORT_SYMBOL (acpi_bus_generate_genetlink_event);static int acpi_event_genetlink_init (void ) {
@@ -245,7 +244,6 @@ int acpi_bus_generate_genetlink_event(struct acpi_device *device, u8 type, {return 0 ; } -EXPORT_SYMBOL (acpi_bus_generate_genetlink_event);static int acpi_event_genetlink_init (void ) {
Quoted 5 lines · Len Brown
Thanks for including the demo program, Rui, it works for me (tm).
Applied -- with the incremental patch below, which I think is correct because the only caller is
bus.c, which is part of the base kernel, not a module.
Dang, mail crossing :)
Are you open to reworking this on top of my multicast patches that I hope to get in soonish, or should I respin my multicast patches to ensure ACPI has a stable family and multicast group number?
johannes
Quoted 11 lines · Johannes Berg
Quoted 5 lines · Len Brown
Thanks for including the demo program, Rui, it works for me (tm).
Applied -- with the incremental patch below, which I think is correct because the only caller is
bus.c, which is part of the base kernel, not a module.Are you open to reworking this on top of my multicast patches that I hope to get in soonish, or should I respin my multicast patches to ensure ACPI has a stable family and multicast group number?
Hi, Johannes,
I missed the discussion about the multicast issues.
You don't need to reserve a family and group ID for ACPI. I'll rework this on your patches.:)
But I don't know when these mutlicast patches can be merged while I hope the function of exporting ACPI event via genetlink can be added ASAP.
I'm okay to hold off on this patch if you think the multicast patches can be merged soon. Or else I tend to apply it first and send an additional patch together with your patches later.
Thanks,
Rui
Quoted 3 lines · Zhang Rui
I missed the discussion about the multicast issues.
You don't need to reserve a family and group ID for ACPI. I'll rework this on your patches.:)
I don't want to hold you, don't worry, I can handle it as well.
Quoted 6 lines
But I don't know when these mutlicast patches can be merged while I hope the function of exporting ACPI event via genetlink can be added ASAP.
I'm okay to hold off on this patch if you think the multicast patches can be merged soon. Or else I tend to apply it first and send an additional patch together with your patches later.
I personally think it's ready to go and haven't received any further comments, but maybe something will come up still. I'll wait a few days and then repost as an actual .23 submission.
johannes
Quoted 7 lines · Johannes Berg
Quoted 3 lines · Zhang Rui
I missed the discussion about the multicast issues.
You don't need to reserve a family and group ID for ACPI. I'll rework this on your patches.:)I don't want to hold you, don't worry, I can handle it as well.
I got your comments on my original patch and it seems that we don't need to change a lot with your patches applied. :)
Quoted 10 lines
Quoted 6 lines
But I don't know when these mutlicast patches can be merged while I hope the function of exporting ACPI event via genetlink can be added ASAP.
I'm okay to hold off on this patch if you think the multicast patches can be merged soon. Or else I tend to apply it first and send an additional patch together with your patches later.
I personally think it's ready to go and haven't received any further comments, but maybe something will come up still. I'll wait a few days and then repost as an actual .23 submission.
That would be great. Can we add the ACPI genetlink patch to your patch set and send them together? I'll refresh it based on your comments.
Thanks,
Rui