diff --git a/scst/include/scst.h b/scst/include/scst.h index e5240b743..0d19a44c3 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -2271,6 +2271,7 @@ struct scst_cmd_threads { int io_context_refcnt; bool io_context_ready; + wait_queue_head_t ioctx_wq; /* io_context_mutex protects io_context and io_context_refcnt. */ struct mutex io_context_mutex; diff --git a/scst/src/scst_lib.c b/scst/src/scst_lib.c index f61269d22..6a8bef0e3 100644 --- a/scst/src/scst_lib.c +++ b/scst/src/scst_lib.c @@ -4495,6 +4495,7 @@ struct scst_acg *scst_tgt_find_acg(struct scst_tgt *tgt, const char *name) static struct scst_tgt_dev *scst_find_shared_io_tgt_dev( struct scst_tgt_dev *tgt_dev) { + struct scst_cmd_threads *a; struct scst_tgt_dev *res = NULL; struct scst_session *sess = tgt_dev->sess; struct scst_acg *acg = tgt_dev->acg_dev->acg; @@ -4566,21 +4567,16 @@ out: return res; found: - if (t->active_cmd_threads == &scst_main_cmd_threads) { - res = t; + res = t; + a = t->active_cmd_threads; + if (a == &scst_main_cmd_threads) { TRACE_DBG("Going to share async IO context %p (res %p, " "ini %s, dev %s, grouping type %d)", t->aic_keeper->aic, res, t->sess->initiator_name, t->dev->virt_name, t->acg_dev->acg->acg_io_grouping_type); } else { - res = t; - if (!*(volatile bool *)&res->active_cmd_threads->io_context_ready) { - TRACE_DBG("IO context for t %p not yet " - "initialized, waiting...", t); - msleep(100); - goto found; - } + wait_event(a->ioctx_wq, a->io_context_ready); smp_rmb(); TRACE_DBG("Going to share IO context %p (res %p, ini %s, " "dev %s, cmd_threads %p, grouping type %d)", diff --git a/scst/src/scst_main.c b/scst/src/scst_main.c index dc37cd1c9..2f681724e 100644 --- a/scst/src/scst_main.c +++ b/scst/src/scst_main.c @@ -1929,11 +1929,8 @@ out_wait: * Wait for io_context gets initialized to avoid possible races * for it from the sharing it tgt_devs. */ - while (!*(volatile bool *)&cmd_threads->io_context_ready) { - TRACE_DBG("Waiting for io_context for cmd_threads %p " - "initialized", cmd_threads); - msleep(50); - } + wait_event(cmd_threads->ioctx_wq, + cmd_threads->io_context_ready); smp_rmb(); } @@ -2182,6 +2179,7 @@ void scst_init_threads(struct scst_cmd_threads *cmd_threads) spin_lock_init(&cmd_threads->cmd_list_lock); INIT_LIST_HEAD(&cmd_threads->active_cmd_list); init_waitqueue_head(&cmd_threads->cmd_list_waitQ); + init_waitqueue_head(&cmd_threads->ioctx_wq); INIT_LIST_HEAD(&cmd_threads->threads_list); mutex_init(&cmd_threads->io_context_mutex); spin_lock_init(&cmd_threads->thr_lock); diff --git a/scst/src/scst_targ.c b/scst/src/scst_targ.c index fb5d07d9d..0380d73fe 100644 --- a/scst/src/scst_targ.c +++ b/scst/src/scst_targ.c @@ -5010,6 +5010,8 @@ int scst_cmd_thread(void *arg) scst_ioctx_get(p_cmd_threads); + wake_up_all(&p_cmd_threads->ioctx_wq); + spin_lock_irq(&p_cmd_threads->cmd_list_lock); while (!kthread_should_stop()) { wait_event_locked(p_cmd_threads->cmd_list_waitQ,