Skip to content

Commit 9526dec

Browse files
floatiousdamien-lemoal
authored andcommitted
ata: libata: Add helper ata_eh_decide_disposition()
Every time I see libata code calling scsi_check_sense(), I get confused why the code path that is working fine for SCSI code, is not sufficient for libata code. The reason is that SCSI usually gets the sense data as part of the completion, and will thus automatically call scsi_check_sense(), which will set the SCSI ML byte (if any). However, for libata queued commands, we always need to fetch the sense data via SCSI EH, and thus do not get the luxury of having scsi_check_sense() called automatically. Add a new helper, ata_eh_decide_disposition(), that has a ata_eh_ prefix to more clearly highlight that this is only needed for code called by EH, while also having a similar name to scsi_decide_disposition(), such that it is easier to compare the libata code with the equivalent SCSI code. Also add a big kdoc comment explaining why this helper is called/needed in the first place. Signed-off-by: Niklas Cassel <[email protected]> Signed-off-by: Damien Le Moal <[email protected]>
1 parent 43d37ff commit 9526dec

File tree

3 files changed

+46
-10
lines changed

3 files changed

+46
-10
lines changed

drivers/ata/libata-eh.c

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,43 @@ unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key)
14011401
return err_mask;
14021402
}
14031403

1404+
/**
1405+
* ata_eh_decide_disposition - Disposition a qc based on sense data
1406+
* @qc: qc to examine
1407+
*
1408+
* For a regular SCSI command, the SCSI completion callback (scsi_done())
1409+
* will call scsi_complete(), which will call scsi_decide_disposition(),
1410+
* which will call scsi_check_sense(). scsi_complete() finally calls
1411+
* scsi_finish_command(). This is fine for SCSI, since any eventual sense
1412+
* data is usually returned in the completion itself (without invoking SCSI
1413+
* EH). However, for a QC, we always need to fetch the sense data
1414+
* explicitly using SCSI EH.
1415+
*
1416+
* A command that is completed via SCSI EH will instead be completed using
1417+
* scsi_eh_flush_done_q(), which will call scsi_finish_command() directly
1418+
* (without ever calling scsi_check_sense()).
1419+
*
1420+
* For a command that went through SCSI EH, it is the responsibility of the
1421+
* SCSI EH strategy handler to call scsi_decide_disposition(), see e.g. how
1422+
* scsi_eh_get_sense() calls scsi_decide_disposition() for SCSI LLDDs that
1423+
* do not get the sense data as part of the completion.
1424+
*
1425+
* Thus, for QC commands that went via SCSI EH, we need to call
1426+
* scsi_check_sense() ourselves, similar to how scsi_eh_get_sense() calls
1427+
* scsi_decide_disposition(), which calls scsi_check_sense(), in order to
1428+
* set the correct SCSI ML byte (if any).
1429+
*
1430+
* LOCKING:
1431+
* EH context.
1432+
*
1433+
* RETURNS:
1434+
* SUCCESS or FAILED or NEEDS_RETRY or ADD_TO_MLQUEUE
1435+
*/
1436+
enum scsi_disposition ata_eh_decide_disposition(struct ata_queued_cmd *qc)
1437+
{
1438+
return scsi_check_sense(qc->scsicmd);
1439+
}
1440+
14041441
/**
14051442
* ata_eh_request_sense - perform REQUEST_SENSE_DATA_EXT
14061443
* @qc: qc to perform REQUEST_SENSE_SENSE_DATA_EXT to
@@ -1627,7 +1664,8 @@ static unsigned int ata_eh_analyze_tf(struct ata_queued_cmd *qc)
16271664
}
16281665

16291666
if (qc->flags & ATA_QCFLAG_SENSE_VALID) {
1630-
enum scsi_disposition ret = scsi_check_sense(qc->scsicmd);
1667+
enum scsi_disposition ret = ata_eh_decide_disposition(qc);
1668+
16311669
/*
16321670
* SUCCESS here means that the sense code could be
16331671
* evaluated and should be passed to the upper layers
@@ -1942,11 +1980,10 @@ static int ata_eh_read_sense_success_non_ncq(struct ata_link *link)
19421980
return -EIO;
19431981

19441982
/*
1945-
* If we have sense data, call scsi_check_sense() in order to set the
1946-
* correct SCSI ML byte (if any). No point in checking the return value,
1947-
* since the command has already completed successfully.
1983+
* No point in checking the return value, since the command has already
1984+
* completed successfully.
19481985
*/
1949-
scsi_check_sense(qc->scsicmd);
1986+
ata_eh_decide_disposition(qc);
19501987

19511988
return 0;
19521989
}

drivers/ata/libata-sata.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,12 +1455,10 @@ int ata_eh_read_sense_success_ncq_log(struct ata_link *link)
14551455
qc->flags |= ATA_QCFLAG_SENSE_VALID;
14561456

14571457
/*
1458-
* If we have sense data, call scsi_check_sense() in order to
1459-
* set the correct SCSI ML byte (if any). No point in checking
1460-
* the return value, since the command has already completed
1461-
* successfully.
1458+
* No point in checking the return value, since the command has
1459+
* already completed successfully.
14621460
*/
1463-
scsi_check_sense(qc->scsicmd);
1461+
ata_eh_decide_disposition(qc);
14641462
}
14651463

14661464
return ret;

drivers/ata/libata.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ extern void ata_eh_finish(struct ata_port *ap);
161161
extern int ata_ering_map(struct ata_ering *ering,
162162
int (*map_fn)(struct ata_ering_entry *, void *),
163163
void *arg);
164+
enum scsi_disposition ata_eh_decide_disposition(struct ata_queued_cmd *qc);
164165
extern unsigned int atapi_eh_tur(struct ata_device *dev, u8 *r_sense_key);
165166
extern unsigned int atapi_eh_request_sense(struct ata_device *dev,
166167
u8 *sense_buf, u8 dfl_sense_key);

0 commit comments

Comments
 (0)