Target/dif: Introduce protection-passthough-only mode
authorSagi Grimberg <sagig@mellanox.com>
Wed, 19 Feb 2014 15:50:17 +0000 (17:50 +0200)
committerNicholas Bellinger <nab@linux-iscsi.org>
Mon, 7 Apr 2014 08:48:42 +0000 (01:48 -0700)
Some transports (iSCSI/iSER/SRP/FC) support hardware INSERT/STRIP
capabilities while other transports like loopback/vhost-scsi need
perform this is software.

This patch allows fabrics using SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC
to signal the early LUN scan handling case where PROTECT CDB bits
are set, but no fabric buffer has been provided.

For transports which use generic new command these buffers have yet
to be allocated.

Also this way, target may support protection information
against legacy initiators (writes are inserted and reads
are stripped).

(Only set prot_pto for loopback during early special case - nab)

Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
drivers/target/loopback/tcm_loop.c
drivers/target/target_core_sbc.c
drivers/target/target_core_transport.c
include/target/target_core_base.h

index fadad7c5f635f01496acdc79d56a678a4e4fb1a6..a49ef0a49fa996f145799f574cc0200e6f11a85a 100644 (file)
@@ -212,6 +212,10 @@ static void tcm_loop_submission_work(struct work_struct *work)
                se_cmd->se_cmd_flags |= SCF_BIDI;
 
        }
+
+       if (!scsi_prot_sg_count(sc) && scsi_get_prot_op(sc) != SCSI_PROT_NORMAL)
+               se_cmd->prot_pto = true;
+
        rc = target_submit_cmd_map_sgls(se_cmd, tl_nexus->se_sess, sc->cmnd,
                        &tl_cmd->tl_sense_buf[0], tl_cmd->sc->device->lun,
                        scsi_bufflen(sc), tcm_loop_sam_attr(sc),
index a1e75dd636acff8f506e201b04e52da0072c1500..c301d9b6874da2d923c638e6398c0d814cfd53fc 100644 (file)
@@ -634,7 +634,7 @@ sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb,
 {
        u8 protect = cdb[1] >> 5;
 
-       if (!cmd->t_prot_sg || !cmd->t_prot_nents)
+       if ((!cmd->t_prot_sg || !cmd->t_prot_nents) && cmd->prot_pto)
                return true;
 
        switch (dev->dev_attrib.pi_prot_type) {
index 4653d826e595ac3f1f02f73806c8bb67a6151dac..0a359fa82bd3eb4bcee3fe5053cf97c0e32d12a8 100644 (file)
@@ -1365,6 +1365,13 @@ int target_submit_cmd_map_sgls(struct se_cmd *se_cmd, struct se_session *se_sess
                target_put_sess_cmd(se_sess, se_cmd);
                return 0;
        }
+
+       rc = target_setup_cmd_from_cdb(se_cmd, cdb);
+       if (rc != 0) {
+               transport_generic_request_failure(se_cmd, rc);
+               return 0;
+       }
+
        /*
         * Save pointers for SGLs containing protection information,
         * if present.
@@ -1374,11 +1381,6 @@ int target_submit_cmd_map_sgls(struct se_cmd *se_cmd, struct se_session *se_sess
                se_cmd->t_prot_nents = sgl_prot_count;
        }
 
-       rc = target_setup_cmd_from_cdb(se_cmd, cdb);
-       if (rc != 0) {
-               transport_generic_request_failure(se_cmd, rc);
-               return 0;
-       }
        /*
         * When a non zero sgl_count has been passed perform SGL passthrough
         * mapping for pre-allocated fabric memory instead of having target
index 5ae92492d1eef5ec7d761f1adcf5a33e5b738720..82cb4ed06f7160df5cd3b7aaeb56b22ccef321b6 100644 (file)
@@ -570,6 +570,7 @@ struct se_cmd {
        enum target_prot_ho     prot_handover;
        sense_reason_t          pi_err;
        sector_t                bad_sector;
+       bool                    prot_pto;
 };
 
 struct se_ua {