Skip to content

Commit 4a9a6c8

Browse files
author
Nicholas Bellinger
committed
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>
1 parent 5277797 commit 4a9a6c8

5 files changed

Lines changed: 7 additions & 252 deletions

File tree

‎drivers/infiniband/ulp/srpt/ib_srpt.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,21 +1352,15 @@ static int srpt_abort_cmd(struct srpt_send_ioctx *ioctx)
13521352

13531353
/* XXX(hch): this is a horrible layering violation.. */
13541354
spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
1355-
ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
13561355
ioctx->cmd.transport_state &= ~CMD_T_ACTIVE;
13571356
spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
1358-
1359-
complete(&ioctx->cmd.transport_lun_stop_comp);
13601357
break;
13611358
case SRPT_STATE_CMD_RSP_SENT:
13621359
/*
13631360
* SRP_RSP sending failed or the SRP_RSP send completion has
13641361
* not been received in time.
13651362
*/
13661363
srpt_unmap_sg_to_ib_sge(ioctx->ch, ioctx);
1367-
spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
1368-
ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
1369-
spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
13701364
target_put_sess_cmd(ioctx->ch->sess, &ioctx->cmd);
13711365
break;
13721366
case SRPT_STATE_MGMT_RSP_SENT:
@@ -1476,7 +1470,6 @@ static void srpt_handle_rdma_err_comp(struct srpt_rdma_ch *ch,
14761470
{
14771471
struct se_cmd *cmd;
14781472
enum srpt_command_state state;
1479-
unsigned long flags;
14801473

14811474
cmd = &ioctx->cmd;
14821475
state = srpt_get_cmd_state(ioctx);
@@ -1496,9 +1489,6 @@ static void srpt_handle_rdma_err_comp(struct srpt_rdma_ch *ch,
14961489
__func__, __LINE__, state);
14971490
break;
14981491
case SRPT_RDMA_WRITE_LAST:
1499-
spin_lock_irqsave(&ioctx->cmd.t_state_lock, flags);
1500-
ioctx->cmd.transport_state |= CMD_T_LUN_STOP;
1501-
spin_unlock_irqrestore(&ioctx->cmd.t_state_lock, flags);
15021492
break;
15031493
default:
15041494
printk(KERN_ERR "%s[%d]: opcode = %u\n", __func__,

‎drivers/target/target_core_tpg.c‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -654,9 +654,7 @@ static int core_tpg_setup_virtual_lun0(struct se_portal_group *se_tpg)
654654
atomic_set(&lun->lun_acl_count, 0);
655655
init_completion(&lun->lun_shutdown_comp);
656656
INIT_LIST_HEAD(&lun->lun_acl_list);
657-
INIT_LIST_HEAD(&lun->lun_cmd_list);
658657
spin_lock_init(&lun->lun_acl_lock);
659-
spin_lock_init(&lun->lun_cmd_lock);
660658
spin_lock_init(&lun->lun_sep_lock);
661659
init_completion(&lun->lun_ref_comp);
662660

@@ -706,9 +704,7 @@ int core_tpg_register(
706704
atomic_set(&lun->lun_acl_count, 0);
707705
init_completion(&lun->lun_shutdown_comp);
708706
INIT_LIST_HEAD(&lun->lun_acl_list);
709-
INIT_LIST_HEAD(&lun->lun_cmd_list);
710707
spin_lock_init(&lun->lun_acl_lock);
711-
spin_lock_init(&lun->lun_cmd_lock);
712708
spin_lock_init(&lun->lun_sep_lock);
713709
init_completion(&lun->lun_ref_comp);
714710
}
@@ -849,14 +845,6 @@ int core_tpg_post_addlun(
849845
return 0;
850846
}
851847

852-
static void core_tpg_shutdown_lun(
853-
struct se_portal_group *tpg,
854-
struct se_lun *lun)
855-
{
856-
core_clear_lun_from_tpg(lun, tpg);
857-
transport_clear_lun_ref(lun);
858-
}
859-
860848
struct se_lun *core_tpg_pre_dellun(
861849
struct se_portal_group *tpg,
862850
u32 unpacked_lun)
@@ -891,7 +879,8 @@ int core_tpg_post_dellun(
891879
struct se_portal_group *tpg,
892880
struct se_lun *lun)
893881
{
894-
core_tpg_shutdown_lun(tpg, lun);
882+
core_clear_lun_from_tpg(lun, tpg);
883+
transport_clear_lun_ref(lun);
895884

896885
core_dev_unexport(lun->lun_se_dev, tpg, lun);
897886

‎drivers/target/target_core_transport.c‎

Lines changed: 2 additions & 217 deletions
Original file line numberDiff line numberDiff line change
@@ -505,23 +505,6 @@ static int transport_cmd_check_stop(struct se_cmd *cmd, bool remove_from_lists,
505505
if (write_pending)
506506
cmd->t_state = TRANSPORT_WRITE_PENDING;
507507

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-
525508
if (remove_from_lists) {
526509
target_remove_from_state_list(cmd);
527510

@@ -1078,13 +1061,10 @@ void transport_init_se_cmd(
10781061
int task_attr,
10791062
unsigned char *sense_buffer)
10801063
{
1081-
INIT_LIST_HEAD(&cmd->se_lun_node);
10821064
INIT_LIST_HEAD(&cmd->se_delayed_node);
10831065
INIT_LIST_HEAD(&cmd->se_qf_node);
10841066
INIT_LIST_HEAD(&cmd->se_cmd_list);
10851067
INIT_LIST_HEAD(&cmd->state_list);
1086-
init_completion(&cmd->transport_lun_fe_stop_comp);
1087-
init_completion(&cmd->transport_lun_stop_comp);
10881068
init_completion(&cmd->t_transport_stop_comp);
10891069
init_completion(&cmd->cmd_wait_comp);
10901070
init_completion(&cmd->task_stop_comp);
@@ -1705,29 +1685,14 @@ void target_execute_cmd(struct se_cmd *cmd)
17051685
/*
17061686
* If the received CDB has aleady been aborted stop processing it here.
17071687
*/
1708-
if (transport_check_aborted_status(cmd, 1)) {
1709-
complete(&cmd->transport_lun_stop_comp);
1688+
if (transport_check_aborted_status(cmd, 1))
17101689
return;
1711-
}
17121690

1713-
/*
1714-
* Determine if IOCTL context caller in requesting the stopping of this
1715-
* command for LUN shutdown purposes.
1716-
*/
1717-
spin_lock_irq(&cmd->t_state_lock);
1718-
if (cmd->transport_state & CMD_T_LUN_STOP) {
1719-
pr_debug("%s:%d CMD_T_LUN_STOP for ITT: 0x%08x\n",
1720-
__func__, __LINE__, cmd->se_tfo->get_task_tag(cmd));
1721-
1722-
cmd->transport_state &= ~CMD_T_ACTIVE;
1723-
spin_unlock_irq(&cmd->t_state_lock);
1724-
complete(&cmd->transport_lun_stop_comp);
1725-
return;
1726-
}
17271691
/*
17281692
* Determine if frontend context caller is requesting the stopping of
17291693
* this command for frontend exceptions.
17301694
*/
1695+
spin_lock_irq(&cmd->t_state_lock);
17311696
if (cmd->transport_state & CMD_T_STOP) {
17321697
pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08x\n",
17331698
__func__, __LINE__,
@@ -2390,149 +2355,6 @@ void target_wait_for_sess_cmds(struct se_session *se_sess)
23902355
}
23912356
EXPORT_SYMBOL(target_wait_for_sess_cmds);
23922357

2393-
/* transport_lun_wait_for_tasks():
2394-
*
2395-
* Called from ConfigFS context to stop the passed struct se_cmd to allow
2396-
* an struct se_lun to be successfully shutdown.
2397-
*/
2398-
static int transport_lun_wait_for_tasks(struct se_cmd *cmd, struct se_lun *lun)
2399-
{
2400-
unsigned long flags;
2401-
int ret = 0;
2402-
2403-
/*
2404-
* If the frontend has already requested this struct se_cmd to
2405-
* be stopped, we can safely ignore this struct se_cmd.
2406-
*/
2407-
spin_lock_irqsave(&cmd->t_state_lock, flags);
2408-
if (cmd->transport_state & CMD_T_STOP) {
2409-
cmd->transport_state &= ~CMD_T_LUN_STOP;
2410-
2411-
pr_debug("ConfigFS ITT[0x%08x] - CMD_T_STOP, skipping\n",
2412-
cmd->se_tfo->get_task_tag(cmd));
2413-
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2414-
transport_cmd_check_stop(cmd, false, false);
2415-
return -EPERM;
2416-
}
2417-
cmd->transport_state |= CMD_T_LUN_FE_STOP;
2418-
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2419-
2420-
// XXX: audit task_flags checks.
2421-
spin_lock_irqsave(&cmd->t_state_lock, flags);
2422-
if ((cmd->transport_state & CMD_T_BUSY) &&
2423-
(cmd->transport_state & CMD_T_SENT)) {
2424-
if (!target_stop_cmd(cmd, &flags))
2425-
ret++;
2426-
}
2427-
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2428-
2429-
pr_debug("ConfigFS: cmd: %p stop tasks ret:"
2430-
" %d\n", cmd, ret);
2431-
if (!ret) {
2432-
pr_debug("ConfigFS: ITT[0x%08x] - stopping cmd....\n",
2433-
cmd->se_tfo->get_task_tag(cmd));
2434-
wait_for_completion(&cmd->transport_lun_stop_comp);
2435-
pr_debug("ConfigFS: ITT[0x%08x] - stopped cmd....\n",
2436-
cmd->se_tfo->get_task_tag(cmd));
2437-
}
2438-
2439-
return 0;
2440-
}
2441-
2442-
static void __transport_clear_lun_from_sessions(struct se_lun *lun)
2443-
{
2444-
struct se_cmd *cmd = NULL;
2445-
unsigned long lun_flags, cmd_flags;
2446-
/*
2447-
* Do exception processing and return CHECK_CONDITION status to the
2448-
* Initiator Port.
2449-
*/
2450-
spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags);
2451-
while (!list_empty(&lun->lun_cmd_list)) {
2452-
cmd = list_first_entry(&lun->lun_cmd_list,
2453-
struct se_cmd, se_lun_node);
2454-
list_del_init(&cmd->se_lun_node);
2455-
2456-
spin_lock(&cmd->t_state_lock);
2457-
pr_debug("SE_LUN[%d] - Setting cmd->transport"
2458-
"_lun_stop for ITT: 0x%08x\n",
2459-
cmd->se_lun->unpacked_lun,
2460-
cmd->se_tfo->get_task_tag(cmd));
2461-
cmd->transport_state |= CMD_T_LUN_STOP;
2462-
spin_unlock(&cmd->t_state_lock);
2463-
2464-
spin_unlock_irqrestore(&lun->lun_cmd_lock, lun_flags);
2465-
2466-
if (!cmd->se_lun) {
2467-
pr_err("ITT: 0x%08x, [i,t]_state: %u/%u\n",
2468-
cmd->se_tfo->get_task_tag(cmd),
2469-
cmd->se_tfo->get_cmd_state(cmd), cmd->t_state);
2470-
BUG();
2471-
}
2472-
/*
2473-
* If the Storage engine still owns the iscsi_cmd_t, determine
2474-
* and/or stop its context.
2475-
*/
2476-
pr_debug("SE_LUN[%d] - ITT: 0x%08x before transport"
2477-
"_lun_wait_for_tasks()\n", cmd->se_lun->unpacked_lun,
2478-
cmd->se_tfo->get_task_tag(cmd));
2479-
2480-
if (transport_lun_wait_for_tasks(cmd, cmd->se_lun) < 0) {
2481-
spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags);
2482-
continue;
2483-
}
2484-
2485-
pr_debug("SE_LUN[%d] - ITT: 0x%08x after transport_lun"
2486-
"_wait_for_tasks(): SUCCESS\n",
2487-
cmd->se_lun->unpacked_lun,
2488-
cmd->se_tfo->get_task_tag(cmd));
2489-
2490-
spin_lock_irqsave(&cmd->t_state_lock, cmd_flags);
2491-
if (!(cmd->transport_state & CMD_T_DEV_ACTIVE)) {
2492-
spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags);
2493-
goto check_cond;
2494-
}
2495-
cmd->transport_state &= ~CMD_T_DEV_ACTIVE;
2496-
target_remove_from_state_list(cmd);
2497-
spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags);
2498-
2499-
/*
2500-
* The Storage engine stopped this struct se_cmd before it was
2501-
* send to the fabric frontend for delivery back to the
2502-
* Initiator Node. Return this SCSI CDB back with an
2503-
* CHECK_CONDITION status.
2504-
*/
2505-
check_cond:
2506-
transport_send_check_condition_and_sense(cmd,
2507-
TCM_NON_EXISTENT_LUN, 0);
2508-
/*
2509-
* If the fabric frontend is waiting for this iscsi_cmd_t to
2510-
* be released, notify the waiting thread now that LU has
2511-
* finished accessing it.
2512-
*/
2513-
spin_lock_irqsave(&cmd->t_state_lock, cmd_flags);
2514-
if (cmd->transport_state & CMD_T_LUN_FE_STOP) {
2515-
pr_debug("SE_LUN[%d] - Detected FE stop for"
2516-
" struct se_cmd: %p ITT: 0x%08x\n",
2517-
lun->unpacked_lun,
2518-
cmd, cmd->se_tfo->get_task_tag(cmd));
2519-
2520-
spin_unlock_irqrestore(&cmd->t_state_lock,
2521-
cmd_flags);
2522-
transport_cmd_check_stop(cmd, false, false);
2523-
complete(&cmd->transport_lun_fe_stop_comp);
2524-
spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags);
2525-
continue;
2526-
}
2527-
pr_debug("SE_LUN[%d] - ITT: 0x%08x finished processing\n",
2528-
lun->unpacked_lun, cmd->se_tfo->get_task_tag(cmd));
2529-
2530-
spin_unlock_irqrestore(&cmd->t_state_lock, cmd_flags);
2531-
spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags);
2532-
}
2533-
spin_unlock_irqrestore(&lun->lun_cmd_lock, lun_flags);
2534-
}
2535-
25362358
static int transport_clear_lun_ref_thread(void *p)
25372359
{
25382360
struct se_lun *lun = p;
@@ -2583,43 +2405,6 @@ bool transport_wait_for_tasks(struct se_cmd *cmd)
25832405
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
25842406
return false;
25852407
}
2586-
/*
2587-
* If we are already stopped due to an external event (ie: LUN shutdown)
2588-
* sleep until the connection can have the passed struct se_cmd back.
2589-
* The cmd->transport_lun_stopped_sem will be upped by
2590-
* transport_clear_lun_from_sessions() once the ConfigFS context caller
2591-
* has completed its operation on the struct se_cmd.
2592-
*/
2593-
if (cmd->transport_state & CMD_T_LUN_STOP) {
2594-
pr_debug("wait_for_tasks: Stopping"
2595-
" wait_for_completion(&cmd->t_tasktransport_lun_fe"
2596-
"_stop_comp); for ITT: 0x%08x\n",
2597-
cmd->se_tfo->get_task_tag(cmd));
2598-
/*
2599-
* There is a special case for WRITES where a FE exception +
2600-
* LUN shutdown means ConfigFS context is still sleeping on
2601-
* transport_lun_stop_comp in transport_lun_wait_for_tasks().
2602-
* We go ahead and up transport_lun_stop_comp just to be sure
2603-
* here.
2604-
*/
2605-
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2606-
complete(&cmd->transport_lun_stop_comp);
2607-
wait_for_completion(&cmd->transport_lun_fe_stop_comp);
2608-
spin_lock_irqsave(&cmd->t_state_lock, flags);
2609-
2610-
target_remove_from_state_list(cmd);
2611-
/*
2612-
* At this point, the frontend who was the originator of this
2613-
* struct se_cmd, now owns the structure and can be released through
2614-
* normal means below.
2615-
*/
2616-
pr_debug("wait_for_tasks: Stopped"
2617-
" wait_for_completion(&cmd->t_tasktransport_lun_fe_"
2618-
"stop_comp); for ITT: 0x%08x\n",
2619-
cmd->se_tfo->get_task_tag(cmd));
2620-
2621-
cmd->transport_state &= ~CMD_T_LUN_STOP;
2622-
}
26232408

26242409
if (!(cmd->transport_state & CMD_T_ACTIVE)) {
26252410
spin_unlock_irqrestore(&cmd->t_state_lock, flags);

‎drivers/target/target_core_xcopy.c‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,10 +574,8 @@ static int target_xcopy_init_pt_lun(
574574
return -ENOMEM;
575575
}
576576
init_completion(&pt_cmd->se_lun->lun_shutdown_comp);
577-
INIT_LIST_HEAD(&pt_cmd->se_lun->lun_cmd_list);
578577
INIT_LIST_HEAD(&pt_cmd->se_lun->lun_acl_list);
579578
spin_lock_init(&pt_cmd->se_lun->lun_acl_lock);
580-
spin_lock_init(&pt_cmd->se_lun->lun_cmd_lock);
581579
spin_lock_init(&pt_cmd->se_lun->lun_sep_lock);
582580
init_completion(&pt_cmd->se_lun->lun_ref_comp);
583581

‎include/target/target_core_base.h‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,6 @@ struct se_cmd {
443443
/* Used for sense data */
444444
void *sense_buffer;
445445
struct list_head se_delayed_node;
446-
struct list_head se_lun_node;
447446
struct list_head se_qf_node;
448447
struct se_device *se_dev;
449448
struct se_dev_entry *se_deve;
@@ -471,15 +470,11 @@ struct se_cmd {
471470
#define CMD_T_SENT (1 << 4)
472471
#define CMD_T_STOP (1 << 5)
473472
#define CMD_T_FAILED (1 << 6)
474-
#define CMD_T_LUN_STOP (1 << 7)
475-
#define CMD_T_LUN_FE_STOP (1 << 8)
476-
#define CMD_T_DEV_ACTIVE (1 << 9)
477-
#define CMD_T_REQUEST_STOP (1 << 10)
478-
#define CMD_T_BUSY (1 << 11)
473+
#define CMD_T_DEV_ACTIVE (1 << 7)
474+
#define CMD_T_REQUEST_STOP (1 << 8)
475+
#define CMD_T_BUSY (1 << 9)
479476
spinlock_t t_state_lock;
480477
struct completion t_transport_stop_comp;
481-
struct completion transport_lun_fe_stop_comp;
482-
struct completion transport_lun_stop_comp;
483478

484479
struct work_struct work;
485480

@@ -751,10 +746,8 @@ struct se_lun {
751746
u32 unpacked_lun;
752747
atomic_t lun_acl_count;
753748
spinlock_t lun_acl_lock;
754-
spinlock_t lun_cmd_lock;
755749
spinlock_t lun_sep_lock;
756750
struct completion lun_shutdown_comp;
757-
struct list_head lun_cmd_list;
758751
struct list_head lun_acl_list;
759752
struct se_device *lun_se_dev;
760753
struct se_port *lun_sep;

0 commit comments

Comments
 (0)