Whamcloud - gitweb
b=18790 Add config check to avoid type conflict.
[fs/lustre-release.git] / lnet / klnds / ptllnd / ptllnd_ptltrace.c
index 91ba7af..bf226bb 100644 (file)
@@ -1,25 +1,44 @@
 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
  * vim:expandtab:shiftwidth=8:tabstop=8:
  *
- * Copyright (C) 2006 Cluster File Systems, Inc. All rights reserved.
+ * GPL HEADER START
  *
- *   This file is part of the Lustre file system, http://www.lustre.org
- *   Lustre is a trademark of Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
- *   This file is confidential source code owned by Cluster File Systems.
- *   No viewing, modification, compilation, redistribution, or any other
- *   form of use is permitted except through a signed license agreement.
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
  *
- *   If you have not signed such an agreement, then you have no rights to
- *   this file.  Please destroy it immediately and contact CFS.
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
  *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ *
+ * GPL HEADER END
+ */
+/*
+ * Copyright  2008 Sun Microsystems, Inc. All rights reserved
+ * Use is subject to license terms.
+ */
+/*
+ * This file is part of Lustre, http://www.lustre.org/
+ * Lustre is a trademark of Sun Microsystems, Inc.
  */
 
 #include "ptllnd.h"
 
 #ifdef CRAY_XT3
-static struct semaphore   ptltrace_mutex;
-static struct semaphore   ptltrace_signal;
+static cfs_semaphore_t    ptltrace_mutex;
+static cfs_waitq_t        ptltrace_debug_ctlwq;
 
 void
 kptllnd_ptltrace_to_file(char *filename)
@@ -82,7 +101,7 @@ kptllnd_ptltrace_to_file(char *filename)
                 }
 
                 if (start < tmpbuf || start + len > tmpbuf + PAGE_SIZE) {
-                        CERROR("ptl_proc_read bug: %p for %d not in %p for %d\n",
+                        CERROR("ptl_proc_read bug: %p for %d not in %p for %ld\n",
                                start, len, tmpbuf, PAGE_SIZE);
                         break;
                 }
@@ -117,10 +136,10 @@ kptllnd_dump_ptltrace_thread(void *arg)
 {
         static char fname[1024];
 
-        libcfs_daemonize("ptltracedump");
+        libcfs_daemonize("kpt_ptltrace_dump");
 
         /* serialise with other instances of me */
-        mutex_down(&ptltrace_mutex);
+        cfs_mutex_down(&ptltrace_mutex);
 
         snprintf(fname, sizeof(fname), "%s.%ld.%ld",
                  *kptllnd_tunables.kptl_ptltrace_basename,
@@ -128,21 +147,24 @@ kptllnd_dump_ptltrace_thread(void *arg)
 
         kptllnd_ptltrace_to_file(fname);
 
-        mutex_up(&ptltrace_mutex);
+        cfs_mutex_up(&ptltrace_mutex);
 
         /* unblock my creator */
-        mutex_up(&ptltrace_signal);
-        
+        cfs_waitq_signal(&ptltrace_debug_ctlwq);
         return 0;
 }
 
 void
 kptllnd_dump_ptltrace(void)
 {
-        int            rc;     
+        int            rc;
+        cfs_waitlink_t wait;
+        ENTRY;
 
-        if (!*kptllnd_tunables.kptl_ptltrace_on_timeout)
-                return;
+        /* taken from libcfs_debug_dumplog */
+        cfs_waitlink_init(&wait);
+        cfs_set_current_state(CFS_TASK_INTERRUPTIBLE);
+        cfs_waitq_add(&ptltrace_debug_ctlwq, &wait);
 
         rc = cfs_kernel_thread(kptllnd_dump_ptltrace_thread,
                                (void *)(long)cfs_curproc_pid(),
@@ -150,28 +172,19 @@ kptllnd_dump_ptltrace(void)
         if (rc < 0) {
                 CERROR("Error %d starting ptltrace dump thread\n", rc);
         } else {
-                /* block until thread completes */
-                mutex_down(&ptltrace_signal);
+                cfs_waitq_wait(&wait, CFS_TASK_INTERRUPTIBLE);
         }
-}
 
-void
-kptllnd_init_ptltrace(void)
-{
-        init_mutex(&ptltrace_mutex);
-        init_mutex_locked(&ptltrace_signal);
-}
-
-#else
-
-void
-kptllnd_dump_ptltrace(void)
-{
+        /* teardown if cfs_kernel_thread() failed */
+        cfs_waitq_del(&ptltrace_debug_ctlwq, &wait);
+        cfs_set_current_state(CFS_TASK_RUNNING);
+        EXIT;
 }
 
 void
 kptllnd_init_ptltrace(void)
 {
+        cfs_waitq_init(&ptltrace_debug_ctlwq);
+        cfs_init_mutex(&ptltrace_mutex);
 }
-
 #endif