All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Bart Van Assche <bvanassche@acm.org>
Cc: "Martin K . Petersen" <martin.petersen@oracle.com>,
	Jaegeuk Kim <jaegeuk@kernel.org>,
	linux-scsi@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Ming Lei <ming.lei@redhat.com>, Hannes Reinecke <hare@suse.de>,
	John Garry <john.g.garry@oracle.com>,
	Mike Christie <michael.christie@oracle.com>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Vishakha Channapattan <vishakhavc@google.com>,
	Jolly Shah <jollys@google.com>,
	Changyuan Lyu <changyuanl@google.com>
Subject: Re: [PATCH 4/4] scsi: Trace SCSI sense data
Date: Tue, 25 Apr 2023 19:52:53 -0400	[thread overview]
Message-ID: <20230425195253.2f3a45a4@gandalf.local.home> (raw)
In-Reply-To: <20230425233446.1231000-5-bvanassche@acm.org>

On Tue, 25 Apr 2023 16:34:46 -0700
Bart Van Assche <bvanassche@acm.org> wrote:

> If a command fails, SCSI sense data is essential to determine why it
> failed. Hence make the SCSI sense data available in the ftrace output.
> 
> Cc: Christoph Hellwig <hch@lst.de>
> Cc: Ming Lei <ming.lei@redhat.com>
> Cc: Hannes Reinecke <hare@suse.de>
> Cc: John Garry <john.g.garry@oracle.com>
> Cc: Mike Christie <michael.christie@oracle.com>
> Signed-off-by: Bart Van Assche <bvanassche@acm.org>
> ---
>  include/trace/events/scsi.h | 17 +++++++++++++++--
>  1 file changed, 15 insertions(+), 2 deletions(-)
> 
> diff --git a/include/trace/events/scsi.h b/include/trace/events/scsi.h
> index a2c7befd451a..bb5f31504fbb 100644
> --- a/include/trace/events/scsi.h
> +++ b/include/trace/events/scsi.h
> @@ -269,6 +269,7 @@ DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template,
>  		__field( unsigned int,	prot_sglen )
>  		__field( unsigned char,	prot_op )
>  		__dynamic_array(unsigned char,	cmnd, cmd->cmd_len)
> +		__array(unsigned char,  sense_data, SCSI_SENSE_BUFFERSIZE)
>  	),
>  
>  	TP_fast_assign(
> @@ -285,11 +286,13 @@ DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template,
>  		__entry->prot_sglen	= scsi_prot_sg_count(cmd);
>  		__entry->prot_op	= scsi_get_prot_op(cmd);
>  		memcpy(__get_dynamic_array(cmnd), cmd->cmnd, cmd->cmd_len);
> +		memcpy(__entry->sense_data, cmd->sense_buffer,
> +		       SCSI_SENSE_BUFFERSIZE);
>  	),
>  
>  	TP_printk("host_no=%u channel=%u id=%u lun=%u data_sgl=%u prot_sgl=%u " \
>  		  "prot_op=%s driver_tag=%d scheduler_tag=%d cmnd=(%s %s raw=%s) " \
> -		  "result=(driver=%s host=%s message=%s status=%s)",
> +		  "result=(driver=%s host=%s message=%s status=%s%s%s)",
>  		  __entry->host_no, __entry->channel, __entry->id,
>  		  __entry->lun, __entry->data_sglen, __entry->prot_sglen,
>  		  show_prot_op_name(__entry->prot_op), __entry->driver_tag,
> @@ -299,7 +302,17 @@ DECLARE_EVENT_CLASS(scsi_cmd_done_timeout_template,
>  		  "DRIVER_OK",
>  		  show_hostbyte_name(((__entry->result) >> 16) & 0xff),
>  		  "COMMAND_COMPLETE",
> -		  show_statusbyte_name(__entry->result & 0xff))
> +		  show_statusbyte_name(__entry->result & 0xff),
> +		  __entry->result & 0xff ? " sense_data=" : "",
> +		  __entry->result & 0xff ?
> +		  ({
> +			  unsigned int len = SCSI_SENSE_BUFFERSIZE;
> +
> +			  while (len && __entry->sense_data[len - 1] == 0)
> +				  len--;
> +			  __print_hex(__entry->sense_data, len);
> +		  })

The above will absolutely break user space parsing.

The TP_printk() isn't supposed to be too complex, as user space uses it to
figure out how to parse the data.

If you are doing the above, I'm guessing that most of the time the
sense_data doesn't use the 96 bytes (defined by SCSI_SENSE_BUFFERSIZE).

Perhaps instead, you should make result a dynamic array, and save writing
a large amount of zeros into the precious ring buffer?

static int sense_data_size(unsigned char *array)
{
	int len = SCSI_SENSE_BUFFERSIZE;

	for (len && array[len - 1] == 0)
		len--;

	return len;
}

		__dynamic_array(unsigned char, sense_data, result_size(cmd->sense_data)

	[..]


		memcpy(__get_dynamic_array(sense_data), cmd->sense_data, result_size(cmd->sense_data));

// Yes, I need a way to pass the "result_size" from the initialization to
// the allocation.


	[..]


		__print_hex(__get_dynamic_array(sense_data),
			    __get_dynamic_array_len(sense_data))

Or something like that.

-- Steve


> +		  : "")
>  );
>  
>  DEFINE_EVENT(scsi_cmd_done_timeout_template, scsi_dispatch_cmd_done,

  reply	other threads:[~2023-04-25 23:53 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-25 23:34 [PATCH 0/4] SCSI core patches Bart Van Assche
2023-04-25 23:34 ` [PATCH 1/4] scsi: core: Use min() instead of open-coding it Bart Van Assche
2023-04-25 23:34 ` [PATCH 2/4] scsi: core: Update a source code comment Bart Van Assche
2023-04-28  5:38   ` Christoph Hellwig
2023-04-28 16:58     ` Bart Van Assche
2023-04-25 23:34 ` [PATCH 3/4] scsi: Only kick the requeue list if necessary Bart Van Assche
2023-04-26  3:23   ` kernel test robot
2023-04-26  5:16   ` kernel test robot
2023-04-25 23:34 ` [PATCH 4/4] scsi: Trace SCSI sense data Bart Van Assche
2023-04-25 23:52   ` Steven Rostedt [this message]
2023-04-28  8:09   ` Niklas Cassel
2023-04-28 18:36     ` Bart Van Assche
2023-05-02  9:52       ` Niklas Cassel
2023-05-02 20:31         ` Bart Van Assche
2023-05-03  7:16           ` Niklas Cassel

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=20230425195253.2f3a45a4@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=bvanassche@acm.org \
    --cc=changyuanl@google.com \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=jaegeuk@kernel.org \
    --cc=john.g.garry@oracle.com \
    --cc=jollys@google.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mhiramat@kernel.org \
    --cc=michael.christie@oracle.com \
    --cc=ming.lei@redhat.com \
    --cc=vishakhavc@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.