Whamcloud - gitweb
LU-3157 llite: A not locked mutex can be unlocked.
[fs/lustre-release.git] / lustre / ptlrpc / ptlrpcd.c
index 5db8f92..669b0d7 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Whamcloud, Inc.
+ * Copyright (c) 2011, 2012, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -410,20 +410,21 @@ static int ptlrpcd(void *arg)
         int rc, exit = 0;
         ENTRY;
 
-        cfs_daemonize_ctxt(pc->pc_name);
-#if defined(CONFIG_SMP) && defined(HAVE_NODE_TO_CPUMASK)
+       cfs_daemonize_ctxt(pc->pc_name);
+#if defined(CONFIG_SMP) && \
+(defined(HAVE_CPUMASK_OF_NODE) || defined(HAVE_NODE_TO_CPUMASK))
        if (test_bit(LIOD_BIND, &pc->pc_flags)) {
-                int index = pc->pc_index;
+               int index = pc->pc_index;
 
                 if (index >= 0 && index < cfs_num_possible_cpus()) {
-                        while (!cpu_online(index)) {
-                                if (++index >= cfs_num_possible_cpus())
-                                        index = 0;
-                        }
-                        cfs_set_cpus_allowed(cfs_current(),
-                                     node_to_cpumask(cpu_to_node(index)));
-                }
-        }
+                       while (!cpu_online(index)) {
+                               if (++index >= cfs_num_possible_cpus())
+                                       index = 0;
+                       }
+                       cfs_set_cpus_allowed(cfs_current(),
+                                    *cpumask_of_node(cpu_to_node(index)));
+               }
+       }
 #endif
         /*
          * XXX So far only "client" ptlrpcd uses an environment. In
@@ -478,11 +479,6 @@ static int ptlrpcd(void *arg)
                 ptlrpc_set_wait(set);
         lu_context_fini(&env.le_ctx);
 
-       clear_bit(LIOD_START, &pc->pc_flags);
-       clear_bit(LIOD_STOP, &pc->pc_flags);
-       clear_bit(LIOD_FORCE, &pc->pc_flags);
-       clear_bit(LIOD_BIND, &pc->pc_flags);
-
        complete(&pc->pc_finishing);
 
         return 0;
@@ -526,14 +522,13 @@ static int ptlrpcd(void *arg)
 # endif
 static int ptlrpcd_bind(int index, int max)
 {
-        struct ptlrpcd_ctl *pc;
-        int rc = 0;
-#if defined(CONFIG_NUMA) && defined(HAVE_NODE_TO_CPUMASK)
-        struct ptlrpcd_ctl *ppc;
-        int node, i, pidx;
-        cpumask_t mask;
+       struct ptlrpcd_ctl *pc;
+       int rc = 0;
+#if defined(CONFIG_NUMA) && \
+(defined(HAVE_CPUMASK_OF_NODE) || defined(HAVE_NODE_TO_CPUMASK))
+       cpumask_t mask;
 #endif
-        ENTRY;
+       ENTRY;
 
         LASSERT(index <= max - 1);
         pc = &ptlrpcds->pd_threads[index];
@@ -549,14 +544,17 @@ static int ptlrpcd_bind(int index, int max)
                 LASSERT(max % 2 == 0);
                 pc->pc_npartners = 1;
                 break;
-        case PDB_POLICY_NEIGHBOR:
-#if defined(CONFIG_NUMA) && defined(HAVE_NODE_TO_CPUMASK)
-                node = cpu_to_node(index);
-                mask = node_to_cpumask(node);
-                for (i = max; i < cfs_num_online_cpus(); i++)
-                        cpu_clear(i, mask);
-                pc->pc_npartners = cpus_weight(mask) - 1;
+       case PDB_POLICY_NEIGHBOR:
+#if defined(CONFIG_NUMA) && \
+(defined(HAVE_CPUMASK_OF_NODE) || defined(HAVE_NODE_TO_CPUMASK))
+       {
+               int i;
+               mask = *cpumask_of_node(cpu_to_node(index));
+               for (i = max; i < cfs_num_online_cpus(); i++)
+                       cpu_clear(i, mask);
+               pc->pc_npartners = cpus_weight(mask) - 1;
                set_bit(LIOD_BIND, &pc->pc_flags);
+       }
 #else
                 LASSERT(max >= 3);
                 pc->pc_npartners = 2;
@@ -584,23 +582,28 @@ static int ptlrpcd_bind(int index, int max)
                                                 pc_partners[0] = pc;
                                 }
                                 break;
-                        case PDB_POLICY_NEIGHBOR:
-#if defined(CONFIG_NUMA) && defined(HAVE_NODE_TO_CPUMASK)
-                                /* partners are cores in the same NUMA node.
-                                 * setup partnership only with ptlrpcd threads
-                                 * that are already initialized
-                                 */
-                                for (pidx = 0, i = 0; i < index; i++) {
-                                        if (cpu_isset(i, mask)) {
-                                                ppc = &ptlrpcds->pd_threads[i];
-                                                pc->pc_partners[pidx++] = ppc;
-                                                ppc->pc_partners[ppc->
-                                                          pc_npartners++] = pc;
-                                        }
-                                }
+                       case PDB_POLICY_NEIGHBOR:
+#if defined(CONFIG_NUMA) && \
+(defined(HAVE_CPUMASK_OF_NODE) || defined(HAVE_NODE_TO_CPUMASK))
+                       {
+                               struct ptlrpcd_ctl *ppc;
+                               int i, pidx;
+                               /* partners are cores in the same NUMA node.
+                                * setup partnership only with ptlrpcd threads
+                                * that are already initialized
+                                */
+                               for (pidx = 0, i = 0; i < index; i++) {
+                                       if (cpu_isset(i, mask)) {
+                                               ppc = &ptlrpcds->pd_threads[i];
+                                               pc->pc_partners[pidx++] = ppc;
+                                               ppc->pc_partners[ppc->
+                                                         pc_npartners++] = pc;
+                                       }
+                               }
                                 /* adjust number of partners to the number
                                  * of partnership really setup */
                                 pc->pc_npartners = pidx;
+                       }
 #else
                                 if (index & 0x1)
                                        set_bit(LIOD_BIND, &pc->pc_flags);
@@ -750,18 +753,32 @@ out:
 
 void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force)
 {
-       struct ptlrpc_request_set *set = pc->pc_set;
-        ENTRY;
+       ENTRY;
 
        if (!test_bit(LIOD_START, &pc->pc_flags)) {
-                CWARN("Thread for pc %p was not started\n", pc);
-                goto out;
-        }
+               CWARN("Thread for pc %p was not started\n", pc);
+               goto out;
+       }
 
        set_bit(LIOD_STOP, &pc->pc_flags);
        if (force)
                set_bit(LIOD_FORCE, &pc->pc_flags);
        cfs_waitq_signal(&pc->pc_set->set_waitq);
+
+out:
+       EXIT;
+}
+
+void ptlrpcd_free(struct ptlrpcd_ctl *pc)
+{
+       struct ptlrpc_request_set *set = pc->pc_set;
+       ENTRY;
+
+       if (!test_bit(LIOD_START, &pc->pc_flags)) {
+               CWARN("Thread for pc %p was not started\n", pc);
+               goto out;
+       }
+
 #ifdef __KERNEL__
        wait_for_completion(&pc->pc_finishing);
 #else
@@ -775,6 +792,11 @@ void ptlrpcd_stop(struct ptlrpcd_ctl *pc, int force)
        spin_unlock(&pc->pc_lock);
        ptlrpc_set_destroy(set);
 
+       clear_bit(LIOD_START, &pc->pc_flags);
+       clear_bit(LIOD_STOP, &pc->pc_flags);
+       clear_bit(LIOD_FORCE, &pc->pc_flags);
+       clear_bit(LIOD_BIND, &pc->pc_flags);
+
 out:
 #ifdef __KERNEL__
         if (pc->pc_npartners > 0) {
@@ -791,18 +813,21 @@ out:
 
 static void ptlrpcd_fini(void)
 {
-        int i;
-        ENTRY;
-
-        if (ptlrpcds != NULL) {
-                for (i = 0; i < ptlrpcds->pd_nthreads; i++)
-                        ptlrpcd_stop(&ptlrpcds->pd_threads[i], 0);
-                ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
-                OBD_FREE(ptlrpcds, ptlrpcds->pd_size);
-                ptlrpcds = NULL;
-        }
+       int i;
+       ENTRY;
+
+       if (ptlrpcds != NULL) {
+               for (i = 0; i < ptlrpcds->pd_nthreads; i++)
+                       ptlrpcd_stop(&ptlrpcds->pd_threads[i], 0);
+               for (i = 0; i < ptlrpcds->pd_nthreads; i++)
+                       ptlrpcd_free(&ptlrpcds->pd_threads[i]);
+               ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
+               ptlrpcd_free(&ptlrpcds->pd_thread_rcv);
+               OBD_FREE(ptlrpcds, ptlrpcds->pd_size);
+               ptlrpcds = NULL;
+       }
 
-        EXIT;
+       EXIT;
 }
 
 static int ptlrpcd_init(void)
@@ -863,7 +888,10 @@ out:
         if (rc != 0 && ptlrpcds != NULL) {
                 for (j = 0; j <= i; j++)
                         ptlrpcd_stop(&ptlrpcds->pd_threads[j], 0);
-                ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
+               for (j = 0; j <= i; j++)
+                       ptlrpcd_free(&ptlrpcds->pd_threads[j]);
+               ptlrpcd_stop(&ptlrpcds->pd_thread_rcv, 0);
+               ptlrpcd_free(&ptlrpcds->pd_thread_rcv);
                 OBD_FREE(ptlrpcds, size);
                 ptlrpcds = NULL;
         }