Re: [PATCH] scsi: sd: Add sd_stop_on_restart parameter for restart device shutdown
From: Sushrut Shirole
Date: Thu Jun 11 2026 - 19:15:01 EST
This issue appears to have been addressed by commit 8fdfdb148816
("scsi: sd: Add manage_restart device attribute to scsi_disk"), merged
in November 2025.
8fdfdb148816 introduces a per-device sysfs attribute manage_restart
which allows stopping a disk on system restart, solving the same
problem this patch was targeting but with finer-grained per-device
control rather than a global module parameter.
Closing this patch as superseded.
Thanks,
Sushrut
On Fri, Sep 26, 2025 at 4:36 PM sushrut <sushrut@xxxxxxxxxx> wrote:
>
> From: Sushrut Shirole <sushrut@xxxxxxxxxx>
>
> Currently, sd_shutdown() skips calling sd_start_stop_device() during
> system restart (SYSTEM_RESTART) to avoid delays during reboot, under
> the assumption that storage devices will maintain power and don't need
> to be explicitly stopped.
>
> However, this assumption doesn't hold for all system designs. Unlike
> traditional servers that can maintain storage power during restart,
> some enterprise network equipment, embedded systems, and specialized
> hardware use centralized power management that immediately cuts power
> to all components during restart. This can result in:
>
> - Filesystem corruption due to incomplete writes
> - SSD firmware corruption during metadata update operations,
> potentially leading to unrecoverable device failure
> - Elevated SMART error counters (e.g., Unexpected_Power_Loss_Ct)
> - Potential data loss in systems without proper power-fail protection
>
> While the kernel provides manage_shutdown and manage_runtime_start_stop
> flags for fine-grained control in other scenarios, there's currently no
> mechanism to ensure proper device shutdown during restart for systems
> that require it.
>
> Add a module parameter 'sd_stop_on_restart' (default: false) to allow
> administrators to enable device stop operations during system restart.
> This maintains backward compatibility while providing the flexibility
> needed for diverse hardware configurations.
>
> The parameter follows established patterns in other SCSI drivers
> (e.g., smartpqi's disable_ctrl_shutdown) and provides a clean
> administrative interface via /sys/module/sd_mod/parameters/.
>
> Signed-off-by: Sushrut Shirole <sushrut@xxxxxxxxxx>
> ---
> drivers/scsi/sd.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> index 5b8668accf8e..d280b395026d 100644
> --- a/drivers/scsi/sd.c
> +++ b/drivers/scsi/sd.c
> @@ -116,6 +116,10 @@ static DEFINE_IDA(sd_index_ida);
> static mempool_t *sd_page_pool;
> static struct lock_class_key sd_bio_compl_lkclass;
>
> +static bool sd_stop_on_restart;
> +module_param(sd_stop_on_restart, bool, 0644);
> +MODULE_PARM_DESC(sd_stop_on_restart, "Issue STOP UNIT command on system restart (default: false)");
> +
> static const char *sd_cache_types[] = {
> "write through", "none", "write back",
> "write back, no read (daft)"
> @@ -4172,6 +4176,9 @@ static void sd_shutdown(struct device *dev)
>
> if ((system_state != SYSTEM_RESTART &&
> sdkp->device->manage_system_start_stop) ||
> + (system_state == SYSTEM_RESTART &&
> + sdkp->device->manage_system_start_stop &&
> + sd_stop_on_restart) ||
> (system_state == SYSTEM_POWER_OFF &&
> sdkp->device->manage_shutdown) ||
> (system_state == SYSTEM_RUNNING &&
> --
> 2.51.0
>