diff mbox series

[06/13] tcm loop: use lio wq cmd submission helper

Message ID 20210209123845.4856-7-michael.christie@oracle.com
State Superseded
Headers show
Series target: fix cmd plugging and completion | expand

Commit Message

Mike Christie Feb. 9, 2021, 12:38 p.m. UTC
Convert loop to use the lio wq cmd submission helper.

Signed-off-by: Mike Christie <michael.christie@oracle.com>
---
 drivers/target/loopback/tcm_loop.c | 34 +++++++++++++++++-------------
 drivers/target/loopback/tcm_loop.h |  1 -
 2 files changed, 19 insertions(+), 16 deletions(-)

Comments

Bodo Stroesser Feb. 9, 2021, 3:59 p.m. UTC | #1
On 09.02.21 13:38, Mike Christie wrote:
> @@ -179,6 +184,11 @@ static void tcm_loop_submission_work(struct work_struct *work)
>   static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)
>   {
>   	struct tcm_loop_cmd *tl_cmd = scsi_cmd_priv(sc);
> +	struct tcm_loop_hba *tl_hba;
> +	struct tcm_loop_tpg *tl_tpg;
> +
> +	tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
> +	tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
>   
>   	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,

AFAICS these new lines are not needed. Or am I missing something?
kernel test robot Feb. 9, 2021, 5:39 p.m. UTC | #2
Hi Mike,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on mkp-scsi/for-next]
[also build test WARNING on vhost/linux-next v5.11-rc7 next-20210125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mike-Christie/target-move-t_task_cdb-initialization/20210209-213926
base:   https://git.kernel.org/pub/scm/linux/kernel/git/mkp/scsi.git for-next
config: h8300-randconfig-s031-20210209 (attached as .config)
compiler: h8300-linux-gcc (GCC) 9.3.0
reproduce:
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # apt-get install sparse
        # sparse version: v0.6.3-215-g0fb77bb6-dirty
        # https://github.com/0day-ci/linux/commit/b5a5f1dde145805b1ea13be05f6a28386284ac2e
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Mike-Christie/target-move-t_task_cdb-initialization/20210209-213926
        git checkout b5a5f1dde145805b1ea13be05f6a28386284ac2e
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-9.3.0 make.cross C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=h8300 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

   drivers/target/loopback/tcm_loop.c: In function 'tcm_loop_queuecommand':
>> drivers/target/loopback/tcm_loop.c:188:23: warning: variable 'tl_tpg' set but not used [-Wunused-but-set-variable]
     188 |  struct tcm_loop_tpg *tl_tpg;
         |                       ^~~~~~


vim +/tl_tpg +188 drivers/target/loopback/tcm_loop.c

   179	
   180	/*
   181	 * ->queuecommand can be and usually is called from interrupt context, so
   182	 * defer the actual submission to a workqueue.
   183	 */
   184	static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)
   185	{
   186		struct tcm_loop_cmd *tl_cmd = scsi_cmd_priv(sc);
   187		struct tcm_loop_hba *tl_hba;
 > 188		struct tcm_loop_tpg *tl_tpg;
   189	
   190		tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
   191		tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
   192	
   193		pr_debug("%s() %d:%d:%d:%llu got CDB: 0x%02x scsi_buf_len: %u\n",
   194			 __func__, sc->device->host->host_no, sc->device->id,
   195			 sc->device->channel, sc->device->lun, sc->cmnd[0],
   196			 scsi_bufflen(sc));
   197	
   198		memset(tl_cmd, 0, sizeof(*tl_cmd));
   199		tl_cmd->sc = sc;
   200		tl_cmd->sc_cmd_tag = sc->request->tag;
   201	
   202		tcm_loop_target_queue_cmd(tl_cmd);
   203		return 0;
   204	}
   205	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Mike Christie Feb. 9, 2021, 6:44 p.m. UTC | #3
On 2/9/21 9:59 AM, Bodo Stroesser wrote:
> On 09.02.21 13:38, Mike Christie wrote:

>> @@ -179,6 +184,11 @@ static void tcm_loop_submission_work(struct work_struct *work)

>>   static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)

>>   {

>>       struct tcm_loop_cmd *tl_cmd = scsi_cmd_priv(sc);

>> +    struct tcm_loop_hba *tl_hba;

>> +    struct tcm_loop_tpg *tl_tpg;

>> +

>> +    tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);

>> +    tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];

>>         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,

> 

> AFAICS these new lines are not needed. Or am I missing something?


You're right. I'll fix it.
diff mbox series

Patch

diff --git a/drivers/target/loopback/tcm_loop.c b/drivers/target/loopback/tcm_loop.c
index 274826a2b0bd..3642f381067e 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;
@@ -106,10 +105,16 @@  static struct device_driver tcm_loop_driverfs = {
  */
 static struct device *tcm_loop_primary;
 
-static void tcm_loop_submission_work(struct work_struct *work)
+static unsigned char *tcm_loop_get_cdb(struct se_cmd *se_cmd)
+{
+	struct tcm_loop_cmd *tl_cmd = container_of(se_cmd, struct tcm_loop_cmd,
+						   tl_se_cmd);
+
+	return tl_cmd->sc->cmnd;
+}
+
+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;
@@ -155,7 +160,7 @@  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,
+	rc = target_queue_cmd_submit(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,
@@ -179,6 +184,11 @@  static void tcm_loop_submission_work(struct work_struct *work)
 static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)
 {
 	struct tcm_loop_cmd *tl_cmd = scsi_cmd_priv(sc);
+	struct tcm_loop_hba *tl_hba;
+	struct tcm_loop_tpg *tl_tpg;
+
+	tl_hba = *(struct tcm_loop_hba **)shost_priv(sc->device->host);
+	tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id];
 
 	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,
@@ -188,8 +198,8 @@  static int tcm_loop_queuecommand(struct Scsi_Host *sh, struct scsi_cmnd *sc)
 	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;
 }
 
@@ -1146,6 +1156,7 @@  static const struct target_core_fabric_ops loop_ops = {
 	.queue_status			= tcm_loop_queue_status,
 	.queue_tm_rsp			= tcm_loop_queue_tm_rsp,
 	.aborted_task			= tcm_loop_aborted_task,
+	.get_cdb			= tcm_loop_get_cdb,
 	.fabric_make_wwn		= tcm_loop_make_scsi_hba,
 	.fabric_drop_wwn		= tcm_loop_drop_scsi_hba,
 	.fabric_make_tpg		= tcm_loop_make_naa_tpg,
@@ -1161,17 +1172,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();
@@ -1188,8 +1195,6 @@  static int __init tcm_loop_fabric_init(void)
 	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;
 }
@@ -1199,7 +1204,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");
diff --git a/drivers/target/loopback/tcm_loop.h b/drivers/target/loopback/tcm_loop.h
index d3110909a213..437663b3905c 100644
--- a/drivers/target/loopback/tcm_loop.h
+++ b/drivers/target/loopback/tcm_loop.h
@@ -16,7 +16,6 @@  struct tcm_loop_cmd {
 	struct scsi_cmnd *sc;
 	/* The TCM I/O descriptor that is accessed via container_of() */
 	struct se_cmd tl_se_cmd;
-	struct work_struct work;
 	struct completion tmr_done;
 	/* Sense buffer that will be mapped into outgoing status */
 	unsigned char tl_sense_buf[TRANSPORT_SENSE_BUFFER];