]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
scsi: sd: Add manage_restart device attribute to scsi_disk
authorMarkus Probst <markus.probst@posteo.de>
Tue, 4 Nov 2025 14:24:32 +0000 (14:24 +0000)
committerMartin K. Petersen <martin.petersen@oracle.com>
Sat, 8 Nov 2025 18:24:55 +0000 (13:24 -0500)
In addition to the already existing manage_shutdown,
manage_system_start_stop and manage_runtime_start_stop device scsi_disk
attributes, add manage_restart, which allows the high-level device
driver (sd) to manage the device power state for SYSTEM_RESTART if set
to 1.

This attribute is necessary for the following commit "ata: stop disk on
restart if ACPI power resources are found" to avoid a potential disk
power failure in the case the SATA power connector does not retain the
power state after a restart.

Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
Signed-off-by: Markus Probst <markus.probst@posteo.de>
Link: https://patch.msgid.link/20251104142413.322347-2-markus.probst@posteo.de
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/scsi/sd.c
include/scsi/scsi_device.h

index 0252d3f6bed1738c1a9cf44a668d23946e749b49..f2c0744b4480cac63db9cf639ae1ae56b5c30da1 100644 (file)
@@ -318,6 +318,35 @@ static ssize_t manage_shutdown_store(struct device *dev,
 }
 static DEVICE_ATTR_RW(manage_shutdown);
 
+static ssize_t manage_restart_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
+{
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
+       struct scsi_device *sdp = sdkp->device;
+
+       return sysfs_emit(buf, "%u\n", sdp->manage_restart);
+}
+
+static ssize_t manage_restart_store(struct device *dev,
+                                   struct device_attribute *attr,
+                                   const char *buf, size_t count)
+{
+       struct scsi_disk *sdkp = to_scsi_disk(dev);
+       struct scsi_device *sdp = sdkp->device;
+       bool v;
+
+       if (!capable(CAP_SYS_ADMIN))
+               return -EACCES;
+
+       if (kstrtobool(buf, &v))
+               return -EINVAL;
+
+       sdp->manage_restart = v;
+
+       return count;
+}
+static DEVICE_ATTR_RW(manage_restart);
+
 static ssize_t
 allow_restart_show(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -654,6 +683,7 @@ static struct attribute *sd_disk_attrs[] = {
        &dev_attr_manage_system_start_stop.attr,
        &dev_attr_manage_runtime_start_stop.attr,
        &dev_attr_manage_shutdown.attr,
+       &dev_attr_manage_restart.attr,
        &dev_attr_protection_type.attr,
        &dev_attr_protection_mode.attr,
        &dev_attr_app_tag_own.attr,
@@ -4177,7 +4207,9 @@ static void sd_shutdown(struct device *dev)
            (system_state == SYSTEM_POWER_OFF &&
             sdkp->device->manage_shutdown) ||
            (system_state == SYSTEM_RUNNING &&
-            sdkp->device->manage_runtime_start_stop)) {
+            sdkp->device->manage_runtime_start_stop) ||
+           (system_state == SYSTEM_RESTART &&
+            sdkp->device->manage_restart)) {
                sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
                sd_start_stop_device(sdkp, 0);
        }
index 6d6500148c4b746c3b364bc8ed4adce649c12233..c7e657ac8b6d02f310a5b36f929054d1ed61d456 100644 (file)
@@ -178,6 +178,12 @@ struct scsi_device {
         */
        unsigned manage_shutdown:1;
 
+       /*
+        * If true, let the high-level device driver (sd) manage the device
+        * power state for system restart (reboot) operations.
+        */
+       unsigned manage_restart:1;
+
        /*
         * If set and if the device is runtime suspended, ask the high-level
         * device driver (sd) to force a runtime resume of the device.