Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

target/tcm_loop: Make TMF processing slightly faster

Target drivers must guarantee that struct se_cmd and struct se_tmr_req
exist as long as target_tmr_work() is in progress. This is why the
tcm_loop driver today passes 1 as second argument to
transport_generic_free_cmd() from inside the TMF code. Instead of
making the TMF code wait, make the TMF code obtain two references
(SCF_ACK_KREF) and drop one reference from inside the .check_stop_free()
callback.

Signed-off-by: Bart Van Assche <bart.vanassche@sandisk.com>
Cc: Christoph Hellwig <hch@lst.de>
Cc: Hannes Reinecke <hare@suse.com>
Cc: David Disseldorp <ddiss@suse.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Bart Van Assche and committed by
Nicholas Bellinger
4c1f0e65 75f141aa

+9 -16
+9 -16
drivers/target/loopback/tcm_loop.c
··· 51 51 */ 52 52 static int tcm_loop_check_stop_free(struct se_cmd *se_cmd) 53 53 { 54 - /* 55 - * Do not release struct se_cmd's containing a valid TMR 56 - * pointer. These will be released directly in tcm_loop_device_reset() 57 - * with transport_generic_free_cmd(). 58 - */ 59 - if (se_cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) 60 - return 0; 61 - /* 62 - * Release the struct se_cmd, which will make a callback to release 63 - * struct tcm_loop_cmd * in tcm_loop_deallocate_core_cmd() 64 - */ 65 - transport_generic_free_cmd(se_cmd, 0); 66 - return 1; 54 + return transport_generic_free_cmd(se_cmd, 0); 67 55 } 68 56 69 57 static void tcm_loop_release_cmd(struct se_cmd *se_cmd) ··· 232 244 se_sess = tl_tpg->tl_nexus->se_sess; 233 245 234 246 rc = target_submit_tmr(se_cmd, se_sess, tl_cmd->tl_sense_buf, lun, 235 - NULL, tmr, GFP_KERNEL, task, 0 /*flags*/); 247 + NULL, tmr, GFP_KERNEL, task, 248 + TARGET_SCF_ACK_KREF); 236 249 if (rc < 0) 237 250 goto release; 238 251 wait_for_completion(&tl_cmd->tmr_done); 239 252 ret = se_cmd->se_tmr_req->response; 253 + target_put_sess_cmd(se_cmd); 254 + 255 + out: 256 + return ret; 240 257 241 258 release: 242 259 if (se_cmd) 243 - transport_generic_free_cmd(se_cmd, 1); 260 + transport_generic_free_cmd(se_cmd, 0); 244 261 else 245 262 kmem_cache_free(tcm_loop_cmd_cache, tl_cmd); 246 - return ret; 263 + goto out; 247 264 } 248 265 249 266 static int tcm_loop_abort_task(struct scsi_cmnd *sc)