Skip to content

Commit e0eb5d3

Browse files
mikechristiemartinkpetersen
authored andcommitted
scsi: target: tcm_loop: Use block cmd allocator for se_cmds
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/[email protected] Tested-by: Laurence Oberman <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Mike Christie <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 6ec29cb commit e0eb5d3

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/target/loopback/tcm_loop.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ static void tcm_loop_release_cmd(struct se_cmd *se_cmd)
6767
{
6868
struct tcm_loop_cmd *tl_cmd = container_of(se_cmd,
6969
struct tcm_loop_cmd, tl_se_cmd);
70+
struct scsi_cmnd *sc = tl_cmd->sc;
7071

71-
kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
72+
if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)
73+
kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
74+
else
75+
sc->scsi_done(sc);
7276
}
7377

7478
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)
164168
return;
165169

166170
out_done:
167-
kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);
168171
sc->scsi_done(sc);
169172
}
170173

@@ -174,20 +177,14 @@ static void tcm_loop_submission_work(struct work_struct *work)
174177
*/
175178
static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)
176179
{
177-
struct tcm_loop_cmd *tl_cmd;
180+
struct tcm_loop_cmd *tl_cmd = scsi_cmd_priv(sc);
178181

179182
pr_debug("%s() %d:%d:%d:%llu got CDB: 0x%02x scsi_buf_len: %u\n",
180183
__func__, sc->device->host->host_no, sc->device->id,
181184
sc->device->channel, sc->device->lun, sc->cmnd[0],
182185
scsi_bufflen(sc));
183186

184-
tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_ATOMIC);
185-
if (!tl_cmd) {
186-
set_host_byte(sc, DID_ERROR);
187-
sc->scsi_done(sc);
188-
return 0;
189-
}
190-
187+
memset(tl_cmd, 0, sizeof(*tl_cmd));
191188
tl_cmd->sc = sc;
192189
tl_cmd->sc_cmd_tag = sc->request->tag;
193190
INIT_WORK(&tl_cmd->work, tcm_loop_submission_work);
@@ -319,6 +316,7 @@ static struct scsi_host_template tcm_loop_driver_template = {
319316
.dma_boundary = PAGE_SIZE - 1,
320317
.module = THIS_MODULE,
321318
.track_queue_depth = 1,
319+
.cmd_size = sizeof(struct tcm_loop_cmd),
322320
};
323321

324322
static int tcm_loop_driver_probe(struct device *dev)
@@ -579,7 +577,6 @@ static int tcm_loop_queue_data_or_status(const char *func,
579577
if ((se_cmd->se_cmd_flags & SCF_OVERFLOW_BIT) ||
580578
(se_cmd->se_cmd_flags & SCF_UNDERFLOW_BIT))
581579
scsi_set_resid(sc, se_cmd->residual_count);
582-
sc->scsi_done(sc);
583580
return 0;
584581
}
585582

0 commit comments

Comments
 (0)