X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Flibcfs%2Fuser-prim.c;h=a912c949c0fc35a94047f80c4684220aa4245008;hb=7629b7f51568a8cb2bedf2460cbfb1f9446769ca;hp=ee381d67a72fd523e65cf8ad2abdc2035fd4ad45;hpb=c8616363809a73b3d4b6c736e6b55a84d7f137b4;p=fs%2Flustre-release.git diff --git a/libcfs/libcfs/user-prim.c b/libcfs/libcfs/user-prim.c index ee381d6..a912c94 100644 --- a/libcfs/libcfs/user-prim.c +++ b/libcfs/libcfs/user-prim.c @@ -1,6 +1,4 @@ -/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*- - * vim:expandtab:shiftwidth=8:tabstop=8: - * +/* * GPL HEADER START * * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. @@ -26,8 +24,10 @@ * GPL HEADER END */ /* - * Copyright 2008 Sun Microsystems, Inc. All rights reserved + * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved. * Use is subject to license terms. + * + * Copyright (c) 2011, 2012, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -46,139 +46,158 @@ #ifndef __KERNEL__ +#include #include /* * Wait queue. No-op implementation. */ -void cfs_waitq_init(struct cfs_waitq *waitq) +void init_waitqueue_head(struct cfs_waitq *waitq) { - LASSERT(waitq != NULL); - (void)waitq; + LASSERT(waitq != NULL); + (void)waitq; } -void cfs_waitlink_init(struct cfs_waitlink *link) +void init_waitqueue_entry_current(struct cfs_waitlink *link) { - LASSERT(link != NULL); - (void)link; + LASSERT(link != NULL); + (void)link; } -void cfs_waitq_add(struct cfs_waitq *waitq, struct cfs_waitlink *link) +void add_wait_queue(struct cfs_waitq *waitq, struct cfs_waitlink *link) { - LASSERT(waitq != NULL); - LASSERT(link != NULL); - (void)waitq; - (void)link; + LASSERT(waitq != NULL); + LASSERT(link != NULL); + (void)waitq; + (void)link; } -void cfs_waitq_add_exclusive(struct cfs_waitq *waitq, struct cfs_waitlink *link) +void add_wait_queue_exclusive(struct cfs_waitq *waitq, struct cfs_waitlink *link) { - LASSERT(waitq != NULL); - LASSERT(link != NULL); - (void)waitq; - (void)link; + LASSERT(waitq != NULL); + LASSERT(link != NULL); + (void)waitq; + (void)link; } -void cfs_waitq_del(struct cfs_waitq *waitq, struct cfs_waitlink *link) +void add_wait_queue_exclusive_head(struct cfs_waitq *waitq, struct cfs_waitlink *link) { - LASSERT(waitq != NULL); - LASSERT(link != NULL); - (void)waitq; - (void)link; + add_wait_queue_exclusive(waitq, link); } -int cfs_waitq_active(struct cfs_waitq *waitq) +void remove_wait_queue(struct cfs_waitq *waitq, struct cfs_waitlink *link) { - LASSERT(waitq != NULL); - (void)waitq; - return 0; + LASSERT(waitq != NULL); + LASSERT(link != NULL); + (void)waitq; + (void)link; } -void cfs_waitq_signal(struct cfs_waitq *waitq) +int waitqueue_active(struct cfs_waitq *waitq) { - LASSERT(waitq != NULL); - (void)waitq; + LASSERT(waitq != NULL); + (void)waitq; + return 0; } -void cfs_waitq_signal_nr(struct cfs_waitq *waitq, int nr) +void wake_up(struct cfs_waitq *waitq) { - LASSERT(waitq != NULL); - (void)waitq; + LASSERT(waitq != NULL); + (void)waitq; } -void cfs_waitq_broadcast(struct cfs_waitq *waitq) +void wake_up_nr(struct cfs_waitq *waitq, int nr) { - LASSERT(waitq != NULL); - (void)waitq; + LASSERT(waitq != NULL); + (void)waitq; } -void cfs_waitq_wait(struct cfs_waitlink *link, cfs_task_state_t state) +void wake_up_all(struct cfs_waitq *waitq) { - LASSERT(link != NULL); - (void)link; + LASSERT(waitq != NULL); + (void)waitq; } -int64_t cfs_waitq_timedwait(struct cfs_waitlink *link, cfs_task_state_t state, - int64_t timeout) +void waitq_wait(struct cfs_waitlink *link, long state) { - LASSERT(link != NULL); - (void)link; - return 0; + LASSERT(link != NULL); + (void)link; + + /* well, wait for something to happen */ + call_wait_handler(0); } -void cfs_schedule_timeout(cfs_task_state_t state, int64_t timeout) +int64_t waitq_timedwait(struct cfs_waitlink *link, long state, + int64_t timeout) { - cfs_waitlink_t l; - /* sleep(timeout) here instead? */ - cfs_waitq_timedwait(&l, state, timeout); + LASSERT(link != NULL); + (void)link; + call_wait_handler(timeout); + return 0; } -void +void schedule_timeout_and_set_state(long state, int64_t timeout) +{ + wait_queue_t l; + /* sleep(timeout) here instead? */ + waitq_timedwait(&l, state, timeout); +} + +void cfs_pause(cfs_duration_t d) { - struct timespec s; - - cfs_duration_nsec(d, &s); - nanosleep(&s, NULL); + struct timespec s; + + cfs_duration_nsec(d, &s); + nanosleep(&s, NULL); +} + +int need_resched(void) +{ + return 0; +} + +void cond_resched(void) +{ } /* * Timer */ -void cfs_init_timer(cfs_timer_t *t) +void cfs_init_timer(struct timer_list *t) { - CFS_INIT_LIST_HEAD(&t->tl_list); + INIT_LIST_HEAD(&t->tl_list); } -void cfs_timer_init(cfs_timer_t *l, cfs_timer_func_t *func, void *arg) +void cfs_timer_init(struct timer_list *l, cfs_timer_func_t *func, void *arg) { - CFS_INIT_LIST_HEAD(&l->tl_list); - l->function = func; - l->data = (ulong_ptr_t)arg; - return; + INIT_LIST_HEAD(&l->tl_list); + l->function = func; + l->data = (ulong_ptr_t)arg; + return; } -int cfs_timer_is_armed(cfs_timer_t *l) +int cfs_timer_is_armed(struct timer_list *l) { - if (cfs_time_before(cfs_time_current(), l->expires)) - return 1; - else - return 0; + if (cfs_time_before(cfs_time_current(), l->expires)) + return 1; + else + return 0; } -void cfs_timer_arm(cfs_timer_t *l, cfs_time_t deadline) +void cfs_timer_arm(struct timer_list *l, cfs_time_t deadline) { - l->expires = deadline; + l->expires = deadline; } -void cfs_timer_disarm(cfs_timer_t *l) +void cfs_timer_disarm(struct timer_list *l) { } -cfs_time_t cfs_timer_deadline(cfs_timer_t *l) +cfs_time_t cfs_timer_deadline(struct timer_list *l) { - return l->expires; + return l->expires; } @@ -189,7 +208,7 @@ cfs_time_t cfs_timer_deadline(cfs_timer_t *l) */ struct lustre_thread_arg { - cfs_thread_t f; + cfs_thread_t f; void *arg; }; static void *cfs_thread_helper(void *data) @@ -199,52 +218,72 @@ static void *cfs_thread_helper(void *data) void *arg = targ->arg; free(targ); - + (void)f(arg); return NULL; } -int cfs_create_thread(cfs_thread_t func, void *arg) + +void *kthread_run(cfs_thread_t func, void *arg, const char namefmt[], ...) { - pthread_t tid; - pthread_attr_t tattr; - int rc; - struct lustre_thread_arg *targ_p = malloc(sizeof(struct lustre_thread_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; + if (targ_p == NULL) + return ERR_PTR(-ENOMEM); - 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; + 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 ERR_PTR(rc); } #endif -uid_t cfs_curproc_uid(void) +struct user_namespace init_user_ns __read_mostly; +EXPORT_SYMBOL(init_user_ns); + +uid_t current_uid(void) { return getuid(); } -int cfs_parse_int_tunable(int *value, char *name) +gid_t current_gid(void) { - char *env = getenv(name); - char *end; - - if (env == NULL) - return 0; + return getgid(); +} - *value = (int)strtoull(env, &end, 0); - if (*end == 0) - return 0; +uid_t current_fsuid(void) +{ + return getuid(); +} - CERROR("Can't parse tunable %s=%s\n", name, env); - return -EINVAL; +gid_t current_fsgid(void) +{ + return getgid(); } +/* Read the environment variable of current process specified by @key. */ +int cfs_get_environ(const char *key, char *value, int *val_len) +{ + char *entry; + int len; + + entry = getenv(key); + if (entry == NULL) + return -ENOENT; + + len = strlcpy(value, entry, *val_len); + if (len >= *val_len) + return -EOVERFLOW; + + return 0; +} void cfs_enter_debugger(void) { @@ -253,59 +292,69 @@ void cfs_enter_debugger(void) */ } -void cfs_daemonize(char *str) +int unshare_fs_struct() { - return; + return 0; } -int cfs_daemonize_ctxt(char *str) +sigset_t cfs_block_allsigs(void) { - return 0; + sigset_t all; + sigset_t old; + int rc; + + sigfillset(&all); + rc = sigprocmask(SIG_BLOCK, &all, &old); + LASSERT(rc == 0); + + return old; } -cfs_sigset_t cfs_block_allsigs(void) +sigset_t cfs_block_sigs(unsigned long sigs) { - cfs_sigset_t all; - cfs_sigset_t old; - int rc; + sigset_t old; + sigset_t blocks = { { sigs } }; /* kludge */ + int rc; - sigfillset(&all); - rc = sigprocmask(SIG_SETMASK, &all, &old); - LASSERT(rc == 0); + rc = sigprocmask(SIG_BLOCK, &blocks, &old); + LASSERT (rc == 0); - return old; + return old; } -cfs_sigset_t cfs_block_sigs(cfs_sigset_t blocks) +/* Block all signals except for the @sigs. It's only used in + * Linux kernel, just a dummy here. */ +sigset_t cfs_block_sigsinv(unsigned long sigs) { - cfs_sigset_t old; - int rc; - - rc = sigprocmask(SIG_SETMASK, &blocks, &old); - LASSERT (rc == 0); + sigset_t old; + int rc; + + /* Return old blocked sigs */ + rc = sigprocmask(SIG_SETMASK, NULL, &old); + LASSERT(rc == 0); - return old; + return old; } -void cfs_restore_sigs(cfs_sigset_t old) +void cfs_restore_sigs(sigset_t old) { - int rc = sigprocmask(SIG_SETMASK, &old, NULL); + int rc = sigprocmask(SIG_SETMASK, &old, NULL); - LASSERT (rc == 0); + LASSERT (rc == 0); } int cfs_signal_pending(void) { - cfs_sigset_t empty; - cfs_sigset_t set; - int rc; + sigset_t empty; + sigset_t set; + int rc; - rc = sigpending(&set); - LASSERT (rc == 0); + rc = sigpending(&set); + LASSERT (rc == 0); - sigemptyset(&empty); + sigemptyset(&empty); - return !memcmp(&empty, &set, sizeof(set)); + return !memcmp(&empty, &set, sizeof(set)); } void cfs_clear_sigpending(void) @@ -346,10 +395,10 @@ void *cfs_stack_trace_frame(struct cfs_stack_trace *trace, int frame_no) /* __linux__ */ #endif -void lbug_with_loc(const char *file, const char *func, const int line) +void lbug_with_loc(struct libcfs_debug_msg_data *msgdata) { /* No libcfs_catastrophe in userspace! */ - libcfs_debug_msg(NULL, 0, D_EMERG, file, func, line, "LBUG\n"); + libcfs_debug_msg(msgdata, "LBUG\n"); abort(); }