Whamcloud - gitweb
LU-4742 mdd: improve error messages in obf_lookup()
[fs/lustre-release.git] / lustre / ptlrpc / ptlrpcd.c
index 5f8f5c2..09aa43c 100644 (file)
@@ -101,7 +101,7 @@ void ptlrpcd_wake(struct ptlrpc_request *req)
 
         LASSERT(rq_set != NULL);
 
-        cfs_waitq_signal(&rq_set->set_waitq);
+       wake_up(&rq_set->set_waitq);
 }
 EXPORT_SYMBOL(ptlrpcd_wake);
 
@@ -114,10 +114,10 @@ ptlrpcd_select_pc(struct ptlrpc_request *req, pdl_policy_t policy, int index)
                 return &ptlrpcds->pd_thread_rcv;
 
 #ifdef __KERNEL__
-        switch (policy) {
-        case PDL_POLICY_SAME:
-                idx = cfs_smp_processor_id() % ptlrpcds->pd_nthreads;
-                break;
+       switch (policy) {
+       case PDL_POLICY_SAME:
+               idx = smp_processor_id() % ptlrpcds->pd_nthreads;
+               break;
         case PDL_POLICY_LOCAL:
                 /* Before CPU partition patches available, process it the same
                  * as "PDL_POLICY_ROUND". */
@@ -128,7 +128,7 @@ ptlrpcd_select_pc(struct ptlrpc_request *req, pdl_policy_t policy, int index)
                  * CPU partition patches are available. */
                 index = -1;
         case PDL_POLICY_PREFERRED:
-                if (index >= 0 && index < cfs_num_online_cpus()) {
+               if (index >= 0 && index < num_online_cpus()) {
                         idx = index % ptlrpcds->pd_nthreads;
                         break;
                 }
@@ -138,7 +138,7 @@ ptlrpcd_select_pc(struct ptlrpc_request *req, pdl_policy_t policy, int index)
         case PDL_POLICY_ROUND:
                 /* We do not care whether it is strict load balance. */
                 idx = ptlrpcds->pd_index + 1;
-                if (idx == cfs_smp_processor_id())
+               if (idx == smp_processor_id())
                         idx++;
                 idx %= ptlrpcds->pd_nthreads;
                 ptlrpcds->pd_index = idx;
@@ -189,15 +189,15 @@ void ptlrpcd_add_rqset(struct ptlrpc_request_set *set)
        count = cfs_atomic_add_return(i, &new->set_new_count);
        cfs_atomic_set(&set->set_remaining, 0);
        spin_unlock(&new->set_new_req_lock);
-        if (count == i) {
-                cfs_waitq_signal(&new->set_waitq);
-
-                /* XXX: It maybe unnecessary to wakeup all the partners. But to
-                 *      guarantee the async RPC can be processed ASAP, we have
-                 *      no other better choice. It maybe fixed in future. */
-                for (i = 0; i < pc->pc_npartners; i++)
-                        cfs_waitq_signal(&pc->pc_partners[i]->pc_set->set_waitq);
-        }
+       if (count == i) {
+               wake_up(&new->set_waitq);
+
+               /* XXX: It maybe unnecessary to wakeup all the partners. But to
+                *      guarantee the async RPC can be processed ASAP, we have
+                *      no other better choice. It maybe fixed in future. */
+               for (i = 0; i < pc->pc_npartners; i++)
+                       wake_up(&pc->pc_partners[i]->pc_set->set_waitq);
+       }
 #endif
 }
 EXPORT_SYMBOL(ptlrpcd_add_rqset);
@@ -259,7 +259,7 @@ void ptlrpcd_add_req(struct ptlrpc_request *req, pdl_policy_t policy, int idx)
                 /* ptlrpc_check_set will decrease the count */
                 cfs_atomic_inc(&req->rq_set->set_remaining);
                spin_unlock(&req->rq_lock);
-               cfs_waitq_signal(&req->rq_set->set_waitq);
+               wake_up(&req->rq_set->set_waitq);
                return;
        } else {
                spin_unlock(&req->rq_lock);
@@ -404,34 +404,38 @@ static int ptlrpcd_check(struct lu_env *env, struct ptlrpcd_ctl *pc)
  */
 static int ptlrpcd(void *arg)
 {
-        struct ptlrpcd_ctl *pc = arg;
-        struct ptlrpc_request_set *set = pc->pc_set;
-        struct lu_env env = { .le_ses = NULL };
-        int rc, exit = 0;
-        ENTRY;
+       struct ptlrpcd_ctl *pc = arg;
+       struct ptlrpc_request_set *set = pc->pc_set;
+       struct lu_context ses = { 0 };
+       struct lu_env env = { .le_ses = &ses };
+       int rc, exit = 0;
+       ENTRY;
 
        unshare_fs_struct();
 #if defined(CONFIG_SMP)
        if (test_bit(LIOD_BIND, &pc->pc_flags)) {
                int index = pc->pc_index;
 
-                if (index >= 0 && index < cfs_num_possible_cpus()) {
+               if (index >= 0 && index < num_possible_cpus()) {
                        while (!cpu_online(index)) {
-                               if (++index >= cfs_num_possible_cpus())
+                               if (++index >= num_possible_cpus())
                                        index = 0;
                        }
-                       cfs_set_cpus_allowed(cfs_current(),
-                                    *cpumask_of_node(cpu_to_node(index)));
+                       set_cpus_allowed_ptr(current,
+                                    cpumask_of_node(cpu_to_node(index)));
                }
        }
 #endif
-        /*
-         * XXX So far only "client" ptlrpcd uses an environment. In
-         * the future, ptlrpcd thread (or a thread-set) has to given
-         * an argument, describing its "scope".
-         */
-        rc = lu_context_init(&env.le_ctx,
-                             LCT_CL_THREAD|LCT_REMEMBER|LCT_NOREF);
+       /* Both client and server (MDT/OST) may use the environment. */
+       rc = lu_context_init(&env.le_ctx, LCT_MD_THREAD | LCT_DT_THREAD |
+                                         LCT_CL_THREAD | LCT_REMEMBER |
+                                         LCT_NOREF);
+       if (rc == 0) {
+               rc = lu_context_init(env.le_ses,
+                                    LCT_SESSION|LCT_REMEMBER|LCT_NOREF);
+               if (rc != 0)
+                       lu_context_fini(&env.le_ctx);
+       }
        complete(&pc->pc_starting);
 
         if (rc != 0)
@@ -451,14 +455,15 @@ static int ptlrpcd(void *arg)
                 lwi = LWI_TIMEOUT(cfs_time_seconds(timeout ? timeout : 1),
                                   ptlrpc_expired_set, set);
 
-                lu_context_enter(&env.le_ctx);
-                l_wait_event(set->set_waitq,
-                             ptlrpcd_check(&env, pc), &lwi);
-                lu_context_exit(&env.le_ctx);
+               lu_context_enter(&env.le_ctx);
+               lu_context_enter(env.le_ses);
+               l_wait_event(set->set_waitq, ptlrpcd_check(&env, pc), &lwi);
+               lu_context_exit(&env.le_ctx);
+               lu_context_exit(env.le_ses);
 
-                /*
-                 * Abort inflight rpcs for forced stop case.
-                 */
+               /*
+                * Abort inflight rpcs for forced stop case.
+                */
                if (test_bit(LIOD_STOP, &pc->pc_flags)) {
                        if (test_bit(LIOD_FORCE, &pc->pc_flags))
                                 ptlrpc_abort_set(set);
@@ -476,11 +481,12 @@ static int ptlrpcd(void *arg)
          */
         if (!cfs_list_empty(&set->set_requests))
                 ptlrpc_set_wait(set);
-        lu_context_fini(&env.le_ctx);
+       lu_context_fini(&env.le_ctx);
+       lu_context_fini(env.le_ses);
 
        complete(&pc->pc_finishing);
 
-        return 0;
+       return 0;
 }
 
 /* XXX: We want multiple CPU cores to share the async RPC load. So we start many
@@ -547,7 +553,7 @@ static int ptlrpcd_bind(int index, int max)
        {
                int i;
                mask = *cpumask_of_node(cpu_to_node(index));
-               for (i = max; i < cfs_num_online_cpus(); i++)
+               for (i = max; i < num_online_cpus(); i++)
                        cpu_clear(i, mask);
                pc->pc_npartners = cpus_weight(mask) - 1;
                set_bit(LIOD_BIND, &pc->pc_flags);
@@ -674,7 +680,6 @@ int ptlrpcd_idle(void *arg)
 int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc)
 {
         int rc;
-        int env = 0;
         ENTRY;
 
         /*
@@ -694,6 +699,16 @@ int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc)
         pc->pc_set = ptlrpc_prep_set();
         if (pc->pc_set == NULL)
                 GOTO(out, rc = -ENOMEM);
+
+#ifndef __KERNEL__
+        pc->pc_wait_callback =
+                liblustre_register_wait_callback("ptlrpcd_check_async_rpcs",
+                                                 &ptlrpcd_check_async_rpcs, pc);
+        pc->pc_idle_callback =
+                liblustre_register_idle_callback("ptlrpcd_check_idle_rpcs",
+                                                 &ptlrpcd_idle, pc);
+       RETURN(0);
+#else
         /*
          * So far only "client" ptlrpcd uses an environment. In the future,
          * ptlrpcd thread (or a thread-set) has to be given an argument,
@@ -701,52 +716,40 @@ int ptlrpcd_start(int index, int max, const char *name, struct ptlrpcd_ctl *pc)
          */
         rc = lu_context_init(&pc->pc_env.le_ctx, LCT_CL_THREAD|LCT_REMEMBER);
         if (rc != 0)
-                GOTO(out, rc);
+               GOTO(out_set, rc);
 
-        env = 1;
-#ifdef __KERNEL__
        {
-               cfs_task_t *task;
+               struct task_struct *task;
                if (index >= 0) {
                        rc = ptlrpcd_bind(index, max);
                        if (rc < 0)
-                               GOTO(out, rc);
+                               GOTO(out_env, rc);
                }
 
                task = kthread_run(ptlrpcd, pc, pc->pc_name);
                if (IS_ERR(task))
-                       GOTO(out, rc = PTR_ERR(task));
+                       GOTO(out_env, rc = PTR_ERR(task));
 
-               rc = 0;
                wait_for_completion(&pc->pc_starting);
        }
-#else
-        pc->pc_wait_callback =
-                liblustre_register_wait_callback("ptlrpcd_check_async_rpcs",
-                                                 &ptlrpcd_check_async_rpcs, pc);
-        pc->pc_idle_callback =
-                liblustre_register_idle_callback("ptlrpcd_check_idle_rpcs",
-                                                 &ptlrpcd_idle, pc);
-#endif
-out:
-        if (rc) {
-#ifdef __KERNEL__
-                if (pc->pc_set != NULL) {
-                        struct ptlrpc_request_set *set = pc->pc_set;
+       RETURN(0);
 
-                       spin_lock(&pc->pc_lock);
-                       pc->pc_set = NULL;
-                       spin_unlock(&pc->pc_lock);
-                       ptlrpc_set_destroy(set);
-               }
-               if (env != 0)
-                       lu_context_fini(&pc->pc_env.le_ctx);
-               clear_bit(LIOD_BIND, &pc->pc_flags);
-#else
-               SET_BUT_UNUSED(env);
-#endif
-               clear_bit(LIOD_START, &pc->pc_flags);
+out_env:
+       lu_context_fini(&pc->pc_env.le_ctx);
+
+out_set:
+       if (pc->pc_set != NULL) {
+               struct ptlrpc_request_set *set = pc->pc_set;
+
+               spin_lock(&pc->pc_lock);
+               pc->pc_set = NULL;
+               spin_unlock(&pc->pc_lock);
+               ptlrpc_set_destroy(set);
        }
+       clear_bit(LIOD_BIND, &pc->pc_flags);
+#endif
+out:
+       clear_bit(LIOD_START, &pc->pc_flags);
        RETURN(rc);
 }
 
@@ -762,7 +765,7 @@ void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force)
        set_bit(LIOD_STOP, &pc->pc_flags);
        if (force)
                set_bit(LIOD_FORCE, &pc->pc_flags);
-       cfs_waitq_signal(&pc->pc_set->set_waitq);
+       wake_up(&pc->pc_set->set_waitq);
 
 out:
        EXIT;
@@ -831,10 +834,10 @@ static void ptlrpcd_fini(void)
 
 static int ptlrpcd_init(void)
 {
-        int nthreads = cfs_num_online_cpus();
-        char name[16];
-        int size, i = -1, j, rc = 0;
-        ENTRY;
+       int     nthreads = num_online_cpus();
+       char    name[16];
+       int     size, i = -1, j, rc = 0;
+       ENTRY;
 
 #ifdef __KERNEL__
         if (max_ptlrpcds > 0 && max_ptlrpcds < nthreads)
@@ -895,7 +898,7 @@ out:
                 ptlrpcds = NULL;
         }
 
-        RETURN(0);
+       RETURN(rc);
 }
 
 int ptlrpcd_addref(void)
@@ -904,8 +907,11 @@ int ptlrpcd_addref(void)
         ENTRY;
 
        mutex_lock(&ptlrpcd_mutex);
-        if (++ptlrpcd_users == 1)
-                rc = ptlrpcd_init();
+        if (++ptlrpcd_users == 1) {
+               rc = ptlrpcd_init();
+               if (rc < 0)
+                       ptlrpcd_users--;
+       }
        mutex_unlock(&ptlrpcd_mutex);
         RETURN(rc);
 }