Skip to content

Commit

Permalink
scsi: target: core: Dynamically set DPO and FUA in usage_bits
Browse files Browse the repository at this point in the history
libiscsi tests check the support of DPO & FUA bits in usage bits of RSOC
response.  This patch adds support for dynamic usage bits for each opcode.
Set support of DPO & FUA bits in usage_bits of RSOC response depending on
support DPOFUA in the backstore device.

Reviewed-by: Roman Bolshakov <[email protected]>
Reviewed-by: Konstantin Shelekhin <[email protected]>
Signed-off-by: Dmitry Bogdanov <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Reviewed-by: Mike Christie <[email protected]>
Signed-off-by: Martin K. Petersen <[email protected]>
  • Loading branch information
logost authored and martinkpetersen committed Oct 27, 2022
1 parent b8908e5 commit 415d82b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
34 changes: 32 additions & 2 deletions drivers/target/target_core_spc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1314,6 +1314,22 @@ spc_emulate_testunitready(struct se_cmd *cmd)
return 0;
}

static void set_dpofua_usage_bits(u8 *usage_bits, struct se_device *dev)
{
if (!target_check_fua(dev))
usage_bits[1] &= ~0x18;
else
usage_bits[1] |= 0x18;
}

static void set_dpofua_usage_bits32(u8 *usage_bits, struct se_device *dev)
{
if (!target_check_fua(dev))
usage_bits[10] &= ~0x18;
else
usage_bits[10] |= 0x18;
}

static struct target_opcode_descriptor tcm_opcode_read6 = {
.support = SCSI_SUPPORT_FULL,
.opcode = READ_6,
Expand All @@ -1329,6 +1345,7 @@ static struct target_opcode_descriptor tcm_opcode_read10 = {
.usage_bits = {READ_10, 0xf8, 0xff, 0xff,
0xff, 0xff, SCSI_GROUP_NUMBER_MASK, 0xff,
0xff, SCSI_CONTROL_MASK},
.update_usage_bits = set_dpofua_usage_bits,
};

static struct target_opcode_descriptor tcm_opcode_read12 = {
Expand All @@ -1338,6 +1355,7 @@ static struct target_opcode_descriptor tcm_opcode_read12 = {
.usage_bits = {READ_12, 0xf8, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, SCSI_GROUP_NUMBER_MASK, SCSI_CONTROL_MASK},
.update_usage_bits = set_dpofua_usage_bits,
};

static struct target_opcode_descriptor tcm_opcode_read16 = {
Expand All @@ -1348,6 +1366,7 @@ static struct target_opcode_descriptor tcm_opcode_read16 = {
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, SCSI_GROUP_NUMBER_MASK, SCSI_CONTROL_MASK},
.update_usage_bits = set_dpofua_usage_bits,
};

static struct target_opcode_descriptor tcm_opcode_write6 = {
Expand All @@ -1365,6 +1384,7 @@ static struct target_opcode_descriptor tcm_opcode_write10 = {
.usage_bits = {WRITE_10, 0xf8, 0xff, 0xff,
0xff, 0xff, SCSI_GROUP_NUMBER_MASK, 0xff,
0xff, SCSI_CONTROL_MASK},
.update_usage_bits = set_dpofua_usage_bits,
};

static struct target_opcode_descriptor tcm_opcode_write_verify10 = {
Expand All @@ -1374,6 +1394,7 @@ static struct target_opcode_descriptor tcm_opcode_write_verify10 = {
.usage_bits = {WRITE_VERIFY, 0xf0, 0xff, 0xff,
0xff, 0xff, SCSI_GROUP_NUMBER_MASK, 0xff,
0xff, SCSI_CONTROL_MASK},
.update_usage_bits = set_dpofua_usage_bits,
};

static struct target_opcode_descriptor tcm_opcode_write12 = {
Expand All @@ -1383,6 +1404,7 @@ static struct target_opcode_descriptor tcm_opcode_write12 = {
.usage_bits = {WRITE_12, 0xf8, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, SCSI_GROUP_NUMBER_MASK, SCSI_CONTROL_MASK},
.update_usage_bits = set_dpofua_usage_bits,
};

static struct target_opcode_descriptor tcm_opcode_write16 = {
Expand All @@ -1393,6 +1415,7 @@ static struct target_opcode_descriptor tcm_opcode_write16 = {
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, SCSI_GROUP_NUMBER_MASK, SCSI_CONTROL_MASK},
.update_usage_bits = set_dpofua_usage_bits,
};

static struct target_opcode_descriptor tcm_opcode_write_verify16 = {
Expand All @@ -1403,6 +1426,7 @@ static struct target_opcode_descriptor tcm_opcode_write_verify16 = {
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, 0xff, 0xff,
0xff, 0xff, SCSI_GROUP_NUMBER_MASK, SCSI_CONTROL_MASK},
.update_usage_bits = set_dpofua_usage_bits,
};

static bool tcm_is_ws_enabled(struct se_cmd *cmd)
Expand All @@ -1429,6 +1453,7 @@ static struct target_opcode_descriptor tcm_opcode_write_same32 = {
0x00, 0x00, 0x00, 0x00,
0xff, 0xff, 0xff, 0xff},
.enabled = tcm_is_ws_enabled,
.update_usage_bits = set_dpofua_usage_bits32,
};

static bool tcm_is_caw_enabled(struct se_cmd *cmd)
Expand All @@ -1447,6 +1472,7 @@ static struct target_opcode_descriptor tcm_opcode_compare_write = {
0xff, 0xff, 0x00, 0x00,
0x00, 0xff, SCSI_GROUP_NUMBER_MASK, SCSI_CONTROL_MASK},
.enabled = tcm_is_caw_enabled,
.update_usage_bits = set_dpofua_usage_bits,
};

static struct target_opcode_descriptor tcm_opcode_read_capacity = {
Expand Down Expand Up @@ -2033,7 +2059,8 @@ spc_rsoc_encode_command_descriptor(unsigned char *buf, u8 ctdp,

static int
spc_rsoc_encode_one_command_descriptor(unsigned char *buf, u8 ctdp,
struct target_opcode_descriptor *descr)
struct target_opcode_descriptor *descr,
struct se_device *dev)
{
int td_size = 0;

Expand All @@ -2045,6 +2072,8 @@ spc_rsoc_encode_one_command_descriptor(unsigned char *buf, u8 ctdp,
buf[1] = (ctdp << 7) | SCSI_SUPPORT_FULL;
put_unaligned_be16(descr->cdb_size, &buf[2]);
memcpy(&buf[4], descr->usage_bits, descr->cdb_size);
if (descr->update_usage_bits)
descr->update_usage_bits(&buf[4], dev);

td_size = spc_rsoc_encode_command_timeouts_descriptor(
&buf[4 + descr->cdb_size], ctdp, descr);
Expand Down Expand Up @@ -2187,7 +2216,8 @@ spc_emulate_report_supp_op_codes(struct se_cmd *cmd)
put_unaligned_be32(response_length - 3, buf);
} else {
response_length = spc_rsoc_encode_one_command_descriptor(
&buf[response_length], rctd, descr);
&buf[response_length], rctd, descr,
cmd->se_dev);
}

memcpy(rbuf, buf, min_t(u32, response_length, cmd->data_length));
Expand Down
2 changes: 2 additions & 0 deletions include/target/target_core_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,8 @@ struct target_opcode_descriptor {
u16 nominal_timeout;
u16 recommended_timeout;
bool (*enabled)(struct se_cmd *cmd);
void (*update_usage_bits)(u8 *usage_bits,
struct se_device *dev);
u8 usage_bits[];
};

Expand Down

0 comments on commit 415d82b

Please sign in to comment.