X-Git-Url: https://git.whamcloud.com/?a=blobdiff_plain;f=libcfs%2Flibcfs%2Flinux%2Flinux-prim.c;h=5609c52015f93a340d75d60097b024ac3c261ade;hb=9013eb2bb5492b1e8321d0ed534bee566f19627b;hp=6bee6341c3b672a20ed59dc22b339f2ef90f0b2b;hpb=70e80ade90af09300396706b8910e196a7928520;p=fs%2Flustre-release.git diff --git a/libcfs/libcfs/linux/linux-prim.c b/libcfs/libcfs/linux/linux-prim.c index 6bee634..5609c52 100644 --- a/libcfs/libcfs/linux/linux-prim.c +++ b/libcfs/libcfs/linux/linux-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. @@ -16,18 +14,16 @@ * 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 [sun.com URL with a - * copy of GPLv2]. - * - * 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. + * version 2 along with this program; If not, see + * http://www.gnu.org/licenses/gpl-2.0.html * * 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, 2013, Intel Corporation. */ /* * This file is part of Lustre, http://www.lustre.org/ @@ -35,148 +31,166 @@ */ #define DEBUG_SUBSYSTEM S_LNET -#ifndef AUTOCONF_INCLUDED -#include -#endif + +#include #include #include -#include +#include +#include +#ifdef HAVE_SCHED_HEADERS +#include +#endif +#include #if defined(CONFIG_KGDB) #include #endif -void cfs_enter_debugger(void) +#include +#include + +#ifndef HAVE_KTIME_GET_TS64 +void ktime_get_ts64(struct timespec64 *ts) { -#if defined(CONFIG_KGDB) - BREAKPOINT(); -#elif defined(__arch_um__) - asm("int $3"); -#else - /* nothing */ -#endif + struct timespec now; + + ktime_get_ts(&now); + *ts = timespec_to_timespec64(now); } +EXPORT_SYMBOL(ktime_get_ts64); +#endif /* HAVE_KTIME_GET_TS64 */ -void cfs_daemonize(char *str) { - unsigned long flags; +#ifndef HAVE_KTIME_GET_REAL_TS64 +void ktime_get_real_ts64(struct timespec64 *ts) +{ + struct timespec now; - lock_kernel(); -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,63)) - daemonize(str); -#else - daemonize(); - exit_files(current); - reparent_to_init(); - snprintf (current->comm, sizeof (current->comm), "%s", str); -#endif - SIGNAL_MASK_LOCK(current, flags); - sigfillset(¤t->blocked); - RECALC_SIGPENDING; - SIGNAL_MASK_UNLOCK(current, flags); - unlock_kernel(); + getnstimeofday(&now); + *ts = timespec_to_timespec64(now); } +EXPORT_SYMBOL(ktime_get_real_ts64); +#endif /* HAVE_KTIME_GET_REAL_TS64 */ -int cfs_daemonize_ctxt(char *str) { - struct task_struct *tsk = current; - struct fs_struct *fs = NULL; - - cfs_daemonize(str); - fs = copy_fs_struct(tsk->fs); - if (fs == NULL) - return -ENOMEM; - exit_fs(tsk); - tsk->fs = fs; - return 0; +#ifndef HAVE_KTIME_GET_REAL_SECONDS +/* + * Get the seconds portion of CLOCK_REALTIME (wall clock). + * This is the clock that can be altered by NTP and is + * independent of a reboot. + */ +time64_t ktime_get_real_seconds(void) +{ + return (time64_t)get_seconds(); } +EXPORT_SYMBOL(ktime_get_real_seconds); +#endif /* HAVE_KTIME_GET_REAL_SECONDS */ - -sigset_t -cfs_get_blockedsigs(void) +#ifndef HAVE_KTIME_GET_SECONDS +/* + * Get the seconds portion of CLOCK_MONOTONIC + * This clock is immutable and is reset across + * reboots. For older platforms this is a + * wrapper around get_seconds which is valid + * until 2038. By that time this will be gone + * one would hope. + */ +time64_t ktime_get_seconds(void) { - unsigned long flags; - sigset_t old; + struct timespec64 now; - SIGNAL_MASK_LOCK(current, flags); - old = current->blocked; - SIGNAL_MASK_UNLOCK(current, flags); - return old; + ktime_get_ts64(&now); + return now.tv_sec; } +EXPORT_SYMBOL(ktime_get_seconds); +#endif /* HAVE_KTIME_GET_SECONDS */ -sigset_t -cfs_block_allsigs(void) -{ - unsigned long flags; - sigset_t old; +static int (*cfs_apply_workqueue_attrs_t)(struct workqueue_struct *wq, + const struct workqueue_attrs *attrs); - SIGNAL_MASK_LOCK(current, flags); - old = current->blocked; - sigfillset(¤t->blocked); - RECALC_SIGPENDING; - SIGNAL_MASK_UNLOCK(current, flags); - - return old; +int cfs_apply_workqueue_attrs(struct workqueue_struct *wq, + const struct workqueue_attrs *attrs) +{ + return cfs_apply_workqueue_attrs_t(wq, attrs); } +EXPORT_SYMBOL_GPL(cfs_apply_workqueue_attrs); -sigset_t -cfs_block_sigs(sigset_t bits) +struct kmem_cache (*radix_tree_node_cachep); + +void __init cfs_arch_init(void) { - unsigned long flags; - sigset_t old; - - SIGNAL_MASK_LOCK(current, flags); - old = current->blocked; - current->blocked = bits; - RECALC_SIGPENDING; - SIGNAL_MASK_UNLOCK(current, flags); - return old; +#ifndef HAVE_WAIT_VAR_EVENT + wait_bit_init(); +#endif + cfs_apply_workqueue_attrs_t = + (void *)kallsyms_lookup_name("apply_workqueue_attrs"); + radix_tree_node_cachep = + (void *)kallsyms_lookup_name("radix_tree_node_cachep"); } -void -cfs_restore_sigs (cfs_sigset_t old) +int cfs_kernel_write(struct file *filp, const void *buf, size_t count, + loff_t *pos) { - unsigned long flags; +#ifdef HAVE_NEW_KERNEL_WRITE + return kernel_write(filp, buf, count, pos); +#else + mm_segment_t __old_fs = get_fs(); + int rc; - SIGNAL_MASK_LOCK(current, flags); - current->blocked = old; - RECALC_SIGPENDING; - SIGNAL_MASK_UNLOCK(current, flags); -} + set_fs(KERNEL_DS); + rc = vfs_write(filp, (__force const char __user *)buf, count, pos); + set_fs(__old_fs); -int -cfs_signal_pending(void) -{ - return signal_pending(current); + return rc; +#endif } +EXPORT_SYMBOL(cfs_kernel_write); -void -cfs_clear_sigpending(void) +ssize_t cfs_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos) { - unsigned long flags; +#ifdef HAVE_KERNEL_READ_LAST_POSP + return kernel_read(file, buf, count, pos); +#else + ssize_t size = kernel_read(file, *pos, buf, count); - SIGNAL_MASK_LOCK(current, flags); - CLEAR_SIGPENDING; - SIGNAL_MASK_UNLOCK(current, flags); + if (size > 0) + *pos += size; + return size; +#endif } +EXPORT_SYMBOL(cfs_kernel_read); -int -libcfs_arch_init(void) +#ifndef HAVE_KSET_FIND_OBJ +struct kobject *kset_find_obj(struct kset *kset, const char *name) { - return 0; + struct kobject *ret = NULL; + struct kobject *k; + + spin_lock(&kset->list_lock); + + list_for_each_entry(k, &kset->list, entry) { + if (kobject_name(k) && !strcmp(kobject_name(k), name)) { + if (kref_get_unless_zero(&k->kref)) + ret = k; + break; + } + } + + spin_unlock(&kset->list_lock); + return ret; } +EXPORT_SYMBOL_GPL(kset_find_obj); +#endif -void -libcfs_arch_cleanup(void) +#ifndef HAVE_KSTRTOBOOL_FROM_USER +int kstrtobool_from_user(const char __user *s, size_t count, bool *res) { - return; + /* Longest string needed to differentiate, newline, terminator */ + char buf[4]; + + count = min(count, sizeof(buf) - 1); + if (copy_from_user(buf, s, count)) + return -EFAULT; + buf[count] = '\0'; + return strtobool(buf, res); } - -EXPORT_SYMBOL(libcfs_arch_init); -EXPORT_SYMBOL(libcfs_arch_cleanup); -EXPORT_SYMBOL(cfs_daemonize); -EXPORT_SYMBOL(cfs_daemonize_ctxt); -EXPORT_SYMBOL(cfs_block_allsigs); -EXPORT_SYMBOL(cfs_block_sigs); -EXPORT_SYMBOL(cfs_get_blockedsigs); -EXPORT_SYMBOL(cfs_restore_sigs); -EXPORT_SYMBOL(cfs_signal_pending); -EXPORT_SYMBOL(cfs_clear_sigpending); +EXPORT_SYMBOL(kstrtobool_from_user); +#endif /* !HAVE_KSTRTOBOOL_FROM_USER */