* [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value
@ 2015-04-01 7:04 Joel Stanley
2015-04-01 7:04 ` [PATCH v2 2/3] kernel/reboot.c: Add orderly_reboot for graceful reboot Joel Stanley
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Joel Stanley @ 2015-04-01 7:04 UTC (permalink / raw)
To: linux-kernel, linuxppc-dev, sparclinux
Cc: fabf, akpm, benh, mpe, rusty, jk, davem
orderly_poweroff() unconditionally returns 0, so remove the dead code
that checks the return value.
A future patch will change the return type to void.
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
drivers/sbus/char/bbc_envctrl.c | 3 +--
drivers/sbus/char/envctrl.c | 7 +------
2 files changed, 2 insertions(+), 8 deletions(-)
diff --git a/drivers/sbus/char/bbc_envctrl.c b/drivers/sbus/char/bbc_envctrl.c
index 0787b97..228c782 100644
--- a/drivers/sbus/char/bbc_envctrl.c
+++ b/drivers/sbus/char/bbc_envctrl.c
@@ -160,8 +160,7 @@ static void do_envctrl_shutdown(struct bbc_cpu_temperature *tp)
printk(KERN_CRIT "kenvctrld: Shutting down the system now.\n");
shutting_down = 1;
- if (orderly_poweroff(true) < 0)
- printk(KERN_CRIT "envctrl: shutdown execution failed\n");
+ orderly_poweroff(true);
}
#define WARN_INTERVAL (30 * HZ)
diff --git a/drivers/sbus/char/envctrl.c b/drivers/sbus/char/envctrl.c
index af15a2f..7946852 100644
--- a/drivers/sbus/char/envctrl.c
+++ b/drivers/sbus/char/envctrl.c
@@ -970,18 +970,13 @@ static struct i2c_child_t *envctrl_get_i2c_child(unsigned char mon_type)
static void envctrl_do_shutdown(void)
{
static int inprog = 0;
- int ret;
if (inprog != 0)
return;
inprog = 1;
printk(KERN_CRIT "kenvctrld: WARNING: Shutting down the system now.\n");
- ret = orderly_poweroff(true);
- if (ret < 0) {
- printk(KERN_CRIT "kenvctrld: WARNING: system shutdown failed!\n");
- inprog = 0; /* unlikely to succeed, but we could try again */
- }
+ orderly_poweroff(true);
}
static struct task_struct *kenvctrld_task;
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 2/3] kernel/reboot.c: Add orderly_reboot for graceful reboot
2015-04-01 7:04 [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value Joel Stanley
@ 2015-04-01 7:04 ` Joel Stanley
2015-04-01 22:27 ` Julian Calaby
2015-04-01 7:04 ` [PATCH v2 3/3] powerpc/powernv: Reboot when requested by firmware Joel Stanley
2015-04-01 16:18 ` [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value David Miller
2 siblings, 1 reply; 5+ messages in thread
From: Joel Stanley @ 2015-04-01 7:04 UTC (permalink / raw)
To: linux-kernel, linuxppc-dev, sparclinux
Cc: fabf, akpm, benh, mpe, rusty, jk, davem
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.
orderly_reboot() should be used when the system wants to allow userspace
to gracefully shut itself down. For cases where the system may
imminently catch on fire, the existing emergency_restart() provides an
immediate reboot without involving userspace.
Signed-off-by: Joel Stanley <joel@jms.id.au>
---
V2:
- remove unused return value from orderly_*
- use correct command in orderly_poweroff
- the reboot command will not have a proc knob to control it, so
it can be made const and static
include/linux/reboot.h | 3 ++-
kernel/reboot.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 50 insertions(+), 6 deletions(-)
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index 48bf152..dc5e3bd 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -67,7 +67,8 @@ void ctrl_alt_del(void);
#define POWEROFF_CMD_PATH_LEN 256
extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN];
-extern int orderly_poweroff(bool force);
+extern void orderly_poweroff(bool force);
+extern void orderly_reboot(void);
/*
* Emergency restart, callable from an interrupt handler.
diff --git a/kernel/reboot.c b/kernel/reboot.c
index a3a9e24..0ace9f6 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";
+static const char reboot_cmd[] = "/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(poweroff_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
@@ -355,15 +380,33 @@ static DECLARE_WORK(poweroff_work, poweroff_work_func);
* This may be called from any context to trigger a system shutdown.
* If the orderly shutdown fails, it will force an immediate shutdown.
*/
-int orderly_poweroff(bool force)
+void orderly_poweroff(bool force)
{
if (force) /* do not override the pending "true" */
poweroff_force = true;
schedule_work(&poweroff_work);
- return 0;
}
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.
+ */
+void orderly_reboot(void)
+{
+ schedule_work(&reboot_work);
+}
+EXPORT_SYMBOL_GPL(orderly_reboot);
+
static int __init reboot_setup(char *str)
{
for (;;) {
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2 3/3] powerpc/powernv: Reboot when requested by firmware
2015-04-01 7:04 [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value Joel Stanley
2015-04-01 7:04 ` [PATCH v2 2/3] kernel/reboot.c: Add orderly_reboot for graceful reboot Joel Stanley
@ 2015-04-01 7:04 ` Joel Stanley
2015-04-01 16:18 ` [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value David Miller
2 siblings, 0 replies; 5+ messages in thread
From: Joel Stanley @ 2015-04-01 7:04 UTC (permalink / raw)
To: linux-kernel, linuxppc-dev, sparclinux
Cc: fabf, akpm, benh, mpe, rusty, jk, davem
Use orderly_reboot so userspace will to shut itself down via the reboot
path. This is required for graceful reboot initiated by the BMC, such
as when a user uses ipmitool to issue a 'chassis power cycle' command.
Signed-off-by: Joel Stanley <joel@jms.id.au>
Acked-by: Michael Ellerman <mpe@ellerman.id.au>
---
arch/powerpc/platforms/powernv/opal-power.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/platforms/powernv/opal-power.c b/arch/powerpc/platforms/powernv/opal-power.c
index 48bf5b0..ac46c2c 100644
--- a/arch/powerpc/platforms/powernv/opal-power.c
+++ b/arch/powerpc/platforms/powernv/opal-power.c
@@ -29,8 +29,9 @@ static int opal_power_control_event(struct notifier_block *nb,
switch (type) {
case SOFT_REBOOT:
- /* Fall through. The service processor is responsible for
- * bringing the machine back up */
+ pr_info("OPAL: reboot requested\n");
+ orderly_reboot();
+ break;
case SOFT_OFF:
pr_info("OPAL: poweroff requested\n");
orderly_poweroff(true);
--
2.1.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value
2015-04-01 7:04 [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value Joel Stanley
2015-04-01 7:04 ` [PATCH v2 2/3] kernel/reboot.c: Add orderly_reboot for graceful reboot Joel Stanley
2015-04-01 7:04 ` [PATCH v2 3/3] powerpc/powernv: Reboot when requested by firmware Joel Stanley
@ 2015-04-01 16:18 ` David Miller
2 siblings, 0 replies; 5+ messages in thread
From: David Miller @ 2015-04-01 16:18 UTC (permalink / raw)
To: joel
Cc: linux-kernel, linuxppc-dev, sparclinux, fabf, akpm, benh, mpe, rusty, jk
From: Joel Stanley <joel@jms.id.au>
Date: Wed, 1 Apr 2015 17:34:46 +1030
> orderly_poweroff() unconditionally returns 0, so remove the dead code
> that checks the return value.
>
> A future patch will change the return type to void.
>
> Signed-off-by: Joel Stanley <joel@jms.id.au>
Acked-by: David S. Miller <davem@davemloft.net>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2 2/3] kernel/reboot.c: Add orderly_reboot for graceful reboot
2015-04-01 7:04 ` [PATCH v2 2/3] kernel/reboot.c: Add orderly_reboot for graceful reboot Joel Stanley
@ 2015-04-01 22:27 ` Julian Calaby
0 siblings, 0 replies; 5+ messages in thread
From: Julian Calaby @ 2015-04-01 22:27 UTC (permalink / raw)
To: Joel Stanley
Cc: linux-kernel, linuxppc-dev, sparclinux, Fabian Frederick,
Andrew Morton, benh, mpe, rusty, jk, David S. Miller
Hi Joel,
On Wed, Apr 1, 2015 at 6:04 PM, Joel Stanley <joel@jms.id.au> wrote:
> 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.
>
> orderly_reboot() should be used when the system wants to allow userspace
> to gracefully shut itself down. For cases where the system may
> imminently catch on fire, the existing emergency_restart() provides an
> immediate reboot without involving userspace.
>
> Signed-off-by: Joel Stanley <joel@jms.id.au>
> ---
> V2:
> - remove unused return value from orderly_*
> - use correct command in orderly_poweroff
> - the reboot command will not have a proc knob to control it, so
> it can be made const and static
>
> include/linux/reboot.h | 3 ++-
> kernel/reboot.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-----
> 2 files changed, 50 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/reboot.h b/include/linux/reboot.h
> index 48bf152..dc5e3bd 100644
> --- a/include/linux/reboot.h
> +++ b/include/linux/reboot.h
> @@ -67,7 +67,8 @@ void ctrl_alt_del(void);
> #define POWEROFF_CMD_PATH_LEN 256
> extern char poweroff_cmd[POWEROFF_CMD_PATH_LEN];
>
> -extern int orderly_poweroff(bool force);
> +extern void orderly_poweroff(bool force);
Should making orderly_poweroff() void be in a separate patch?
Thanks,
--
Julian Calaby
Email: julian.calaby@gmail.com
Profile: http://www.google.com/profiles/julian.calaby/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2015-04-01 22:28 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-01 7:04 [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value Joel Stanley
2015-04-01 7:04 ` [PATCH v2 2/3] kernel/reboot.c: Add orderly_reboot for graceful reboot Joel Stanley
2015-04-01 22:27 ` Julian Calaby
2015-04-01 7:04 ` [PATCH v2 3/3] powerpc/powernv: Reboot when requested by firmware Joel Stanley
2015-04-01 16:18 ` [PATCH v2 1/3] envctrl: Ignore orderly_poweroff return value David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).