Skip to content

Commit 7b2cc7d

Browse files
KAGA-KOKOmartinkpetersen
authored andcommitted
scsi: target: Simplify the code for waiting for command completion
Instead of embedding the completion that is used for waiting for command completion in struct se_cmd, let the context that waits for command completion allocate it. This makes it possible to have a single code path for non-aborted and aborted commands in target_release_cmd_kref() and avoids that transport_generic_free_cmd() has to call cmd->se_tfo->release_cmd() directly. This patch does not change any functionality. Note: transport_generic_free_cmd() only waits until the se_cmd reference count has reached zero after it has set both CMD_T_FABRIC_STOP and CMD_T_ABORTED. Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com> Reviewed-by: Mike Christie <mchristi@redhat.com> Cc: Hannes Reinecke <hare@suse.com> Cc: Christoph Hellwig <hch@lst.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent edf46ee commit 7b2cc7d

2 files changed

Lines changed: 9 additions & 17 deletions

File tree

‎drivers/target/target_core_transport.c‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1309,7 +1309,7 @@ void transport_init_se_cmd(
13091309
INIT_LIST_HEAD(&cmd->se_cmd_list);
13101310
INIT_LIST_HEAD(&cmd->state_list);
13111311
init_completion(&cmd->t_transport_stop_comp);
1312-
init_completion(&cmd->cmd_wait_comp);
1312+
cmd->compl = NULL;
13131313
spin_lock_init(&cmd->t_state_lock);
13141314
INIT_WORK(&cmd->work, NULL);
13151315
kref_init(&cmd->cmd_kref);
@@ -2658,6 +2658,7 @@ static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted, bool *tas)
26582658
*/
26592659
int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks)
26602660
{
2661+
DECLARE_COMPLETION_ONSTACK(compl);
26612662
int ret = 0;
26622663
bool aborted = false, tas = false;
26632664

@@ -2676,12 +2677,13 @@ int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks)
26762677
if (cmd->se_lun)
26772678
transport_lun_remove_cmd(cmd);
26782679
}
2680+
if (aborted)
2681+
cmd->compl = &compl;
26792682
if (!aborted || tas)
26802683
ret = target_put_sess_cmd(cmd);
26812684
if (aborted) {
26822685
pr_debug("Detected CMD_T_ABORTED for ITT: %llu\n", cmd->tag);
2683-
wait_for_completion(&cmd->cmd_wait_comp);
2684-
cmd->se_tfo->release_cmd(cmd);
2686+
wait_for_completion(&compl);
26852687
ret = 1;
26862688
}
26872689
return ret;
@@ -2742,31 +2744,21 @@ static void target_release_cmd_kref(struct kref *kref)
27422744
{
27432745
struct se_cmd *se_cmd = container_of(kref, struct se_cmd, cmd_kref);
27442746
struct se_session *se_sess = se_cmd->se_sess;
2747+
struct completion *compl = se_cmd->compl;
27452748
unsigned long flags;
2746-
bool fabric_stop;
27472749

27482750
if (se_sess) {
27492751
spin_lock_irqsave(&se_sess->sess_cmd_lock, flags);
27502752
list_del_init(&se_cmd->se_cmd_list);
27512753
if (list_empty(&se_sess->sess_cmd_list))
27522754
wake_up(&se_sess->cmd_list_wq);
2753-
2754-
spin_lock(&se_cmd->t_state_lock);
2755-
fabric_stop = (se_cmd->transport_state & CMD_T_FABRIC_STOP) &&
2756-
(se_cmd->transport_state & CMD_T_ABORTED);
2757-
spin_unlock(&se_cmd->t_state_lock);
2758-
2759-
if (fabric_stop) {
2760-
spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
2761-
target_free_cmd_mem(se_cmd);
2762-
complete(&se_cmd->cmd_wait_comp);
2763-
return;
2764-
}
27652755
spin_unlock_irqrestore(&se_sess->sess_cmd_lock, flags);
27662756
}
27672757

27682758
target_free_cmd_mem(se_cmd);
27692759
se_cmd->se_tfo->release_cmd(se_cmd);
2760+
if (compl)
2761+
complete(compl);
27702762
}
27712763

27722764
/**

‎include/target/target_core_base.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ struct se_cmd {
475475
struct se_session *se_sess;
476476
struct se_tmr_req *se_tmr_req;
477477
struct list_head se_cmd_list;
478-
struct completion cmd_wait_comp;
478+
struct completion *compl;
479479
const struct target_core_fabric_ops *se_tfo;
480480
sense_reason_t (*execute_cmd)(struct se_cmd *);
481481
sense_reason_t (*transport_complete_callback)(struct se_cmd *, bool, int *);

0 commit comments

Comments
 (0)