In case a LU spans 64bit sectors, fixed size sense data information field is only 32 bits which means the sector information will be truncated. Thus, if the LU spans 64bit sectors, use descriptor format sense data to correctly report sector information.
Unified · Split
| @@ -176,3 +176,8 @@ core_delete_hba(struct se_hba *hba) · 175 unmodified lines | |||
| 176 | kfree(hba); | 176 | kfree(hba); |
| 177 | return 0; | 177 | return 0; |
| 178 | } | 178 | } |
| 179 | |||
| 180 | bool target_sense_desc_format(struct se_device *dev) | ||
| 181 | { | ||
| 182 | return dev->transport->get_blocks(dev) > U32_MAX; | ||
| 183 | } | ||
| @@ -761,7 +761,12 @@ static int spc_modesense_control(struct se_cmd *cmd, u8 pc, u8 *p) · 760 unmodified lines | |||
| 761 | if (pc == 1) | 761 | if (pc == 1) |
| 762 | goto out; | 762 | goto out; |
| 763 | 763 | ||
| 764 | p[2] = 2; | 764 | /* GLTSD: No implicit save of log parameters */ |
| 765 | p[2] = (1 << 1); | ||
| 766 | if (target_sense_desc_format(dev)) | ||
| 767 | /* D_SENSE: Descriptor format sense data for 64bit sectors */ | ||
| 768 | p[2] |= (1 << 2); | ||
| 769 | |||
| 765 | /* | 770 | /* |
| 766 | * From spc4r23, 7.4.7 Control mode page | 771 | * From spc4r23, 7.4.7 Control mode page |
| 767 | * | 772 | * |
| @@ -1144,6 +1149,7 @@ static sense_reason_t spc_emulate_request_sense(struct se_cmd *cmd) · 376 unmodified lines | |||
| 1144 | unsigned char *rbuf; | 1149 | unsigned char *rbuf; |
| 1145 | u8 ua_asc = 0, ua_ascq = 0; | 1150 | u8 ua_asc = 0, ua_ascq = 0; |
| 1146 | unsigned char buf[SE_SENSE_BUF]; | 1151 | unsigned char buf[SE_SENSE_BUF]; |
| 1152 | bool desc_format = target_sense_desc_format(cmd->se_dev); | ||
| 1147 | 1153 | ||
| 1148 | memset(buf, 0, SE_SENSE_BUF); | 1154 | memset(buf, 0, SE_SENSE_BUF); |
| 1149 | 1155 | ||
| @@ -1158,10 +1164,10 @@ static sense_reason_t spc_emulate_request_sense(struct se_cmd *cmd) · 8 unmodified lines | |||
| 1158 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; | 1164 | return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE; |
| 1159 | 1165 | ||
| 1160 | if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) | 1166 | if (!core_scsi3_ua_clear_for_request_sense(cmd, &ua_asc, &ua_ascq)) |
| 1161 | scsi_build_sense_buffer(0, buf, UNIT_ATTENTION, | 1167 | scsi_build_sense_buffer(desc_format, buf, UNIT_ATTENTION, |
| 1162 | ua_asc, ua_ascq); | 1168 | ua_asc, ua_ascq); |
| 1163 | else | 1169 | else |
| 1164 | scsi_build_sense_buffer(0, buf, NO_SENSE, 0x0, 0x0); | 1170 | scsi_build_sense_buffer(desc_format, buf, NO_SENSE, 0x0, 0x0); |
| 1165 | 1171 | ||
| 1166 | memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length)); | 1172 | memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length)); |
| 1167 | transport_kunmap_data_sg(cmd); | 1173 | transport_kunmap_data_sg(cmd); |
| @@ -2735,6 +2735,7 @@ static int translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason) · 2734 unmodified lines | |||
| 2735 | u8 *buffer = cmd->sense_buffer; | 2735 | u8 *buffer = cmd->sense_buffer; |
| 2736 | int r = (__force int)reason; | 2736 | int r = (__force int)reason; |
| 2737 | u8 asc, ascq; | 2737 | u8 asc, ascq; |
| 2738 | bool desc_format = target_sense_desc_format(cmd->se_dev); | ||
| 2738 | 2739 | ||
| 2739 | if (r < ARRAY_SIZE(sense_info_table) && sense_info_table[r].key) | 2740 | if (r < ARRAY_SIZE(sense_info_table) && sense_info_table[r].key) |
| 2740 | si = &sense_info_table[r]; | 2741 | si = &sense_info_table[r]; |
| @@ -2754,7 +2755,7 @@ static int translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason) · 13 unmodified lines | |||
| 2754 | ascq = si->ascq; | 2755 | ascq = si->ascq; |
| 2755 | } | 2756 | } |
| 2756 | 2757 | ||
| 2757 | scsi_build_sense_buffer(0, buffer, si->key, asc, ascq); | 2758 | scsi_build_sense_buffer(desc_format, buffer, si->key, asc, ascq); |
| 2758 | if (si->add_sector_info) | 2759 | if (si->add_sector_info) |
| 2759 | return scsi_set_sense_information(buffer, | 2760 | return scsi_set_sense_information(buffer, |
| 2760 | cmd->scsi_sense_length, | 2761 | cmd->scsi_sense_length, |
| @@ -93,4 +93,6 @@ bool target_lun_is_rdonly(struct se_cmd *); · 92 unmodified lines | |||
| 93 | sense_reason_t passthrough_parse_cdb(struct se_cmd *cmd, | 93 | sense_reason_t passthrough_parse_cdb(struct se_cmd *cmd, |
| 94 | sense_reason_t (*exec_cmd)(struct se_cmd *cmd)); | 94 | sense_reason_t (*exec_cmd)(struct se_cmd *cmd)); |
| 95 | 95 | ||
| 96 | bool target_sense_desc_format(struct se_device *dev); | ||
| 97 | |||
| 96 | #endif /* TARGET_CORE_BACKEND_H */ | 98 | #endif /* TARGET_CORE_BACKEND_H */ |