Commit 76736db3 authored by Sagi Grimberg's avatar Sagi Grimberg Committed by Nicholas Bellinger

target: Report bad sector in sense data for DIF errors

SPC-4 states that data-integrity errors shall also report
the failed sector in CHECK_CONDITION response sense data
information field.
Signed-off-by: default avatarSagi Grimberg <sagig@mellanox.com>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent 676687c6
...@@ -1131,6 +1131,7 @@ sbc_dif_verify_write(struct se_cmd *cmd, sector_t start, unsigned int sectors, ...@@ -1131,6 +1131,7 @@ sbc_dif_verify_write(struct se_cmd *cmd, sector_t start, unsigned int sectors,
if (rc) { if (rc) {
kunmap_atomic(paddr); kunmap_atomic(paddr);
kunmap_atomic(daddr); kunmap_atomic(daddr);
cmd->bad_sector = sector;
return rc; return rc;
} }
...@@ -1191,6 +1192,7 @@ sbc_dif_verify_read(struct se_cmd *cmd, sector_t start, unsigned int sectors, ...@@ -1191,6 +1192,7 @@ sbc_dif_verify_read(struct se_cmd *cmd, sector_t start, unsigned int sectors,
if (rc) { if (rc) {
kunmap_atomic(paddr); kunmap_atomic(paddr);
kunmap_atomic(daddr); kunmap_atomic(daddr);
cmd->bad_sector = sector;
return rc; return rc;
} }
......
...@@ -2493,6 +2493,19 @@ static int transport_get_sense_codes( ...@@ -2493,6 +2493,19 @@ static int transport_get_sense_codes(
return 0; return 0;
} }
static
void transport_err_sector_info(unsigned char *buffer, sector_t bad_sector)
{
/* Place failed LBA in sense data information descriptor 0. */
buffer[SPC_ADD_SENSE_LEN_OFFSET] = 0xc;
buffer[SPC_DESC_TYPE_OFFSET] = 0; /* Information */
buffer[SPC_ADDITIONAL_DESC_LEN_OFFSET] = 0xa;
buffer[SPC_VALIDITY_OFFSET] = 0x80;
/* Descriptor Information: failing sector */
put_unaligned_be64(bad_sector, &buffer[12]);
}
int int
transport_send_check_condition_and_sense(struct se_cmd *cmd, transport_send_check_condition_and_sense(struct se_cmd *cmd,
sense_reason_t reason, int from_transport) sense_reason_t reason, int from_transport)
...@@ -2695,6 +2708,7 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd, ...@@ -2695,6 +2708,7 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd,
/* LOGICAL BLOCK GUARD CHECK FAILED */ /* LOGICAL BLOCK GUARD CHECK FAILED */
buffer[SPC_ASC_KEY_OFFSET] = 0x10; buffer[SPC_ASC_KEY_OFFSET] = 0x10;
buffer[SPC_ASCQ_KEY_OFFSET] = 0x01; buffer[SPC_ASCQ_KEY_OFFSET] = 0x01;
transport_err_sector_info(buffer, cmd->bad_sector);
break; break;
case TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED: case TCM_LOGICAL_BLOCK_APP_TAG_CHECK_FAILED:
/* CURRENT ERROR */ /* CURRENT ERROR */
...@@ -2705,6 +2719,7 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd, ...@@ -2705,6 +2719,7 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd,
/* LOGICAL BLOCK APPLICATION TAG CHECK FAILED */ /* LOGICAL BLOCK APPLICATION TAG CHECK FAILED */
buffer[SPC_ASC_KEY_OFFSET] = 0x10; buffer[SPC_ASC_KEY_OFFSET] = 0x10;
buffer[SPC_ASCQ_KEY_OFFSET] = 0x02; buffer[SPC_ASCQ_KEY_OFFSET] = 0x02;
transport_err_sector_info(buffer, cmd->bad_sector);
break; break;
case TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED: case TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED:
/* CURRENT ERROR */ /* CURRENT ERROR */
...@@ -2715,6 +2730,7 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd, ...@@ -2715,6 +2730,7 @@ transport_send_check_condition_and_sense(struct se_cmd *cmd,
/* LOGICAL BLOCK REFERENCE TAG CHECK FAILED */ /* LOGICAL BLOCK REFERENCE TAG CHECK FAILED */
buffer[SPC_ASC_KEY_OFFSET] = 0x10; buffer[SPC_ASC_KEY_OFFSET] = 0x10;
buffer[SPC_ASCQ_KEY_OFFSET] = 0x03; buffer[SPC_ASCQ_KEY_OFFSET] = 0x03;
transport_err_sector_info(buffer, cmd->bad_sector);
break; break;
case TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE: case TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE:
default: default:
......
...@@ -37,6 +37,9 @@ ...@@ -37,6 +37,9 @@
/* Used by transport_send_check_condition_and_sense() */ /* Used by transport_send_check_condition_and_sense() */
#define SPC_SENSE_KEY_OFFSET 2 #define SPC_SENSE_KEY_OFFSET 2
#define SPC_ADD_SENSE_LEN_OFFSET 7 #define SPC_ADD_SENSE_LEN_OFFSET 7
#define SPC_DESC_TYPE_OFFSET 8
#define SPC_ADDITIONAL_DESC_LEN_OFFSET 9
#define SPC_VALIDITY_OFFSET 10
#define SPC_ASC_KEY_OFFSET 12 #define SPC_ASC_KEY_OFFSET 12
#define SPC_ASCQ_KEY_OFFSET 13 #define SPC_ASCQ_KEY_OFFSET 13
#define TRANSPORT_IQN_LEN 224 #define TRANSPORT_IQN_LEN 224
...@@ -560,7 +563,7 @@ struct se_cmd { ...@@ -560,7 +563,7 @@ struct se_cmd {
unsigned int t_prot_nents; unsigned int t_prot_nents;
enum target_prot_ho prot_handover; enum target_prot_ho prot_handover;
sense_reason_t pi_err; sense_reason_t pi_err;
u32 block_num; sector_t bad_sector;
}; };
struct se_ua { struct se_ua {
......
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