|
1 | 1 | // SPDX-License-Identifier: GPL-2.0 |
2 | 2 | #include <linux/bitops.h> |
| 3 | +#include <linux/cleanup.h> |
3 | 4 | #include <linux/seq_file.h> |
4 | 5 | #include <scsi/scsi_cmnd.h> |
5 | 6 | #include <scsi/scsi_dbg.h> |
@@ -32,38 +33,43 @@ static int scsi_flags_show(struct seq_file *m, const unsigned long flags, |
32 | 33 | return 0; |
33 | 34 | } |
34 | 35 |
|
35 | | -void scsi_show_rq(struct seq_file *m, struct request *rq) |
| 36 | +static const char *scsi_cmd_list_info(struct scsi_cmnd *cmd) |
36 | 37 | { |
37 | | - struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq), *cmd2; |
38 | 38 | struct Scsi_Host *shost = cmd->device->host; |
| 39 | + struct scsi_cmnd *cmd2; |
| 40 | + |
| 41 | + guard(spinlock_irq)(shost->host_lock); |
| 42 | + |
| 43 | + list_for_each_entry(cmd2, &shost->eh_abort_list, eh_entry) |
| 44 | + if (cmd == cmd2) |
| 45 | + return "on eh_abort_list"; |
| 46 | + |
| 47 | + list_for_each_entry(cmd2, &shost->eh_cmd_q, eh_entry) |
| 48 | + if (cmd == cmd2) |
| 49 | + return "on eh_cmd_q"; |
| 50 | + |
| 51 | + return NULL; |
| 52 | +} |
| 53 | + |
| 54 | +void scsi_show_rq(struct seq_file *m, struct request *rq) |
| 55 | +{ |
| 56 | + struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq); |
39 | 57 | int alloc_ms = jiffies_to_msecs(jiffies - cmd->jiffies_at_alloc); |
40 | 58 | int timeout_ms = jiffies_to_msecs(rq->timeout); |
41 | | - const char *list_info = NULL; |
42 | 59 | char buf[80] = "(?)"; |
43 | 60 |
|
44 | | - spin_lock_irq(shost->host_lock); |
45 | | - list_for_each_entry(cmd2, &shost->eh_abort_list, eh_entry) { |
46 | | - if (cmd == cmd2) { |
47 | | - list_info = "on eh_abort_list"; |
48 | | - goto unlock; |
49 | | - } |
50 | | - } |
51 | | - list_for_each_entry(cmd2, &shost->eh_cmd_q, eh_entry) { |
52 | | - if (cmd == cmd2) { |
53 | | - list_info = "on eh_cmd_q"; |
54 | | - goto unlock; |
55 | | - } |
56 | | - } |
57 | | -unlock: |
58 | | - spin_unlock_irq(shost->host_lock); |
| 61 | + if (cmd->flags & SCMD_INITIALIZED) { |
| 62 | + const char *list_info = scsi_cmd_list_info(cmd); |
59 | 63 |
|
60 | | - __scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len); |
61 | | - seq_printf(m, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x, %s%s.flags=", |
62 | | - buf, cmd->retries, cmd->allowed, cmd->result, |
63 | | - list_info ? : "", list_info ? ", " : ""); |
| 64 | + __scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len); |
| 65 | + seq_printf(m, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x%s%s", |
| 66 | + buf, cmd->retries, cmd->allowed, cmd->result, |
| 67 | + list_info ? ", " : "", list_info ? : ""); |
| 68 | + seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago", |
| 69 | + timeout_ms / 1000, timeout_ms % 1000, |
| 70 | + alloc_ms / 1000, alloc_ms % 1000); |
| 71 | + } |
| 72 | + seq_printf(m, ", .flags="); |
64 | 73 | scsi_flags_show(m, cmd->flags, scsi_cmd_flags, |
65 | 74 | ARRAY_SIZE(scsi_cmd_flags)); |
66 | | - seq_printf(m, ", .timeout=%d.%03d, allocated %d.%03d s ago", |
67 | | - timeout_ms / 1000, timeout_ms % 1000, |
68 | | - alloc_ms / 1000, alloc_ms % 1000); |
69 | 75 | } |
0 commit comments