-/* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
- * vim:expandtab:shiftwidth=8:tabstop=8:
+/*
+ * GPL HEADER START
*
- * Copyright (c) 2002, 2003 Cluster File Systems, Inc.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
- * This file is part of Lustre, http://www.lustre.org.
+ * 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.
+ *
+ * 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.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ */
+/*
+ * 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/
+ * Lustre is a trademark of Sun Microsystems, Inc.
*/
#define DEBUG_SUBSYSTEM S_LNET
-#ifndef AUTOCONF_INCLUDED
-#include <linux/config.h>
-#endif
#include <linux/module.h>
#include <linux/kernel.h>
+#include <linux/fs_struct.h>
+#include <linux/sched.h>
+
#include <libcfs/libcfs.h>
#if defined(CONFIG_KGDB)
#include <asm/kgdb.h>
#endif
-void cfs_enter_debugger(void)
+void cfs_init_timer(struct timer_list *t)
{
-#if defined(CONFIG_KGDB)
- BREAKPOINT();
-#elif defined(__arch_um__)
- asm("int $3");
-#else
- /* nothing */
-#endif
+ init_timer(t);
}
+EXPORT_SYMBOL(cfs_init_timer);
-void cfs_daemonize(char *str) {
- unsigned long flags;
-
- 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();
+void cfs_timer_init(struct timer_list *t, cfs_timer_func_t *func, void *arg)
+{
+ init_timer(t);
+ t->function = func;
+ t->data = (unsigned long)arg;
}
+EXPORT_SYMBOL(cfs_timer_init);
-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;
+void cfs_timer_arm(struct timer_list *t, cfs_time_t deadline)
+{
+ mod_timer(t, deadline);
}
+EXPORT_SYMBOL(cfs_timer_arm);
-
-sigset_t
-cfs_get_blockedsigs(void)
+void cfs_timer_disarm(struct timer_list *t)
{
- unsigned long flags;
- sigset_t old;
+ del_timer(t);
+}
+EXPORT_SYMBOL(cfs_timer_disarm);
- SIGNAL_MASK_LOCK(current, flags);
- old = current->blocked;
- SIGNAL_MASK_UNLOCK(current, flags);
- return old;
+int cfs_timer_is_armed(struct timer_list *t)
+{
+ return timer_pending(t);
}
+EXPORT_SYMBOL(cfs_timer_is_armed);
-sigset_t
-cfs_block_allsigs(void)
+cfs_time_t cfs_timer_deadline(struct timer_list *t)
{
- unsigned long flags;
- sigset_t old;
+ return t->expires;
+}
+EXPORT_SYMBOL(cfs_timer_deadline);
- SIGNAL_MASK_LOCK(current, flags);
- old = current->blocked;
- sigfillset(¤t->blocked);
- RECALC_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
+#ifndef HAVE_KTIME_GET_TS64
+void ktime_get_ts64(struct timespec64 *ts)
+{
+ struct timespec now;
- return old;
+ ktime_get_ts(&now);
+ *ts = timespec_to_timespec64(now);
}
+EXPORT_SYMBOL(ktime_get_ts64);
+#endif /* HAVE_KTIME_GET_TS64 */
-sigset_t
-cfs_block_sigs(sigset_t bits)
+#ifndef HAVE_KTIME_GET_REAL_TS64
+void ktime_get_real_ts64(struct timespec64 *ts)
{
- 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;
-}
+ struct timespec now;
-void
-cfs_restore_sigs (cfs_sigset_t old)
+ getnstimeofday(&now);
+ *ts = timespec_to_timespec64(now);
+}
+EXPORT_SYMBOL(ktime_get_real_ts64);
+#endif /* HAVE_KTIME_GET_REAL_TS64 */
+
+#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 */
+
+#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;
+ struct timespec64 now;
- SIGNAL_MASK_LOCK(current, flags);
- current->blocked = old;
- RECALC_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
+ ktime_get_ts64(&now);
+ return now.tv_sec;
}
+EXPORT_SYMBOL(ktime_get_seconds);
+#endif /* HAVE_KTIME_GET_SECONDS */
-int
-cfs_signal_pending(void)
+sigset_t
+cfs_block_allsigs(void)
{
- return signal_pending(current);
+ unsigned long flags;
+ sigset_t old;
+
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ old = current->blocked;
+ sigfillset(¤t->blocked);
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+ return old;
}
+EXPORT_SYMBOL(cfs_block_allsigs);
-void
-cfs_clear_sigpending(void)
+sigset_t cfs_block_sigs(unsigned long sigs)
{
- unsigned long flags;
-
- SIGNAL_MASK_LOCK(current, flags);
- CLEAR_SIGPENDING;
- SIGNAL_MASK_UNLOCK(current, flags);
+ unsigned long flags;
+ sigset_t old;
+
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ old = current->blocked;
+ sigaddsetmask(¤t->blocked, sigs);
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+ return old;
}
+EXPORT_SYMBOL(cfs_block_sigs);
-int
-libcfs_arch_init(void)
+/* Block all signals except for the @sigs */
+sigset_t cfs_block_sigsinv(unsigned long sigs)
{
- return 0;
+ unsigned long flags;
+ sigset_t old;
+
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ old = current->blocked;
+ sigaddsetmask(¤t->blocked, ~sigs);
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+ return old;
}
+EXPORT_SYMBOL(cfs_block_sigsinv);
void
-libcfs_arch_cleanup(void)
+cfs_restore_sigs(sigset_t old)
{
- return;
-}
+ unsigned long flags;
-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);
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ current->blocked = old;
+ recalc_sigpending();
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+}
EXPORT_SYMBOL(cfs_restore_sigs);
-EXPORT_SYMBOL(cfs_signal_pending);
+
+void
+cfs_clear_sigpending(void)
+{
+ unsigned long flags;
+
+ spin_lock_irqsave(¤t->sighand->siglock, flags);
+ clear_tsk_thread_flag(current, TIF_SIGPENDING);
+ spin_unlock_irqrestore(¤t->sighand->siglock, flags);
+}
EXPORT_SYMBOL(cfs_clear_sigpending);