Whamcloud - gitweb
LU-6142 libcfs: use BIT() macro where appropriate
[fs/lustre-release.git] / libcfs / libcfs / debug.c
index f48d9e5..280ada3 100644 (file)
@@ -65,21 +65,15 @@ static int libcfs_param_debug_mb_set(const char *val,
        if (rc < 0)
                return rc;
 
-/*
- * RHEL6 does not support any kind of locking so we have to provide
- * our own
- */
-       if (!*((unsigned int *)kp->arg)) {
-               *((unsigned int *)kp->arg) = num;
-               return 0;
-       }
-
-       rc = cfs_trace_set_debug_mb(num);
+       num = cfs_trace_set_debug_mb(num);
 
-       if (!rc)
-               *((unsigned int *)kp->arg) = cfs_trace_get_debug_mb();
+       *((unsigned int *)kp->arg) = num;
+       num = cfs_trace_get_debug_mb();
+       if (num)
+               /* This value is more precise */
+               *((unsigned int *)kp->arg) = num;
 
-       return rc;
+       return 0;
 }
 
 /*
@@ -305,7 +299,7 @@ libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys)
                len = 1;
        } else {                                /* space-separated tokens */
                for (i = 0; i < 32; i++) {
-                       if ((mask & (1 << i)) == 0)
+                       if ((mask & BIT(i)) == 0)
                                continue;
 
                        token = fn(i);
@@ -400,11 +394,17 @@ static int libcfs_debug_dumplog_thread(void *arg)
        return 0;
 }
 
+static DEFINE_MUTEX(libcfs_debug_dumplog_lock);
+
 void libcfs_debug_dumplog(void)
 {
        struct task_struct *dumper;
 
        ENTRY;
+
+       if (mutex_trylock(&libcfs_debug_dumplog_lock) == 0)
+               return;
+
        /* If a previous call was interrupted, debug_complete->done
         * might be elevated, and so we won't actually wait here.
         * So we reinit the completion to ensure we wait for
@@ -413,13 +413,15 @@ void libcfs_debug_dumplog(void)
         */
        reinit_completion(&debug_complete);
        dumper = kthread_run(libcfs_debug_dumplog_thread,
-                            (void *)(long)current_pid(),
+                            (void *)(long)current->pid,
                             "libcfs_debug_dumper");
        if (IS_ERR(dumper))
                pr_err("LustreError: cannot start log dump thread: rc = %ld\n",
                       PTR_ERR(dumper));
        else
                wait_for_completion_interruptible(&debug_complete);
+
+       mutex_unlock(&libcfs_debug_dumplog_lock);
 }
 EXPORT_SYMBOL(libcfs_debug_dumplog);
 
@@ -441,11 +443,10 @@ int libcfs_debug_init(unsigned long bufsize)
                        sizeof(libcfs_debug_file_path_arr));
        }
 
-       /*
-        * If libcfs_debug_mb is set to an invalid value or uninitialized
-        * then just make the total buffers smp_num_cpus * TCD_MAX_PAGES
+       /* If libcfs_debug_mb is uninitialized then just make the
+        * total buffers smp_num_cpus * TCD_MAX_PAGES
         */
-       if (max > cfs_trace_max_debug_mb() || max < num_possible_cpus()) {
+       if (max < num_possible_cpus()) {
                max = TCD_MAX_PAGES;
        } else {
                max = (max / num_possible_cpus());