diff mbox series

[RESEND,v4,1/2] kernel/reboot: Add SYS_OFF_MODE_RESTART_PREPARE mode

Message ID 20220929070526.143907-1-kai.heng.feng@canonical.com (mailing list archive)
State Mainlined, archived
Headers show
Series [RESEND,v4,1/2] kernel/reboot: Add SYS_OFF_MODE_RESTART_PREPARE mode | expand

Commit Message

Kai-Heng Feng Sept. 29, 2022, 7:05 a.m. UTC
Add SYS_OFF_MODE_RESTART_PREPARE callbacks can be invoked before system
restart.

This is a preparation for next patch.

Suggested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v4:
 - Correct typo in comment.
v3:
 - New patch.

 include/linux/reboot.h |  8 ++++++++
 kernel/reboot.c        | 17 +++++++++++++++++
 2 files changed, 25 insertions(+)

Comments

Rafael J. Wysocki Oct. 4, 2022, 2:02 p.m. UTC | #1
On Thu, Sep 29, 2022 at 9:06 AM Kai-Heng Feng
<kai.heng.feng@canonical.com> wrote:
>
> Add SYS_OFF_MODE_RESTART_PREPARE callbacks can be invoked before system
> restart.
>
> This is a preparation for next patch.
>
> Suggested-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Reviewed-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>

Applied as 6.1-rc material along with the [2/2], thanks!

> ---
> v4:
>  - Correct typo in comment.
> v3:
>  - New patch.
>
>  include/linux/reboot.h |  8 ++++++++
>  kernel/reboot.c        | 17 +++++++++++++++++
>  2 files changed, 25 insertions(+)
>
> diff --git a/include/linux/reboot.h b/include/linux/reboot.h
> index e5d9ef886179c..2b6bb593be5b6 100644
> --- a/include/linux/reboot.h
> +++ b/include/linux/reboot.h
> @@ -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:
>          *
> diff --git a/kernel/reboot.c b/kernel/reboot.c
> index 3c35445bf5ad3..3bba88c7ffc6b 100644
> --- a/kernel/reboot.c
> +++ b/kernel/reboot.c
> @@ -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
> @@ -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)
> @@ -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;
> --
> 2.37.2
>
diff mbox series

Patch

diff --git a/include/linux/reboot.h b/include/linux/reboot.h
index e5d9ef886179c..2b6bb593be5b6 100644
--- a/include/linux/reboot.h
+++ b/include/linux/reboot.h
@@ -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:
 	 *
diff --git a/kernel/reboot.c b/kernel/reboot.c
index 3c35445bf5ad3..3bba88c7ffc6b 100644
--- a/kernel/reboot.c
+++ b/kernel/reboot.c
@@ -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
@@ -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)
@@ -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;