Skip to content

Commit 8fdfdb1

Browse files
0xIO32martinkpetersen
authored andcommitted
scsi: sd: Add manage_restart device attribute to scsi_disk
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>
1 parent 3a86608 commit 8fdfdb1

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

drivers/scsi/sd.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,35 @@ static ssize_t manage_shutdown_store(struct device *dev,
318318
}
319319
static DEVICE_ATTR_RW(manage_shutdown);
320320

321+
static ssize_t manage_restart_show(struct device *dev,
322+
struct device_attribute *attr, char *buf)
323+
{
324+
struct scsi_disk *sdkp = to_scsi_disk(dev);
325+
struct scsi_device *sdp = sdkp->device;
326+
327+
return sysfs_emit(buf, "%u\n", sdp->manage_restart);
328+
}
329+
330+
static ssize_t manage_restart_store(struct device *dev,
331+
struct device_attribute *attr,
332+
const char *buf, size_t count)
333+
{
334+
struct scsi_disk *sdkp = to_scsi_disk(dev);
335+
struct scsi_device *sdp = sdkp->device;
336+
bool v;
337+
338+
if (!capable(CAP_SYS_ADMIN))
339+
return -EACCES;
340+
341+
if (kstrtobool(buf, &v))
342+
return -EINVAL;
343+
344+
sdp->manage_restart = v;
345+
346+
return count;
347+
}
348+
static DEVICE_ATTR_RW(manage_restart);
349+
321350
static ssize_t
322351
allow_restart_show(struct device *dev, struct device_attribute *attr, char *buf)
323352
{
@@ -654,6 +683,7 @@ static struct attribute *sd_disk_attrs[] = {
654683
&dev_attr_manage_system_start_stop.attr,
655684
&dev_attr_manage_runtime_start_stop.attr,
656685
&dev_attr_manage_shutdown.attr,
686+
&dev_attr_manage_restart.attr,
657687
&dev_attr_protection_type.attr,
658688
&dev_attr_protection_mode.attr,
659689
&dev_attr_app_tag_own.attr,
@@ -4177,7 +4207,9 @@ static void sd_shutdown(struct device *dev)
41774207
(system_state == SYSTEM_POWER_OFF &&
41784208
sdkp->device->manage_shutdown) ||
41794209
(system_state == SYSTEM_RUNNING &&
4180-
sdkp->device->manage_runtime_start_stop)) {
4210+
sdkp->device->manage_runtime_start_stop) ||
4211+
(system_state == SYSTEM_RESTART &&
4212+
sdkp->device->manage_restart)) {
41814213
sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n");
41824214
sd_start_stop_device(sdkp, 0);
41834215
}

include/scsi/scsi_device.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ struct scsi_device {
178178
*/
179179
unsigned manage_shutdown:1;
180180

181+
/*
182+
* If true, let the high-level device driver (sd) manage the device
183+
* power state for system restart (reboot) operations.
184+
*/
185+
unsigned manage_restart:1;
186+
181187
/*
182188
* If set and if the device is runtime suspended, ask the high-level
183189
* device driver (sd) to force a runtime resume of the device.

0 commit comments

Comments
 (0)