X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lnet%2Flibcfs%2Fuser-prim.c;h=519374585780612e134ef3c8aecc09afc13a4f37;hp=7bfe07400143ae05fa13f34385abe1729dc6d0a3;hb=c1f6b32958c799412c830f35f8d16ed7275407ea;hpb=ae4dbafdc71a713e8b00977447c1ac9cb4826206 diff --git a/lnet/libcfs/user-prim.c b/lnet/libcfs/user-prim.c index 7bfe074..5193745 100644 --- a/lnet/libcfs/user-prim.c +++ b/lnet/libcfs/user-prim.c @@ -31,6 +31,9 @@ #ifndef __KERNEL__ +#include +#include + #include #ifndef __CYGWIN__ #include @@ -48,10 +51,9 @@ #include #include #include +#ifdef HAVE_SYS_VFS_H #include - -#include -#include +#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 - */ -#ifdef __LINUX__ -#include -#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