Whamcloud - gitweb
LU-4423 libcfs: disable preempt while sampling processor id.
[fs/lustre-release.git] / libcfs / libcfs / libcfs_cpu.c
index 18c4839..c80f9d4 100644 (file)
@@ -678,19 +678,20 @@ EXPORT_SYMBOL(cfs_cpt_spread_node);
 
 int cfs_cpt_current(struct cfs_cpt_table *cptab, int remap)
 {
-       int cpu = smp_processor_id();
-       int cpt = cptab->ctb_cpu2cpt[cpu];
+       int cpu;
+       int cpt;
 
-       if (cpt < 0) {
-               if (!remap)
-                       return cpt;
+       preempt_disable();
+       cpu = smp_processor_id();
+       cpt = cptab->ctb_cpu2cpt[cpu];
 
+       if (cpt < 0 && remap) {
                /* don't return negative value for safety of upper layer,
                 * instead we shadow the unknown cpu to a valid partition ID
                 */
                cpt = cpu % cptab->ctb_nparts;
        }
-
+       preempt_enable();
        return cpt;
 }
 EXPORT_SYMBOL(cfs_cpt_current);