From ff60ad9a52d27630cf5ac36e4f8bcde3564b635b Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Sat, 17 Sep 2011 15:23:36 +0000 Subject: [PATCH] ib_srpt: Don't wait forever for the Last WQE event git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@3857 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/src/ib_srpt.c | 21 +++++++++++++++++++-- srpt/src/ib_srpt.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index c50aeffdf..0e74d6c73 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -151,6 +151,7 @@ static void srpt_unregister_procfs_entry(struct scst_tgt_template *tgt); #endif /*CONFIG_SCST_PROC*/ static void srpt_unmap_sg_to_ib_sge(struct srpt_rdma_ch *ch, struct srpt_send_ioctx *ioctx); +static void srpt_drain_channel(struct ib_cm_id *cm_id); static void srpt_free_ch(struct scst_session *sess); static enum rdma_ch_state @@ -354,9 +355,9 @@ static void srpt_qp_event(struct ib_event *event, struct srpt_rdma_ch *ch) break; case IB_EVENT_QP_LAST_WQE_REACHED: if (srpt_test_and_set_ch_state(ch, CH_DRAINING, CH_RELEASING)) - wake_up_process(ch->thread); + wake_up(&ch->last_wqe); else - TRACE_DBG("%s: state %d - ignored LAST_WQE.", + TRACE_DBG("%s: state %d - ignored Last WQE event.", ch->sess_name, ch->state); break; default: @@ -1982,6 +1983,7 @@ static void srpt_completion(struct ib_cq *cq, void *ctx) static int srpt_compl_thread(void *arg) { struct srpt_rdma_ch *ch; + int ret; /* Hibernation / freezing of the SRPT kernel thread is not supported. */ current->flags |= PF_NOFREEZE; @@ -1998,6 +2000,20 @@ static int srpt_compl_thread(void *arg) set_current_state(TASK_RUNNING); WARN_ON(ch->state <= CH_LIVE); + + ret = wait_event_timeout(ch->last_wqe, ch->state == CH_RELEASING, + 2 * RDMA_COMPL_TIMEOUT_S * HZ); + WARN_ON(ret < 0); + if (!ret) { + PRINT_ERROR("%s: %s has not been received in time.", + ch->sess_name, + ch->state == CH_DISCONNECTING ? "DREP message" : + ch->state == CH_DRAINING ? "Last WQE event" : + "(?)"); + srpt_drain_channel(ch->cm_id); + srpt_test_and_set_ch_state(ch, CH_DRAINING, CH_RELEASING); + } + TRACE_DBG("ch %s: about to invoke scst_unregister_session()", ch->sess_name); scst_unregister_session(ch->scst_sess, false, srpt_free_ch); @@ -2421,6 +2437,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, spin_lock_init(&ch->spinlock); ch->state = CH_CONNECTING; INIT_LIST_HEAD(&ch->cmd_wait_list); + init_waitqueue_head(&ch->last_wqe); ch->ioctx_ring = (struct srpt_send_ioctx **) srpt_alloc_ioctx_ring(ch->sport->sdev, ch->rq_size, sizeof(*ch->ioctx_ring[0]), diff --git a/srpt/src/ib_srpt.h b/srpt/src/ib_srpt.h index 26c092943..1dce7d972 100644 --- a/srpt/src/ib_srpt.h +++ b/srpt/src/ib_srpt.h @@ -333,6 +333,7 @@ struct srpt_rdma_ch { enum rdma_ch_state state; struct list_head list; struct list_head cmd_wait_list; + wait_queue_head_t last_wqe; struct scst_session *scst_sess; u8 sess_name[36];