aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2011-09-13 17:08:42 -0400
committerNicholas Bellinger <nab@linux-iscsi.org>2011-10-23 23:20:34 -0400
commit4911e3ccbec047ed1f728e19a70ad87729a3fb01 (patch)
tree710a5799da6c38843560b412b7918b7d3c63bf29
parentd3df7825aed2e69e12732f9e32ef9093b01302d8 (diff)
target: simplify transport_put_cmd
Inline two simple functions only used by it, and replace a goto with a simple if else construct. Note that the code moved from transport_dec_and_check seems fairly buggy - the atomic_read check on a variable where we'd do an atomic_dec_and_test looks racy if we'll ever get someone increment it without the lock held around them (which it looks like we do), and not decrementing the second counter if the first one doesn't hit zero also at least needs an explanation. (nab: Fix transport_put_cmd breakage) Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>
-rw-r--r--drivers/target/target_core_transport.c61
1 files changed, 20 insertions, 41 deletions
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index bee923fd5750..a650100d997a 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -3732,36 +3732,6 @@ static inline void transport_free_pages(struct se_cmd *cmd)
3732 cmd->t_bidi_data_nents = 0; 3732 cmd->t_bidi_data_nents = 0;
3733} 3733}
3734 3734
3735static inline void transport_release_tasks(struct se_cmd *cmd)
3736{
3737 transport_free_dev_tasks(cmd);
3738}
3739
3740static inline int transport_dec_and_check(struct se_cmd *cmd)
3741{
3742 unsigned long flags;
3743
3744 spin_lock_irqsave(&cmd->t_state_lock, flags);
3745 if (atomic_read(&cmd->t_fe_count)) {
3746 if (!atomic_dec_and_test(&cmd->t_fe_count)) {
3747 spin_unlock_irqrestore(&cmd->t_state_lock,
3748 flags);
3749 return 1;
3750 }
3751 }
3752
3753 if (atomic_read(&cmd->t_se_count)) {
3754 if (!atomic_dec_and_test(&cmd->t_se_count)) {
3755 spin_unlock_irqrestore(&cmd->t_state_lock,
3756 flags);
3757 return 1;
3758 }
3759 }
3760 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
3761
3762 return 0;
3763}
3764
3765/** 3735/**
3766 * transport_put_cmd - release a reference to a command 3736 * transport_put_cmd - release a reference to a command
3767 * @cmd: command to release 3737 * @cmd: command to release
@@ -3771,26 +3741,35 @@ static inline int transport_dec_and_check(struct se_cmd *cmd)
3771static bool transport_put_cmd(struct se_cmd *cmd) 3741static bool transport_put_cmd(struct se_cmd *cmd)
3772{ 3742{
3773 unsigned long flags; 3743 unsigned long flags;
3774 3744 int free_tasks = 0;
3775 if (transport_dec_and_check(cmd))
3776 return false;
3777 3745
3778 spin_lock_irqsave(&cmd->t_state_lock, flags); 3746 spin_lock_irqsave(&cmd->t_state_lock, flags);
3779 if (!atomic_read(&cmd->transport_dev_active)) { 3747 if (atomic_read(&cmd->t_fe_count)) {
3780 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 3748 if (!atomic_dec_and_test(&cmd->t_fe_count))
3781 goto free_pages; 3749 goto out_busy;
3750 }
3751
3752 if (atomic_read(&cmd->t_se_count)) {
3753 if (!atomic_dec_and_test(&cmd->t_se_count))
3754 goto out_busy;
3755 }
3756
3757 if (atomic_read(&cmd->transport_dev_active)) {
3758 atomic_set(&cmd->transport_dev_active, 0);
3759 transport_all_task_dev_remove_state(cmd);
3760 free_tasks = 1;
3782 } 3761 }
3783 atomic_set(&cmd->transport_dev_active, 0);
3784 transport_all_task_dev_remove_state(cmd);
3785 spin_unlock_irqrestore(&cmd->t_state_lock, flags); 3762 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
3786 3763
3787 transport_release_tasks(cmd); 3764 if (free_tasks != 0)
3788 return true; 3765 transport_free_dev_tasks(cmd);
3789 3766
3790free_pages:
3791 transport_free_pages(cmd); 3767 transport_free_pages(cmd);
3792 transport_release_cmd(cmd); 3768 transport_release_cmd(cmd);
3793 return true; 3769 return true;
3770out_busy:
3771 spin_unlock_irqrestore(&cmd->t_state_lock, flags);
3772 return false;
3794} 3773}
3795 3774
3796static int 3775static int