Skip to content

Commit 371b74c

Browse files
committed
ata: libata-sata: Simplify ata_change_queue_depth()
Commit 141f3d6 ("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 7f87585 ("ata: libata-scsi: Use correct device no in ata_find_dev()"). Undo some of the changes of commit 141f3d6: 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 <[email protected]> Reviewed-by: Jason Yan <[email protected]> Reviewed-by: John Garry <[email protected]>
1 parent e4c26a1 commit 371b74c

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

drivers/ata/libata-sata.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,32 +1023,34 @@ EXPORT_SYMBOL_GPL(dev_attr_sw_activity);
10231023
/**
10241024
* ata_change_queue_depth - Set a device maximum queue depth
10251025
* @ap: ATA port of the target device
1026-
* @dev: target ATA device
10271026
* @sdev: SCSI device to configure queue depth for
10281027
* @queue_depth: new queue depth
10291028
*
10301029
* Helper to set a device maximum queue depth, usable with both libsas
10311030
* and libata.
10321031
*
10331032
*/
1034-
int ata_change_queue_depth(struct ata_port *ap, struct ata_device *dev,
1035-
struct scsi_device *sdev, int queue_depth)
1033+
int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1034+
int queue_depth)
10361035
{
1036+
struct ata_device *dev;
10371037
unsigned long flags;
10381038

1039-
if (!dev || !ata_dev_enabled(dev))
1040-
return sdev->queue_depth;
1039+
spin_lock_irqsave(ap->lock, flags);
10411040

1042-
if (queue_depth < 1 || queue_depth == sdev->queue_depth)
1041+
dev = ata_scsi_find_dev(ap, sdev);
1042+
if (!dev || queue_depth < 1 || queue_depth == sdev->queue_depth) {
1043+
spin_unlock_irqrestore(ap->lock, flags);
10431044
return sdev->queue_depth;
1045+
}
10441046

10451047
/* NCQ enabled? */
1046-
spin_lock_irqsave(ap->lock, flags);
10471048
dev->flags &= ~ATA_DFLAG_NCQ_OFF;
10481049
if (queue_depth == 1 || !ata_ncq_enabled(dev)) {
10491050
dev->flags |= ATA_DFLAG_NCQ_OFF;
10501051
queue_depth = 1;
10511052
}
1053+
10521054
spin_unlock_irqrestore(ap->lock, flags);
10531055

10541056
/* limit and apply queue depth */
@@ -1082,8 +1084,7 @@ int ata_scsi_change_queue_depth(struct scsi_device *sdev, int queue_depth)
10821084
{
10831085
struct ata_port *ap = ata_shost_to_port(sdev->host);
10841086

1085-
return ata_change_queue_depth(ap, ata_scsi_find_dev(ap, sdev),
1086-
sdev, queue_depth);
1087+
return ata_change_queue_depth(ap, sdev, queue_depth);
10871088
}
10881089
EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth);
10891090

drivers/scsi/libsas/sas_scsi_host.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,8 +872,7 @@ int sas_change_queue_depth(struct scsi_device *sdev, int depth)
872872
struct domain_device *dev = sdev_to_domain_dev(sdev);
873873

874874
if (dev_is_sata(dev))
875-
return ata_change_queue_depth(dev->sata_dev.ap,
876-
sas_to_ata_dev(dev), sdev, depth);
875+
return ata_change_queue_depth(dev->sata_dev.ap, sdev, depth);
877876

878877
if (!sdev->tagged_supported)
879878
depth = 1;

include/linux/libata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,8 +1144,8 @@ extern int ata_scsi_slave_config(struct scsi_device *sdev);
11441144
extern void ata_scsi_slave_destroy(struct scsi_device *sdev);
11451145
extern int ata_scsi_change_queue_depth(struct scsi_device *sdev,
11461146
int queue_depth);
1147-
extern int ata_change_queue_depth(struct ata_port *ap, struct ata_device *dev,
1148-
struct scsi_device *sdev, int queue_depth);
1147+
extern int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev,
1148+
int queue_depth);
11491149
extern struct ata_device *ata_dev_pair(struct ata_device *adev);
11501150
extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev);
11511151
extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);

0 commit comments

Comments
 (0)