Skip to content

Commit 4dad7ef

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 8e34607 commit 4dad7ef

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
@@ -1691,6 +1691,42 @@ static void ata_scsi_qc_complete(struct ata_queued_cmd *qc)
16911691
ata_qc_done(qc);
16921692
}
16931693

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

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

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

17391781
ata_sg_init(qc, scsi_sglist(cmd), scsi_sg_count(cmd));
1740-
17411782
qc->dma_dir = cmd->sc_data_direction;
17421783
}
17431784

17441785
qc->complete_fn = ata_scsi_qc_complete;
17451786

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

1757-
return 0;
1758-
1759-
early_finish:
1760-
ata_qc_free(qc);
1761-
scsi_done(cmd);
1762-
return 0;
1790+
return ata_scsi_qc_issue(ap, qc);
17631791

1764-
err_did:
1792+
done:
17651793
ata_qc_free(qc);
1766-
cmd->result = (DID_ERROR << 16);
17671794
scsi_done(cmd);
1768-
err_mem:
17691795
return 0;
1770-
1771-
defer:
1772-
ata_qc_free(qc);
1773-
if (rc == ATA_DEFER_LINK)
1774-
return SCSI_MLQUEUE_DEVICE_BUSY;
1775-
else
1776-
return SCSI_MLQUEUE_HOST_BUSY;
17771796
}
17781797

17791798
/**

0 commit comments

Comments
 (0)