Whamcloud - gitweb
LU-506 kernel: Add config check for sb_any_quota_loaded
[fs/lustre-release.git] / lustre / ptlrpc / ptlrpcd.c
index 56a64ec..69bd210 100644 (file)
@@ -250,6 +250,8 @@ void ptlrpcd_add_req(struct ptlrpc_request *req, pdl_policy_t policy, int idx)
                 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);
 
@@ -279,12 +281,13 @@ static inline void ptlrpc_reqset_get(struct ptlrpc_request_set *set)
  * 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)) {
@@ -303,6 +306,25 @@ static int ptlrpcd_check(const struct lu_env *env, struct ptlrpcd_ctl *pc)
                 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);
 
@@ -330,6 +352,8 @@ static int ptlrpcd_check(const struct lu_env *env, struct ptlrpcd_ctl *pc)
                 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;
@@ -421,22 +445,6 @@ static int ptlrpcd(void *arg)
                 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);
@@ -696,6 +704,8 @@ out:
                 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);
         }