Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: target: Allows backend drivers to fail with specific sense codes

Currently, backend drivers can fail I/O with SAM_STAT_CHECK_CONDITION which
gets us TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE.

Add a new helper that allows backend drivers to fail with specific sense
codes.

This is based on a patch from Mike Christie <michael.christie@oracle.com>.

Cc: Mike Christie <michael.christie@oracle.com>
Link: https://lore.kernel.org/r/20210803145410.80147-2-s.samoylenko@yadro.com
Reviewed-by: David Disseldorp <ddiss@suse.de>
Signed-off-by: Sergey Samoylenko <s.samoylenko@yadro.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Sergey Samoylenko and committed by
Martin K. Petersen
44678553 5f492a7a

+15 -3
+12 -3
drivers/target/target_core_transport.c
··· 736 736 { 737 737 struct se_cmd *cmd = container_of(work, struct se_cmd, work); 738 738 739 - transport_generic_request_failure(cmd, 740 - TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE); 739 + transport_generic_request_failure(cmd, cmd->sense_reason); 741 740 } 742 741 743 742 /* ··· 854 855 } 855 856 856 857 /* May be called from interrupt context so must not sleep. */ 857 - void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) 858 + void target_complete_cmd_with_sense(struct se_cmd *cmd, u8 scsi_status, 859 + sense_reason_t sense_reason) 858 860 { 859 861 struct se_wwn *wwn = cmd->se_sess->se_tpg->se_tpg_wwn; 860 862 int success, cpu; ··· 865 865 return; 866 866 867 867 cmd->scsi_status = scsi_status; 868 + cmd->sense_reason = sense_reason; 868 869 869 870 spin_lock_irqsave(&cmd->t_state_lock, flags); 870 871 switch (cmd->scsi_status) { ··· 893 892 cpu = wwn->cmd_compl_affinity; 894 893 895 894 queue_work_on(cpu, target_completion_wq, &cmd->work); 895 + } 896 + EXPORT_SYMBOL(target_complete_cmd_with_sense); 897 + 898 + void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) 899 + { 900 + target_complete_cmd_with_sense(cmd, scsi_status, scsi_status ? 901 + TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE : 902 + TCM_NO_SENSE); 896 903 } 897 904 EXPORT_SYMBOL(target_complete_cmd); 898 905
+1
include/target/target_core_backend.h
··· 75 75 76 76 void target_complete_cmd(struct se_cmd *, u8); 77 77 void target_set_cmd_data_length(struct se_cmd *, int); 78 + void target_complete_cmd_with_sense(struct se_cmd *, u8, sense_reason_t); 78 79 void target_complete_cmd_with_length(struct se_cmd *, u8, int); 79 80 80 81 void transport_copy_sense_to_cmd(struct se_cmd *, unsigned char *);
+2
include/target/target_core_base.h
··· 457 457 #define TCM_ACA_TAG 0x24 458 458 459 459 struct se_cmd { 460 + /* Used for fail with specific sense codes */ 461 + sense_reason_t sense_reason; 460 462 /* SAM response code being sent to initiator */ 461 463 u8 scsi_status; 462 464 u16 scsi_sense_length;