Skip to content

Commit afd73f1

Browse files
author
Nicholas Bellinger
committed
target: Perform PROTECT sanity checks for WRITE_SAME
This patch adds a call to sbc_check_prot() within sbc_setup_write_same() code to perform the various protection releated sanity checks, including failing if WRPROTECT or RDPROTECT is set for a backend device that has not advertised support for T10-PI. Also, since WRITE_SAME + T10-PI is currently not supported by IBLOCK + FILEIO backends, go ahead and fail if ->execute_write_same() is invoked with a non zero cmd->prot_op. Cc: Martin Petersen <[email protected]> Cc: Sagi Grimberg <[email protected]> Signed-off-by: Nicholas Bellinger <[email protected]>
1 parent f7b7c06 commit afd73f1

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

drivers/target/target_core_file.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,11 @@ fd_execute_write_same(struct se_cmd *cmd)
494494
target_complete_cmd(cmd, SAM_STAT_GOOD);
495495
return 0;
496496
}
497+
if (cmd->prot_op) {
498+
pr_err("WRITE_SAME: Protection information with FILEIO"
499+
" backends not supported\n");
500+
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
501+
}
497502
sg = &cmd->t_data_sg[0];
498503

499504
if (cmd->t_data_nents > 1 ||

drivers/target/target_core_iblock.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ iblock_execute_write_same(struct se_cmd *cmd)
464464
sector_t block_lba = cmd->t_task_lba;
465465
sector_t sectors = sbc_get_write_same_sectors(cmd);
466466

467+
if (cmd->prot_op) {
468+
pr_err("WRITE_SAME: Protection information with IBLOCK"
469+
" backends not supported\n");
470+
return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
471+
}
467472
sg = &cmd->t_data_sg[0];
468473

469474
if (cmd->t_data_nents > 1 ||

drivers/target/target_core_sbc.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@
3636
#include "target_core_ua.h"
3737
#include "target_core_alua.h"
3838

39+
static sense_reason_t
40+
sbc_check_prot(struct se_device *, struct se_cmd *, unsigned char *, u32, bool);
41+
3942
static sense_reason_t
4043
sbc_emulate_readcapacity(struct se_cmd *cmd)
4144
{
@@ -254,6 +257,7 @@ sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *o
254257
struct se_device *dev = cmd->se_dev;
255258
sector_t end_lba = dev->transport->get_blocks(dev) + 1;
256259
unsigned int sectors = sbc_get_write_same_sectors(cmd);
260+
sense_reason_t ret;
257261

258262
if ((flags[0] & 0x04) || (flags[0] & 0x02)) {
259263
pr_err("WRITE_SAME PBDATA and LBDATA"
@@ -295,6 +299,10 @@ sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *o
295299
if (!ops->execute_write_same)
296300
return TCM_UNSUPPORTED_SCSI_OPCODE;
297301

302+
ret = sbc_check_prot(dev, cmd, &cmd->t_task_cdb[0], sectors, true);
303+
if (ret)
304+
return ret;
305+
298306
cmd->execute_cmd = ops->execute_write_same;
299307
return 0;
300308
}

0 commit comments

Comments
 (0)