aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/target
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@infradead.org>2012-07-08 15:58:38 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2012-07-16 20:35:15 -0400
commitf7113a47e2c3880ed5f8a05ff9c54ead4ee7351c (patch)
treeef1098a4177ea24ddc20f9ec81435633636e08e5 /drivers/target
parente85276871978614723830684096f7e44903963b3 (diff)
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: 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_transport.c124
1 files changed, 62 insertions, 62 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index 803ac5202fcd..3f20fbd88cd4 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -467,18 +467,7 @@ static void target_remove_from_state_list(struct se_cmd *cmd)
467 spin_unlock_irqrestore(&dev->execute_task_lock, flags); 467 spin_unlock_irqrestore(&dev->execute_task_lock, flags);
468} 468}
469 469
470/* transport_cmd_check_stop(): 470static int transport_cmd_check_stop(struct se_cmd *cmd, bool remove_from_lists)
471 *
472 * 'transport_off = 1' determines if CMD_T_ACTIVE should be cleared.
473 * 'transport_off = 2' determines if task_dev_state should be removed.
474 *
475 * A non-zero u8 t_state sets cmd->t_state.
476 * Returns 1 when command is stopped, else 0.
477 */
478static int transport_cmd_check_stop(
479 struct se_cmd *cmd,
480 int transport_off,
481 u8 t_state)
482{ 471{
483 unsigned long flags; 472 unsigned long flags;
484 473
@@ -492,13 +481,23 @@ static int transport_cmd_check_stop(
492 __func__, __LINE__, cmd->se_tfo->get_task_tag(cmd)); 481 __func__, __LINE__, cmd->se_tfo->get_task_tag(cmd));
493 482
494 cmd->transport_state &= ~CMD_T_ACTIVE; 483 cmd->transport_state &= ~CMD_T_ACTIVE;
495 if (transport_off == 2) 484 if (remove_from_lists)
496 target_remove_from_state_list(cmd); 485 target_remove_from_state_list(cmd);
497 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 486 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
498 487
499 complete(&cmd->transport_lun_stop_comp); 488 complete(&cmd->transport_lun_stop_comp);
500 return 1; 489 return 1;
501 } 490 }
491
492 if (remove_from_lists) {
493 target_remove_from_state_list(cmd);
494
495 /*
496 * Clear struct se_cmd->se_lun before the handoff to FE.
497 */
498 cmd->se_lun = NULL;
499 }
500
502 /* 501 /*
503 * Determine if frontend context caller is requesting the stopping of 502 * Determine if frontend context caller is requesting the stopping of
504 * this command for frontend exceptions. 503 * this command for frontend exceptions.
@@ -508,58 +507,36 @@ static int transport_cmd_check_stop(
508 __func__, __LINE__, 507 __func__, __LINE__,
509 cmd->se_tfo->get_task_tag(cmd)); 508 cmd->se_tfo->get_task_tag(cmd));
510 509
511 if (transport_off == 2)
512 target_remove_from_state_list(cmd);
513
514 /*
515 * Clear struct se_cmd->se_lun before the transport_off == 2 handoff
516 * to FE.
517 */
518 if (transport_off == 2)
519 cmd->se_lun = NULL;
520 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 510 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
521 511
522 complete(&cmd->t_transport_stop_comp); 512 complete(&cmd->t_transport_stop_comp);
523 return 1; 513 return 1;
524 } 514 }
525 if (transport_off) { 515
526 cmd->transport_state &= ~CMD_T_ACTIVE; 516 cmd->transport_state &= ~CMD_T_ACTIVE;
527 if (transport_off == 2) { 517 if (remove_from_lists) {
528 target_remove_from_state_list(cmd); 518 /*
529 /* 519 * Some fabric modules like tcm_loop can release
530 * Clear struct se_cmd->se_lun before the transport_off == 2 520 * their internally allocated I/O reference now and
531 * handoff to fabric module. 521 * struct se_cmd now.
532 */ 522 *
533 cmd->se_lun = NULL; 523 * Fabric modules are expected to return '1' here if the
534 /* 524 * se_cmd being passed is released at this point,
535 * Some fabric modules like tcm_loop can release 525 * or zero if not being released.
536 * their internally allocated I/O reference now and 526 */
537 * struct se_cmd now. 527 if (cmd->se_tfo->check_stop_free != NULL) {
538 * 528 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
539 * Fabric modules are expected to return '1' here if the 529 return cmd->se_tfo->check_stop_free(cmd);
540 * se_cmd being passed is released at this point,
541 * or zero if not being released.
542 */
543 if (cmd->se_tfo->check_stop_free != NULL) {
544 spin_unlock_irqrestore(
545 &cmd->t_state_lock, flags);
546
547 return cmd->se_tfo->check_stop_free(cmd);
548 }
549 } 530 }
550 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 531 }
551 532
552 return 0;
553 } else if (t_state)
554 cmd->t_state = t_state;
555 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 533 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
556
557 return 0; 534 return 0;
558} 535}
559 536
560static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) 537static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd)
561{ 538{
562 return transport_cmd_check_stop(cmd, 2, 0); 539 return transport_cmd_check_stop(cmd, true);
563} 540}
564 541
565static void transport_lun_remove_cmd(struct se_cmd *cmd) 542static void transport_lun_remove_cmd(struct se_cmd *cmd)
@@ -1887,8 +1864,36 @@ static void target_execute_cmd(struct se_cmd *cmd)
1887{ 1864{
1888 struct se_device *dev = cmd->se_dev; 1865 struct se_device *dev = cmd->se_dev;
1889 1866
1890 if (transport_cmd_check_stop(cmd, 0, TRANSPORT_PROCESSING)) 1867 /*
1868 * Determine if IOCTL context caller in requesting the stopping of this
1869 * command for LUN shutdown purposes.
1870 */
1871 spin_lock_irq(&cmd->t_state_lock);
1872 if (cmd->transport_state & CMD_T_LUN_STOP) {
1873 pr_debug("%s:%d CMD_T_LUN_STOP for ITT: 0x%08x\n",
1874 __func__, __LINE__, cmd->se_tfo->get_task_tag(cmd));
1875
1876 cmd->transport_state &= ~CMD_T_ACTIVE;
1877 spin_unlock_irq(&cmd->t_state_lock);
1878 complete(&cmd->transport_lun_stop_comp);
1879 return;
1880 }
1881 /*
1882 * Determine if frontend context caller is requesting the stopping of
1883 * this command for frontend exceptions.
1884 */
1885 if (cmd->transport_state & CMD_T_STOP) {
1886 pr_debug("%s:%d CMD_T_STOP for ITT: 0x%08x\n",
1887 __func__, __LINE__,
1888 cmd->se_tfo->get_task_tag(cmd));
1889
1890 spin_unlock_irq(&cmd->t_state_lock);
1891 complete(&cmd->t_transport_stop_comp);
1891 return; 1892 return;
1893 }
1894
1895 cmd->t_state = TRANSPORT_PROCESSING;
1896 spin_unlock_irq(&cmd->t_state_lock);
1892 1897
1893 if (dev->dev_task_attr_type != SAM_TASK_ATTR_EMULATED) 1898 if (dev->dev_task_attr_type != SAM_TASK_ATTR_EMULATED)
1894 goto execute; 1899 goto execute;
@@ -2530,10 +2535,10 @@ static int transport_generic_write_pending(struct se_cmd *cmd)
2530 * Clear the se_cmd for WRITE_PENDING status in order to set 2535 * Clear the se_cmd for WRITE_PENDING status in order to set
2531 * CMD_T_ACTIVE so that transport_generic_handle_data can be called 2536 * CMD_T_ACTIVE so that transport_generic_handle_data can be called
2532 * from HW target mode interrupt code. This is safe to be called 2537 * from HW target mode interrupt code. This is safe to be called
2533 * with transport_off=1 before the cmd->se_tfo->write_pending 2538 * with remove_from_lists false before the cmd->se_tfo->write_pending
2534 * because the se_cmd->se_lun pointer is not being cleared. 2539 * because the se_cmd->se_lun pointer is not being cleared.
2535 */ 2540 */
2536 transport_cmd_check_stop(cmd, 1, 0); 2541 transport_cmd_check_stop(cmd, false);
2537 2542
2538 /* 2543 /*
2539 * Call the fabric write_pending function here to let the 2544 * 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 pr_debug("ConfigFS ITT[0x%08x] - CMD_T_STOP, skipping\n", 2728 pr_debug("ConfigFS ITT[0x%08x] - CMD_T_STOP, skipping\n",
2724 cmd->se_tfo->get_task_tag(cmd)); 2729 cmd->se_tfo->get_task_tag(cmd));
2725 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 2730 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
2726 transport_cmd_check_stop(cmd, 1, 0); 2731 transport_cmd_check_stop(cmd, false);
2727 return -EPERM; 2732 return -EPERM;
2728 } 2733 }
2729 cmd->transport_state |= CMD_T_LUN_FE_STOP; 2734 cmd->transport_state |= CMD_T_LUN_FE_STOP;
@@ -2768,11 +2773,6 @@ static void __transport_clear_lun_from_sessions(struct se_lun *lun)
2768 struct se_cmd, se_lun_node); 2773 struct se_cmd, se_lun_node);
2769 list_del_init(&cmd->se_lun_node); 2774 list_del_init(&cmd->se_lun_node);
2770 2775
2771 /*
2772 * This will notify iscsi_target_transport.c:
2773 * transport_cmd_check_stop() that a LUN shutdown is in
2774 * progress for the iscsi_cmd_t.
2775 */
2776 spin_lock(&cmd->t_state_lock); 2776 spin_lock(&cmd->t_state_lock);
2777 pr_debug("SE_LUN[%d] - Setting cmd->transport" 2777 pr_debug("SE_LUN[%d] - Setting cmd->transport"
2778 "_lun_stop for ITT: 0x%08x\n", 2778 "_lun_stop for ITT: 0x%08x\n",
@@ -2839,7 +2839,7 @@ check_cond:
2839 2839
2840 spin_unlock_irqrestore(&cmd->t_state_lock, 2840 spin_unlock_irqrestore(&cmd->t_state_lock,
2841 cmd_flags); 2841 cmd_flags);
2842 transport_cmd_check_stop(cmd, 1, 0); 2842 transport_cmd_check_stop(cmd, false);
2843 complete(&cmd->transport_lun_fe_stop_comp); 2843 complete(&cmd->transport_lun_fe_stop_comp);
2844 spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags); 2844 spin_lock_irqsave(&lun->lun_cmd_lock, lun_flags);
2845 continue; 2845 continue;