aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2011-10-17 13:56:46 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2011-10-23 23:21:41 -0400
commitcdbb70bb4c17dad0ee23a357030021892a0f60f0 (patch)
tree8387550cc921a1fb92de73b455b25fdd3cc98e92 /drivers/target
parent0c2cfe5fe78e682d6235a1d32a363460b1c77528 (diff)
target: factor some duplicate code for stopping a task
Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
Diffstat (limited to 'drivers/target')
-rw-r--r--drivers/target/target_core_tmr.c19
-rw-r--r--drivers/target/target_core_transport.c47
2 files changed, 30 insertions, 36 deletions
diff --git a/drivers/target/target_core_tmr.c b/drivers/target/target_core_tmr.c
index b8a780fff367..4e963da74a0d 100644
--- a/drivers/target/target_core_tmr.c
+++ b/drivers/target/target_core_tmr.c
@@ -236,7 +236,6 @@ static void core_tmr_drain_task_list(
236 list_del(&task->t_state_list); 236 list_del(&task->t_state_list);
237 cmd = task->task_se_cmd; 237 cmd = task->task_se_cmd;
238 238
239 spin_lock_irqsave(&cmd->t_state_lock, flags);
240 pr_debug("LUN_RESET: %s cmd: %p task: %p" 239 pr_debug("LUN_RESET: %s cmd: %p task: %p"
241 " ITT/CmdSN: 0x%08x/0x%08x, i_state: %d, t_state/" 240 " ITT/CmdSN: 0x%08x/0x%08x, i_state: %d, t_state/"
242 "def_t_state: %d/%d cdb: 0x%02x\n", 241 "def_t_state: %d/%d cdb: 0x%02x\n",
@@ -256,22 +255,8 @@ static void core_tmr_drain_task_list(
256 atomic_read(&cmd->t_transport_stop), 255 atomic_read(&cmd->t_transport_stop),
257 atomic_read(&cmd->t_transport_sent)); 256 atomic_read(&cmd->t_transport_sent));
258 257
259 if (task->task_flags & TF_ACTIVE) { 258 spin_lock_irqsave(&cmd->t_state_lock, flags);
260 task->task_flags |= TF_REQUEST_STOP; 259 target_stop_task(task, &flags);
261 spin_unlock_irqrestore(
262 &cmd->t_state_lock, flags);
263
264 pr_debug("LUN_RESET: Waiting for task: %p to shutdown"
265 " for dev: %p\n", task, dev);
266 wait_for_completion(&task->task_stop_comp);
267 pr_debug("LUN_RESET Completed task: %p shutdown for"
268 " dev: %p\n", task, dev);
269
270 spin_lock_irqsave(&cmd->t_state_lock, flags);
271 atomic_dec(&cmd->t_task_cdbs_left);
272 task->task_flags &= ~(TF_ACTIVE | TF_REQUEST_STOP);
273 }
274 __transport_stop_task_timer(task, &flags);
275 260
276 if (!atomic_dec_and_test(&cmd->t_task_cdbs_ex_left)) { 261 if (!atomic_dec_and_test(&cmd->t_task_cdbs_ex_left)) {
277 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 262 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 4dc492d6ae1b..6dab8198ace8 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -1762,6 +1762,33 @@ void transport_generic_free_cmd_intr(
1762} 1762}
1763EXPORT_SYMBOL(transport_generic_free_cmd_intr); 1763EXPORT_SYMBOL(transport_generic_free_cmd_intr);
1764 1764
1765/*
1766 * If the task is active, request it to be stopped and sleep until it
1767 * has completed.
1768 */
1769bool target_stop_task(struct se_task *task, unsigned long *flags)
1770{
1771 struct se_cmd *cmd = task->task_se_cmd;
1772 bool was_active = false;
1773
1774 if (task->task_flags & TF_ACTIVE) {
1775 task->task_flags |= TF_REQUEST_STOP;
1776 spin_unlock_irqrestore(&cmd->t_state_lock, *flags);
1777
1778 pr_debug("Task %p waiting to complete\n", task);
1779 wait_for_completion(&task->task_stop_comp);
1780 pr_debug("Task %p stopped successfully\n", task);
1781
1782 spin_lock_irqsave(&cmd->t_state_lock, *flags);
1783 atomic_dec(&cmd->t_task_cdbs_left);
1784 task->task_flags &= ~(TF_ACTIVE | TF_REQUEST_STOP);
1785 was_active = true;
1786 }
1787
1788 __transport_stop_task_timer(task, flags);
1789 return was_active;
1790}
1791
1765static int transport_stop_tasks_for_cmd(struct se_cmd *cmd) 1792static int transport_stop_tasks_for_cmd(struct se_cmd *cmd)
1766{ 1793{
1767 struct se_task *task, *task_tmp; 1794 struct se_task *task, *task_tmp;
@@ -1793,28 +1820,10 @@ static int transport_stop_tasks_for_cmd(struct se_cmd *cmd)
1793 continue; 1820 continue;
1794 } 1821 }
1795 1822
1796 /* 1823 if (!target_stop_task(task, &flags)) {
1797 * If the struct se_task is active, sleep until it is returned
1798 * from the plugin.
1799 */
1800 if (task->task_flags & TF_ACTIVE) {
1801 task->task_flags |= TF_REQUEST_STOP;
1802 spin_unlock_irqrestore(&cmd->t_state_lock,
1803 flags);
1804
1805 pr_debug("Task %p waiting to complete\n", task);
1806 wait_for_completion(&task->task_stop_comp);
1807 pr_debug("Task %p stopped successfully\n", task);
1808
1809 spin_lock_irqsave(&cmd->t_state_lock, flags);
1810 atomic_dec(&cmd->t_task_cdbs_left);
1811 task->task_flags &= ~(TF_ACTIVE | TF_REQUEST_STOP);
1812 } else {
1813 pr_debug("Task %p - did nothing\n", task); 1824 pr_debug("Task %p - did nothing\n", task);
1814 ret++; 1825 ret++;
1815 } 1826 }
1816
1817 __transport_stop_task_timer(task, &flags);
1818 } 1827 }
1819 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 1828 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
1820 1829