Commit f7113a47 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Nicholas Bellinger

target: split transport_cmd_check_stop

Inline the transport_off == 0 case into target_execute_cmd to simplify
the function for the remaining cases.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent e8527687
...@@ -467,18 +467,7 @@ static void target_remove_from_state_list(struct se_cmd *cmd) ...@@ -467,18 +467,7 @@ static void target_remove_from_state_list(struct se_cmd *cmd)
spin_unlock_irqrestore(&dev->execute_task_lock, flags); spin_unlock_irqrestore(&dev->execute_task_lock, flags);
} }
/* transport_cmd_check_stop(): static int transport_cmd_check_stop(struct se_cmd *cmd, bool remove_from_lists)
*
* 'transport_off = 1' determines if CMD_T_ACTIVE should be cleared.
* 'transport_off = 2' determines if task_dev_state should be removed.
*
* A non-zero u8 t_state sets cmd->t_state.
* Returns 1 when command is stopped, else 0.
*/
static int transport_cmd_check_stop(
struct se_cmd *cmd,
int transport_off,
u8 t_state)
{ {
unsigned long flags; unsigned long flags;
...@@ -492,13 +481,23 @@ static int transport_cmd_check_stop( ...@@ -492,13 +481,23 @@ static int transport_cmd_check_stop(
__func__, __LINE__, cmd->se_tfo->get_task_tag(cmd)); __func__, __LINE__, cmd->se_tfo->get_task_tag(cmd));
cmd->transport_state &= ~CMD_T_ACTIVE; cmd->transport_state &= ~CMD_T_ACTIVE;
if (transport_off == 2) if (remove_from_lists)
target_remove_from_state_list(cmd); target_remove_from_state_list(cmd);
spin_unlock_irqrestore(&cmd->t_state_lock, flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags);
complete(&cmd->transport_lun_stop_comp); complete(&cmd->transport_lun_stop_comp);
return 1; return 1;
} }
if (remove_from_lists) {
target_remove_from_state_list(cmd);
/*
* Clear struct se_cmd->se_lun before the handoff to FE.
*/
cmd->se_lun = NULL;
}
/* /*
* Determine if frontend context caller is requesting the stopping of * Determine if frontend context caller is requesting the stopping of
* this command for frontend exceptions. * this command for frontend exceptions.
...@@ -508,29 +507,14 @@ static int transport_cmd_check_stop( ...@@ -508,29 +507,14 @@ static int transport_cmd_check_stop(
__func__, __LINE__, __func__, __LINE__,
cmd->se_tfo->get_task_tag(cmd)); cmd->se_tfo->get_task_tag(cmd));
if (transport_off == 2)
target_remove_from_state_list(cmd);
/*
* Clear struct se_cmd->se_lun before the transport_off == 2 handoff
* to FE.
*/
if (transport_off == 2)
cmd->se_lun = NULL;
spin_unlock_irqrestore(&cmd->t_state_lock, flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags);
complete(&cmd->t_transport_stop_comp); complete(&cmd->t_transport_stop_comp);
return 1; return 1;
} }
if (transport_off) {
cmd->transport_state &= ~CMD_T_ACTIVE; cmd->transport_state &= ~CMD_T_ACTIVE;
if (transport_off == 2) { if (remove_from_lists) {
target_remove_from_state_list(cmd);
/*
* Clear struct se_cmd->se_lun before the transport_off == 2
* handoff to fabric module.
*/
cmd->se_lun = NULL;
/* /*
* Some fabric modules like tcm_loop can release * Some fabric modules like tcm_loop can release
* their internally allocated I/O reference now and * their internally allocated I/O reference now and
...@@ -541,25 +525,18 @@ static int transport_cmd_check_stop( ...@@ -541,25 +525,18 @@ static int transport_cmd_check_stop(
* or zero if not being released. * or zero if not being released.
*/ */
if (cmd->se_tfo->check_stop_free != NULL) { if (cmd->se_tfo->check_stop_free != NULL) {
spin_unlock_irqrestore( spin_unlock_irqrestore(&cmd->t_state_lock, flags);
&cmd->t_state_lock, flags);
return cmd->se_tfo->check_stop_free(cmd); return cmd->se_tfo->check_stop_free(cmd);
} }
} }
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
return 0;
} else if (t_state)
cmd->t_state = t_state;
spin_unlock_irqrestore(&cmd->t_state_lock, flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags);
return 0; return 0;
} }
static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd)
{ {
return transport_cmd_check_stop(cmd, 2, 0); return transport_cmd_check_stop(cmd, true);
} }
static void transport_lun_remove_cmd(struct se_cmd *cmd) static void transport_lun_remove_cmd(struct se_cmd *cmd)
...@@ -1887,8 +1864,36 @@ static void target_execute_cmd(struct se_cmd *cmd) ...@@ -1887,8 +1864,36 @@ static void target_execute_cmd(struct se_cmd *cmd)
{ {
struct se_device *dev = cmd->se_dev; struct se_device *dev = cmd->se_dev;
if (transport_cmd_check_stop(cmd, 0, TRANSPORT_PROCESSING)) /*
* Determine if IOCTL context caller in requesting the stopping of this
* command for LUN shutdown purposes.
*/
spin_lock_irq(&cmd->t_state_lock);
if (cmd->transport_state & CMD_T_LUN_STOP) {
pr_debug("%s:%d CMD_T_LUN_STOP for ITT: 0x%08x\n",
__func__, __LINE__, cmd->se_tfo->get_task_tag(cmd));
cmd->transport_state &= ~CMD_T_ACTIVE;
spin_unlock_irq(&cmd->t_state_lock);
complete(&cmd->transport_lun_stop_comp);
return; return;
}
/*
* Determine if frontend context caller is requesting the stopping of
* this command for frontend exceptions.
*/
if (cmd->transport_state & CMD_T_STOP) {
pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08x\n",
__func__, __LINE__,
cmd->se_tfo->get_task_tag(cmd));
spin_unlock_irq(&cmd->t_state_lock);
complete(&cmd->t_transport_stop_comp);
return;
}
cmd->t_state = TRANSPORT_PROCESSING;
spin_unlock_irq(&cmd->t_state_lock);
if (dev->dev_task_attr_type != SAM_TASK_ATTR_EMULATED) if (dev->dev_task_attr_type != SAM_TASK_ATTR_EMULATED)
goto execute; goto execute;
...@@ -2530,10 +2535,10 @@ static int transport_generic_write_pending(struct se_cmd *cmd) ...@@ -2530,10 +2535,10 @@ static int transport_generic_write_pending(struct se_cmd *cmd)
* Clear the se_cmd for WRITE_PENDING status in order to set * Clear the se_cmd for WRITE_PENDING status in order to set
* CMD_T_ACTIVE so that transport_generic_handle_data can be called * CMD_T_ACTIVE so that transport_generic_handle_data can be called
* from HW target mode interrupt code. This is safe to be called * from HW target mode interrupt code. This is safe to be called
* with transport_off=1 before the cmd->se_tfo->write_pending * with remove_from_lists false before the cmd->se_tfo->write_pending
* because the se_cmd->se_lun pointer is not being cleared. * because the se_cmd->se_lun pointer is not being cleared.
*/ */
transport_cmd_check_stop(cmd, 1, 0); transport_cmd_check_stop(cmd, false);
/* /*
* Call the fabric write_pending function here to let the * Call the fabric write_pending function here to let the
...@@ -2723,7 +2728,7 @@ static int transport_lun_wait_for_tasks(struct se_cmd *cmd, struct se_lun *lun) ...@@ -2723,7 +2728,7 @@ static int transport_lun_wait_for_tasks(struct se_cmd *cmd, struct se_lun *lun)
pr_debug("ConfigFS ITT[0x%08x] - CMD_T_STOP, skipping\n", pr_debug("ConfigFS ITT[0x%08x] - CMD_T_STOP, skipping\n",
cmd->se_tfo->get_task_tag(cmd)); cmd->se_tfo->get_task_tag(cmd));
spin_unlock_irqrestore(&cmd->t_state_lock, flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags);
transport_cmd_check_stop(cmd, 1, 0); transport_cmd_check_stop(cmd, false);
return -EPERM; return -EPERM;
} }
cmd->transport_state |= CMD_T_LUN_FE_STOP; cmd->transport_state |= CMD_T_LUN_FE_STOP;
...@@ -2768,11 +2773,6 @@ static void __transport_clear_lun_from_sessions(struct se_lun *lun) ...@@ -2768,11 +2773,6 @@ static void __transport_clear_lun_from_sessions(struct se_lun *lun)
struct se_cmd, se_lun_node); struct se_cmd, se_lun_node);
list_del_init(&cmd->se_lun_node); list_del_init(&cmd->se_lun_node);
/*
* This will notify iscsi_target_transport.c:
* transport_cmd_check_stop() that a LUN shutdown is in
* progress for the iscsi_cmd_t.
*/
spin_lock(&cmd->t_state_lock); spin_lock(&cmd->t_state_lock);
pr_debug("SE_LUN[%d] - Setting cmd->transport" pr_debug("SE_LUN[%d] - Setting cmd->transport"
"_lun_stop for ITT: 0x%08x\n", "_lun_stop for ITT: 0x%08x\n",
...@@ -2839,7 +2839,7 @@ static void __transport_clear_lun_from_sessions(struct se_lun *lun) ...@@ -2839,7 +2839,7 @@ static void __transport_clear_lun_from_sessions(struct se_lun *lun)
spin_unlock_irqrestore(&cmd->t_state_lock, spin_unlock_irqrestore(&cmd->t_state_lock,
cmd_flags); cmd_flags);
transport_cmd_check_stop(cmd, 1, 0); transport_cmd_check_stop(cmd, false);
complete(&cmd->transport_lun_fe_stop_comp); complete(&cmd->transport_lun_fe_stop_comp);
spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags);
continue; continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment