4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2011, 2013, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
33 #define DEBUG_SUBSYSTEM S_LNET
34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/fs_struct.h>
37 #include <linux/sched.h>
38 #ifdef HAVE_SCHED_HEADERS
39 #include <linux/sched/signal.h>
40 #include <linux/sched/mm.h>
42 #include <libcfs/libcfs.h>
44 #if defined(CONFIG_KGDB)
48 #ifndef HAVE_KTIME_GET_TS64
49 void ktime_get_ts64(struct timespec64 *ts)
54 *ts = timespec_to_timespec64(now);
56 EXPORT_SYMBOL(ktime_get_ts64);
57 #endif /* HAVE_KTIME_GET_TS64 */
59 #ifndef HAVE_KTIME_GET_REAL_TS64
60 void ktime_get_real_ts64(struct timespec64 *ts)
65 *ts = timespec_to_timespec64(now);
67 EXPORT_SYMBOL(ktime_get_real_ts64);
68 #endif /* HAVE_KTIME_GET_REAL_TS64 */
70 #ifndef HAVE_KTIME_GET_REAL_SECONDS
72 * Get the seconds portion of CLOCK_REALTIME (wall clock).
73 * This is the clock that can be altered by NTP and is
74 * independent of a reboot.
76 time64_t ktime_get_real_seconds(void)
78 return (time64_t)get_seconds();
80 EXPORT_SYMBOL(ktime_get_real_seconds);
81 #endif /* HAVE_KTIME_GET_REAL_SECONDS */
83 #ifndef HAVE_KTIME_GET_SECONDS
85 * Get the seconds portion of CLOCK_MONOTONIC
86 * This clock is immutable and is reset across
87 * reboots. For older platforms this is a
88 * wrapper around get_seconds which is valid
89 * until 2038. By that time this will be gone
92 time64_t ktime_get_seconds(void)
94 struct timespec64 now;
99 EXPORT_SYMBOL(ktime_get_seconds);
100 #endif /* HAVE_KTIME_GET_SECONDS */
102 #ifndef HAVE_KSET_FIND_OBJ
103 struct kobject *kset_find_obj(struct kset *kset, const char *name)
105 struct kobject *ret = NULL;
108 spin_lock(&kset->list_lock);
110 list_for_each_entry(k, &kset->list, entry) {
111 if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
112 if (kref_get_unless_zero(&k->kref))
118 spin_unlock(&kset->list_lock);
121 EXPORT_SYMBOL_GPL(kset_find_obj);
125 cfs_block_allsigs(void)
130 spin_lock_irqsave(¤t->sighand->siglock, flags);
131 old = current->blocked;
132 sigfillset(¤t->blocked);
134 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
137 EXPORT_SYMBOL(cfs_block_allsigs);
139 sigset_t cfs_block_sigs(unsigned long sigs)
144 spin_lock_irqsave(¤t->sighand->siglock, flags);
145 old = current->blocked;
146 sigaddsetmask(¤t->blocked, sigs);
148 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
151 EXPORT_SYMBOL(cfs_block_sigs);
153 /* Block all signals except for the @sigs */
154 sigset_t cfs_block_sigsinv(unsigned long sigs)
159 spin_lock_irqsave(¤t->sighand->siglock, flags);
160 old = current->blocked;
161 sigaddsetmask(¤t->blocked, ~sigs);
163 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
166 EXPORT_SYMBOL(cfs_block_sigsinv);
169 cfs_restore_sigs(sigset_t old)
173 spin_lock_irqsave(¤t->sighand->siglock, flags);
174 current->blocked = old;
176 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
178 EXPORT_SYMBOL(cfs_restore_sigs);
181 cfs_clear_sigpending(void)
185 spin_lock_irqsave(¤t->sighand->siglock, flags);
186 clear_tsk_thread_flag(current, TIF_SIGPENDING);
187 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
189 EXPORT_SYMBOL(cfs_clear_sigpending);