/*
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
* Use is subject to license terms.
- */
-/*
- * Copyright (c) 2011 Whamcloud, Inc.
+ *
+ * Copyright (c) 2011, 2012, Whamcloud, Inc.
*/
/*
* This file is part of Lustre, http://www.lustre.org/
#endif
static struct ptlrpcd *ptlrpcds;
-cfs_semaphore_t ptlrpcd_sem;
+cfs_mutex_t ptlrpcd_mutex;
static int ptlrpcd_users = 0;
void ptlrpcd_wake(struct ptlrpc_request *req)
cfs_spin_unlock(&req->rq_lock);
l_wait_event(req->rq_set_waitq, (req->rq_set == NULL), &lwi);
} else if (req->rq_set) {
+ /* If we have a vaid "rq_set", just reuse it to avoid double
+ * linked. */
LASSERT(req->rq_phase == RQ_PHASE_NEW);
LASSERT(req->rq_send_state == LUSTRE_IMP_REPLAY);
* Check if there is more work to do on ptlrpcd set.
* Returns 1 if yes.
*/
-static int ptlrpcd_check(const struct lu_env *env, struct ptlrpcd_ctl *pc)
+static int ptlrpcd_check(struct lu_env *env, struct ptlrpcd_ctl *pc)
{
cfs_list_t *tmp, *pos;
struct ptlrpc_request *req;
struct ptlrpc_request_set *set = pc->pc_set;
int rc = 0;
+ int rc2;
ENTRY;
if (cfs_atomic_read(&set->set_new_count)) {
cfs_spin_unlock(&set->set_new_req_lock);
}
+ /* We should call lu_env_refill() before handling new requests to make
+ * sure that env key the requests depending on really exists.
+ */
+ rc2 = lu_env_refill(env);
+ if (rc2 != 0) {
+ /*
+ * XXX This is very awkward situation, because
+ * execution can neither continue (request
+ * interpreters assume that env is set up), nor repeat
+ * the loop (as this potentially results in a tight
+ * loop of -ENOMEM's).
+ *
+ * Fortunately, refill only ever does something when
+ * new modules are loaded, i.e., early during boot up.
+ */
+ CERROR("Failure to refill session: %d\n", rc2);
+ RETURN(rc);
+ }
+
if (cfs_atomic_read(&set->set_remaining))
rc |= ptlrpc_check_set(env, set);
rc = cfs_atomic_read(&set->set_new_count);
#ifdef __KERNEL__
+ /* If we have nothing to do, check whether we can take some
+ * work from our partner threads. */
if (rc == 0 && pc->pc_npartners > 0) {
struct ptlrpcd_ctl *partner;
struct ptlrpc_request_set *ps;
if (rc > 0)
CDEBUG(D_RPCTRACE, "transfer %d"
" async RPCs [%d->%d]\n",
- rc, pc->pc_index,
- partner->pc_index);
+ rc, partner->pc_index,
+ pc->pc_index);
}
ptlrpc_reqset_put(ps);
} while (rc == 0 && pc->pc_cursor != first);
struct l_wait_info lwi;
int timeout;
- rc = lu_env_refill(&env);
- if (rc != 0) {
- /*
- * XXX This is very awkward situation, because
- * execution can neither continue (request
- * interpreters assume that env is set up), nor repeat
- * the loop (as this potentially results in a tight
- * loop of -ENOMEM's).
- *
- * Fortunately, refill only ever does something when
- * new modules are loaded, i.e., early during boot up.
- */
- CERROR("Failure to refill session: %d\n", rc);
- continue;
- }
-
timeout = ptlrpc_set_next_timeout(set);
lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1),
ptlrpc_expired_set, set);
if (env != 0)
lu_context_fini(&pc->pc_env.le_ctx);
cfs_clear_bit(LIOD_BIND, &pc->pc_flags);
+#else
+ SET_BUT_UNUSED(env);
#endif
cfs_clear_bit(LIOD_START, &pc->pc_flags);
}
int rc = 0;
ENTRY;
- cfs_mutex_down(&ptlrpcd_sem);
+ cfs_mutex_lock(&ptlrpcd_mutex);
if (++ptlrpcd_users == 1)
rc = ptlrpcd_init();
- cfs_mutex_up(&ptlrpcd_sem);
+ cfs_mutex_unlock(&ptlrpcd_mutex);
RETURN(rc);
}
void ptlrpcd_decref(void)
{
- cfs_mutex_down(&ptlrpcd_sem);
+ cfs_mutex_lock(&ptlrpcd_mutex);
if (--ptlrpcd_users == 0)
ptlrpcd_fini();
- cfs_mutex_up(&ptlrpcd_sem);
+ cfs_mutex_unlock(&ptlrpcd_mutex);
}
/** @} ptlrpcd */