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

target: Drop left-over se_lun->lun_cmd_list shutdown code

Now with percpu refcounting for se_lun in place, go ahead and drop
the legacy per se_cmd accounting for se_lun shutdown.

This includes __transport_clear_lun_from_sessions(), the associated
transport_lun_wait_for_tasks() logic, along with a handful of now
unused se_cmd structure members and ->transport_state bits.

Cc: Kent Overstreet <kmo@daterainc.com>
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

+7 -252
-10
drivers/infiniband/ulp/srpt/ib_srpt.c
··· 1352 1352 1353 1353 /* XXX(hch): this is a horrible layering violation.. */ 1354 1354 spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags); 1355 - ioctx->cmd.transport_state |= CMD_T_LUN_STOP; 1356 1355 ioctx->cmd.transport_state &= ~CMD_T_ACTIVE; 1357 1356 spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags); 1358 - 1359 - complete(&ioctx->cmd.transport_lun_stop_comp); 1360 1357 break; 1361 1358 case SRPT_STATE_CMD_RSP_SENT: 1362 1359 /* ··· 1361 1364 * not been received in time. 1362 1365 */ 1363 1366 srpt_unmap_sg_to_ib_sge(ioctx->ch, ioctx); 1364 - spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags); 1365 - ioctx->cmd.transport_state |= CMD_T_LUN_STOP; 1366 - spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags); 1367 1367 target_put_sess_cmd(ioctx->ch->sess, &ioctx->cmd); 1368 1368 break; 1369 1369 case SRPT_STATE_MGMT_RSP_SENT: ··· 1470 1476 { 1471 1477 struct se_cmd *cmd; 1472 1478 enum srpt_command_state state; 1473 - unsigned long flags; 1474 1479 1475 1480 cmd = &ioctx->cmd; 1476 1481 state = srpt_get_cmd_state(ioctx); ··· 1489 1496 __func__, __LINE__, state); 1490 1497 break; 1491 1498 case SRPT_RDMA_WRITE_LAST: 1492 - spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags); 1493 - ioctx->cmd.transport_state |= CMD_T_LUN_STOP; 1494 - spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags); 1495 1499 break; 1496 1500 default: 1497 1501 printk(KERN_ERR "%s[%d]: opcode = %u\n", __func__,
+2 -13
drivers/target/target_core_tpg.c
··· 654 654 atomic_set(&lun->lun_acl_count, 0); 655 655 init_completion(&lun->lun_shutdown_comp); 656 656 INIT_LIST_HEAD(&lun->lun_acl_list); 657 - INIT_LIST_HEAD(&lun->lun_cmd_list); 658 657 spin_lock_init(&lun->lun_acl_lock); 659 - spin_lock_init(&lun->lun_cmd_lock); 660 658 spin_lock_init(&lun->lun_sep_lock); 661 659 init_completion(&lun->lun_ref_comp); 662 660 ··· 704 706 atomic_set(&lun->lun_acl_count, 0); 705 707 init_completion(&lun->lun_shutdown_comp); 706 708 INIT_LIST_HEAD(&lun->lun_acl_list); 707 - INIT_LIST_HEAD(&lun->lun_cmd_list); 708 709 spin_lock_init(&lun->lun_acl_lock); 709 - spin_lock_init(&lun->lun_cmd_lock); 710 710 spin_lock_init(&lun->lun_sep_lock); 711 711 init_completion(&lun->lun_ref_comp); 712 712 } ··· 845 849 return 0; 846 850 } 847 851 848 - static void core_tpg_shutdown_lun( 849 - struct se_portal_group *tpg, 850 - struct se_lun *lun) 851 - { 852 - core_clear_lun_from_tpg(lun, tpg); 853 - transport_clear_lun_ref(lun); 854 - } 855 - 856 852 struct se_lun *core_tpg_pre_dellun( 857 853 struct se_portal_group *tpg, 858 854 u32 unpacked_lun) ··· 879 891 struct se_portal_group *tpg, 880 892 struct se_lun *lun) 881 893 { 882 - core_tpg_shutdown_lun(tpg, lun); 894 + core_clear_lun_from_tpg(lun, tpg); 895 + transport_clear_lun_ref(lun); 883 896 884 897 core_dev_unexport(lun->lun_se_dev, tpg, lun); 885 898
+2 -217
drivers/target/target_core_transport.c
··· 505 505 if (write_pending) 506 506 cmd->t_state = TRANSPORT_WRITE_PENDING; 507 507 508 - /* 509 - * Determine if IOCTL context caller in requesting the stopping of this 510 - * command for LUN shutdown purposes. 511 - */ 512 - if (cmd->transport_state & CMD_T_LUN_STOP) { 513 - pr_debug("%s:%d CMD_T_LUN_STOP for ITT: 0x%08x\n", 514 - __func__, __LINE__, cmd->se_tfo->get_task_tag(cmd)); 515 - 516 - cmd->transport_state &= ~CMD_T_ACTIVE; 517 - if (remove_from_lists) 518 - target_remove_from_state_list(cmd); 519 - spin_unlock_irqrestore(&cmd->t_state_lock, flags); 520 - 521 - complete(&cmd->transport_lun_stop_comp); 522 - return 1; 523 - } 524 - 525 508 if (remove_from_lists) { 526 509 target_remove_from_state_list(cmd); 527 510 ··· 1061 1078 int task_attr, 1062 1079 unsigned char *sense_buffer) 1063 1080 { 1064 - INIT_LIST_HEAD(&cmd->se_lun_node); 1065 1081 INIT_LIST_HEAD(&cmd->se_delayed_node); 1066 1082 INIT_LIST_HEAD(&cmd->se_qf_node); 1067 1083 INIT_LIST_HEAD(&cmd->se_cmd_list); 1068 1084 INIT_LIST_HEAD(&cmd->state_list); 1069 - init_completion(&cmd->transport_lun_fe_stop_comp); 1070 - init_completion(&cmd->transport_lun_stop_comp); 1071 1085 init_completion(&cmd->t_transport_stop_comp); 1072 1086 init_completion(&cmd->cmd_wait_comp); 1073 1087 init_completion(&cmd->task_stop_comp); ··· 1685 1705 /* 1686 1706 * If the received CDB has aleady been aborted stop processing it here. 1687 1707 */ 1688 - if (transport_check_aborted_status(cmd, 1)) { 1689 - complete(&cmd->transport_lun_stop_comp); 1708 + if (transport_check_aborted_status(cmd, 1)) 1690 1709 return; 1691 - } 1692 1710 1693 - /* 1694 - * Determine if IOCTL context caller in requesting the stopping of this 1695 - * command for LUN shutdown purposes. 1696 - */ 1697 - spin_lock_irq(&cmd->t_state_lock); 1698 - if (cmd->transport_state & CMD_T_LUN_STOP) { 1699 - pr_debug("%s:%d CMD_T_LUN_STOP for ITT: 0x%08x\n", 1700 - __func__, __LINE__, cmd->se_tfo->get_task_tag(cmd)); 1701 - 1702 - cmd->transport_state &= ~CMD_T_ACTIVE; 1703 - spin_unlock_irq(&cmd->t_state_lock); 1704 - complete(&cmd->transport_lun_stop_comp); 1705 - return; 1706 - } 1707 1711 /* 1708 1712 * Determine if frontend context caller is requesting the stopping of 1709 1713 * this command for frontend exceptions. 1710 1714 */ 1715 + spin_lock_irq(&cmd->t_state_lock); 1711 1716 if (cmd->transport_state & CMD_T_STOP) { 1712 1717 pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08x\n", 1713 1718 __func__, __LINE__, ··· 2355 2390 } 2356 2391 EXPORT_SYMBOL(target_wait_for_sess_cmds); 2357 2392 2358 - /* transport_lun_wait_for_tasks(): 2359 - * 2360 - * Called from ConfigFS context to stop the passed struct se_cmd to allow 2361 - * an struct se_lun to be successfully shutdown. 2362 - */ 2363 - static int transport_lun_wait_for_tasks(struct se_cmd *cmd, struct se_lun *lun) 2364 - { 2365 - unsigned long flags; 2366 - int ret = 0; 2367 - 2368 - /* 2369 - * If the frontend has already requested this struct se_cmd to 2370 - * be stopped, we can safely ignore this struct se_cmd. 2371 - */ 2372 - spin_lock_irqsave(&cmd->t_state_lock, flags); 2373 - if (cmd->transport_state & CMD_T_STOP) { 2374 - cmd->transport_state &= ~CMD_T_LUN_STOP; 2375 - 2376 - pr_debug("ConfigFS ITT[0x%08x] - CMD_T_STOP, skipping\n", 2377 - cmd->se_tfo->get_task_tag(cmd)); 2378 - spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2379 - transport_cmd_check_stop(cmd, false, false); 2380 - return -EPERM; 2381 - } 2382 - cmd->transport_state |= CMD_T_LUN_FE_STOP; 2383 - spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2384 - 2385 - // XXX: audit task_flags checks. 2386 - spin_lock_irqsave(&cmd->t_state_lock, flags); 2387 - if ((cmd->transport_state & CMD_T_BUSY) && 2388 - (cmd->transport_state & CMD_T_SENT)) { 2389 - if (!target_stop_cmd(cmd, &flags)) 2390 - ret++; 2391 - } 2392 - spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2393 - 2394 - pr_debug("ConfigFS: cmd: %p stop tasks ret:" 2395 - " %d\n", cmd, ret); 2396 - if (!ret) { 2397 - pr_debug("ConfigFS: ITT[0x%08x] - stopping cmd....\n", 2398 - cmd->se_tfo->get_task_tag(cmd)); 2399 - wait_for_completion(&cmd->transport_lun_stop_comp); 2400 - pr_debug("ConfigFS: ITT[0x%08x] - stopped cmd....\n", 2401 - cmd->se_tfo->get_task_tag(cmd)); 2402 - } 2403 - 2404 - return 0; 2405 - } 2406 - 2407 - static void __transport_clear_lun_from_sessions(struct se_lun *lun) 2408 - { 2409 - struct se_cmd *cmd = NULL; 2410 - unsigned long lun_flags, cmd_flags; 2411 - /* 2412 - * Do exception processing and return CHECK_CONDITION status to the 2413 - * Initiator Port. 2414 - */ 2415 - spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); 2416 - while (!list_empty(&lun->lun_cmd_list)) { 2417 - cmd = list_first_entry(&lun->lun_cmd_list, 2418 - struct se_cmd, se_lun_node); 2419 - list_del_init(&cmd->se_lun_node); 2420 - 2421 - spin_lock(&cmd->t_state_lock); 2422 - pr_debug("SE_LUN[%d] - Setting cmd->transport" 2423 - "_lun_stop for ITT: 0x%08x\n", 2424 - cmd->se_lun->unpacked_lun, 2425 - cmd->se_tfo->get_task_tag(cmd)); 2426 - cmd->transport_state |= CMD_T_LUN_STOP; 2427 - spin_unlock(&cmd->t_state_lock); 2428 - 2429 - spin_unlock_irqrestore(&lun->lun_cmd_lock, lun_flags); 2430 - 2431 - if (!cmd->se_lun) { 2432 - pr_err("ITT: 0x%08x, [i,t]_state: %u/%u\n", 2433 - cmd->se_tfo->get_task_tag(cmd), 2434 - cmd->se_tfo->get_cmd_state(cmd), cmd->t_state); 2435 - BUG(); 2436 - } 2437 - /* 2438 - * If the Storage engine still owns the iscsi_cmd_t, determine 2439 - * and/or stop its context. 2440 - */ 2441 - pr_debug("SE_LUN[%d] - ITT: 0x%08x before transport" 2442 - "_lun_wait_for_tasks()\n", cmd->se_lun->unpacked_lun, 2443 - cmd->se_tfo->get_task_tag(cmd)); 2444 - 2445 - if (transport_lun_wait_for_tasks(cmd, cmd->se_lun) < 0) { 2446 - spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); 2447 - continue; 2448 - } 2449 - 2450 - pr_debug("SE_LUN[%d] - ITT: 0x%08x after transport_lun" 2451 - "_wait_for_tasks(): SUCCESS\n", 2452 - cmd->se_lun->unpacked_lun, 2453 - cmd->se_tfo->get_task_tag(cmd)); 2454 - 2455 - spin_lock_irqsave(&cmd->t_state_lock, cmd_flags); 2456 - if (!(cmd->transport_state & CMD_T_DEV_ACTIVE)) { 2457 - spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags); 2458 - goto check_cond; 2459 - } 2460 - cmd->transport_state &= ~CMD_T_DEV_ACTIVE; 2461 - target_remove_from_state_list(cmd); 2462 - spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags); 2463 - 2464 - /* 2465 - * The Storage engine stopped this struct se_cmd before it was 2466 - * send to the fabric frontend for delivery back to the 2467 - * Initiator Node. Return this SCSI CDB back with an 2468 - * CHECK_CONDITION status. 2469 - */ 2470 - check_cond: 2471 - transport_send_check_condition_and_sense(cmd, 2472 - TCM_NON_EXISTENT_LUN, 0); 2473 - /* 2474 - * If the fabric frontend is waiting for this iscsi_cmd_t to 2475 - * be released, notify the waiting thread now that LU has 2476 - * finished accessing it. 2477 - */ 2478 - spin_lock_irqsave(&cmd->t_state_lock, cmd_flags); 2479 - if (cmd->transport_state & CMD_T_LUN_FE_STOP) { 2480 - pr_debug("SE_LUN[%d] - Detected FE stop for" 2481 - " struct se_cmd: %p ITT: 0x%08x\n", 2482 - lun->unpacked_lun, 2483 - cmd, cmd->se_tfo->get_task_tag(cmd)); 2484 - 2485 - spin_unlock_irqrestore(&cmd->t_state_lock, 2486 - cmd_flags); 2487 - transport_cmd_check_stop(cmd, false, false); 2488 - complete(&cmd->transport_lun_fe_stop_comp); 2489 - spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); 2490 - continue; 2491 - } 2492 - pr_debug("SE_LUN[%d] - ITT: 0x%08x finished processing\n", 2493 - lun->unpacked_lun, cmd->se_tfo->get_task_tag(cmd)); 2494 - 2495 - spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags); 2496 - spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); 2497 - } 2498 - spin_unlock_irqrestore(&lun->lun_cmd_lock, lun_flags); 2499 - } 2500 - 2501 2393 static int transport_clear_lun_ref_thread(void *p) 2502 2394 { 2503 2395 struct se_lun *lun = p; ··· 2404 2582 !(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { 2405 2583 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2406 2584 return false; 2407 - } 2408 - /* 2409 - * If we are already stopped due to an external event (ie: LUN shutdown) 2410 - * sleep until the connection can have the passed struct se_cmd back. 2411 - * The cmd->transport_lun_stopped_sem will be upped by 2412 - * transport_clear_lun_from_sessions() once the ConfigFS context caller 2413 - * has completed its operation on the struct se_cmd. 2414 - */ 2415 - if (cmd->transport_state & CMD_T_LUN_STOP) { 2416 - pr_debug("wait_for_tasks: Stopping" 2417 - " wait_for_completion(&cmd->t_tasktransport_lun_fe" 2418 - "_stop_comp); for ITT: 0x%08x\n", 2419 - cmd->se_tfo->get_task_tag(cmd)); 2420 - /* 2421 - * There is a special case for WRITES where a FE exception + 2422 - * LUN shutdown means ConfigFS context is still sleeping on 2423 - * transport_lun_stop_comp in transport_lun_wait_for_tasks(). 2424 - * We go ahead and up transport_lun_stop_comp just to be sure 2425 - * here. 2426 - */ 2427 - spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2428 - complete(&cmd->transport_lun_stop_comp); 2429 - wait_for_completion(&cmd->transport_lun_fe_stop_comp); 2430 - spin_lock_irqsave(&cmd->t_state_lock, flags); 2431 - 2432 - target_remove_from_state_list(cmd); 2433 - /* 2434 - * At this point, the frontend who was the originator of this 2435 - * struct se_cmd, now owns the structure and can be released through 2436 - * normal means below. 2437 - */ 2438 - pr_debug("wait_for_tasks: Stopped" 2439 - " wait_for_completion(&cmd->t_tasktransport_lun_fe_" 2440 - "stop_comp); for ITT: 0x%08x\n", 2441 - cmd->se_tfo->get_task_tag(cmd)); 2442 - 2443 - cmd->transport_state &= ~CMD_T_LUN_STOP; 2444 2585 } 2445 2586 2446 2587 if (!(cmd->transport_state & CMD_T_ACTIVE)) {
-2
drivers/target/target_core_xcopy.c
··· 574 574 return -ENOMEM; 575 575 } 576 576 init_completion(&pt_cmd->se_lun->lun_shutdown_comp); 577 - INIT_LIST_HEAD(&pt_cmd->se_lun->lun_cmd_list); 578 577 INIT_LIST_HEAD(&pt_cmd->se_lun->lun_acl_list); 579 578 spin_lock_init(&pt_cmd->se_lun->lun_acl_lock); 580 - spin_lock_init(&pt_cmd->se_lun->lun_cmd_lock); 581 579 spin_lock_init(&pt_cmd->se_lun->lun_sep_lock); 582 580 init_completion(&pt_cmd->se_lun->lun_ref_comp); 583 581
+3 -10
include/target/target_core_base.h
··· 443 443 /* Used for sense data */ 444 444 void *sense_buffer; 445 445 struct list_head se_delayed_node; 446 - struct list_head se_lun_node; 447 446 struct list_head se_qf_node; 448 447 struct se_device *se_dev; 449 448 struct se_dev_entry *se_deve; ··· 470 471 #define CMD_T_SENT (1 << 4) 471 472 #define CMD_T_STOP (1 << 5) 472 473 #define CMD_T_FAILED (1 << 6) 473 - #define CMD_T_LUN_STOP (1 << 7) 474 - #define CMD_T_LUN_FE_STOP (1 << 8) 475 - #define CMD_T_DEV_ACTIVE (1 << 9) 476 - #define CMD_T_REQUEST_STOP (1 << 10) 477 - #define CMD_T_BUSY (1 << 11) 474 + #define CMD_T_DEV_ACTIVE (1 << 7) 475 + #define CMD_T_REQUEST_STOP (1 << 8) 476 + #define CMD_T_BUSY (1 << 9) 478 477 spinlock_t t_state_lock; 479 478 struct completion t_transport_stop_comp; 480 - struct completion transport_lun_fe_stop_comp; 481 - struct completion transport_lun_stop_comp; 482 479 483 480 struct work_struct work; 484 481 ··· 746 751 u32 unpacked_lun; 747 752 atomic_t lun_acl_count; 748 753 spinlock_t lun_acl_lock; 749 - spinlock_t lun_cmd_lock; 750 754 spinlock_t lun_sep_lock; 751 755 struct completion lun_shutdown_comp; 752 - struct list_head lun_cmd_list; 753 756 struct list_head lun_acl_list; 754 757 struct se_device *lun_se_dev; 755 758 struct se_port *lun_sep;