From patchwork Mon Jun 26 06:26:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: joeyli X-Patchwork-Id: 9808677 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2018560209 for ; Mon, 26 Jun 2017 06:27:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B95A2838B for ; Mon, 26 Jun 2017 06:27:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0EDC028429; Mon, 26 Jun 2017 06:27:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 816E12838B for ; Mon, 26 Jun 2017 06:27:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751146AbdFZG1N (ORCPT ); Mon, 26 Jun 2017 02:27:13 -0400 Received: from smtp.nue.novell.com ([195.135.221.5]:40656 "EHLO smtp.nue.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751008AbdFZG1M (ORCPT ); Mon, 26 Jun 2017 02:27:12 -0400 Received: from linux-l9pv.suse ([45.122.156.254]) by smtp.nue.novell.com with ESMTP (TLS encrypted); Mon, 26 Jun 2017 08:27:06 +0200 Date: Mon, 26 Jun 2017 14:26:57 +0800 From: joeyli To: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Yasuaki Ishimatsu , Michal Hocko Subject: A udev rule to serve the change event of ACPI container? Message-ID: <20170626062657.GE4229@linux-l9pv.suse> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Hi all, If ACPI received ejection request for a ACPI container, kernel emits KOBJ_CHANGE uevent when it found 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. That means that kernel relies on users space to peform the offline and ejection jobs to acpi container and children devices. The discussion is here: https://lkml.org/lkml/2013/11/28/520 The mail loop didn't explain why the userspace is responsible for the whole container offlining. Is it possible to do that transparently from the kernel? What's the difference between offlining memory and processors which happends without any cleanup and container which does essentially the same except it happens at once? - After a couple of years, can we let the container hot-remove process transparently? - Except udev rule, does there have any other mechanism to trigger auto offline/ejection? The attached patch is a udev rule that it's used to perform the offlien/ejection jobs on user space. I want to send it to systemd. Thanks a lot! Joey Lee From 6c95d4858e0e7c280e490491c1a00c1b5226a029 Mon Sep 17 00:00:00 2001 From: "Lee, Chun-Yi" Date: Mon, 26 Jun 2017 11:40:03 +0800 Subject: [PATCH] rules: handle the change event of ACPI container 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 Cc: Rafael J. Wysocki Cc: Michal Hocko Signed-off-by: "Lee, Chun-Yi" --- 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'"