Commit 7010645b authored by Roman Bolshakov's avatar Roman Bolshakov Committed by Martin K. Petersen

scsi: target: core: Add CONTROL field for trace events

trace-cmd report doesn't show events from target subsystem because
scsi_command_size() leaks through event format string:

  [target:target_sequencer_start] function scsi_command_size not defined
  [target:target_cmd_complete] function scsi_command_size not defined

Addition of scsi_command_size() to plugin_scsi.c in trace-cmd doesn't
help because an expression is used inside TP_printk(). trace-cmd event
parser doesn't understand minus sign inside [ ]:

  Error: expected ']' but read '-'

Rather than duplicating kernel code in plugin_scsi.c, provide a dedicated
field for CONTROL byte.

Link: https://lore.kernel.org/r/20200929125957.83069-1-r.bolshakov@yadro.comReviewed-by: default avatarMike Christie <michael.christie@oracle.com>
Signed-off-by: default avatarRoman Bolshakov <r.bolshakov@yadro.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 718c2fe9
...@@ -25,6 +25,13 @@ scsi_command_size(const unsigned char *cmnd) ...@@ -25,6 +25,13 @@ scsi_command_size(const unsigned char *cmnd)
scsi_varlen_cdb_length(cmnd) : COMMAND_SIZE(cmnd[0]); scsi_varlen_cdb_length(cmnd) : COMMAND_SIZE(cmnd[0]);
} }
static inline unsigned char
scsi_command_control(const unsigned char *cmnd)
{
return (cmnd[0] == VARIABLE_LENGTH_CMD) ?
cmnd[1] : cmnd[COMMAND_SIZE(cmnd[0]) - 1];
}
/* Returns a human-readable name for the device */ /* Returns a human-readable name for the device */
extern const char *scsi_device_type(unsigned type); extern const char *scsi_device_type(unsigned type);
......
...@@ -141,6 +141,7 @@ TRACE_EVENT(target_sequencer_start, ...@@ -141,6 +141,7 @@ TRACE_EVENT(target_sequencer_start,
__field( unsigned int, opcode ) __field( unsigned int, opcode )
__field( unsigned int, data_length ) __field( unsigned int, data_length )
__field( unsigned int, task_attribute ) __field( unsigned int, task_attribute )
__field( unsigned char, control )
__array( unsigned char, cdb, TCM_MAX_COMMAND_SIZE ) __array( unsigned char, cdb, TCM_MAX_COMMAND_SIZE )
__string( initiator, cmd->se_sess->se_node_acl->initiatorname ) __string( initiator, cmd->se_sess->se_node_acl->initiatorname )
), ),
...@@ -151,6 +152,7 @@ TRACE_EVENT(target_sequencer_start, ...@@ -151,6 +152,7 @@ TRACE_EVENT(target_sequencer_start,
__entry->opcode = cmd->t_task_cdb[0]; __entry->opcode = cmd->t_task_cdb[0];
__entry->data_length = cmd->data_length; __entry->data_length = cmd->data_length;
__entry->task_attribute = cmd->sam_task_attr; __entry->task_attribute = cmd->sam_task_attr;
__entry->control = scsi_command_control(cmd->t_task_cdb);
memcpy(__entry->cdb, cmd->t_task_cdb, TCM_MAX_COMMAND_SIZE); memcpy(__entry->cdb, cmd->t_task_cdb, TCM_MAX_COMMAND_SIZE);
__assign_str(initiator, cmd->se_sess->se_node_acl->initiatorname); __assign_str(initiator, cmd->se_sess->se_node_acl->initiatorname);
), ),
...@@ -160,9 +162,7 @@ TRACE_EVENT(target_sequencer_start, ...@@ -160,9 +162,7 @@ TRACE_EVENT(target_sequencer_start,
__entry->tag, show_opcode_name(__entry->opcode), __entry->tag, show_opcode_name(__entry->opcode),
__entry->data_length, __print_hex(__entry->cdb, 16), __entry->data_length, __print_hex(__entry->cdb, 16),
show_task_attribute_name(__entry->task_attribute), show_task_attribute_name(__entry->task_attribute),
scsi_command_size(__entry->cdb) <= 16 ? __entry->control
__entry->cdb[scsi_command_size(__entry->cdb) - 1] :
__entry->cdb[1]
) )
); );
...@@ -178,6 +178,7 @@ TRACE_EVENT(target_cmd_complete, ...@@ -178,6 +178,7 @@ TRACE_EVENT(target_cmd_complete,
__field( unsigned int, opcode ) __field( unsigned int, opcode )
__field( unsigned int, data_length ) __field( unsigned int, data_length )
__field( unsigned int, task_attribute ) __field( unsigned int, task_attribute )
__field( unsigned char, control )
__field( unsigned char, scsi_status ) __field( unsigned char, scsi_status )
__field( unsigned char, sense_length ) __field( unsigned char, sense_length )
__array( unsigned char, cdb, TCM_MAX_COMMAND_SIZE ) __array( unsigned char, cdb, TCM_MAX_COMMAND_SIZE )
...@@ -191,6 +192,7 @@ TRACE_EVENT(target_cmd_complete, ...@@ -191,6 +192,7 @@ TRACE_EVENT(target_cmd_complete,
__entry->opcode = cmd->t_task_cdb[0]; __entry->opcode = cmd->t_task_cdb[0];
__entry->data_length = cmd->data_length; __entry->data_length = cmd->data_length;
__entry->task_attribute = cmd->sam_task_attr; __entry->task_attribute = cmd->sam_task_attr;
__entry->control = scsi_command_control(cmd->t_task_cdb);
__entry->scsi_status = cmd->scsi_status; __entry->scsi_status = cmd->scsi_status;
__entry->sense_length = cmd->scsi_status == SAM_STAT_CHECK_CONDITION ? __entry->sense_length = cmd->scsi_status == SAM_STAT_CHECK_CONDITION ?
min(18, ((u8 *) cmd->sense_buffer)[SPC_ADD_SENSE_LEN_OFFSET] + 8) : 0; min(18, ((u8 *) cmd->sense_buffer)[SPC_ADD_SENSE_LEN_OFFSET] + 8) : 0;
...@@ -208,9 +210,7 @@ TRACE_EVENT(target_cmd_complete, ...@@ -208,9 +210,7 @@ TRACE_EVENT(target_cmd_complete,
show_opcode_name(__entry->opcode), show_opcode_name(__entry->opcode),
__entry->data_length, __print_hex(__entry->cdb, 16), __entry->data_length, __print_hex(__entry->cdb, 16),
show_task_attribute_name(__entry->task_attribute), show_task_attribute_name(__entry->task_attribute),
scsi_command_size(__entry->cdb) <= 16 ? __entry->control
__entry->cdb[scsi_command_size(__entry->cdb) - 1] :
__entry->cdb[1]
) )
); );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment