target: Add internal WRITE_STRIP support
authorNicholas Bellinger <nab@linux-iscsi.org>
Sun, 8 Feb 2015 11:06:17 +0000 (03:06 -0800)
committerNicholas Bellinger <nab@linux-iscsi.org>
Wed, 8 Apr 2015 06:26:43 +0000 (23:26 -0700)
This patch adds WRITE_STRIP support in target_write_prot_action() that
invokes sbc_dif_verify_write() for checking T10-PI metadata before
submitting the I/O to a backend driver.

Upon verify failure, the specific sense code is propigated up the
failure path up to transport_generic_request_failure().

Also, update sbc_dif_verify_write() to only perform the subsequent
protection metadata copy when a valid *sg is passed.

(Use ilog2 instead of division and unlikely for pi_err - Sagi)

Reviewed-by: Martin Petersen <martin.petersen@oracle.com>
Reviewed-by: Sagi Grimberg <sagig@mellanox.com>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/target_core_sbc.c
drivers/target/target_core_transport.c

index 67bc1886f004ff9635ced8e151ea8397f8223ac9..315ff641408bb6122815392cd7de0c4fc7cdb8ef 100644 (file)
@@ -1342,6 +1342,9 @@ sbc_dif_verify_write(struct se_cmd *cmd, sector_t start, unsigned int sectors,
                kunmap_atomic(paddr);
                kunmap_atomic(daddr);
        }
+       if (!sg)
+               return 0;
+
        sbc_dif_copy_prot(cmd, sectors, false, sg, sg_off);
 
        return 0;
index 2a0c36bf322684ba99cf1858f7a5ed900c4d2300..0fe58bfabfc286176b339e721c5e98481cb0cd81 100644 (file)
@@ -1740,6 +1740,7 @@ void __target_execute_cmd(struct se_cmd *cmd)
 
 static int target_write_prot_action(struct se_cmd *cmd)
 {
+       u32 sectors;
        /*
         * Perform WRITE_INSERT of PI using software emulation when backend
         * device has PI enabled, if the transport has not already generated
@@ -1750,6 +1751,21 @@ static int target_write_prot_action(struct se_cmd *cmd)
                if (!(cmd->se_sess->sup_prot_ops & TARGET_PROT_DOUT_INSERT))
                        sbc_dif_generate(cmd);
                break;
+       case TARGET_PROT_DOUT_STRIP:
+               if (cmd->se_sess->sup_prot_ops & TARGET_PROT_DOUT_STRIP)
+                       break;
+
+               sectors = cmd->data_length >> ilog2(cmd->se_dev->dev_attrib.block_size);
+               cmd->pi_err = sbc_dif_verify_write(cmd, cmd->t_task_lba,
+                                                  sectors, 0, NULL, 0);
+               if (unlikely(cmd->pi_err)) {
+                       spin_lock_irq(&cmd->t_state_lock);
+                       cmd->transport_state &= ~CMD_T_BUSY|CMD_T_SENT;
+                       spin_unlock_irq(&cmd->t_state_lock);
+                       transport_generic_request_failure(cmd, cmd->pi_err);
+                       return -1;
+               }
+               break;
        default:
                break;
        }