linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH (v2)] scsi: sd: add parameter to stop disks before reboot
@ 2020-06-28 18:32 Simon Arlott
  2020-06-29  8:09 ` Christoph Hellwig
  0 siblings, 1 reply; 4+ messages in thread
From: Simon Arlott @ 2020-06-28 18:32 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Jonathan Corbet,
	Linux Kernel Mailing List, linux-scsi, linux-doc
  Cc: Bart Van Assche, Christoph Hellwig, Damien Le Moal, Pavel Machek,
	Henrique de Moraes Holschuh

I need to use "reboot=p" on my desktop because one of the PCIe devices
does not appear after a warm boot. This results in a very cold boot
because the BIOS turns the PSU off and on.

The scsi sd shutdown process does not send a stop command to disks
before the reboot happens (stop commands are only sent for a shutdown).

The result is that all of my SSDs experience a sudden power loss on
every reboot, which is undesirable behaviour because it could cause data
to be corrupted. These events are recorded in the SMART attributes.

Add a "stop_before_reboot" module parameter that can be used to control
the shutdown behaviour of disks before a reboot. The default will be
the existing behaviour (disks are not stopped).

  sd_mod.stop_before_reboot=<integer>
    0 = disabled (default)
    1 = enabled

The behaviour on shutdown is unchanged: all disks are unconditionally
stopped.

Signed-off-by: Simon Arlott <simon@octiron.net>
---
 Documentation/scsi/scsi-parameters.rst |  5 +++++
 drivers/scsi/sd.c                      | 14 +++++++++++---
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/Documentation/scsi/scsi-parameters.rst b/Documentation/scsi/scsi-parameters.rst
index 9aba897c97ac..324610870de5 100644
--- a/Documentation/scsi/scsi-parameters.rst
+++ b/Documentation/scsi/scsi-parameters.rst
@@ -101,6 +101,11 @@ parameters may be changed at runtime by the command
 			allowing boot to proceed.  none ignores them, expecting
 			user space to do the scan.
 
+	sd_mod.stop_before_reboot=
+			[SCSI] configure stop action for disks before a reboot
+			Format: <integer>
+			0 = disabled (default), 1 = enabled
+
 	sim710=		[SCSI,HW]
 			See header of drivers/scsi/sim710.c.
 
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index d90fefffe31b..506904bf15da 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -98,6 +98,12 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD);
 MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC);
 MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
 
+static unsigned int stop_before_reboot = 0;
+
+module_param(stop_before_reboot, uint, 0644);
+MODULE_PARM_DESC(stop_before_reboot,
+		 "stop disks before reboot");
+
 #if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT)
 #define SD_MINORS	16
 #else
@@ -3576,9 +3582,11 @@ static void sd_shutdown(struct device *dev)
 		sd_sync_cache(sdkp, NULL);
 	}
 
-	if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) {
-		sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
-		sd_start_stop_device(sdkp, 0);
+	if (sdkp->device->manage_start_stop) {
+		if (system_state != SYSTEM_RESTART || stop_before_reboot) {
+			sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
+			sd_start_stop_device(sdkp, 0);
+		}
 	}
 }
 
-- 
2.17.1

-- 
Simon Arlott

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH (v2)] scsi: sd: add parameter to stop disks before reboot
  2020-06-28 18:32 [PATCH (v2)] scsi: sd: add parameter to stop disks before reboot Simon Arlott
@ 2020-06-29  8:09 ` Christoph Hellwig
  2020-06-30  1:35   ` Martin K. Petersen
  0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2020-06-29  8:09 UTC (permalink / raw)
  To: Simon Arlott
  Cc: James E.J. Bottomley, Martin K. Petersen, Jonathan Corbet,
	Linux Kernel Mailing List, linux-scsi, linux-doc,
	Bart Van Assche, Christoph Hellwig, Damien Le Moal, Pavel Machek,
	Henrique de Moraes Holschuh

On Sun, Jun 28, 2020 at 07:32:51PM +0100, Simon Arlott wrote:
> I need to use "reboot=p" on my desktop because one of the PCIe devices
> does not appear after a warm boot. This results in a very cold boot
> because the BIOS turns the PSU off and on.
> 
> The scsi sd shutdown process does not send a stop command to disks
> before the reboot happens (stop commands are only sent for a shutdown).
> 
> The result is that all of my SSDs experience a sudden power loss on
> every reboot, which is undesirable behaviour because it could cause data
> to be corrupted. These events are recorded in the SMART attributes.
> 
> Add a "stop_before_reboot" module parameter that can be used to control
> the shutdown behaviour of disks before a reboot. The default will be
> the existing behaviour (disks are not stopped).
> 
>   sd_mod.stop_before_reboot=<integer>
>     0 = disabled (default)
>     1 = enabled
> 
> The behaviour on shutdown is unchanged: all disks are unconditionally
> stopped.

What happened to the suggestion to treat reboot=p like a poweroff
instead?  That seems to be fundamentally the right thing to do.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH (v2)] scsi: sd: add parameter to stop disks before reboot
  2020-06-29  8:09 ` Christoph Hellwig
@ 2020-06-30  1:35   ` Martin K. Petersen
  2020-07-15  9:25     ` Simon Arlott
  0 siblings, 1 reply; 4+ messages in thread
From: Martin K. Petersen @ 2020-06-30  1:35 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Simon Arlott, James E.J. Bottomley, Martin K. Petersen,
	Jonathan Corbet, Linux Kernel Mailing List, linux-scsi,
	linux-doc, Bart Van Assche, Damien Le Moal, Pavel Machek,
	Henrique de Moraes Holschuh


Christoph,

> What happened to the suggestion to treat reboot=p like a poweroff
> instead?  That seems to be fundamentally the right thing to do.

I agree!

-- 
Martin K. Petersen	Oracle Linux Engineering

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH (v2)] scsi: sd: add parameter to stop disks before reboot
  2020-06-30  1:35   ` Martin K. Petersen
@ 2020-07-15  9:25     ` Simon Arlott
  0 siblings, 0 replies; 4+ messages in thread
From: Simon Arlott @ 2020-07-15  9:25 UTC (permalink / raw)
  To: Martin K. Petersen, Christoph Hellwig
  Cc: Linux Kernel Mailing List, linux-scsi

On 30/06/2020 02:35, Martin K. Petersen wrote:
>> What happened to the suggestion to treat reboot=p like a poweroff
>> instead?  That seems to be fundamentally the right thing to do.
> 
> I agree!

I've done that but so far it has been ignored:
https://lore.kernel.org/lkml/f4a7b539-eeac-1a59-2350-3eefc8c17801@0882a8b5-c6c3-11e9-b005-00805fc181fe/

-- 
Simon Arlott

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-07-15  9:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-28 18:32 [PATCH (v2)] scsi: sd: add parameter to stop disks before reboot Simon Arlott
2020-06-29  8:09 ` Christoph Hellwig
2020-06-30  1:35   ` Martin K. Petersen
2020-07-15  9:25     ` Simon Arlott

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).