Whamcloud - gitweb
use special macro for print time_t, cleanup in includes.
[fs/lustre-release.git] / lnet / libcfs / user-prim.c
index 7bfe074..5193745 100644 (file)
@@ -31,6 +31,9 @@
 
 #ifndef __KERNEL__
 
+#include <libcfs/libcfs.h>
+#include <libcfs/kp30.h>
+
 #include <sys/mman.h>
 #ifndef  __CYGWIN__
 #include <stdint.h>
 #include <signal.h>
 #include <errno.h>
 #include <sys/stat.h>
+#ifdef HAVE_SYS_VFS_H
 #include <sys/vfs.h>
-
-#include <libcfs/libcfs.h>
-#include <libcfs/kp30.h>
+#endif
 
 /*
  * Sleep channel. No-op implementation.
@@ -120,13 +122,13 @@ void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr)
         (void)waitq;
 }
 
-void cfs_waitq_broadcast(struct cfs_waitq *waitq, int state)
+void cfs_waitq_broadcast(struct cfs_waitq *waitq)
 {
         LASSERT(waitq != NULL);
         (void)waitq;
 }
 
-void cfs_waitq_wait(struct cfs_waitlink *link)
+void cfs_waitq_wait(struct cfs_waitlink *link, int state)
 {
         LASSERT(link != NULL);
         (void)link;
@@ -139,6 +141,69 @@ int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, int state, int64_t timeou
         return 0;
 }
 
+#ifdef HAVE_LIBPTHREAD
+
+/*
+ * Threads
+ */
+
+struct lustre_thread_arg {
+        cfs_thread_t f; 
+        void *arg;
+};
+static void *cfs_thread_helper(void *data)
+{
+        struct lustre_thread_arg *targ = data;
+        cfs_thread_t f  = targ->f;
+        void *arg = targ->arg;
+
+        free(targ);
+        
+        (void)f(arg);
+        return NULL;
+}
+int cfs_create_thread(cfs_thread_t func, void *arg)
+{
+        pthread_t tid;
+        pthread_attr_t tattr;
+        int rc;
+        struct lustre_thread_arg *targ_p = malloc(sizeof(struct lustre_thread_arg));
+
+        if ( targ_p == NULL )
+                return -ENOMEM;
+        
+        targ_p->f = func;
+        targ_p->arg = arg;
+
+        pthread_attr_init(&tattr); 
+        pthread_attr_setdetachstate(&tattr, PTHREAD_CREATE_DETACHED);
+        rc = pthread_create(&tid, &tattr, cfs_thread_helper, targ_p);
+        pthread_attr_destroy(&tattr);
+        return -rc;
+}
+#endif
+
+uid_t cfs_curproc_uid(void)
+{
+        return getuid();
+}
+
+int cfs_parse_int_tunable(int *value, char *name)
+{
+        char    *env = getenv(name);
+        char    *end;
+
+        if (env == NULL)
+                return 0;
+
+        *value = strtoull(env, &end, 0);
+        if (*end == 0)
+                return 0;
+
+        CERROR("Can't parse tunable %s=%s\n", name, env);
+        return -EINVAL;
+}
+
 /*
  * Allocator
  */
@@ -213,13 +278,6 @@ void cfs_mem_cache_free(cfs_mem_cache_t *c, void *addr)
         cfs_free(addr);
 }
 
-/*
- * This uses user-visible declarations from <linux/kdev_t.h>
- */
-#ifdef __LINUX__
-#include <linux/kdev_t.h>
-#endif
-
 void cfs_enter_debugger(void)
 {
         /*
@@ -282,7 +340,7 @@ void cfs_clear_sigpending(void)
         return;
 }
 
-#ifdef __LINUX__
+#ifdef __linux__
 
 /*
  * In glibc (NOT in Linux, so check above is not right), implement
@@ -312,7 +370,7 @@ void *cfs_stack_trace_frame(struct cfs_stack_trace *trace, int frame_no)
         return NULL;
 }
 
-/* __LINUX__ */
+/* __linux__ */
 #endif
 
 void lbug_with_loc(char *file, const char *func, const int line)
@@ -322,7 +380,6 @@ void lbug_with_loc(char *file, const char *func, const int line)
         abort();
 }
 
-
 /* !__KERNEL__ */
 #endif