Commit 4911e3cc authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Nicholas Bellinger

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: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarNicholas Bellinger <nab@linux-iscsi.org>
parent d3df7825
...@@ -3732,36 +3732,6 @@ static inline void transport_free_pages(struct se_cmd *cmd) ...@@ -3732,36 +3732,6 @@ static inline void transport_free_pages(struct se_cmd *cmd)
cmd->t_bidi_data_nents = 0; cmd->t_bidi_data_nents = 0;
} }
static inline void transport_release_tasks(struct se_cmd *cmd)
{
transport_free_dev_tasks(cmd);
}
static inline int transport_dec_and_check(struct se_cmd *cmd)
{
unsigned long flags;
spin_lock_irqsave(&cmd->t_state_lock, flags);
if (atomic_read(&cmd->t_fe_count)) {
if (!atomic_dec_and_test(&cmd->t_fe_count)) {
spin_unlock_irqrestore(&cmd->t_state_lock,
flags);
return 1;
}
}
if (atomic_read(&cmd->t_se_count)) {
if (!atomic_dec_and_test(&cmd->t_se_count)) {
spin_unlock_irqrestore(&cmd->t_state_lock,
flags);
return 1;
}
}
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
return 0;
}
/** /**
* transport_put_cmd - release a reference to a command * transport_put_cmd - release a reference to a command
* @cmd: command to release * @cmd: command to release
...@@ -3771,26 +3741,35 @@ static inline int transport_dec_and_check(struct se_cmd *cmd) ...@@ -3771,26 +3741,35 @@ static inline int transport_dec_and_check(struct se_cmd *cmd)
static bool transport_put_cmd(struct se_cmd *cmd) static bool transport_put_cmd(struct se_cmd *cmd)
{ {
unsigned long flags; unsigned long flags;
int free_tasks = 0;
if (transport_dec_and_check(cmd))
return false;
spin_lock_irqsave(&cmd->t_state_lock, flags); spin_lock_irqsave(&cmd->t_state_lock, flags);
if (!atomic_read(&cmd->transport_dev_active)) { if (atomic_read(&cmd->t_fe_count)) {
spin_unlock_irqrestore(&cmd->t_state_lock, flags); if (!atomic_dec_and_test(&cmd->t_fe_count))
goto free_pages; goto out_busy;
}
if (atomic_read(&cmd->t_se_count)) {
if (!atomic_dec_and_test(&cmd->t_se_count))
goto out_busy;
}
if (atomic_read(&cmd->transport_dev_active)) {
atomic_set(&cmd->transport_dev_active, 0);
transport_all_task_dev_remove_state(cmd);
free_tasks = 1;
} }
atomic_set(&cmd->transport_dev_active, 0);
transport_all_task_dev_remove_state(cmd);
spin_unlock_irqrestore(&cmd->t_state_lock, flags); spin_unlock_irqrestore(&cmd->t_state_lock, flags);
transport_release_tasks(cmd); if (free_tasks != 0)
return true; transport_free_dev_tasks(cmd);
free_pages:
transport_free_pages(cmd); transport_free_pages(cmd);
transport_release_cmd(cmd); transport_release_cmd(cmd);
return true; return true;
out_busy:
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
return false;
} }
static int static int
......
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