Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ata: libata-sata: Simplify ata_change_queue_depth()

Commit 141f3d6256e5 ("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 7f875850f20a ("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>

+13 -13
+10 -9
drivers/ata/libata-sata.c
··· 1023 1023 /** 1024 1024 * ata_change_queue_depth - Set a device maximum queue depth 1025 1025 * @ap: ATA port of the target device 1026 - * @dev: target ATA device 1027 1026 * @sdev: SCSI device to configure queue depth for 1028 1027 * @queue_depth: new queue depth 1029 1028 * ··· 1030 1031 * and libata. 1031 1032 * 1032 1033 */ 1033 - int ata_change_queue_depth(struct ata_port *ap, struct ata_device *dev, 1034 - struct scsi_device *sdev, int queue_depth) 1034 + int ata_change_queue_depth(struct ata_port *ap, struct scsi_device *sdev, 1035 + int queue_depth) 1035 1036 { 1037 + struct ata_device *dev; 1036 1038 unsigned long flags; 1037 1039 1038 - if (!dev || !ata_dev_enabled(dev)) 1039 - return sdev->queue_depth; 1040 + spin_lock_irqsave(ap->lock, flags); 1040 1041 1041 - if (queue_depth < 1 || queue_depth == sdev->queue_depth) 1042 + dev = ata_scsi_find_dev(ap, sdev); 1043 + if (!dev || queue_depth < 1 || queue_depth == sdev->queue_depth) { 1044 + spin_unlock_irqrestore(ap->lock, flags); 1042 1045 return sdev->queue_depth; 1046 + } 1043 1047 1044 1048 /* NCQ enabled? */ 1045 - spin_lock_irqsave(ap->lock, flags); 1046 1049 dev->flags &= ~ATA_DFLAG_NCQ_OFF; 1047 1050 if (queue_depth == 1 || !ata_ncq_enabled(dev)) { 1048 1051 dev->flags |= ATA_DFLAG_NCQ_OFF; 1049 1052 queue_depth = 1; 1050 1053 } 1054 + 1051 1055 spin_unlock_irqrestore(ap->lock, flags); 1052 1056 1053 1057 /* limit and apply queue depth */ ··· 1084 1082 { 1085 1083 struct ata_port *ap = ata_shost_to_port(sdev->host); 1086 1084 1087 - return ata_change_queue_depth(ap, ata_scsi_find_dev(ap, sdev), 1088 - sdev, queue_depth); 1085 + return ata_change_queue_depth(ap, sdev, queue_depth); 1089 1086 } 1090 1087 EXPORT_SYMBOL_GPL(ata_scsi_change_queue_depth); 1091 1088
+1 -2
drivers/scsi/libsas/sas_scsi_host.c
··· 872 872 struct domain_device *dev = sdev_to_domain_dev(sdev); 873 873 874 874 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); 877 876 878 877 if (!sdev->tagged_supported) 879 878 depth = 1;
+2 -2
include/linux/libata.h
··· 1144 1144 extern void ata_scsi_slave_destroy(struct scsi_device *sdev); 1145 1145 extern int ata_scsi_change_queue_depth(struct scsi_device *sdev, 1146 1146 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); 1149 1149 extern struct ata_device *ata_dev_pair(struct ata_device *adev); 1150 1150 extern int ata_do_set_mode(struct ata_link *link, struct ata_device **r_failed_dev); 1151 1151 extern void ata_scsi_port_error_handler(struct Scsi_Host *host, struct ata_port *ap);