Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] Refactor sys_reboot into reusable parts

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>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Eric W. Biederman and committed by
Linus Torvalds
4a00ea1e 47f61f39

+73 -42
+9
include/linux/reboot.h
··· 55 55 struct pt_regs; 56 56 extern void machine_crash_shutdown(struct pt_regs *); 57 57 58 + /* 59 + * Architecture independent implemenations of sys_reboot commands. 60 + */ 61 + 62 + extern void kernel_restart(char *cmd); 63 + extern void kernel_halt(void); 64 + extern void kernel_power_off(void); 65 + extern void kernel_kexec(void); 66 + 58 67 #endif 59 68 60 69 #endif /* _LINUX_REBOOT_H */
+64 -42
kernel/sys.c
··· 361 361 return retval; 362 362 } 363 363 364 + void kernel_restart(char *cmd) 365 + { 366 + notifier_call_chain(&reboot_notifier_list, SYS_RESTART, cmd); 367 + system_state = SYSTEM_RESTART; 368 + device_suspend(PMSG_FREEZE); 369 + device_shutdown(); 370 + if (!cmd) { 371 + printk(KERN_EMERG "Restarting system.\n"); 372 + } else { 373 + printk(KERN_EMERG "Restarting system with command '%s'.\n", cmd); 374 + } 375 + printk(".\n"); 376 + machine_restart(cmd); 377 + } 378 + EXPORT_SYMBOL_GPL(kernel_restart); 379 + 380 + void kernel_kexec(void) 381 + { 382 + #ifdef CONFIG_KEXEC 383 + struct kimage *image; 384 + image = xchg(&kexec_image, 0); 385 + if (!image) { 386 + return; 387 + } 388 + notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL); 389 + system_state = SYSTEM_RESTART; 390 + device_suspend(PMSG_FREEZE); 391 + device_shutdown(); 392 + printk(KERN_EMERG "Starting new kernel\n"); 393 + machine_shutdown(); 394 + machine_kexec(image); 395 + #endif 396 + } 397 + EXPORT_SYMBOL_GPL(kernel_kexec); 398 + 399 + void kernel_halt(void) 400 + { 401 + notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL); 402 + system_state = SYSTEM_HALT; 403 + device_suspend(PMSG_SUSPEND); 404 + device_shutdown(); 405 + printk(KERN_EMERG "System halted.\n"); 406 + machine_halt(); 407 + } 408 + EXPORT_SYMBOL_GPL(kernel_halt); 409 + 410 + void kernel_power_off(void) 411 + { 412 + notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL); 413 + system_state = SYSTEM_POWER_OFF; 414 + device_suspend(PMSG_SUSPEND); 415 + device_shutdown(); 416 + printk(KERN_EMERG "Power down.\n"); 417 + machine_power_off(); 418 + } 419 + EXPORT_SYMBOL_GPL(kernel_power_off); 364 420 365 421 /* 366 422 * Reboot system call: for obvious reasons only root may call it, ··· 445 389 lock_kernel(); 446 390 switch (cmd) { 447 391 case LINUX_REBOOT_CMD_RESTART: 448 - notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL); 449 - system_state = SYSTEM_RESTART; 450 - device_suspend(PMSG_FREEZE); 451 - device_shutdown(); 452 - printk(KERN_EMERG "Restarting system.\n"); 453 - machine_restart(NULL); 392 + kernel_restart(NULL); 454 393 break; 455 394 456 395 case LINUX_REBOOT_CMD_CAD_ON: ··· 457 406 break; 458 407 459 408 case LINUX_REBOOT_CMD_HALT: 460 - notifier_call_chain(&reboot_notifier_list, SYS_HALT, NULL); 461 - system_state = SYSTEM_HALT; 462 - device_suspend(PMSG_SUSPEND); 463 - device_shutdown(); 464 - printk(KERN_EMERG "System halted.\n"); 465 - machine_halt(); 409 + kernel_halt(); 466 410 unlock_kernel(); 467 411 do_exit(0); 468 412 break; 469 413 470 414 case LINUX_REBOOT_CMD_POWER_OFF: 471 - notifier_call_chain(&reboot_notifier_list, SYS_POWER_OFF, NULL); 472 - system_state = SYSTEM_POWER_OFF; 473 - device_suspend(PMSG_SUSPEND); 474 - device_shutdown(); 475 - printk(KERN_EMERG "Power down.\n"); 476 - machine_power_off(); 415 + kernel_power_off(); 477 416 unlock_kernel(); 478 417 do_exit(0); 479 418 break; ··· 475 434 } 476 435 buffer[sizeof(buffer) - 1] = '\0'; 477 436 478 - notifier_call_chain(&reboot_notifier_list, SYS_RESTART, buffer); 479 - system_state = SYSTEM_RESTART; 480 - device_suspend(PMSG_FREEZE); 481 - device_shutdown(); 482 - printk(KERN_EMERG "Restarting system with command '%s'.\n", buffer); 483 - machine_restart(buffer); 437 + kernel_restart(buffer); 484 438 break; 485 439 486 - #ifdef CONFIG_KEXEC 487 440 case LINUX_REBOOT_CMD_KEXEC: 488 - { 489 - struct kimage *image; 490 - image = xchg(&kexec_image, 0); 491 - if (!image) { 492 - unlock_kernel(); 493 - return -EINVAL; 494 - } 495 - notifier_call_chain(&reboot_notifier_list, SYS_RESTART, NULL); 496 - system_state = SYSTEM_RESTART; 497 - device_suspend(PMSG_FREEZE); 498 - device_shutdown(); 499 - printk(KERN_EMERG "Starting new kernel\n"); 500 - machine_shutdown(); 501 - machine_kexec(image); 502 - break; 503 - } 504 - #endif 441 + kernel_kexec(); 442 + unlock_kernel(); 443 + return -EINVAL; 444 + 505 445 #ifdef CONFIG_SOFTWARE_SUSPEND 506 446 case LINUX_REBOOT_CMD_SW_SUSPEND: 507 447 {