Skip to content

Commit

Permalink
kernel/reboot: Add SYS_OFF_MODE_RESTART_PREPARE mode
Browse files Browse the repository at this point in the history
Add SYS_OFF_MODE_RESTART_PREPARE callbacks to be invoked before
a system restart.

Suggested-by: Dmitry Osipenko <[email protected]>
Reviewed-by: Dmitry Osipenko <[email protected]>
Signed-off-by: Kai-Heng Feng <[email protected]>
[ rjw: Changelog edits ]
Signed-off-by: Rafael J. Wysocki <[email protected]>
  • Loading branch information
khfeng authored and rafaeljw committed Oct 4, 2022
1 parent f76349c commit e7fd8b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/linux/reboot.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ enum sys_off_mode {
*/
SYS_OFF_MODE_POWER_OFF,

/**
* @SYS_OFF_MODE_RESTART_PREPARE:
*
* Handlers prepare system to be restarted. Handlers are
* allowed to sleep.
*/
SYS_OFF_MODE_RESTART_PREPARE,

/**
* @SYS_OFF_MODE_RESTART:
*
Expand Down
17 changes: 17 additions & 0 deletions kernel/reboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ void migrate_to_reboot_cpu(void)
set_cpus_allowed_ptr(current, cpumask_of(cpu));
}

/*
* Notifier list for kernel code which wants to be called
* to prepare system for restart.
*/
static BLOCKING_NOTIFIER_HEAD(restart_prep_handler_list);

static void do_kernel_restart_prepare(void)
{
blocking_notifier_call_chain(&restart_prep_handler_list, 0, NULL);
}

/**
* kernel_restart - reboot the system
* @cmd: pointer to buffer containing command to execute for restart
Expand All @@ -254,6 +265,7 @@ void migrate_to_reboot_cpu(void)
void kernel_restart(char *cmd)
{
kernel_restart_prepare(cmd);
do_kernel_restart_prepare();
migrate_to_reboot_cpu();
syscore_shutdown();
if (!cmd)
Expand Down Expand Up @@ -396,6 +408,11 @@ register_sys_off_handler(enum sys_off_mode mode,
handler->list = &power_off_handler_list;
break;

case SYS_OFF_MODE_RESTART_PREPARE:
handler->list = &restart_prep_handler_list;
handler->blocking = true;
break;

case SYS_OFF_MODE_RESTART:
handler->list = &restart_handler_list;
break;
Expand Down

0 comments on commit e7fd8b6

Please sign in to comment.