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>
37 #include <linux/fs_struct.h>
38 #include <linux/sched.h>
39 #ifdef HAVE_SCHED_HEADERS
40 #include <linux/sched/signal.h>
41 #include <linux/sched/mm.h>
43 #include <linux/uaccess.h>
45 #if defined(CONFIG_KGDB)
49 #include <libcfs/linux/linux-time.h>
51 #ifndef HAVE_KTIME_GET_TS64
52 void ktime_get_ts64(struct timespec64 *ts)
57 *ts = timespec_to_timespec64(now);
59 EXPORT_SYMBOL(ktime_get_ts64);
60 #endif /* HAVE_KTIME_GET_TS64 */
62 #ifndef HAVE_KTIME_GET_REAL_TS64
63 void ktime_get_real_ts64(struct timespec64 *ts)
68 *ts = timespec_to_timespec64(now);
70 EXPORT_SYMBOL(ktime_get_real_ts64);
71 #endif /* HAVE_KTIME_GET_REAL_TS64 */
73 #ifndef HAVE_KTIME_GET_REAL_SECONDS
75 * Get the seconds portion of CLOCK_REALTIME (wall clock).
76 * This is the clock that can be altered by NTP and is
77 * independent of a reboot.
79 time64_t ktime_get_real_seconds(void)
81 return (time64_t)get_seconds();
83 EXPORT_SYMBOL(ktime_get_real_seconds);
84 #endif /* HAVE_KTIME_GET_REAL_SECONDS */
86 #ifndef HAVE_KTIME_GET_SECONDS
88 * Get the seconds portion of CLOCK_MONOTONIC
89 * This clock is immutable and is reset across
90 * reboots. For older platforms this is a
91 * wrapper around get_seconds which is valid
92 * until 2038. By that time this will be gone
95 time64_t ktime_get_seconds(void)
97 struct timespec64 now;
102 EXPORT_SYMBOL(ktime_get_seconds);
103 #endif /* HAVE_KTIME_GET_SECONDS */
105 int cfs_kernel_write(struct file *filp, const void *buf, size_t count,
108 #ifdef HAVE_NEW_KERNEL_WRITE
109 return kernel_write(filp, buf, count, pos);
111 mm_segment_t __old_fs = get_fs();
115 rc = vfs_write(filp, (__force const char __user *)buf, count, pos);
121 EXPORT_SYMBOL(cfs_kernel_write);
123 #ifndef HAVE_KSET_FIND_OBJ
124 struct kobject *kset_find_obj(struct kset *kset, const char *name)
126 struct kobject *ret = NULL;
129 spin_lock(&kset->list_lock);
131 list_for_each_entry(k, &kset->list, entry) {
132 if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
133 if (kref_get_unless_zero(&k->kref))
139 spin_unlock(&kset->list_lock);
142 EXPORT_SYMBOL_GPL(kset_find_obj);
145 #ifndef HAVE_KSTRTOBOOL_FROM_USER
146 int kstrtobool_from_user(const char __user *s, size_t count, bool *res)
148 /* Longest string needed to differentiate, newline, terminator */
151 count = min(count, sizeof(buf) - 1);
152 if (copy_from_user(buf, s, count))
155 return strtobool(buf, res);
157 EXPORT_SYMBOL(kstrtobool_from_user);
158 #endif /* !HAVE_KSTRTOBOOL_FROM_USER */
161 cfs_block_allsigs(void)
166 spin_lock_irqsave(¤t->sighand->siglock, flags);
167 old = current->blocked;
168 sigfillset(¤t->blocked);
170 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
173 EXPORT_SYMBOL(cfs_block_allsigs);
175 sigset_t cfs_block_sigs(unsigned long sigs)
180 spin_lock_irqsave(¤t->sighand->siglock, flags);
181 old = current->blocked;
182 sigaddsetmask(¤t->blocked, sigs);
184 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
187 EXPORT_SYMBOL(cfs_block_sigs);
189 /* Block all signals except for the @sigs */
190 sigset_t cfs_block_sigsinv(unsigned long sigs)
195 spin_lock_irqsave(¤t->sighand->siglock, flags);
196 old = current->blocked;
197 sigaddsetmask(¤t->blocked, ~sigs);
199 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
202 EXPORT_SYMBOL(cfs_block_sigsinv);
205 cfs_restore_sigs(sigset_t old)
209 spin_lock_irqsave(¤t->sighand->siglock, flags);
210 current->blocked = old;
212 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
214 EXPORT_SYMBOL(cfs_restore_sigs);
217 cfs_clear_sigpending(void)
221 spin_lock_irqsave(¤t->sighand->siglock, flags);
222 clear_tsk_thread_flag(current, TIF_SIGPENDING);
223 spin_unlock_irqrestore(¤t->sighand->siglock, flags);
225 EXPORT_SYMBOL(cfs_clear_sigpending);