ata: libata-sata: Simplify ata_change_queue_depth()

Commit 141f3d6256 ("ata: libata-sata: Fix device queue depth control")
added a struct ata_device argument to ata_change_queue_depth() to
address problems with changing the queue depth of ATA devices managed
through libsas. This was due to problems with ata_scsi_find_dev() which
are now fixed with commit 7f875850f2 ("ata: libata-scsi: Use correct
device no in ata_find_dev()").

Undo some of the changes of commit 141f3d6256e5: remove the added struct
ata_device aregument and use again ata_scsi_find_dev() to find the
target ATA device structure. While doing this, also make sure that
ata_scsi_find_dev() is called with ap->lock held, as it should.

libsas and libata call sites of ata_change_queue_depth() are updated to
match the modified function arguments.

Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Jason Yan <yanaijie@huawei.com>
Reviewed-by: John Garry <john.g.garry@oracle.com>
This commit is contained in:
Damien Le Moal 2023-05-30 16:29:24 +09:00
parent e4c26a1b74
commit 371b74c8ba
3 changed files with 13 additions and 13 deletions

View File

@ -1023,7 +1023,6 @@ EXPORT_SYMBOL_GPL(dev_attr_sw_activity);
/** /**
* ata_change_queue_depth - Set a device maximum queue depth * ata_change_queue_depth - Set a device maximum queue depth
* @ap: ATA port of the target device * @ap: ATA port of the target device
* @dev: target ATA device
* @sdev: SCSI device to configure queue depth for * @sdev: SCSI device to configure queue depth for
* @queue_depth: new queue depth * @queue_depth: new queue depth
* *
@ -1031,24 +1030,27 @@ EXPORT_SYMBOL_GPL(dev_attr_sw_activity);
* and libata. * and libata.
* *
*/ */
int ata_change_queue_depth(struct ata_port *ap, struct ata_device *dev, int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
struct scsi_device *sdev, int queue_depth) int queue_depth)
{ {
struct ata_device *dev;
unsigned long flags; unsigned long flags;
if (!dev || !ata_dev_enabled(dev)) spin_lock_irqsave(ap->lock, flags);
return sdev->queue_depth;
if (queue_depth < 1 || queue_depth == sdev->queue_depth) dev = ata_scsi_find_dev(ap, sdev);
if (!dev || queue_depth < 1 || queue_depth == sdev->queue_depth) {
spin_unlock_irqrestore(ap->lock, flags);
return sdev->queue_depth; return sdev->queue_depth;
}
/* NCQ enabled? */ /* NCQ enabled? */
spin_lock_irqsave(ap->lock, flags);
dev->flags &= ~ATA_DFLAG_NCQ_OFF; dev->flags &= ~ATA_DFLAG_NCQ_OFF;
if (queue_depth == 1 || !ata_ncq_enabled(dev)) { if (queue_depth == 1 || !ata_ncq_enabled(dev)) {
dev->flags |= ATA_DFLAG_NCQ_OFF; dev->flags |= ATA_DFLAG_NCQ_OFF;
queue_depth = 1; queue_depth = 1;
} }
spin_unlock_irqrestore(ap->lock, flags); spin_unlock_irqrestore(ap->lock, flags);
/* limit and apply queue depth */ /* limit and apply queue depth */
@ -1082,8 +1084,7 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
{ {
struct ata_port *ap = ata_shost_to_port(sdev->host); struct ata_port *ap = ata_shost_to_port(sdev->host);
return ata_change_queue_depth(ap, ata_scsi_find_dev(ap, sdev), return ata_change_queue_depth(ap, sdev, queue_depth);
sdev, queue_depth);
} }
EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth); EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth);

View File

@ -872,8 +872,7 @@ int sas_change_queue_depth(struct scsi_device *sdev, int depth)
struct domain_device *dev = sdev_to_domain_dev(sdev); struct domain_device *dev = sdev_to_domain_dev(sdev);
if (dev_is_sata(dev)) if (dev_is_sata(dev))
return ata_change_queue_depth(dev->sata_dev.ap, return ata_change_queue_depth(dev->sata_dev.ap, sdev, depth);
sas_to_ata_dev(dev), sdev, depth);
if (!sdev->tagged_supported) if (!sdev->tagged_supported)
depth = 1; depth = 1;

View File

@ -1144,8 +1144,8 @@ extern int ata_scsi_slave_config(struct scsi_device *sdev);
extern void ata_scsi_slave_destroy(struct scsi_device *sdev); extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
int queue_depth); int queue_depth);
extern int ata_change_queue_depth(struct ata_port *ap, struct ata_device *dev, extern int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
struct scsi_device *sdev, int queue_depth); int queue_depth);
extern struct ata_device *ata_dev_pair(struct ata_device *adev); extern struct ata_device *ata_dev_pair(struct ata_device *adev);
extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev); extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap); extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);