aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaolo Bonzini <pbonzini@redhat.com>2012-09-07 11:30:36 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2012-09-07 14:14:21 -0400
commit32a8811ff164f882712c17946e58e52444f464a7 (patch)
treef7af9ff41cd4f4e6c61a831c4e14fb1d57ebe05d
parent3717ef0c63e90686d959158e9728a13a49229be6 (diff)
target: support zero allocation length in REQUEST SENSE
Similar to INQUIRY and MODE SENSE, construct the sense data in a buffer and later copy it to the scatterlist. Do not do anything, but still clear a pending unit attention condition, if the allocation length is zero. However, SPC tells us that "If a REQUEST SENSE command is terminated with CHECK CONDITION status [and] the REQUEST SENSE command was received on an I_T nexus with a pending unit attention condition (i.e., before the device server reports CHECK CONDITION status), then the device server shall not clear the pending unit attention condition." Do the transport_kmap_data_sg early to detect this case. It also tells us "Device servers shall not adjust the additional sense length to reflect truncation if the allocation length is less than the sense data available", so do not do that! Note that the err variable is write-only. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r--drivers/target/target_core_spc.c35
-rw-r--r--include/target/target_core_base.h1
2 files changed, 19 insertions, 17 deletions
diff --git a/drivers/target/target_core_spc.c b/drivers/target/target_core_spc.c
index 4c861de538c9..388a922c8f6d 100644
--- a/drivers/target/target_core_spc.c
+++ b/drivers/target/target_core_spc.c
@@ -877,9 +877,11 @@ static int spc_emulate_modesense(struct se_cmd *cmd)
877static int spc_emulate_request_sense(struct se_cmd *cmd) 877static int spc_emulate_request_sense(struct se_cmd *cmd)
878{ 878{
879 unsigned char *cdb = cmd->t_task_cdb; 879 unsigned char *cdb = cmd->t_task_cdb;
880 unsigned char *buf; 880 unsigned char *rbuf;
881 u8 ua_asc = 0, ua_ascq = 0; 881 u8 ua_asc = 0, ua_ascq = 0;
882 int err = 0; 882 unsigned char buf[SE_SENSE_BUF];
883
884 memset(buf, 0, SE_SENSE_BUF);
883 885
884 if (cdb[1] & 0x01) { 886 if (cdb[1] & 0x01) {
885 pr_err("REQUEST_SENSE description emulation not" 887 pr_err("REQUEST_SENSE description emulation not"
@@ -888,20 +890,21 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
888 return -ENOSYS; 890 return -ENOSYS;
889 } 891 }
890 892
891 buf = transport_kmap_data_sg(cmd); 893 rbuf = transport_kmap_data_sg(cmd);
892 894 if (cmd->scsi_sense_reason != 0) {
893 if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) { 895 /*
896 * Out of memory. We will fail with CHECK CONDITION, so
897 * we must not clear the unit attention condition.
898 */
899 target_complete_cmd(cmd, CHECK_CONDITION);
900 return 0;
901 } else if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) {
894 /* 902 /*
895 * CURRENT ERROR, UNIT ATTENTION 903 * CURRENT ERROR, UNIT ATTENTION
896 */ 904 */
897 buf[0] = 0x70; 905 buf[0] = 0x70;
898 buf[SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION; 906 buf[SPC_SENSE_KEY_OFFSET] = UNIT_ATTENTION;
899 907
900 if (cmd->data_length < 18) {
901 buf[7] = 0x00;
902 err = -EINVAL;
903 goto end;
904 }
905 /* 908 /*
906 * The Additional Sense Code (ASC) from the UNIT ATTENTION 909 * The Additional Sense Code (ASC) from the UNIT ATTENTION
907 */ 910 */
@@ -915,11 +918,6 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
915 buf[0] = 0x70; 918 buf[0] = 0x70;
916 buf[SPC_SENSE_KEY_OFFSET] = NO_SENSE; 919 buf[SPC_SENSE_KEY_OFFSET] = NO_SENSE;
917 920
918 if (cmd->data_length < 18) {
919 buf[7] = 0x00;
920 err = -EINVAL;
921 goto end;
922 }
923 /* 921 /*
924 * NO ADDITIONAL SENSE INFORMATION 922 * NO ADDITIONAL SENSE INFORMATION
925 */ 923 */
@@ -927,8 +925,11 @@ static int spc_emulate_request_sense(struct se_cmd *cmd)
927 buf[7] = 0x0A; 925 buf[7] = 0x0A;
928 } 926 }
929 927
930end: 928 if (rbuf) {
931 transport_kunmap_data_sg(cmd); 929 memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length));
930 transport_kunmap_data_sg(cmd);
931 }
932
932 target_complete_cmd(cmd, GOOD); 933 target_complete_cmd(cmd, GOOD);
933 return 0; 934 return 0;
934} 935}
diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
index 015cea01ae39..5be89373ceac 100644
--- a/include/target/target_core_base.h
+++ b/include/target/target_core_base.h
@@ -121,6 +121,7 @@
121 121
122#define SE_INQUIRY_BUF 512 122#define SE_INQUIRY_BUF 512
123#define SE_MODE_PAGE_BUF 512 123#define SE_MODE_PAGE_BUF 512
124#define SE_SENSE_BUF 96
124 125
125/* struct se_hba->hba_flags */ 126/* struct se_hba->hba_flags */
126enum hba_flags_table { 127enum hba_flags_table {