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

tcm_loop: separate out tcm_loop_issue_tmr

No functional change.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Hannes Reinecke and committed by
Nicholas Bellinger
a314d700 fb2b2844

+74 -56
+73 -56
drivers/target/loopback/tcm_loop.c
··· 245 245 * Called from SCSI EH process context to issue a LUN_RESET TMR 246 246 * to struct scsi_device 247 247 */ 248 - static int tcm_loop_device_reset(struct scsi_cmnd *sc) 248 + static int tcm_loop_issue_tmr(struct tcm_loop_tpg *tl_tpg, 249 + struct tcm_loop_nexus *tl_nexus, 250 + int lun, enum tcm_tmreq_table tmr) 249 251 { 250 252 struct se_cmd *se_cmd = NULL; 251 - struct se_portal_group *se_tpg; 252 253 struct se_session *se_sess; 254 + struct se_portal_group *se_tpg; 253 255 struct tcm_loop_cmd *tl_cmd = NULL; 256 + struct tcm_loop_tmr *tl_tmr = NULL; 257 + int ret = TMR_FUNCTION_FAILED, rc; 258 + 259 + tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_KERNEL); 260 + if (!tl_cmd) { 261 + pr_err("Unable to allocate memory for tl_cmd\n"); 262 + return ret; 263 + } 264 + 265 + tl_tmr = kzalloc(sizeof(struct tcm_loop_tmr), GFP_KERNEL); 266 + if (!tl_tmr) { 267 + pr_err("Unable to allocate memory for tl_tmr\n"); 268 + goto release; 269 + } 270 + init_waitqueue_head(&tl_tmr->tl_tmr_wait); 271 + 272 + se_cmd = &tl_cmd->tl_se_cmd; 273 + se_tpg = &tl_tpg->tl_se_tpg; 274 + se_sess = tl_nexus->se_sess; 275 + /* 276 + * Initialize struct se_cmd descriptor from target_core_mod infrastructure 277 + */ 278 + transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, 0, 279 + DMA_NONE, MSG_SIMPLE_TAG, 280 + &tl_cmd->tl_sense_buf[0]); 281 + 282 + rc = core_tmr_alloc_req(se_cmd, tl_tmr, tmr, GFP_KERNEL); 283 + if (rc < 0) 284 + goto release; 285 + 286 + /* 287 + * Locate the underlying TCM struct se_lun 288 + */ 289 + if (transport_lookup_tmr_lun(se_cmd, lun) < 0) { 290 + ret = TMR_LUN_DOES_NOT_EXIST; 291 + goto release; 292 + } 293 + /* 294 + * Queue the TMR to TCM Core and sleep waiting for 295 + * tcm_loop_queue_tm_rsp() to wake us up. 296 + */ 297 + transport_generic_handle_tmr(se_cmd); 298 + wait_event(tl_tmr->tl_tmr_wait, atomic_read(&tl_tmr->tmr_complete)); 299 + /* 300 + * The TMR LUN_RESET has completed, check the response status and 301 + * then release allocations. 302 + */ 303 + ret = se_cmd->se_tmr_req->response; 304 + release: 305 + if (se_cmd) 306 + transport_generic_free_cmd(se_cmd, 1); 307 + else 308 + kmem_cache_free(tcm_loop_cmd_cache, tl_cmd); 309 + kfree(tl_tmr); 310 + return ret; 311 + } 312 + 313 + /* 314 + * Called from SCSI EH process context to issue a LUN_RESET TMR 315 + * to struct scsi_device 316 + */ 317 + static int tcm_loop_device_reset(struct scsi_cmnd *sc) 318 + { 254 319 struct tcm_loop_hba *tl_hba; 255 320 struct tcm_loop_nexus *tl_nexus; 256 - struct tcm_loop_tmr *tl_tmr = NULL; 257 321 struct tcm_loop_tpg *tl_tpg; 258 - int ret = FAILED, rc; 322 + int ret = FAILED; 323 + 259 324 /* 260 325 * Locate the tcm_loop_hba_t pointer 261 326 */ ··· 334 269 " active I_T Nexus\n"); 335 270 return FAILED; 336 271 } 337 - se_sess = tl_nexus->se_sess; 338 272 /* 339 - * Locate the tl_tpg and se_tpg pointers from TargetID in sc->device->id 273 + * Locate the tl_tpg pointer from TargetID in sc->device->id 340 274 */ 341 275 tl_tpg = &tl_hba->tl_hba_tpgs[sc->device->id]; 342 - se_tpg = &tl_tpg->tl_se_tpg; 343 - 344 - tl_cmd = kmem_cache_zalloc(tcm_loop_cmd_cache, GFP_KERNEL); 345 - if (!tl_cmd) { 346 - pr_err("Unable to allocate memory for tl_cmd\n"); 347 - return FAILED; 348 - } 349 - 350 - tl_tmr = kzalloc(sizeof(struct tcm_loop_tmr), GFP_KERNEL); 351 - if (!tl_tmr) { 352 - pr_err("Unable to allocate memory for tl_tmr\n"); 353 - goto release; 354 - } 355 - init_waitqueue_head(&tl_tmr->tl_tmr_wait); 356 - 357 - se_cmd = &tl_cmd->tl_se_cmd; 358 - /* 359 - * Initialize struct se_cmd descriptor from target_core_mod infrastructure 360 - */ 361 - transport_init_se_cmd(se_cmd, se_tpg->se_tpg_tfo, se_sess, 0, 362 - DMA_NONE, MSG_SIMPLE_TAG, 363 - &tl_cmd->tl_sense_buf[0]); 364 - 365 - rc = core_tmr_alloc_req(se_cmd, tl_tmr, TMR_LUN_RESET, GFP_KERNEL); 366 - if (rc < 0) 367 - goto release; 368 - /* 369 - * Locate the underlying TCM struct se_lun from sc->device->lun 370 - */ 371 - if (transport_lookup_tmr_lun(se_cmd, sc->device->lun) < 0) 372 - goto release; 373 - /* 374 - * Queue the TMR to TCM Core and sleep waiting for tcm_loop_queue_tm_rsp() 375 - * to wake us up. 376 - */ 377 - transport_generic_handle_tmr(se_cmd); 378 - wait_event(tl_tmr->tl_tmr_wait, atomic_read(&tl_tmr->tmr_complete)); 379 - /* 380 - * The TMR LUN_RESET has completed, check the response status and 381 - * then release allocations. 382 - */ 383 - ret = (se_cmd->se_tmr_req->response == TMR_FUNCTION_COMPLETE) ? 384 - SUCCESS : FAILED; 385 - release: 386 - if (se_cmd) 387 - transport_generic_free_cmd(se_cmd, 1); 388 - else 389 - kmem_cache_free(tcm_loop_cmd_cache, tl_cmd); 390 - kfree(tl_tmr); 391 - return ret; 276 + ret = tcm_loop_issue_tmr(tl_tpg, tl_nexus, 277 + sc->device->lun, TMR_LUN_RESET); 278 + return (ret == TMR_FUNCTION_COMPLETE) ? SUCCESS : FAILED; 392 279 } 393 280 394 281 static int tcm_loop_slave_alloc(struct scsi_device *sd)
+1
include/target/target_core_base.h
··· 227 227 228 228 /* fabric independent task management response values */ 229 229 enum tcm_tmrsp_table { 230 + TMR_FUNCTION_FAILED = 0, 230 231 TMR_FUNCTION_COMPLETE = 1, 231 232 TMR_TASK_DOES_NOT_EXIST = 2, 232 233 TMR_LUN_DOES_NOT_EXIST = 3,