From patchwork Mon Mar 30 02:15:32 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Stanley X-Patchwork-Id: 455961 X-Patchwork-Delegate: michael@ellerman.id.au Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id F3D42140161 for ; Mon, 30 Mar 2015 13:17:09 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=neutral reason="verification failed; unprotected key/testing" header.d=jms.id.au header.i=@jms.id.au header.b=UAWeU6lX; dkim-adsp=none (unprotected policy); dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id C027A1A04BC for ; Mon, 30 Mar 2015 13:17:09 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=neutral reason="verification failed; unprotected key/testing" header.d=jms.id.au header.i=@jms.id.au header.b=UAWeU6lX; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from mail-pa0-x22b.google.com (mail-pa0-x22b.google.com [IPv6:2607:f8b0:400e:c03::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3876A1A01AA for ; Mon, 30 Mar 2015 13:15:48 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=pass reason="1024-bit key; unprotected key/testing" header.d=jms.id.au header.i=@jms.id.au header.b=UAWeU6lX; dkim-adsp=pass; dkim-atps=neutral Received: by pacgg7 with SMTP id gg7so23362927pac.0 for ; Sun, 29 Mar 2015 19:15:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jms.id.au; s=google; h=from:to:cc:subject:date:message-id; bh=MTu0f2g5WvepmqA7qjKAAcIL1cNJ3UU003ttXylMnKs=; b=UAWeU6lXAnQBdPzDTTzBHcpIcCHMP0Jvd6MS19VqWMYS3bx+wI+ErMgfvrXyFExoIx IdeYnZFMoa1Jc3C4vfrwTMwwfUVfPH5bj9UD/qaKO0DOLzGZ7ZCLkpvF0sygJKtAzzsz kdWFImFxFlTJD+EFnrKutPm0vzF5qMrwZXreI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=MTu0f2g5WvepmqA7qjKAAcIL1cNJ3UU003ttXylMnKs=; b=GijdConLGJG1sjOYf3/bGUSYn96CDu7gikUvKgxCCH8sq6ToGUY18VDotA32eApLAm kYqaPiJ9u6hUEkCSxtntpEmX8iwWSHY9T7P4Kq5G0ewKotvPSQMUyQdITL0P7O0w9jWL giXW0VKTWSysmbs95KHzxSEN+UUbBhXroxZO2Skh78h7FVDTtHL1rcBDvEXloYZPqjmN nqCnFoKBt9VV5S+R+sxijCVBNyesknXRqcMlHrzAedfu835J4RL/v2HzYn+4ulxHAsub E+2K5a0MziJSF6WFmf/297trLiGjlDSUFt9PQAyS4k9u8gu6MJP+YHUWaunLDLC0gMGD 2vbQ== X-Gm-Message-State: ALoCoQm/LUor+mVZ6PWDCqAjdIMFDtai9Mwz/w8yHrVeS2dFj5ddc+X8afNvE4sER86zoLeNU1TW X-Received: by 10.68.205.226 with SMTP id lj2mr22064449pbc.52.1427681744601; Sun, 29 Mar 2015 19:15:44 -0700 (PDT) Received: from icarus.au.ibm.com (220-244-113-206.static.tpgi.com.au. [220.244.113.206]) by mx.google.com with ESMTPSA id ob7sm8707667pdb.13.2015.03.29.19.15.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 29 Mar 2015 19:15:43 -0700 (PDT) From: Joel Stanley To: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/2] kernel/reboot.c: Add orderly_reboot for graceful reboot Date: Mon, 30 Mar 2015 12:45:32 +1030 Message-Id: <1427681733-25488-1-git-send-email-joel@jms.id.au> X-Mailer: git-send-email 2.1.4 Cc: rusty@rustcorp.com.au, fabf@skynet.be, jk@ozlabs.org, akpm@linux-foundation.org X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" The kernel has orderly_poweroff which allows the kernel to initiate a graceful shutdown of userspace, by running /sbin/poweroff. This adds orderly_reboot that will cause userspace to shut itself down by calling /sbin/reboot. This will be used for shutdown initiated by a system controller on platforms that do not use ACPI. Signed-off-by: Joel Stanley --- include/linux/reboot.h | 1 + kernel/reboot.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/include/linux/reboot.h b/include/linux/reboot.h index 48bf152..a4ffcd9 100644 --- a/include/linux/reboot.h +++ b/include/linux/reboot.h @@ -68,6 +68,7 @@ void ctrl_alt_del(void); extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN]; extern int orderly_poweroff(bool force); +extern int orderly_reboot(void); /* * Emergency restart, callable from an interrupt handler. diff --git a/kernel/reboot.c b/kernel/reboot.c index a3a9e24..d0aa1ec 100644 --- a/kernel/reboot.c +++ b/kernel/reboot.c @@ -306,8 +306,9 @@ void ctrl_alt_del(void) } char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff"; +char reboot_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/reboot"; -static int __orderly_poweroff(bool force) +static int run_cmd(const char *cmd) { char **argv; static char *envp[] = { @@ -316,8 +317,7 @@ static int __orderly_poweroff(bool force) NULL }; int ret; - - argv = argv_split(GFP_KERNEL, poweroff_cmd, NULL); + argv = argv_split(GFP_KERNEL, cmd, NULL); if (argv) { ret = call_usermodehelper(argv[0], argv, envp, UMH_WAIT_EXEC); argv_free(argv); @@ -325,8 +325,33 @@ static int __orderly_poweroff(bool force) ret = -ENOMEM; } + return ret; +} + +static int __orderly_reboot(void) +{ + int ret; + + ret = run_cmd(reboot_cmd); + + if (ret) { + pr_warn("Failed to start orderly reboot: forcing the issue\n"); + emergency_sync(); + kernel_restart(NULL); + } + + return ret; +} + +static int __orderly_poweroff(bool force) +{ + int ret; + + ret = run_cmd(reboot_cmd); + if (ret && force) { pr_warn("Failed to start orderly shutdown: forcing the issue\n"); + /* * I guess this should try to kick off some daemon to sync and * poweroff asap. Or not even bother syncing if we're doing an @@ -364,6 +389,26 @@ int orderly_poweroff(bool force) } EXPORT_SYMBOL_GPL(orderly_poweroff); +static void reboot_work_func(struct work_struct *work) +{ + __orderly_reboot(); +} + +static DECLARE_WORK(reboot_work, reboot_work_func); + +/** + * orderly_reboot - Trigger an orderly system reboot + * + * This may be called from any context to trigger a system reboot. + * If the orderly reboot fails, it will force an immediate reboot. + */ +int orderly_reboot(void) +{ + schedule_work(&reboot_work); + return 0; +} +EXPORT_SYMBOL_GPL(orderly_reboot); + static int __init reboot_setup(char *str) { for (;;) {