Skip to content

Commit ba0f09b

Browse files
bvanasschemartinkpetersen
authored andcommitted
scsi: core: Improve the code for showing commands in debugfs
Some but not all command information is cleared by scsi_end_request(). As an example, if scsi_show_rq() is called after a SCSI command has been allocated and before SCMD_INITIALIZED is set, .cmnd holds the CDB of a previous command. Showing that information in debugfs is confusing. Hence this patch that restricts the information shown in debugfs to valid information. Signed-off-by: Bart Van Assche <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 9972c02 commit ba0f09b

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/scsi/scsi_debugfs.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,20 @@ void scsi_show_rq(struct seq_file *m, struct request *rq)
5656
struct scsi_cmnd *cmd = blk_mq_rq_to_pdu(rq);
5757
int alloc_ms = jiffies_to_msecs(jiffies - cmd->jiffies_at_alloc);
5858
int timeout_ms = jiffies_to_msecs(rq->timeout);
59-
const char *list_info = scsi_cmd_list_info(cmd);
6059
char buf[80] = "(?)";
6160

62-
__scsi_format_command(buf, sizeof(buf), cmd->cmnd, cmd->cmd_len);
63-
seq_printf(m, ", .cmd=%s, .retries=%d, .allowed=%d, .result = %#x, %s%s.flags=",
64-
buf, cmd->retries, cmd->allowed, cmd->result,
65-
list_info ? : "", list_info ? ", " : "");
61+
if (cmd->flags & SCMD_INITIALIZED) {
62+
const char *list_info = scsi_cmd_list_info(cmd);
63+
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=");
6673
scsi_flags_show(m, cmd->flags, scsi_cmd_flags,
6774
ARRAY_SIZE(scsi_cmd_flags));
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);
7175
}

0 commit comments

Comments
 (0)