All of lore.kernel.org
 help / color / mirror / Atom feed
From: Igor Pylypiv <ipylypiv@google.com>
To: Niklas Cassel <cassel@kernel.org>
Cc: Damien Le Moal <dlemoal@kernel.org>,
	Hannes Reinecke <hare@suse.de>,
	John Garry <john.g.garry@oracle.com>,
	Jason Yan <yanaijie@huawei.com>,
	"James E.J. Bottomley" <jejb@linux.ibm.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>,
	Jack Wang <jinpu.wang@cloud.ionos.com>,
	Xiang Chen <chenxiang66@hisilicon.com>,
	Artur Paszkiewicz <artur.paszkiewicz@intel.com>,
	Bart Van Assche <bvanassche@acm.org>,
	TJ Adams <tadamsjr@google.com>,
	linux-ide@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v7 2/7] scsi: libsas: Define NCQ Priority sysfs attributes for SATA devices
Date: Thu, 7 Mar 2024 13:41:09 -0800	[thread overview]
Message-ID: <Zeo0dVf-bT9i4P1N@google.com> (raw)
In-Reply-To: <ZemOKZAWuIY1hcpU@ryzen>

On Thu, Mar 07, 2024 at 10:51:37AM +0100, Niklas Cassel wrote:
> On Wed, Mar 06, 2024 at 11:28:42AM -0800, Igor Pylypiv wrote:
> > On Wed, Mar 06, 2024 at 11:54:52AM +0100, Niklas Cassel wrote:
> > > On Tue, Mar 05, 2024 at 05:22:21PM -0800, Igor Pylypiv wrote:
> > > > Libata sysfs attributes cannot be used for libsas managed SATA devices
> > > > because the ata_port location is different for libsas.
> > > > 
> > > > Defined sysfs attributes (visible for SATA devices only):
> > > > - /sys/block/sda/device/ncq_prio_enable
> > > > - /sys/block/sda/device/ncq_prio_supported
> > > > 
> > > > The newly defined attributes will pass the correct ata_port to libata
> > > > helper functions.
> > > > 
> > > > Reviewed-by: John Garry <john.g.garry@oracle.com>
> > > > Reviewed-by: Damien Le Moal <dlemoal@kernel.org>
> > > > Reviewed-by: Jason Yan <yanaijie@huawei.com>
> > > > Signed-off-by: Igor Pylypiv <ipylypiv@google.com>
> > > > ---
> > > >  drivers/scsi/libsas/sas_ata.c | 94 +++++++++++++++++++++++++++++++++++
> > > >  include/scsi/sas_ata.h        |  6 +++
> > > >  2 files changed, 100 insertions(+)
> > > > 
> > > > diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
> > > > index 12e2653846e3..04b0bd9a4e01 100644
> > > > --- a/drivers/scsi/libsas/sas_ata.c
> > > > +++ b/drivers/scsi/libsas/sas_ata.c
> > > > @@ -964,3 +964,97 @@ int sas_execute_ata_cmd(struct domain_device *device, u8 *fis, int force_phy_id)
> > > >  			       force_phy_id, &tmf_task);
> > > >  }
> > > >  EXPORT_SYMBOL_GPL(sas_execute_ata_cmd);
> > > > +
> > > > +static ssize_t sas_ncq_prio_supported_show(struct device *device,
> > > > +					   struct device_attribute *attr,
> > > > +					   char *buf)
> > > > +{
> > > > +	struct scsi_device *sdev = to_scsi_device(device);
> > > > +	struct domain_device *ddev = sdev_to_domain_dev(sdev);
> > > > +	bool supported;
> > > > +	int rc;
> > > > +
> > > > +	/* This attribute shall be visible for SATA devices only */
> > > > +	if (WARN_ON_ONCE(!dev_is_sata(ddev)))
> > > > +		return -EINVAL;
> > > 
> > > Like Hannes commented, I don't believe this is needed.
> > > 
> > 
> > The intention for the check is to serve as a fail-safe in case 'is_visible()'
> > callback gets incorrectly modified and stops hiding the sysfs attributes
> > for non-SATA devices.
> > 
> > Just want to clarify should I remove the WARN_ON_ONCE and keep the fail-safe
> > check or should I get rid of the check completely and trust 'is_visible()'
> > to always hide the sysfs attributes for non-SATA devices?
> 
> I think that you can remove both the WARN_ON_ONCE and the
> if (!dev_is_sata()).
> 
> We usually don't keep code around "just in case someone modifies some
> other function sometime in the future".
> 
> 
> If someone changes is_visible() to remove the dev_is_sata() check,
> then they would introuce a bug. I don't see why anyone would change that,
> but if someone tried to remove that check from is_visible() anyway,
> I'm assuming that someone would catch it during code review.
> 

Ack, makes sense. I'll remove the checks in v8. Thanks!
> 
> > 
> > > 
> > > > +
> > > > +	rc = ata_ncq_prio_supported(ddev->sata_dev.ap, sdev, &supported);
> > > > +	if (rc)
> > > > +		return rc;
> > > > +
> > > > +	return sysfs_emit(buf, "%d\n", supported);
> > > > +}
> > > > +
> > > 
> > > While this is a bit different depending on file, the most common way is to
> > > have no blank link before the DEVICE_ATTR().
> > >
> > 
> > In "[PATCH 1/3] ata: libata-sata: Factor out NCQ Priority configuration helpers"
> > Damien asked to keep the blank link before the DEVICE_ATTR() in libata-sata.c.
> > 
> > Non-prio sysfs attributes in libata-sata.c don't have blank lines
> > before DEVICE_ATTR() so I'm more inclined to remove the lines.
> > 
> > I'm fine with either of ways, just want to get a consensus and make it 
> > consistent for both libata-sata.c and sas_ata.c.
> 
> While it is a bit different depending on file, it is slightly more common
> to no have a extra blank line before DEVICE_ATTR():
> 
> $ git grep -B 1 DEVICE_ATTR | grep "}" | wc -l
> 2167
> 
> $ git grep -B 1 DEVICE_ATTR | grep -- "c-$" | wc -l
> 1725
> 
> But I'm fine to keep it like it is, especially if Damien already had expresed
> a preference.
>

Thank you Niklas. Let's keep the extra blank line as Damien suggested.

Thanks,
Igor

> 
> Kind regards,
> Niklas
>
> >  
> > > 
> > > > +DEVICE_ATTR(ncq_prio_supported, S_IRUGO, sas_ncq_prio_supported_show, NULL);
> > > > +
> > > > +static ssize_t sas_ncq_prio_enable_show(struct device *device,
> > > > +					struct device_attribute *attr,
> > > > +					char *buf)
> > > > +{
> > > > +	struct scsi_device *sdev = to_scsi_device(device);
> > > > +	struct domain_device *ddev = sdev_to_domain_dev(sdev);
> > > > +	bool enabled;
> > > > +	int rc;
> > > > +
> > > > +	/* This attribute shall be visible for SATA devices only */
> > > > +	if (WARN_ON_ONCE(!dev_is_sata(ddev)))
> > > > +		return -EINVAL;
> > > > +
> > > > +	rc = ata_ncq_prio_enabled(ddev->sata_dev.ap, sdev, &enabled);
> > > > +	if (rc)
> > > > +		return rc;
> > > > +
> > > > +	return sysfs_emit(buf, "%d\n", enabled);
> > > > +}
> > > > +
> > > > +static ssize_t sas_ncq_prio_enable_store(struct device *device,
> > > > +					 struct device_attribute *attr,
> > > > +					 const char *buf, size_t len)
> > > > +{
> > > > +	struct scsi_device *sdev = to_scsi_device(device);
> > > > +	struct domain_device *ddev = sdev_to_domain_dev(sdev);
> > > > +	bool enable;
> > > > +	int rc;
> > > > +
> > > > +	/* This attribute shall be visible for SATA devices only */
> > > > +	if (WARN_ON_ONCE(!dev_is_sata(ddev)))
> > > > +		return -EINVAL;
> > > > +
> > > > +	rc = kstrtobool(buf, &enable);
> > > > +	if (rc)
> > > > +		return rc;
> > > > +
> > > > +	rc = ata_ncq_prio_enable(ddev->sata_dev.ap, sdev, enable);
> > > > +	if (rc)
> > > > +		return rc;
> > > > +
> > > > +	return len;
> > > > +}
> > > > +
> > > > +DEVICE_ATTR(ncq_prio_enable, S_IRUGO | S_IWUSR,
> > > > +	    sas_ncq_prio_enable_show, sas_ncq_prio_enable_store);
> > > > +
> > > > +static struct attribute *sas_ata_sdev_attrs[] = {
> > > > +	&dev_attr_ncq_prio_supported.attr,
> > > > +	&dev_attr_ncq_prio_enable.attr,
> > > > +	NULL
> > > > +};
> > > > +
> > > > +static umode_t sas_ata_attr_is_visible(struct kobject *kobj,
> > > > +				       struct attribute *attr, int i)
> > > > +{
> > > > +	struct device *dev = kobj_to_dev(kobj);
> > > > +	struct scsi_device *sdev = to_scsi_device(dev);
> > > > +	struct domain_device *ddev = sdev_to_domain_dev(sdev);
> > > > +
> > > > +	if (!dev_is_sata(ddev))
> > > > +		return 0;
> > > > +
> > > > +	return attr->mode;
> > > > +}
> > > > +
> > > > +const struct attribute_group sas_ata_sdev_attr_group = {
> > > > +	.attrs = sas_ata_sdev_attrs,
> > > > +	.is_visible = sas_ata_attr_is_visible,
> > > > +};
> > > > +EXPORT_SYMBOL_GPL(sas_ata_sdev_attr_group);
> > > > diff --git a/include/scsi/sas_ata.h b/include/scsi/sas_ata.h
> > > > index 2f8c719840a6..92e27e7bf088 100644
> > > > --- a/include/scsi/sas_ata.h
> > > > +++ b/include/scsi/sas_ata.h
> > > > @@ -39,6 +39,9 @@ int smp_ata_check_ready_type(struct ata_link *link);
> > > >  int sas_discover_sata(struct domain_device *dev);
> > > >  int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *phy,
> > > >  		    struct domain_device *child, int phy_id);
> > > > +
> > > > +extern const struct attribute_group sas_ata_sdev_attr_group;
> > > > +
> > > >  #else
> > > >  
> > > >  static inline void sas_ata_disabled_notice(void)
> > > > @@ -123,6 +126,9 @@ static inline int sas_ata_add_dev(struct domain_device *parent, struct ex_phy *p
> > > >  	sas_ata_disabled_notice();
> > > >  	return -ENODEV;
> > > >  }
> > > > +
> > > > +#define sas_ata_sdev_attr_group ((struct attribute_group) {})
> > > > +
> > > >  #endif
> > > >  
> > > >  #endif /* _SAS_ATA_H_ */
> > > > -- 
> > > > 2.44.0.278.ge034bb2e1d-goog
> > > > 

  reply	other threads:[~2024-03-07 21:41 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-06  1:22 [PATCH v7 0/7] NCQ Priority sysfs sttributes for libsas Igor Pylypiv
2024-03-06  1:22 ` [PATCH v7 1/7] ata: libata-sata: Factor out NCQ Priority configuration helpers Igor Pylypiv
2024-03-06 10:54   ` Niklas Cassel
2024-03-06  1:22 ` [PATCH v7 2/7] scsi: libsas: Define NCQ Priority sysfs attributes for SATA devices Igor Pylypiv
2024-03-06 10:54   ` Niklas Cassel
2024-03-06 19:28     ` Igor Pylypiv
2024-03-07  9:51       ` Niklas Cassel
2024-03-07 21:41         ` Igor Pylypiv [this message]
2024-03-06  1:22 ` [PATCH v7 3/7] scsi: pm80xx: Add libsas SATA sysfs attributes group Igor Pylypiv
2024-03-06 10:55   ` Niklas Cassel
2024-03-06  1:22 ` [PATCH v7 4/7] scsi: mvsas: " Igor Pylypiv
2024-03-06 10:55   ` Niklas Cassel
2024-03-06 21:13     ` Igor Pylypiv
2024-03-07  9:52       ` Niklas Cassel
2024-03-07 20:35         ` Igor Pylypiv
2024-03-06  1:22 ` [PATCH v7 5/7] scsi: hisi_sas: " Igor Pylypiv
2024-03-06 10:55   ` Niklas Cassel
2024-03-06 20:56     ` Igor Pylypiv
2024-03-07  8:55       ` John Garry
2024-03-07  9:59         ` Niklas Cassel
2024-03-07 11:17           ` John Garry
2024-03-06  1:22 ` [PATCH v7 6/7] scsi: aic94xx: " Igor Pylypiv
2024-03-06 10:55   ` Niklas Cassel
2024-03-06 21:17     ` Igor Pylypiv
2024-03-06  1:22 ` [PATCH v7 7/7] scsi: isci: " Igor Pylypiv
2024-03-06 10:55   ` Niklas Cassel
2024-03-06 10:54 ` [PATCH v7 0/7] NCQ Priority sysfs sttributes for libsas Niklas Cassel
2024-03-06 21:33   ` Igor Pylypiv

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=Zeo0dVf-bT9i4P1N@google.com \
    --to=ipylypiv@google.com \
    --cc=artur.paszkiewicz@intel.com \
    --cc=bvanassche@acm.org \
    --cc=cassel@kernel.org \
    --cc=chenxiang66@hisilicon.com \
    --cc=dlemoal@kernel.org \
    --cc=hare@suse.de \
    --cc=jejb@linux.ibm.com \
    --cc=jinpu.wang@cloud.ionos.com \
    --cc=john.g.garry@oracle.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=tadamsjr@google.com \
    --cc=yanaijie@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.