Skip to content
/ linux Public

Commit 97503a8

Browse files
damien-lemoalSasha Levin
authored andcommitted
ata: libata-scsi: refactor ata_scsi_translate()
commit bb3a815 upstream. Factor out of ata_scsi_translate() the code handling queued command deferral using the port qc_defer callback and issuing the queued command with ata_qc_issue() into the new function ata_scsi_qc_issue(), and simplify the goto used in ata_scsi_translate(). While at it, also add a lockdep annotation to check that the port lock is held when ata_scsi_translate() is called. No functional changes. Cc: stable@vger.kernel.org Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Niklas Cassel <cassel@kernel.org> Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com> Reviewed-by: John Garry <john.g.garry@oracle.com> Reviewed-by: Igor Pylypiv <ipylypiv@google.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 51680e9 commit 97503a8

File tree

1 file changed

+50
-31
lines changed

1 file changed

+50
-31
lines changed

drivers/ata/libata-scsi.c

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,42 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
17361736
ata_qc_done(qc);
17371737
}
17381738

1739+
static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
1740+
{
1741+
int ret;
1742+
1743+
if (!ap->ops->qc_defer)
1744+
goto issue;
1745+
1746+
/* Check if the command needs to be deferred. */
1747+
ret = ap->ops->qc_defer(qc);
1748+
switch (ret) {
1749+
case 0:
1750+
break;
1751+
case ATA_DEFER_LINK:
1752+
ret = SCSI_MLQUEUE_DEVICE_BUSY;
1753+
break;
1754+
case ATA_DEFER_PORT:
1755+
ret = SCSI_MLQUEUE_HOST_BUSY;
1756+
break;
1757+
default:
1758+
WARN_ON_ONCE(1);
1759+
ret = SCSI_MLQUEUE_HOST_BUSY;
1760+
break;
1761+
}
1762+
1763+
if (ret) {
1764+
/* Force a requeue of the command to defer its execution. */
1765+
ata_qc_free(qc);
1766+
return ret;
1767+
}
1768+
1769+
issue:
1770+
ata_qc_issue(qc);
1771+
1772+
return 0;
1773+
}
1774+
17391775
/**
17401776
* ata_scsi_translate - Translate then issue SCSI command to ATA device
17411777
* @dev: ATA device to which the command is addressed
@@ -1759,66 +1795,49 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
17591795
* spin_lock_irqsave(host lock)
17601796
*
17611797
* RETURNS:
1762-
* 0 on success, SCSI_ML_QUEUE_DEVICE_BUSY if the command
1763-
* needs to be deferred.
1798+
* 0 on success, SCSI_ML_QUEUE_DEVICE_BUSY or SCSI_MLQUEUE_HOST_BUSY if the
1799+
* command needs to be deferred.
17641800
*/
17651801
static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
17661802
ata_xlat_func_t xlat_func)
17671803
{
17681804
struct ata_port *ap = dev->link->ap;
17691805
struct ata_queued_cmd *qc;
1770-
int rc;
17711806

1807+
lockdep_assert_held(ap->lock);
1808+
1809+
/*
1810+
* ata_scsi_qc_new() calls scsi_done(cmd) in case of failure. So we
1811+
* have nothing further to do when allocating a qc fails.
1812+
*/
17721813
qc = ata_scsi_qc_new(dev, cmd);
17731814
if (!qc)
1774-
goto err_mem;
1815+
return 0;
17751816

17761817
/* data is present; dma-map it */
17771818
if (cmd->sc_data_direction == DMA_FROM_DEVICE ||
17781819
cmd->sc_data_direction == DMA_TO_DEVICE) {
17791820
if (unlikely(scsi_bufflen(cmd) < 1)) {
17801821
ata_dev_warn(dev, "WARNING: zero len r/w req\n");
1781-
goto err_did;
1822+
cmd->result = (DID_ERROR << 16);
1823+
goto done;
17821824
}
17831825

17841826
ata_sg_init(qc, scsi_sglist(cmd), scsi_sg_count(cmd));
1785-
17861827
qc->dma_dir = cmd->sc_data_direction;
17871828
}
17881829

17891830
qc->complete_fn = ata_scsi_qc_complete;
17901831

17911832
if (xlat_func(qc))
1792-
goto early_finish;
1793-
1794-
if (ap->ops->qc_defer) {
1795-
if ((rc = ap->ops->qc_defer(qc)))
1796-
goto defer;
1797-
}
1798-
1799-
/* select device, send command to hardware */
1800-
ata_qc_issue(qc);
1833+
goto done;
18011834

1802-
return 0;
1803-
1804-
early_finish:
1805-
ata_qc_free(qc);
1806-
scsi_done(cmd);
1807-
return 0;
1835+
return ata_scsi_qc_issue(ap, qc);
18081836

1809-
err_did:
1837+
done:
18101838
ata_qc_free(qc);
1811-
cmd->result = (DID_ERROR << 16);
18121839
scsi_done(cmd);
1813-
err_mem:
18141840
return 0;
1815-
1816-
defer:
1817-
ata_qc_free(qc);
1818-
if (rc == ATA_DEFER_LINK)
1819-
return SCSI_MLQUEUE_DEVICE_BUSY;
1820-
else
1821-
return SCSI_MLQUEUE_HOST_BUSY;
18221841
}
18231842

18241843
struct ata_scsi_args {

0 commit comments

Comments
 (0)