Whamcloud - gitweb
LU-9859 libcfs: move tracefile locking from linux-tracefile.c
[fs/lustre-release.git] / libcfs / libcfs / tracefile.c
index 555a5bb..7513f92 100644 (file)
@@ -58,6 +58,7 @@ static DEFINE_MUTEX(cfs_trace_thread_mutex);
 static int thread_running = 0;
 
 static atomic_t cfs_tage_allocated = ATOMIC_INIT(0);
+static DECLARE_RWSEM(cfs_tracefile_sem);
 
 static void put_pages_on_tcd_daemon_list(struct page_collection *pc,
                                        struct cfs_trace_cpu_data *tcd);
@@ -642,7 +643,7 @@ int cfs_tracefile_dump_all_pages(char *filename)
        char                    *buf;
        int rc;
 
-       cfs_tracefile_write_lock();
+       down_write(&cfs_tracefile_sem);
 
        filp = filp_open(filename, O_CREAT|O_EXCL|O_WRONLY|O_LARGEFILE, 0600);
        if (IS_ERR(filp)) {
@@ -686,7 +687,7 @@ int cfs_tracefile_dump_all_pages(char *filename)
 close:
        filp_close(filp, NULL);
 out:
-       cfs_tracefile_write_unlock();
+       up_write(&cfs_tracefile_sem);
        return rc;
 }
 
@@ -799,12 +800,12 @@ int cfs_trace_daemon_command(char *str)
 {
         int       rc = 0;
 
-        cfs_tracefile_write_lock();
+       down_write(&cfs_tracefile_sem);
 
         if (strcmp(str, "stop") == 0) {
-                cfs_tracefile_write_unlock();
+               up_write(&cfs_tracefile_sem);
                 cfs_trace_stop_thread();
-                cfs_tracefile_write_lock();
+               down_write(&cfs_tracefile_sem);
                 memset(cfs_tracefile, 0, sizeof(cfs_tracefile));
 
        } else if (strncmp(str, "size=", 5) == 0) {
@@ -830,7 +831,7 @@ int cfs_trace_daemon_command(char *str)
                cfs_trace_start_thread();
         }
 
-        cfs_tracefile_write_unlock();
+       up_write(&cfs_tracefile_sem);
         return rc;
 }
 
@@ -875,12 +876,12 @@ int cfs_trace_set_debug_mb(int mb)
        mb /= num_possible_cpus();
        pages = mb << (20 - PAGE_SHIFT);
 
-       cfs_tracefile_write_lock();
+       down_write(&cfs_tracefile_sem);
 
        cfs_tcd_for_each(tcd, i, j)
                tcd->tcd_max_pages = (pages * tcd->tcd_pages_factor) / 100;
 
-       cfs_tracefile_write_unlock();
+       up_write(&cfs_tracefile_sem);
 
        return 0;
 }
@@ -892,12 +893,12 @@ int cfs_trace_get_debug_mb(void)
         struct cfs_trace_cpu_data *tcd;
         int total_pages = 0;
 
-        cfs_tracefile_read_lock();
+       down_read(&cfs_tracefile_sem);
 
         cfs_tcd_for_each(tcd, i, j)
                 total_pages += tcd->tcd_max_pages;
 
-        cfs_tracefile_read_unlock();
+       up_read(&cfs_tracefile_sem);
 
        return (total_pages >> (20 - PAGE_SHIFT)) + 1;
 }
@@ -927,7 +928,7 @@ static int tracefiled(void *arg)
                         goto end_loop;
 
                 filp = NULL;
-                cfs_tracefile_read_lock();
+               down_read(&cfs_tracefile_sem);
                 if (cfs_tracefile[0] != 0) {
                        filp = filp_open(cfs_tracefile,
                                         O_CREAT | O_RDWR | O_LARGEFILE,
@@ -939,7 +940,7 @@ static int tracefiled(void *arg)
                                        cfs_tracefile, rc);
                        }
                }
-                cfs_tracefile_read_unlock();
+               up_read(&cfs_tracefile_sem);
                 if (filp == NULL) {
                         put_pages_on_daemon_list(&pc);
                        __LASSERT(list_empty(&pc.pc_pages));