target: Perform PROTECT sanity checks for WRITE_SAME
authorNicholas Bellinger <nab@linux-iscsi.org>
Sat, 14 Feb 2015 01:32:11 +0000 (01:32 +0000)
committerNicholas Bellinger <nab@linux-iscsi.org>
Sat, 14 Feb 2015 02:09:45 +0000 (02:09 +0000)
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 <martin.petersen@oracle.com>
Cc: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_file.c
drivers/target/target_core_iblock.c
drivers/target/target_core_sbc.c

index c2aea099ea4adf7c0ee60ac7949fa02089162932..9f1ed773e976105d2ea01599228182a8f516d163 100644 (file)
@@ -494,6 +494,11 @@ fd_execute_write_same(struct se_cmd *cmd)
                target_complete_cmd(cmd, SAM_STAT_GOOD);
                return 0;
        }
+       if (cmd->prot_op) {
+               pr_err("WRITE_SAME: Protection information with FILEIO"
+                      " backends not supported\n");
+               return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+       }
        sg = &cmd->t_data_sg[0];
 
        if (cmd->t_data_nents > 1 ||
index 3efff94fbd9788838f565218965d180b78a67604..303299efa3a6db7c659a31d6eed8cc7857107cf8 100644 (file)
@@ -464,6 +464,11 @@ iblock_execute_write_same(struct se_cmd *cmd)
        sector_t block_lba = cmd->t_task_lba;
        sector_t sectors = sbc_get_write_same_sectors(cmd);
 
+       if (cmd->prot_op) {
+               pr_err("WRITE_SAME: Protection information with IBLOCK"
+                      " backends not supported\n");
+               return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE;
+       }
        sg = &cmd->t_data_sg[0];
 
        if (cmd->t_data_nents > 1 ||
index 1bb8b4a93a66838ea46e960d1a5a0a6677671d4e..87cbbe2201516a89b50ba3ab52be00e57163fcff 100644 (file)
@@ -36,6 +36,9 @@
 #include "target_core_ua.h"
 #include "target_core_alua.h"
 
+static sense_reason_t
+sbc_check_prot(struct se_device *, struct se_cmd *, unsigned char *, u32, bool);
+
 static sense_reason_t
 sbc_emulate_readcapacity(struct se_cmd *cmd)
 {
@@ -254,6 +257,7 @@ sbc_setup_write_same(struct se_cmd *cmd, unsigned char *flags, struct sbc_ops *o
        struct se_device *dev = cmd->se_dev;
        sector_t end_lba = dev->transport->get_blocks(dev) + 1;
        unsigned int sectors = sbc_get_write_same_sectors(cmd);
+       sense_reason_t ret;
 
        if ((flags[0] & 0x04) || (flags[0] & 0x02)) {
                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
        if (!ops->execute_write_same)
                return TCM_UNSUPPORTED_SCSI_OPCODE;
 
+       ret = sbc_check_prot(dev, cmd, &cmd->t_task_cdb[0], sectors, true);
+       if (ret)
+               return ret;
+
        cmd->execute_cmd = ops->execute_write_same;
        return 0;
 }