From: Hannes Reinecke <hare@suse.de>
To: James Bottomley <jbottomley@parallels.com>
Cc: Ewan Milne <emilne@redhat.com>,
Christoph Hellwig <hch@infradead.org>,
linux-scsi@vger.kernel.org, Robert Elliot <elliot@hp.com>,
Yoshihiro Yunomae <yoshihiro.ynomae.ez@hitachi.com>,
Hannes Reinecke <hare@suse.de>
Subject: [PATCH 13/22] scsi: use local buffer for printing the opcode
Date: Thu, 28 Aug 2014 19:33:27 +0200 [thread overview]
Message-ID: <1409247216-76074-14-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1409247216-76074-1-git-send-email-hare@suse.de>
SCSI opcode printing is tricky and needs to take into account
several different corner cases. So instead of trying to come
up with an elaborate printk() statement we should be printing
it into a local buffer.
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/scsi/constants.c | 72 ++++++++++++++++++++++++++++++------------------
1 file changed, 45 insertions(+), 27 deletions(-)
diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
index 813c482..e9c099d 100644
--- a/drivers/scsi/constants.c
+++ b/drivers/scsi/constants.c
@@ -295,18 +295,20 @@ static int scsi_opcode_sa_name(int cmd, int service_action,
}
/* attempt to guess cdb length if cdb_len==0 . No trailing linefeed. */
-static void print_opcode_name(unsigned char * cdbp, int cdb_len)
+static int print_opcode_name(unsigned char * cdbp, int cdb_len,
+ char *buf, int buf_len)
{
- int sa, len, cdb0;
- const char * name;
+ int sa, len, cdb0, off;
+ const char * name = NULL;
cdb0 = cdbp[0];
if (cdb0 == VARIABLE_LENGTH_CMD) {
len = scsi_varlen_cdb_length(cdbp);
if (len < 10) {
- printk("short variable length command, "
- "len=%d ext_len=%d", len, cdb_len);
- return;
+ off = scnprintf(buf, buf_len,
+ "short variable length command, "
+ "len=%d ext_len=%d", len, cdb_len);
+ return off;
}
sa = (cdbp[8] << 8) + cdbp[9];
} else {
@@ -318,41 +320,51 @@ static void print_opcode_name(unsigned char * cdbp, int cdb_len)
if (cdb0 < 0xc0) {
name = cdb_byte0_names[cdb0];
if (name)
- printk("%s", name);
+ off = scnprintf(buf, buf_len, "%s", name);
else
- printk("cdb[0]=0x%x (reserved)", cdb0);
+ off = scnprintf(buf, buf_len,
+ "cdb[0]=0x%x (reserved)", cdb0);
} else
- printk("cdb[0]=0x%x (vendor)", cdb0);
+ off = scnprintf(buf, buf_len,
+ "cdb[0]=0x%x (vendor)", cdb0);
} else {
if (name)
- printk("%s", name);
+ off = scnprintf(buf, buf_len, "%s", name);
else
- printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
+ off = scnprintf(buf, buf_len,
+ "cdb[0]=0x%x, sa=0x%x", cdb0, sa);
if ((cdb_len > 0) && (len != cdb_len))
- printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len);
+ off += scnprintf(buf + off, buf_len - off,
+ ", in_cdb_len=%d, ext_len=%d",
+ len, cdb_len);
}
+ return off;
}
#else /* ifndef CONFIG_SCSI_CONSTANTS */
-static void print_opcode_name(unsigned char * cdbp, int cdb_len)
+static int print_opcode_name(unsigned char * cdbp, int cdb_len,
+ char *buf, int buf_len)
{
- int sa, len, cdb0;
+ int sa, len, cdb0, off;
cdb0 = cdbp[0];
switch(cdb0) {
case VARIABLE_LENGTH_CMD:
len = scsi_varlen_cdb_length(cdbp);
if (len < 10) {
- printk("short opcode=0x%x command, len=%d "
- "ext_len=%d", cdb0, len, cdb_len);
+ off = scnprintf(buf, buf_len,
+ "short opcode=0x%x command, len=%d "
+ "ext_len=%d", cdb0, len, cdb_len);
break;
}
sa = (cdbp[8] << 8) + cdbp[9];
- printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
+ off = scnprintf(buf, buf_len, "cdb[0]=0x%x, sa=0x%x", cdb0, sa);
if (len != cdb_len)
- printk(", in_cdb_len=%d, ext_len=%d", len, cdb_len);
+ off += scnprintf(buf + off, buflen - off,
+ ", in_cdb_len=%d, ext_len=%d",
+ len, cdb_len);
break;
case MAINTENANCE_IN:
case MAINTENANCE_OUT:
@@ -366,23 +378,29 @@ static void print_opcode_name(unsigned char * cdbp, int cdb_len)
case THIRD_PARTY_COPY_IN:
case THIRD_PARTY_COPY_OUT:
sa = cdbp[1] & 0x1f;
- printk("cdb[0]=0x%x, sa=0x%x", cdb0, sa);
+ off = scnprintf(buf + off, buflen - off,
+ "cdb[0]=0x%x, sa=0x%x", cdb0, sa);
break;
default:
if (cdb0 < 0xc0)
- printk("cdb[0]=0x%x", cdb0);
+ off = scnprintf(buf + off, buf_len - off,
+ "cdb[0]=0x%x", cdb0);
else
- printk("cdb[0]=0x%x (vendor)", cdb0);
+ off = scnprintf(buf + off, buf_len - off,
+ "cdb[0]=0x%x (vendor)", cdb0);
break;
}
+ return off;
}
#endif
void __scsi_print_command(unsigned char *cdb)
{
- int k, len;
+ char buf[80];
+ int k, len, off = 0;
- print_opcode_name(cdb, 0);
+ off = print_opcode_name(cdb, 0, buf, 80);
+ printk("%s", buf);
len = scsi_command_size(cdb);
/* print out all bytes in cdb */
for (k = 0; k < len; ++k)
@@ -393,16 +411,16 @@ EXPORT_SYMBOL(__scsi_print_command);
void scsi_print_command(struct scsi_cmnd *cmd)
{
- int k;
+ char buf[80];
+ int k, off = 0;
if (cmd->cmnd == NULL)
return;
- scmd_printk(KERN_INFO, cmd, "CDB: ");
- print_opcode_name(cmd->cmnd, cmd->cmd_len);
+ off = print_opcode_name(cmd->cmnd, cmd->cmd_len, buf, 80);
+ scmd_printk(KERN_INFO, cmd, "CDB: %s:", buf);
/* print out all bytes in cdb */
- printk(":");
for (k = 0; k < cmd->cmd_len; ++k)
printk(" %02x", cmd->cmnd[k]);
printk("\n");
--
1.8.5.2
next prev parent reply other threads:[~2014-08-28 17:33 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-28 17:33 [PATCH 00/22] scsi logging update Hannes Reinecke
2014-08-28 17:33 ` [PATCH 01/22] Remove scsi_cmd_print_sense_hdr() Hannes Reinecke
2014-08-31 21:39 ` Christoph Hellwig
2014-08-28 17:33 ` [PATCH 02/22] aha152x: Remove #ifdef 0 section Hannes Reinecke
2014-08-31 21:40 ` Christoph Hellwig
2014-08-28 17:33 ` [PATCH 03/22] sd: Remove scsi_print_sense() in sd_done() Hannes Reinecke
2014-08-31 21:40 ` Christoph Hellwig
2014-08-28 17:33 ` [PATCH 04/22] scsi: introduce sdev_prefix_printk() Hannes Reinecke
2014-08-31 21:43 ` Christoph Hellwig
2014-09-01 7:54 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 05/22] scsi: Use sdev as argument for sense code printing Hannes Reinecke
2014-08-31 21:55 ` Christoph Hellwig
2014-09-01 8:00 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 06/22] scsi: stop decoding if scsi_normalize_sense() fails Hannes Reinecke
2014-08-31 22:00 ` Christoph Hellwig
2014-09-01 8:06 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 07/22] scsi: do not decode sense extras Hannes Reinecke
2014-08-31 22:06 ` Christoph Hellwig
2014-09-01 8:10 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 08/22] scsi: dump sense buffer only for debugging Hannes Reinecke
2014-08-31 22:09 ` Christoph Hellwig
2014-09-01 8:26 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 09/22] Use sdev as argument for scsi_print_result Hannes Reinecke
2014-08-31 22:11 ` Christoph Hellwig
2014-09-01 8:43 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 10/22] scsi: consolidate scsi_print_status() Hannes Reinecke
2014-08-31 22:14 ` Christoph Hellwig
2014-09-01 8:46 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 11/22] Implement scsi_opcode_sa_name Hannes Reinecke
2014-08-28 23:50 ` Douglas Gilbert
2014-08-31 22:16 ` Christoph Hellwig
2014-08-28 17:33 ` [PATCH 12/22] scsi: remove obsolete __scsi_print_command() usages Hannes Reinecke
2014-08-31 22:18 ` Christoph Hellwig
2014-09-01 6:56 ` Hannes Reinecke
2014-08-28 17:33 ` Hannes Reinecke [this message]
2014-08-31 22:19 ` [PATCH 13/22] scsi: use local buffer for printing the opcode Christoph Hellwig
2014-09-01 8:57 ` Hannes Reinecke
2014-09-01 14:42 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 14/22] scsi: pass in string buffer to __scsi_print_command() Hannes Reinecke
2014-08-28 17:33 ` [PATCH 15/22] scsi: use dev_printk() variants in scsi_print_command() Hannes Reinecke
2014-08-28 17:33 ` [PATCH 16/22] libata: use __scsi_print_command() Hannes Reinecke
2014-08-28 17:33 ` [PATCH 17/22] scsi: print disposition in scsi_print_result() Hannes Reinecke
2014-08-31 22:23 ` Christoph Hellwig
2014-08-28 17:33 ` [PATCH 18/22] scsi_error: format abort error message Hannes Reinecke
2014-08-31 22:25 ` Christoph Hellwig
2014-08-28 17:33 ` [PATCH 19/22] scsi: use local buffer for scsi_log_(send|completion) Hannes Reinecke
2014-08-28 17:33 ` [PATCH 20/22] scsi: align logging messages Hannes Reinecke
2014-08-31 22:25 ` Christoph Hellwig
2014-09-01 1:00 ` Elliott, Robert (Server Storage)
2014-09-06 0:34 ` Christoph Hellwig
2014-09-18 23:58 ` Elliott, Robert (Server Storage)
2014-09-19 6:26 ` Hannes Reinecke
2014-09-19 11:35 ` Christoph Hellwig
2014-09-19 11:56 ` Hannes Reinecke
2014-08-28 17:33 ` [PATCH 21/22] scsi: reduce messages for command failure Hannes Reinecke
2014-08-31 22:28 ` Christoph Hellwig
2014-09-01 1:14 ` Elliott, Robert (Server Storage)
2014-09-06 0:35 ` Christoph Hellwig
2014-08-28 17:33 ` [PATCH 22/22] sd: Reduce logging output Hannes Reinecke
2014-08-31 22:29 ` Christoph Hellwig
2014-09-03 7:58 ` Hannes Reinecke
2014-08-28 19:24 ` [PATCH 00/22] scsi logging update Douglas Gilbert
2014-08-29 9:48 ` Hannes Reinecke
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1409247216-76074-14-git-send-email-hare@suse.de \
--to=hare@suse.de \
--cc=elliot@hp.com \
--cc=emilne@redhat.com \
--cc=hch@infradead.org \
--cc=jbottomley@parallels.com \
--cc=linux-scsi@vger.kernel.org \
--cc=yoshihiro.ynomae.ez@hitachi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox