From: Yoshihiro YUNOMAE <yoshihiro.yunomae.ez@hitachi.com>
To: Hannes Reinecke <hare@suse.de>
Cc: Christoph Hellwig <hch@infradead.org>,
James Bottomley <jbottomley@parallels.com>,
Ewan Milne <emilne@redhat.com>,
linux-scsi@vger.kernel.org
Subject: Re: [PATCH 14/20] scsi: use local buffer for printing CDB
Date: Fri, 05 Sep 2014 11:02:35 +0900 [thread overview]
Message-ID: <540919BB.3070104@hitachi.com> (raw)
In-Reply-To: <1409738775-80876-15-git-send-email-hare@suse.de>
(2014/09/03 19:06), Hannes Reinecke wrote:
> The CDB needs to be printed in one line (ie with one printk
> statement) to avoid the individual bytes to be broken up
> under high load.
> As using individual printk() statements here would lead to
> unnecessary complicated code and needs the stack space to
> hold the format string we should be using a local buffer
> here. If the CDB is longer than the provided buffer
> it will be printed in several lines.
>
> Signed-off-by: Hannes Reinecke <hare@suse.de>
> ---
> drivers/scsi/ch.c | 5 +--
> drivers/scsi/constants.c | 82 ++++++++++++++++++++++++++++++++----------------
> drivers/scsi/sr_ioctl.c | 9 ++++--
> include/scsi/scsi_dbg.h | 2 +-
> 4 files changed, 65 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/scsi/ch.c b/drivers/scsi/ch.c
> index eea94a9..f0df02e 100644
> --- a/drivers/scsi/ch.c
> +++ b/drivers/scsi/ch.c
> @@ -189,6 +189,7 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
> {
> int errno, retries = 0, timeout, result;
> struct scsi_sense_hdr sshdr;
> + char buf[80];
This patch introduces some magic numbers like here,
but we had better define those.
Thanks,
Yoshihiro YUNOMAE
> timeout = (cmd[0] == INITIALIZE_ELEMENT_STATUS)
> ? timeout_init : timeout_move;
> @@ -196,8 +197,8 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd,
> retry:
> errno = 0;
> if (debug) {
> - DPRINTK("command: ");
> - __scsi_print_command(cmd);
> + __scsi_print_command(cmd, buf, 80);
> + DPRINTK("command: %s", buf);
> }
>
> result = scsi_execute_req(ch->device, cmd, direction, buffer,
> diff --git a/drivers/scsi/constants.c b/drivers/scsi/constants.c
> index 6076969..5486816 100644
> --- a/drivers/scsi/constants.c
> +++ b/drivers/scsi/constants.c
> @@ -322,19 +322,20 @@ static bool scsi_opcode_sa_name(int cmd, int service_action,
> return true;
> }
>
> -/* attempt to guess cdb length if cdb_len==0 . No trailing linefeed. */
> -static void print_opcode_name(unsigned char * cdbp, int cdb_len)
> +/* attempt to guess cdb length if cdb_len==0 */
> +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 = 0;
> const char *cdb_name = NULL, *sa_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;
> + return scnprintf(buf, buf_len,
> + "short variable length command, "
> + "len=%d ext_len=%d", len, cdb_len);
> }
> sa = (cdbp[8] << 8) + cdbp[9];
> } else {
> @@ -344,54 +345,81 @@ static void print_opcode_name(unsigned char * cdbp, int cdb_len)
>
> if (!scsi_opcode_sa_name(cdb0, sa, &cdb_name, &sa_name)) {
> if (cdb_name)
> - printk("%s", cdb_name);
> + off = scnprintf(buf, buf_len, "%s", cdb_name);
> else if (cdb0 > 0xc0)
> - printk("cdb[0]=0x%x (vendor)", cdb0);
> + off = scnprintf(buf, buf_len,
> + "cdb[0]=0x%x (vendor)", cdb0);
> else if (cdb0 > 0x60 && cdb0 < 0x7e)
> - printk("cdb[0]=0x%x (reserved)", cdb0);
> + off = scnprintf(buf, buf_len,
> + "cdb[0]=0x%x (reserved)", cdb0);
> else
> - printk("cdb[0]=0x%x", cdb0);
> + off = scnprintf(buf, buf_len, "cdb[0]=0x%x", cdb0);
> } else {
> if (sa_name)
> - printk("%s", sa_name);
> + off = scnprintf(buf, buf_len, "%s", sa_name);
> else if (cdb_name)
> - printk("%s, sa=0x%x", cdb_name, sa);
> + off = scnprintf(buf, buf_len,
> + "%s, sa=0x%x", cdb_name, sa);
> 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;
> }
>
> -void __scsi_print_command(unsigned char *cdb)
> +void __scsi_print_command(unsigned char *cdb, char *buf, int buf_len)
> {
> - int k, len;
> + int len, off;
>
> - print_opcode_name(cdb, 0);
> + off = print_opcode_name(cdb, 0, buf, buf_len);
> len = scsi_command_size(cdb);
> + /* Variable length CDBs are not supported */
> + if (len > 16)
> + return;
> /* print out all bytes in cdb */
> - for (k = 0; k < len; ++k)
> - printk(" %02x", cdb[k]);
> - printk("\n");
> + hex_dump_to_buffer(cdb, len, 16, 1,
> + buf, buf_len - off, false);
> }
> EXPORT_SYMBOL(__scsi_print_command);
>
> void scsi_print_command(struct scsi_cmnd *cmd)
> {
> - int k;
> + int k, off = 0;
> + /* 16 bytes + space take up 48 bytes */
> + char buf[48];
> + int buf_len = 48, linelen;
>
> 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, buf_len);
>
> /* print out all bytes in cdb */
> - printk(":");
> - for (k = 0; k < cmd->cmd_len; ++k)
> - printk(" %02x", cmd->cmnd[k]);
> - printk("\n");
> + if (buf_len - off > cmd->cmd_len * 3 + 2) {
> + /* If we have enough space print CDB in one line */
> + off += scnprintf(buf + off, buf_len - off, ": ");
> + hex_dump_to_buffer(cmd->cmnd, cmd->cmd_len, 16, 1,
> + buf, buf_len - off, false);
> + scmd_printk(KERN_INFO, cmd, "CDB: %s\n", buf);
> + } else {
> + /*
> + * Otherwise print opcode in one line and use
> + * separate lines for the CDB
> + */
> + scmd_printk(KERN_INFO, cmd, "CDB: %s\n", buf);
> + for (k = 0; k < cmd->cmd_len; k += 16) {
> + linelen = min(cmd->cmd_len - k, 16);
> + hex_dump_to_buffer(cmd->cmnd, linelen, 16, 1,
> + buf, sizeof(buf), false);
> + scmd_printk(KERN_INFO, cmd, "CDB[%0x2]: %s\n",
> + k / 16, buf);
> + }
> + }
> }
> EXPORT_SYMBOL(scsi_print_command);
>
> diff --git a/drivers/scsi/sr_ioctl.c b/drivers/scsi/sr_ioctl.c
> index 17e0c2b..8090571 100644
> --- a/drivers/scsi/sr_ioctl.c
> +++ b/drivers/scsi/sr_ioctl.c
> @@ -188,6 +188,7 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
> struct scsi_sense_hdr sshdr;
> int result, err = 0, retries = 0;
> struct request_sense *sense = cgc->sense;
> + char buf[80];
>
> SDev = cd->device;
>
> @@ -257,14 +258,16 @@ int sr_do_ioctl(Scsi_CD *cd, struct packet_command *cgc)
> /* sense: Invalid command operation code */
> err = -EDRIVE_CANT_DO_THIS;
> #ifdef DEBUG
> - __scsi_print_command(cgc->cmd);
> + __scsi_print_command(cgc->cmd, buf, 80);
> + sr_printk(KERN_ERR, cd,
> + "CDROM (ioctl) invalid command %s\n", buf);
> scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
> #endif
> break;
> default:
> + __scsi_print_command(cgc->cmd, buf, 80);
> sr_printk(KERN_ERR, cd,
> - "CDROM (ioctl) error, command: ");
> - __scsi_print_command(cgc->cmd);
> + "CDROM (ioctl) error, command: %s\n", buf);
> scsi_print_sense_hdr(cd->device, cd->cdi.name, &sshdr);
> err = -EIO;
> }
> diff --git a/include/scsi/scsi_dbg.h b/include/scsi/scsi_dbg.h
> index 44bea15..5020e5e 100644
> --- a/include/scsi/scsi_dbg.h
> +++ b/include/scsi/scsi_dbg.h
> @@ -6,7 +6,7 @@ struct scsi_device;
> struct scsi_sense_hdr;
>
> extern void scsi_print_command(struct scsi_cmnd *);
> -extern void __scsi_print_command(unsigned char *);
> +extern void __scsi_print_command(unsigned char *, char *, int);
> extern void scsi_show_extd_sense(struct scsi_device *, const char *,
> unsigned char, unsigned char);
> extern void scsi_show_sense_hdr(struct scsi_device *, const char *,
>
--
Yoshihiro YUNOMAE
Software Platform Research Dept. Linux Technology Center
Hitachi, Ltd., Yokohama Research Laboratory
E-mail: yoshihiro.yunomae.ez@hitachi.com
next prev parent reply other threads:[~2014-09-05 2:02 UTC|newest]
Thread overview: 49+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-03 10:05 [PATCHv2 00/20] scsi logging update Hannes Reinecke
2014-09-03 10:05 ` [PATCH 01/20] Remove scsi_cmd_print_sense_hdr() Hannes Reinecke
2014-09-03 10:05 ` [PATCH 02/20] aha152x: Debug output update and whitespace cleanup Hannes Reinecke
2014-09-06 0:02 ` Christoph Hellwig
2014-09-03 10:05 ` [PATCH 03/20] sd: Remove scsi_print_sense() in sd_done() Hannes Reinecke
2014-09-03 10:05 ` [PATCH 04/20] scsi: introduce sdev_prefix_printk() Hannes Reinecke
2014-09-06 0:03 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 05/20] scsi: Use sdev as argument for sense code printing Hannes Reinecke
2014-09-03 10:06 ` [PATCH 06/20] scsi: stop decoding if scsi_normalize_sense() fails Hannes Reinecke
2014-09-06 0:04 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 07/20] scsi: do not decode sense extras Hannes Reinecke
2014-09-06 0:04 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 08/20] scsi: use 'bool' as return value for scsi_normalize_sense() Hannes Reinecke
2014-09-05 0:51 ` Yoshihiro YUNOMAE
2014-09-05 6:07 ` Hannes Reinecke
2014-09-06 0:09 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 09/20] scsi: remove scsi_print_status() Hannes Reinecke
2014-09-06 0:10 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 10/20] Implement scsi_opcode_sa_name Hannes Reinecke
2014-09-03 10:06 ` [PATCH 11/20] scsi: Use scsi_print_command() where possible Hannes Reinecke
2014-09-06 0:11 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 12/20] scsi: merge print_opcode_name() Hannes Reinecke
2014-09-05 1:24 ` Yoshihiro YUNOMAE
2014-09-06 0:12 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 13/20] scsi: consolidate opcode lookup in scsi_opcode_sa_name() Hannes Reinecke
2014-09-06 0:46 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 14/20] scsi: use local buffer for printing CDB Hannes Reinecke
2014-09-05 2:02 ` Yoshihiro YUNOMAE [this message]
2014-09-07 16:10 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 15/20] libata: use __scsi_print_command() Hannes Reinecke
2014-09-03 10:06 ` [PATCH 16/20] scsi: separate out scsi_retval_string() Hannes Reinecke
2014-09-05 2:04 ` Yoshihiro YUNOMAE
2014-09-05 6:14 ` Hannes Reinecke
2014-09-07 16:11 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 17/20] scsi: separate out scsi_host_hostbyte() and scsi_show_driverbyte() Hannes Reinecke
2014-09-05 4:19 ` Yoshihiro YUNOMAE
2014-09-07 16:12 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 18/20] scsi: remove scsi_show_result() Hannes Reinecke
2014-09-05 4:22 ` Yoshihiro YUNOMAE
2014-09-07 16:17 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 19/20] sd: Reduce logging output Hannes Reinecke
2014-09-07 16:17 ` Christoph Hellwig
2014-09-03 10:06 ` [PATCH 20/20] scsi_error: format abort error message Hannes Reinecke
2014-09-05 4:23 ` Yoshihiro YUNOMAE
2014-09-06 0:33 ` Christoph Hellwig
2014-09-13 1:07 ` Elliott, Robert (Server Storage)
2014-09-14 10:49 ` Hannes Reinecke
2014-09-14 16:40 ` Christoph Hellwig
2014-09-06 0:51 ` [PATCHv2 00/20] scsi logging update Christoph Hellwig
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=540919BB.3070104@hitachi.com \
--to=yoshihiro.yunomae.ez@hitachi.com \
--cc=emilne@redhat.com \
--cc=hare@suse.de \
--cc=hch@infradead.org \
--cc=jbottomley@parallels.com \
--cc=linux-scsi@vger.kernel.org \
/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