Show the SCSI CDB, .eh_eflags and .result for pending SCSI commands in /sys/kernel/debug/block/*/mq/*/dispatch and */rq_list. Signed-off-by: Bart Van Assche <bart.vanassche@xxxxxxxxxxx> Cc: Martin K. Petersen <martin.petersen@xxxxxxxxxx> Cc: James Bottomley <James.Bottomley@xxxxxxxxxxxxxxxxxxxxx> Cc: Omar Sandoval <osandov@xxxxxx> Cc: Hannes Reinecke <hare@xxxxxxxx> Cc: <linux-scsi@xxxxxxxxxxxxxxx> --- drivers/scsi/scsi_lib.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index 7bc4513bf4e4..7d3efb8924ee 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -2126,6 +2126,32 @@ static void scsi_exit_rq(struct request_queue *q, struct request *rq) scsi_free_sense_buffer(shost, cmd->sense_buffer); } +static const char *const ehflag_name[] = { + [ilog2(SCSI_EH_CANCEL_CMD)] = "CANCEL_CMD", + [ilog2(SCSI_EH_ABORT_SCHEDULED)] = "ABORT_SCHEDULED", +}; + +static void scsi_show_rq(struct request *rq, char *info, unsigned int info_sz) +{ + char *p = info, *const end = info + info_sz; + struct scsi_cmnd *cmd = container_of(scsi_req(rq), typeof(*cmd), req); + unsigned int i; + + p += scnprintf(p, end - p, ".cmd ="); + for (i = 0; i < cmd->cmd_len; i++) + p += scnprintf(p, end - p, " %02x", cmd->cmnd[i]); + p += scnprintf(p, end - p, ", .eh_eflags ="); + for (i = 0; i < sizeof(cmd->eh_eflags) * BITS_PER_BYTE; i++) { + if (!(cmd->eh_eflags & BIT(i))) + continue; + if (i < ARRAY_SIZE(ehflag_name) && ehflag_name[i]) + p += scnprintf(p, end - p, " %s", ehflag_name[i]); + else + p += scnprintf(p, end - p, " %d", i); + } + p += scnprintf(p, end - p, ", .result = %#06x", cmd->result); +} + struct request_queue *scsi_alloc_queue(struct scsi_device *sdev) { struct Scsi_Host *shost = sdev->host; @@ -2158,6 +2184,7 @@ static const struct blk_mq_ops scsi_mq_ops = { .queue_rq = scsi_queue_rq, .complete = scsi_softirq_done, .timeout = scsi_timeout, + .show_rq = scsi_show_rq, .init_request = scsi_init_request, .exit_request = scsi_exit_request, .map_queues = scsi_map_queues, -- 2.12.0