mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Markus Probst <markus.probst@posteo.de>
To: Damien Le Moal <dlemoal@kernel.org>,
	Niklas Cassel <cassel@kernel.org>,
	 "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org,
	 linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/2] Add manage_restart device attribute to scsi_disk
Date: Mon, 06 Oct 2025 12:11:46 +0000	[thread overview]
Message-ID: <568ee07cc0155f3d05a868ae6dce102916b83566.camel@posteo.de> (raw)
In-Reply-To: <524f67bf-f4df-41bf-bf1b-5cd0a79649eb@kernel.org>

On Mon, 2025-10-06 at 09:58 +0900, Damien Le Moal wrote:
> On 10/6/25 04:06, Markus Probst wrote:
> > there is already manage_shutdown, manage_system_start_stop and
> > manage_runtime_start_stop device attributes that allows the high-
> > level
> > device driver (sd) manage the device power state, expect for the
> > system_state SYSTEM_RESTART. With this device attribute, it is
> > possible to
> > let the high-level device driver (sd) manage the device power state
> > for
> > SYSTEM_RESTART too.
> > 
> > Signed-off-by: Markus Probst <markus.probst@posteo.de>
> > ---
> >  drivers/scsi/sd.c          | 35
> > ++++++++++++++++++++++++++++++++++-
> >  include/scsi/scsi_device.h |  6 ++++++
> >  2 files changed, 40 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
> > index 5b8668accf8e..a3e9c2e9d9f4 100644
> > --- a/drivers/scsi/sd.c
> > +++ b/drivers/scsi/sd.c
> > @@ -318,6 +318,36 @@ 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;
> 
> sdp is not really needed.

Then it would be inconsistent with manage_shutdown_*,
manage_runtime_start_stop_*, manage_system_start_stop_*, there it has
the sdp variable declared.

> 
> > +
> > +	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;
> 
> Same here.
> 
> > +	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 +684,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,
> > @@ -4175,7 +4206,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);
> >  	}
> > diff --git a/include/scsi/scsi_device.h
> > b/include/scsi/scsi_device.h
> > index 6d6500148c4b..c7e657ac8b6d 100644
> > --- a/include/scsi/scsi_device.h
> > +++ b/include/scsi/scsi_device.h
> > @@ -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.
> 
> What about cold boot ? Same is needed, no ?
Not sure what you mean with cold boot here.

> The name "manage_restart" is a bit
> confusing since we already have manage_system_start_stop,
> manage_runtime_start_stop and manage_shutdown. I do not have a better
> suggestion
> though.
In that case, we could remove the DEVICE_ATTR_RW(manage_restart), so it
would not be exposed to userspace yet and can later by changed without
breaking userspace?
> 
> > +	 */
> > +	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.
> 

Thanks
- Markus Probst

  reply	other threads:[~2025-10-06 12:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-05 19:05 [PATCH 0/2] Support power resources in ata ports Markus Probst
2025-10-05 19:06 ` [PATCH 1/2] Add manage_restart device attribute to scsi_disk Markus Probst
2025-10-05 19:06   ` [PATCH 2/2] Power on ata ports defined in ACPI before probing ports Markus Probst
2025-10-06  1:09     ` Damien Le Moal
2025-10-09 11:07       ` Markus Probst
2025-10-06 15:07     ` Niklas Cassel
2025-10-06 15:50       ` Markus Probst
2025-10-09 11:41         ` Niklas Cassel
2025-10-06  0:58   ` [PATCH 1/2] Add manage_restart device attribute to scsi_disk Damien Le Moal
2025-10-06 12:11     ` Markus Probst [this message]
2025-10-09 11:24 ` [PATCH v2 0/2] Support power resources defined in acpi on ata Markus Probst
2025-10-09 11:24   ` [PATCH v2 1/2] scsi: sd: Add manage_restart device attribute to scsi_disk Markus Probst
2025-10-09 11:24   ` [PATCH v2 2/2] ata: Use ACPI methods to power on ata ports Markus Probst
2025-10-09 11:59     ` Niklas Cassel
2025-10-09 12:03       ` Niklas Cassel
2025-10-09 13:48       ` Markus Probst
2025-10-10 15:52     ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=568ee07cc0155f3d05a868ae6dce102916b83566.camel@posteo.de \
    --to=markus.probst@posteo.de \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=cassel@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®