diff options
Diffstat (limited to 'drivers/target/loopback/tcm_loop.c')
| -rw-r--r-- | drivers/target/loopback/tcm_loop.c | 60 | 
1 files changed, 23 insertions, 37 deletions
| diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c index badba437e5f9..2687fd7d45db 100644 --- a/drivers/target/loopback/tcm_loop.c +++ b/drivers/target/loopback/tcm_loop.c @@ -39,7 +39,6 @@  #define to_tcm_loop_hba(hba)	container_of(hba, struct tcm_loop_hba, dev) -static struct workqueue_struct *tcm_loop_workqueue;  static struct kmem_cache *tcm_loop_cmd_cache;  static int tcm_loop_hba_no_cnt; @@ -67,8 +66,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) @@ -102,10 +105,8 @@ static struct device_driver tcm_loop_driverfs = {   */  static struct device *tcm_loop_primary; -static void tcm_loop_submission_work(struct work_struct *work) +static void tcm_loop_target_queue_cmd(struct tcm_loop_cmd *tl_cmd)  { -	struct tcm_loop_cmd *tl_cmd = -		container_of(work, struct tcm_loop_cmd, work);  	struct se_cmd *se_cmd = &tl_cmd->tl_se_cmd;  	struct scsi_cmnd *sc = tl_cmd->sc;  	struct tcm_loop_nexus *tl_nexus; @@ -113,7 +114,6 @@ static void tcm_loop_submission_work(struct work_struct *work)  	struct tcm_loop_tpg *tl_tpg;  	struct scatterlist *sgl_bidi = NULL;  	u32 sgl_bidi_count = 0, transfer_length; -	int rc;  	tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);  	tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; @@ -151,21 +151,20 @@ static void tcm_loop_submission_work(struct work_struct *work)  	}  	se_cmd->tag = tl_cmd->sc_cmd_tag; -	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, -			transfer_length, TCM_SIMPLE_TAG, -			sc->sc_data_direction, 0, -			scsi_sglist(sc), scsi_sg_count(sc), -			sgl_bidi, sgl_bidi_count, -			scsi_prot_sglist(sc), scsi_prot_sg_count(sc)); -	if (rc < 0) { -		set_host_byte(sc, DID_NO_CONNECT); -		goto out_done; -	} +	target_init_cmd(se_cmd, tl_nexus->se_sess, &tl_cmd->tl_sense_buf[0], +			tl_cmd->sc->device->lun, transfer_length, +			TCM_SIMPLE_TAG, sc->sc_data_direction, 0); + +	if (target_submit_prep(se_cmd, sc->cmnd, scsi_sglist(sc), +			       scsi_sg_count(sc), sgl_bidi, sgl_bidi_count, +			       scsi_prot_sglist(sc), scsi_prot_sg_count(sc), +			       GFP_ATOMIC)) +		return; + +	target_queue_submission(se_cmd);  	return;  out_done: -	kmem_cache_free(tcm_loop_cmd_cache, tl_cmd);  	sc->scsi_done(sc);  } @@ -175,24 +174,18 @@ 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); -	queue_work(tcm_loop_workqueue, &tl_cmd->work); + +	tcm_loop_target_queue_cmd(tl_cmd);  	return 0;  } @@ -320,6 +313,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) @@ -580,7 +574,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;  } @@ -1164,17 +1157,13 @@ static int __init tcm_loop_fabric_init(void)  {  	int ret = -ENOMEM; -	tcm_loop_workqueue = alloc_workqueue("tcm_loop", 0, 0); -	if (!tcm_loop_workqueue) -		goto out; -  	tcm_loop_cmd_cache = kmem_cache_create("tcm_loop_cmd_cache",  				sizeof(struct tcm_loop_cmd),  				__alignof__(struct tcm_loop_cmd),  				0, NULL);  	if (!tcm_loop_cmd_cache) {  		pr_debug("kmem_cache_create() for tcm_loop_cmd_cache failed\n"); -		goto out_destroy_workqueue; +		goto out;  	}  	ret = tcm_loop_alloc_core_bus(); @@ -1191,8 +1180,6 @@ out_release_core_bus:  	tcm_loop_release_core_bus();  out_destroy_cache:  	kmem_cache_destroy(tcm_loop_cmd_cache); -out_destroy_workqueue: -	destroy_workqueue(tcm_loop_workqueue);  out:  	return ret;  } @@ -1202,7 +1189,6 @@ static void __exit tcm_loop_fabric_exit(void)  	target_unregister_template(&loop_ops);  	tcm_loop_release_core_bus();  	kmem_cache_destroy(tcm_loop_cmd_cache); -	destroy_workqueue(tcm_loop_workqueue);  }  MODULE_DESCRIPTION("TCM loopback virtual Linux/SCSI fabric module"); | 
