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
35 #include <linux/kallsyms.h>
36 #include <linux/module.h>
37 #include <linux/kernel.h>
39 #include <linux/fs_struct.h>
40 #include <linux/sched.h>
41 #ifdef HAVE_SCHED_HEADERS
42 #include <linux/sched/signal.h>
43 #include <linux/sched/mm.h>
45 #include <linux/uaccess.h>
47 #if defined(CONFIG_KGDB)
51 #include <libcfs/linux/linux-time.h>
52 #include <libcfs/linux/linux-wait.h>
54 #ifndef HAVE_KTIME_GET_TS64
55 void ktime_get_ts64(struct timespec64 *ts)
60 *ts = timespec_to_timespec64(now);
62 EXPORT_SYMBOL(ktime_get_ts64);
63 #endif /* HAVE_KTIME_GET_TS64 */
65 #ifndef HAVE_KTIME_GET_REAL_TS64
66 void ktime_get_real_ts64(struct timespec64 *ts)
71 *ts = timespec_to_timespec64(now);
73 EXPORT_SYMBOL(ktime_get_real_ts64);
74 #endif /* HAVE_KTIME_GET_REAL_TS64 */
76 #ifndef HAVE_KTIME_GET_REAL_SECONDS
78 * Get the seconds portion of CLOCK_REALTIME (wall clock).
79 * This is the clock that can be altered by NTP and is
80 * independent of a reboot.
82 time64_t ktime_get_real_seconds(void)
84 return (time64_t)get_seconds();
86 EXPORT_SYMBOL(ktime_get_real_seconds);
87 #endif /* HAVE_KTIME_GET_REAL_SECONDS */
89 #ifndef HAVE_KTIME_GET_SECONDS
91 * Get the seconds portion of CLOCK_MONOTONIC
92 * This clock is immutable and is reset across
93 * reboots. For older platforms this is a
94 * wrapper around get_seconds which is valid
95 * until 2038. By that time this will be gone
98 time64_t ktime_get_seconds(void)
100 struct timespec64 now;
102 ktime_get_ts64(&now);
105 EXPORT_SYMBOL(ktime_get_seconds);
106 #endif /* HAVE_KTIME_GET_SECONDS */
108 static int (*cfs_apply_workqueue_attrs_t)(struct workqueue_struct *wq,
109 const struct workqueue_attrs *attrs);
111 int cfs_apply_workqueue_attrs(struct workqueue_struct *wq,
112 const struct workqueue_attrs *attrs)
114 return cfs_apply_workqueue_attrs_t(wq, attrs);
116 EXPORT_SYMBOL_GPL(cfs_apply_workqueue_attrs);
118 struct kmem_cache (*cfs_radix_tree_node_cachep);
120 void __init cfs_arch_init(void)
122 #ifndef HAVE_WAIT_VAR_EVENT
125 cfs_apply_workqueue_attrs_t =
126 (void *)kallsyms_lookup_name("apply_workqueue_attrs");
129 int cfs_kernel_write(struct file *filp, const void *buf, size_t count,
132 #ifdef HAVE_NEW_KERNEL_WRITE
133 return kernel_write(filp, buf, count, pos);
135 mm_segment_t __old_fs = get_fs();
139 rc = vfs_write(filp, (__force const char __user *)buf, count, pos);
145 EXPORT_SYMBOL(cfs_kernel_write);
147 ssize_t cfs_kernel_read(struct file *file, void *buf, size_t count, loff_t *pos)
149 #ifdef HAVE_KERNEL_READ_LAST_POSP
150 return kernel_read(file, buf, count, pos);
152 ssize_t size = kernel_read(file, *pos, buf, count);
159 EXPORT_SYMBOL(cfs_kernel_read);
161 #ifndef HAVE_KSET_FIND_OBJ
162 struct kobject *kset_find_obj(struct kset *kset, const char *name)
164 struct kobject *ret = NULL;
167 spin_lock(&kset->list_lock);
169 list_for_each_entry(k, &kset->list, entry) {
170 if (kobject_name(k) && !strcmp(kobject_name(k), name)) {
171 if (kref_get_unless_zero(&k->kref))
177 spin_unlock(&kset->list_lock);
180 EXPORT_SYMBOL_GPL(kset_find_obj);
183 #ifndef HAVE_KSTRTOBOOL_FROM_USER
184 int kstrtobool_from_user(const char __user *s, size_t count, bool *res)
186 /* Longest string needed to differentiate, newline, terminator */
189 count = min(count, sizeof(buf) - 1);
190 if (copy_from_user(buf, s, count))
193 return strtobool(buf, res);
195 EXPORT_SYMBOL(kstrtobool_from_user);
196 #endif /* !HAVE_KSTRTOBOOL_FROM_USER */
198 /* Block all signals except for the @sigs */
199 void cfs_block_sigsinv(unsigned long sigs, sigset_t *old)
203 siginitsetinv(&new, sigs);
204 sigorsets(&new, ¤t->blocked, &new);
205 sigprocmask(SIG_BLOCK, &new, old);
207 EXPORT_SYMBOL(cfs_block_sigsinv);
210 cfs_restore_sigs(sigset_t *old)
212 sigprocmask(SIG_SETMASK, old, NULL);
214 EXPORT_SYMBOL(cfs_restore_sigs);