scsi: target: tcm_loop: Use block cmd allocator for se_cmds
authorMike Christie <michael.christie@oracle.com>
Sat, 27 Feb 2021 16:59:59 +0000 (10:59 -0600)
committerMartin K. Petersen <martin.petersen@oracle.com>
Thu, 4 Mar 2021 22:37:02 +0000 (17:37 -0500)
Make tcm_loop use the block layer cmd allocator for se_cmds instead of
using the tcm_loop_cmd_cache. In the future when we can use the host tags
for internal requests like TMFs we can completely kill the
tcm_loop_cmd_cache.

Link: https://lore.kernel.org/r/20210227170006.5077-19-michael.christie@oracle.com
Tested-by: Laurence Oberman <loberman@redhat.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Mike Christie <michael.christie@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
drivers/target/loopback/tcm_loop.c

index 677e4b8..fb877ae 100644 (file)
@@ -67,8 +67,12 @@ static void tcm_loop_release_cmd(struct se_cmd *se_cmd)
 {
        struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
                                struct tcm_loop_cmd, tl_se_cmd);
+       struct scsi_cmnd *sc = tl_cmd->sc;
 
-       kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
+       if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)
+               kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
+       else
+               sc->scsi_done(sc);
 }
 
 static int tcm_loop_show_info(struct seq_file *m, struct Scsi_Host *host)
@@ -164,7 +168,6 @@ static void tcm_loop_submission_work(struct work_struct *work)
        return;
 
 out_done:
-       kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
        sc->scsi_done(sc);
 }
 
@@ -174,20 +177,14 @@ out_done:
  */
 static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)
 {
-       struct tcm_loop_cmd *tl_cmd;
+       struct tcm_loop_cmd *tl_cmd = scsi_cmd_priv(sc);
 
        pr_debug("%s() %d:%d:%d:%llu got CDB: 0x%02x scsi_buf_len: %u\n",
                 __func__, sc->device->host->host_no, sc->device->id,
                 sc->device->channel, sc->device->lun, sc->cmnd[0],
                 scsi_bufflen(sc));
 
-       tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_ATOMIC);
-       if (!tl_cmd) {
-               set_host_byte(sc, DID_ERROR);
-               sc->scsi_done(sc);
-               return 0;
-       }
-
+       memset(tl_cmd, 0, sizeof(*tl_cmd));
        tl_cmd->sc = sc;
        tl_cmd->sc_cmd_tag = sc->request->tag;
        INIT_WORK(&tl_cmd->work, tcm_loop_submission_work);
@@ -319,6 +316,7 @@ static struct scsi_host_template tcm_loop_driver_template = {
        .dma_boundary           = PAGE_SIZE - 1,
        .module                 = THIS_MODULE,
        .track_queue_depth      = 1,
+       .cmd_size               = sizeof(struct tcm_loop_cmd),
 };
 
 static int tcm_loop_driver_probe(struct device *dev)
@@ -579,7 +577,6 @@ static int tcm_loop_queue_data_or_status(const char *func,
        if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) ||
            (se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT))
                scsi_set_resid(sc, se_cmd->residual_count);
-       sc->scsi_done(sc);
        return 0;
 }