[PATCH] rules: handle the change event of ACPI container

From: Lee, Chun-Yi
Date: Sun Jun 25 2017 - 23:40:03 EST


Currently the ACPI in kernel emits KOBJ_CHANGE uevent when there
have online children devices below the acpi container.

Base on the description of caa73ea15 kernel patch, user space
is expected to offline all devices below the container and the
container itself. Then, user space can finalize the removal of
the container with the help of its ACPI device object's eject
attribute in sysfs.

This udev rule can be a default user space application to meet
kernel's expectations. This rule walks through the sysfs tree
to trigger the offline of each child device then ejects the
container.

The ACPI_CONTAINER_EJECT environoment variable can be used to
turn off the the ejection logic of container if the ejection
will be triggered by other ways, e.g. BIOS or other user space
application.

Reference: https://lkml.org/lkml/2013/11/28/520
Cc: Yasuaki Ishimatsu <isimatu.yasuaki@xxxxxxxxxxxxxx>
Cc: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Cc: Michal Hocko <mhocko@xxxxxxx>
Signed-off-by: "Lee, Chun-Yi" <jlee@xxxxxxxx>
---
rules/80-acpi-container-hotremove.rules | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
create mode 100644 rules/80-acpi-container-hotremove.rules

diff --git a/rules/80-acpi-container-hotremove.rules b/rules/80-acpi-container-hotremove.rules
new file mode 100644
index 000000000..ef4ceb5fb
--- /dev/null
+++ b/rules/80-acpi-container-hotremove.rules
@@ -0,0 +1,16 @@
+# do not edit this file, it will be overwritten on update
+
+SUBSYSTEM=="container", ACTION=="change", DEVPATH=="*/ACPI0004:??", ENV{ACPI_CONTAINER_EJECT}="1"\
+RUN+="/bin/sh -c ' \
+if [ $(cat /sys/$env{DEVPATH}/online) -eq 1 ]; then \
+ find -L /sys/$env{DEVPATH}/firmware_node/*/physical_node* -maxdepth 1 -name online | \
+ while read line; do \
+ if [ $(cat $line) -eq 1 ]; then \
+ /bin/echo 0 > $line; \
+ fi \
+ done; \
+ /bin/echo 0 > /sys/$env{DEVPATH}/online; \
+ if [$env{ACPI_CONTAINER_EJECT} -eq 1] && [ $(cat /sys/$env{DEVPATH}/online) -eq 0 ]; then \
+ /bin/echo 1 > /sys/$env{DEVPATH}/firmware_node/eject; \
+ fi \
+fi'"
--
2.12.0