Skip to content

Commit 410336f

Browse files
damien-lemoalgregkh
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 62a16b2 commit 410336f

1 file changed

Lines changed: 50 additions & 31 deletions

File tree

drivers/ata/libata-scsi.c

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,6 +1690,42 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
16901690
ata_qc_done(qc);
16911691
}
16921692

1693+
static int ata_scsi_qc_issue(struct ata_port *ap, struct ata_queued_cmd *qc)
1694+
{
1695+
int ret;
1696+
1697+
if (!ap->ops->qc_defer)
1698+
goto issue;
1699+
1700+
/* Check if the command needs to be deferred. */
1701+
ret = ap->ops->qc_defer(qc);
1702+
switch (ret) {
1703+
case 0:
1704+
break;
1705+
case ATA_DEFER_LINK:
1706+
ret = SCSI_MLQUEUE_DEVICE_BUSY;
1707+
break;
1708+
case ATA_DEFER_PORT:
1709+
ret = SCSI_MLQUEUE_HOST_BUSY;
1710+
break;
1711+
default:
1712+
WARN_ON_ONCE(1);
1713+
ret = SCSI_MLQUEUE_HOST_BUSY;
1714+
break;
1715+
}
1716+
1717+
if (ret) {
1718+
/* Force a requeue of the command to defer its execution. */
1719+
ata_qc_free(qc);
1720+
return ret;
1721+
}
1722+
1723+
issue:
1724+
ata_qc_issue(qc);
1725+
1726+
return 0;
1727+
}
1728+
16931729
/**
16941730
* ata_scsi_translate - Translate then issue SCSI command to ATA device
16951731
* @dev: ATA device to which the command is addressed
@@ -1713,66 +1749,49 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
17131749
* spin_lock_irqsave(host lock)
17141750
*
17151751
* RETURNS:
1716-
* 0 on success, SCSI_ML_QUEUE_DEVICE_BUSY if the command
1717-
* needs to be deferred.
1752+
* 0 on success, SCSI_ML_QUEUE_DEVICE_BUSY or SCSI_MLQUEUE_HOST_BUSY if the
1753+
* command needs to be deferred.
17181754
*/
17191755
static int ata_scsi_translate(struct ata_device *dev, struct scsi_cmnd *cmd,
17201756
ata_xlat_func_t xlat_func)
17211757
{
17221758
struct ata_port *ap = dev->link->ap;
17231759
struct ata_queued_cmd *qc;
1724-
int rc;
17251760

1761+
lockdep_assert_held(ap->lock);
1762+
1763+
/*
1764+
* ata_scsi_qc_new() calls scsi_done(cmd) in case of failure. So we
1765+
* have nothing further to do when allocating a qc fails.
1766+
*/
17261767
qc = ata_scsi_qc_new(dev, cmd);
17271768
if (!qc)
1728-
goto err_mem;
1769+
return 0;
17291770

17301771
/* data is present; dma-map it */
17311772
if (cmd->sc_data_direction == DMA_FROM_DEVICE ||
17321773
cmd->sc_data_direction == DMA_TO_DEVICE) {
17331774
if (unlikely(scsi_bufflen(cmd) < 1)) {
17341775
ata_dev_warn(dev, "WARNING: zero len r/w req\n");
1735-
goto err_did;
1776+
cmd->result = (DID_ERROR << 16);
1777+
goto done;
17361778
}
17371779

17381780
ata_sg_init(qc, scsi_sglist(cmd), scsi_sg_count(cmd));
1739-
17401781
qc->dma_dir = cmd->sc_data_direction;
17411782
}
17421783

17431784
qc->complete_fn = ata_scsi_qc_complete;
17441785

17451786
if (xlat_func(qc))
1746-
goto early_finish;
1747-
1748-
if (ap->ops->qc_defer) {
1749-
if ((rc = ap->ops->qc_defer(qc)))
1750-
goto defer;
1751-
}
1752-
1753-
/* select device, send command to hardware */
1754-
ata_qc_issue(qc);
1787+
goto done;
17551788

1756-
return 0;
1757-
1758-
early_finish:
1759-
ata_qc_free(qc);
1760-
scsi_done(cmd);
1761-
return 0;
1789+
return ata_scsi_qc_issue(ap, qc);
17621790

1763-
err_did:
1791+
done:
17641792
ata_qc_free(qc);
1765-
cmd->result = (DID_ERROR << 16);
17661793
scsi_done(cmd);
1767-
err_mem:
17681794
return 0;
1769-
1770-
defer:
1771-
ata_qc_free(qc);
1772-
if (rc == ATA_DEFER_LINK)
1773-
return SCSI_MLQUEUE_DEVICE_BUSY;
1774-
else
1775-
return SCSI_MLQUEUE_HOST_BUSY;
17761795
}
17771796

17781797
/**

0 commit comments

Comments
 (0)