+ struct ptlrpcd_ctl *pc;
+ enum pscope_thread pt;
+ int rc;
+
+ LASSERT(scope < PSCOPE_NR);
+
+ cfs_spin_lock(&req->rq_lock);
+ if (req->rq_invalid_rqset) {
+ cfs_duration_t timeout;
+ struct l_wait_info lwi;
+
+ req->rq_invalid_rqset = 0;
+ cfs_spin_unlock(&req->rq_lock);
+
+ timeout = cfs_time_seconds(5);
+ lwi = LWI_TIMEOUT(timeout, back_to_sleep, NULL);
+ l_wait_event(req->rq_set_waitq, (req->rq_set == NULL), &lwi);
+ } else if (req->rq_set) {
+ LASSERT(req->rq_phase == RQ_PHASE_NEW);
+ LASSERT(req->rq_send_state == LUSTRE_IMP_REPLAY);
+
+ /* ptlrpc_check_set will decrease the count */
+ cfs_atomic_inc(&req->rq_set->set_remaining);
+ cfs_spin_unlock(&req->rq_lock);
+
+ cfs_waitq_signal(&req->rq_set->set_waitq);
+ } else {
+ cfs_spin_unlock(&req->rq_lock);
+ }
+
+ pt = req->rq_send_state == LUSTRE_IMP_FULL ? PT_NORMAL : PT_RECOVERY;
+ pc = &ptlrpcd_scopes[scope].pscope_thread[pt].pt_ctl;
+ rc = ptlrpc_set_add_new_req(pc, req);
+ /*
+ * XXX disable this for CLIO: environment is needed for interpreter.
+ * add debug temporary to check rc.
+ */
+ LASSERTF(rc == 0, "ptlrpcd_add_req failed (rc = %d)\n", rc);
+ if (rc && 0) {
+ /*
+ * Thread is probably in stop now so we need to
+ * kill this rpc as it was not added. Let's call
+ * interpret for it to let know we're killing it
+ * so that higher levels might free associated
+ * resources.
+ */
+ ptlrpc_req_interpret(NULL, req, -EBADR);
+ req->rq_set = NULL;
+ ptlrpc_req_finished(req);
+ } else if (req->rq_send_state == LUSTRE_IMP_CONNECTING) {
+ /*
+ * The request is for recovery, should be sent ASAP.
+ */
+ cfs_waitq_signal(&pc->pc_set->set_waitq);
+ }