mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: ebiederm@xmission.com (Eric W. Biederman)
To: Andrew Morton <akpm@osdl.org>
Cc: Linus Torvalds <torvalds@osdl.org>, <linux-kernel@vger.kernel.org>
Subject: [PATCH 2/23] Refactor sys_reboot into reusable parts
Date: Tue, 26 Jul 2005 11:24:14 -0600	[thread overview]
Message-ID: <m1ek9leb0h.fsf_-_@ebiederm.dsl.xmission.com> (raw)
In-Reply-To: <m1iryxeb4t.fsf@ebiederm.dsl.xmission.com> (Eric W. Biederman's message of "Tue, 26 Jul 2005 11:21:38 -0600")


Because the factors of sys_reboot don't exist people calling
into the reboot path duplicate the code badly, leading to
inconsistent expectations of code in the reboot path.

This patch should is just code motion.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---

 include/linux/reboot.h |    9 ++++
 kernel/sys.c           |  106 +++++++++++++++++++++++++++++-------------------
 2 files changed, 73 insertions(+), 42 deletions(-)

bbc94d1109869fe5054f7cd697c978d494edeb62
diff --git a/include/linux/reboot.h b/include/linux/reboot.h
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -55,6 +55,15 @@ extern void machine_shutdown(void);
 struct pt_regs;
 extern void machine_crash_shutdown(struct pt_regs *);
 
+/* 
+ * Architecture independent implemenations of sys_reboot commands.
+ */
+
+extern void kernel_restart(char *cmd);
+extern void kernel_halt(void);
+extern void kernel_power_off(void);
+extern void kernel_kexec(void);
+
 #endif
 
 #endif /* _LINUX_REBOOT_H */
diff --git a/kernel/sys.c b/kernel/sys.c
--- a/kernel/sys.c
+++ b/kernel/sys.c
@@ -361,6 +361,62 @@ out_unlock:
 	return retval;
 }
 
+void kernel_restart(char *cmd)
+{
+	notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd);
+	system_state = SYSTEM_RESTART;
+	device_suspend(PMSG_FREEZE);
+	device_shutdown();
+	if (!cmd) {
+		printk(KERN_EMERG "Restarting system.\n");
+	} else {
+		printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd);
+	}
+	printk(".\n");
+	machine_restart(cmd);
+}
+EXPORT_SYMBOL_GPL(kernel_restart);
+
+void kernel_kexec(void)
+{
+#ifdef CONFIG_KEXEC
+	struct kimage *image;
+	image = xchg(&kexec_image, 0);
+	if (!image) {
+		return;
+	}
+	notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
+	system_state = SYSTEM_RESTART;
+	device_suspend(PMSG_FREEZE);
+	device_shutdown();
+	printk(KERN_EMERG "Starting new kernel\n");
+	machine_shutdown();
+	machine_kexec(image);
+#endif
+}
+EXPORT_SYMBOL_GPL(kernel_kexec);
+
+void kernel_halt(void)
+{
+	notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
+	system_state = SYSTEM_HALT;
+	device_suspend(PMSG_SUSPEND);
+	device_shutdown();
+	printk(KERN_EMERG "System halted.\n");
+	machine_halt();
+}
+EXPORT_SYMBOL_GPL(kernel_halt);
+
+void kernel_power_off(void)
+{
+	notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
+	system_state = SYSTEM_POWER_OFF;
+	device_suspend(PMSG_SUSPEND);
+	device_shutdown();
+	printk(KERN_EMERG "Power down.\n");
+	machine_power_off();
+}
+EXPORT_SYMBOL_GPL(kernel_power_off);
 
 /*
  * Reboot system call: for obvious reasons only root may call it,
@@ -389,12 +445,7 @@ asmlinkage long sys_reboot(int magic1, i
 	lock_kernel();
 	switch (cmd) {
 	case LINUX_REBOOT_CMD_RESTART:
-		notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
-		system_state = SYSTEM_RESTART;
-		device_suspend(PMSG_FREEZE);
-		device_shutdown();
-		printk(KERN_EMERG "Restarting system.\n");
-		machine_restart(NULL);
+		kernel_restart(NULL);
 		break;
 
 	case LINUX_REBOOT_CMD_CAD_ON:
@@ -406,23 +457,13 @@ asmlinkage long sys_reboot(int magic1, i
 		break;
 
 	case LINUX_REBOOT_CMD_HALT:
-		notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL);
-		system_state = SYSTEM_HALT;
-		device_suspend(PMSG_SUSPEND);
-		device_shutdown();
-		printk(KERN_EMERG "System halted.\n");
-		machine_halt();
+		kernel_halt();
 		unlock_kernel();
 		do_exit(0);
 		break;
 
 	case LINUX_REBOOT_CMD_POWER_OFF:
-		notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL);
-		system_state = SYSTEM_POWER_OFF;
-		device_suspend(PMSG_SUSPEND);
-		device_shutdown();
-		printk(KERN_EMERG "Power down.\n");
-		machine_power_off();
+		kernel_power_off();
 		unlock_kernel();
 		do_exit(0);
 		break;
@@ -434,33 +475,14 @@ asmlinkage long sys_reboot(int magic1, i
 		}
 		buffer[sizeof(buffer) - 1] = '\0';
 
-		notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer);
-		system_state = SYSTEM_RESTART;
-		device_suspend(PMSG_FREEZE);
-		device_shutdown();
-		printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer);
-		machine_restart(buffer);
+		kernel_restart(buffer);
 		break;
 
-#ifdef CONFIG_KEXEC
 	case LINUX_REBOOT_CMD_KEXEC:
-	{
-		struct kimage *image;
-		image = xchg(&kexec_image, 0);
-		if (!image) {
-			unlock_kernel();
-			return -EINVAL;
-		}
-		notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL);
-		system_state = SYSTEM_RESTART;
-		device_suspend(PMSG_FREEZE);
-		device_shutdown();
-		printk(KERN_EMERG "Starting new kernel\n");
-		machine_shutdown();
-		machine_kexec(image);
-		break;
-	}
-#endif
+		kernel_kexec();
+		unlock_kernel();
+		return -EINVAL;
+
 #ifdef CONFIG_SOFTWARE_SUSPEND
 	case LINUX_REBOOT_CMD_SW_SUSPEND:
 		{

  reply	other threads:[~2005-07-26 17:26 UTC|newest]

Thread overview: 65+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-07-26 17:19 [PATCH 0/23] reboot-fixes Eric W. Biederman
2005-07-26 17:21 ` [PATCH 1/23] Add missing device_suspsend(PMSG_FREEZE) calls Eric W. Biederman
2005-07-26 17:24   ` Eric W. Biederman [this message]
2005-07-26 17:27     ` [PATCH 3/23] Make ctrl_alt_del call kernel_restart to get a proper reboot Eric W. Biederman
2005-07-26 17:29       ` [PATCH 4/23] Add emergency_restart() Eric W. Biederman
2005-07-26 17:32         ` [PATCH 5/23] Fix the arguments to machine_restart on cris Eric W. Biederman
2005-07-26 17:36           ` [PATCH 6/23] Don't export machine_restart, machine_halt, or machine_power_off Eric W. Biederman
2005-07-26 17:41             ` [PATCH 7/23] i386: Implement machine_emergency_reboot Eric W. Biederman
2005-07-26 17:44               ` [PATCH 8/23] x86_64: Fix reboot_force Eric W. Biederman
2005-07-26 17:45                 ` [PATCH 9/23] x86_64: Implemenent machine_emergency_restart Eric W. Biederman
2005-07-26 17:47                   ` [PATCH 10/23] Use kernel_power_off in sysrq-o Eric W. Biederman
2005-07-26 17:49                     ` [PATCH 11/23] Call emergency_reboot from panic Eric W. Biederman
2005-07-26 17:51                       ` [PATCH 12/23] Update sysrq-B to use emergency_restart() Eric W. Biederman
2005-07-26 17:53                         ` [PATCH 13/23] Fix watchdog drivers to call emergency_reboot() Eric W. Biederman
2005-07-26 17:55                           ` [PATCH 14/23] In hangcheck-timer.c call emergency_restart() Eric W. Biederman
2005-07-26 17:59                             ` [PATCH 15/23] 68328serial: sysrq should use emergency_reboot Eric W. Biederman
2005-07-26 18:01                               ` [PATCH 16/23] swpsuspend: Have suspend to disk use factors of sys_reboot Eric W. Biederman
2005-07-26 18:03                                 ` [PATCH 17/23] pcwd.c: Call kernel_power_off not machine_power_off Eric W. Biederman
2005-07-26 18:07                                   ` [PATCH 18/23] machine_shutdown: Typo fix to actually allow specifying which cpu to reboot on Eric W. Biederman
2005-07-26 18:08                                     ` [PATCH 19/23] i386 machine_power_off cleanup Eric W. Biederman
2005-07-26 18:10                                       ` [PATCH 20/23] APM: Remove redundant call to set_cpus_allowed Eric W. Biederman
2005-07-26 18:14                                         ` [PATCH 21/23] x86_64 sync machine_power_off with i386 Eric W. Biederman
2005-07-26 18:16                                           ` [PATCH 22/23] acpi_power_off: Don't switch to the boot cpu Eric W. Biederman
2005-07-26 18:17                                             ` [PATCH 23/23] acpi: Don't call acpi_sleep_prepare from acpi_power_off Eric W. Biederman
2005-07-26 20:57                                 ` [PATCH 16/23] swpsuspend: Have suspend to disk use factors of sys_reboot Andrew Morton
2005-07-26 21:02                                   ` Pavel Machek
2005-07-26 23:55             ` [PATCH 6/23] Don't export machine_restart, machine_halt, or machine_power_off Marc Ballarin
2005-07-27  0:20               ` Eric W. Biederman
2005-07-27  0:26                 ` Andrew Morton
2005-07-27  0:31                 ` Linus Torvalds
2005-07-26 17:54   ` [PATCH 1/23] Add missing device_suspsend(PMSG_FREEZE) calls Nigel Cunningham
2005-07-28  1:12     ` Eric W. Biederman
2005-07-28  2:21       ` [linux-pm] " david-b
2005-07-28  2:44       ` Shaohua Li
2005-07-26 20:08 ` [PATCH 0/23] reboot-fixes Pavel Machek
2005-07-27  9:59 ` Andrew Morton
2005-07-27 15:32   ` Eric W. Biederman
2005-07-27 15:56     ` Eric W. Biederman
2005-07-27 17:41     ` Andrew Morton
2005-07-27 18:15       ` Eric W. Biederman
2005-07-27 18:17         ` Eric W. Biederman
2005-07-27 18:29         ` Andrew Morton
2005-07-27 18:43           ` Eric W. Biederman
2005-07-27 22:47         ` Pavel Machek
2005-07-27 22:51           ` Andrew Morton
2005-07-27 22:54             ` Pavel Machek
2005-08-04  3:24               ` Nigel Cunningham
2005-08-04 21:45                 ` Pavel Machek
2005-08-04 22:16                   ` Nigel Cunningham
     [not found]                     ` <m1ackah4r3.fsf@ebiederm.dsl.xmission.com>
     [not found]                       ` <20050725161548.274d3d67.akpm@osdl.org>
     [not found]                         ` <dnpst4v5px.fsf@magla.zg.iskon.hr>
     [not found]                           ` <m1oe8o9stl.fsf@ebiederm.dsl.xmission.com>
     [not found]                             ` <dny87s6oe9.fsf@magla.zg.iskon.hr>
     [not found]                               ` <m1r7dk82a4.fsf@ebiederm.dsl.xmission.com>
     [not found]                                 ` <42E8439E.9030103@ribosome.natur.cuni.cz>
     [not found]                                   ` <20050727193911.2cb4df88.akpm@osdl.org>
     [not found]                                     ` <42F121CD.5070903@ribosome.natur.cuni.cz>
     [not found]                                       ` <20050803200514.3ddb8195.akpm@osdl.org>
     [not found]                                         ` <20050805140837.GA5556@localhost>
     [not found]                                           ` <42F52AC5.1060109@ribosome.natur.cuni.cz>
     [not found]                                             ` <m1hde2xy74.fsf@ebiederm.dsl.xmission.com>
2005-08-07 12:48                                               ` FYI: device_suspend(...) in kernel_power_off() Eric W. Biederman
2005-08-07 19:02                                                 ` Pavel Machek
2005-08-07 19:46                                                   ` Eric W. Biederman
2005-08-07 21:11                                                     ` Pavel Machek
2005-08-09 17:25                                                       ` Eric W. Biederman
2005-08-09 21:29                                                         ` Nigel Cunningham
2005-08-10 13:08                                                         ` Pavel Machek
2005-07-27 22:51           ` [PATCH 0/23] reboot-fixes Linus Torvalds
2005-07-27 22:53             ` Pavel Machek
2005-07-27 23:20               ` Eric W. Biederman
2005-07-28  7:43                 ` Pavel Machek
2005-07-28 14:54                   ` Eric W. Biederman
2005-07-29  3:11                   ` Eric W. Biederman
2005-07-27 23:07           ` Eric W. Biederman
2005-07-28  7:42             ` Pavel Machek
2005-07-29  3:12               ` Eric W. Biederman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m1ek9leb0h.fsf_-_@ebiederm.dsl.xmission.com \
    --to=ebiederm@xmission.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome