1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 only,
10 * as published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License version 2 for more details (a copy is included
16 * in the LICENSE file that accompanied this code).
18 * You should have received a copy of the GNU General Public License
19 * version 2 along with this program; If not, see
20 * http://www.sun.com/software/products/lustre/docs/GPLv2.pdf
22 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
23 * CA 95054 USA or visit www.sun.com if you need additional information or
29 * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
30 * Use is subject to license terms.
33 * This file is part of Lustre, http://www.lustre.org/
34 * Lustre is a trademark of Sun Microsystems, Inc.
37 #define DEBUG_SUBSYSTEM S_LNET
38 #ifndef AUTOCONF_INCLUDED
39 #include <linux/config.h>
41 #include <linux/module.h>
42 #include <linux/kernel.h>
43 #include <linux/fs_struct.h>
44 #include <linux/sched.h>
46 #include <libcfs/libcfs.h>
48 #if defined(CONFIG_KGDB)
52 #define LINUX_WAITQ(w) ((wait_queue_t *) w)
53 #define LINUX_WAITQ_HEAD(w) ((wait_queue_head_t *) w)
56 cfs_waitq_init(cfs_waitq_t *waitq)
58 init_waitqueue_head(LINUX_WAITQ_HEAD(waitq));
60 EXPORT_SYMBOL(cfs_waitq_init);
63 cfs_waitlink_init(cfs_waitlink_t *link)
65 init_waitqueue_entry(LINUX_WAITQ(link), current);
67 EXPORT_SYMBOL(cfs_waitlink_init);
70 cfs_waitq_add(cfs_waitq_t *waitq, cfs_waitlink_t *link)
72 add_wait_queue(LINUX_WAITQ_HEAD(waitq), LINUX_WAITQ(link));
74 EXPORT_SYMBOL(cfs_waitq_add);
77 cfs_waitq_add_exclusive(cfs_waitq_t *waitq,
80 add_wait_queue_exclusive(LINUX_WAITQ_HEAD(waitq), LINUX_WAITQ(link));
82 EXPORT_SYMBOL(cfs_waitq_add_exclusive);
85 cfs_waitq_del(cfs_waitq_t *waitq, cfs_waitlink_t *link)
87 remove_wait_queue(LINUX_WAITQ_HEAD(waitq), LINUX_WAITQ(link));
89 EXPORT_SYMBOL(cfs_waitq_del);
92 cfs_waitq_active(cfs_waitq_t *waitq)
94 return waitqueue_active(LINUX_WAITQ_HEAD(waitq));
96 EXPORT_SYMBOL(cfs_waitq_active);
99 cfs_waitq_signal(cfs_waitq_t *waitq)
101 wake_up(LINUX_WAITQ_HEAD(waitq));
103 EXPORT_SYMBOL(cfs_waitq_signal);
106 cfs_waitq_signal_nr(cfs_waitq_t *waitq, int nr)
108 wake_up_nr(LINUX_WAITQ_HEAD(waitq), nr);
110 EXPORT_SYMBOL(cfs_waitq_signal_nr);
113 cfs_waitq_broadcast(cfs_waitq_t *waitq)
115 wake_up_all(LINUX_WAITQ_HEAD(waitq));
117 EXPORT_SYMBOL(cfs_waitq_broadcast);
120 cfs_waitq_wait(cfs_waitlink_t *link, cfs_task_state_t state)
124 EXPORT_SYMBOL(cfs_waitq_wait);
127 cfs_waitq_timedwait(cfs_waitlink_t *link, cfs_task_state_t state,
130 return schedule_timeout(timeout);
132 EXPORT_SYMBOL(cfs_waitq_timedwait);
135 cfs_schedule_timeout_and_set_state(cfs_task_state_t state, int64_t timeout)
137 set_current_state(state);
138 schedule_timeout(timeout);
140 EXPORT_SYMBOL(cfs_schedule_timeout_and_set_state);
143 cfs_schedule_timeout(int64_t timeout)
145 schedule_timeout(timeout);
147 EXPORT_SYMBOL(cfs_schedule_timeout);
154 EXPORT_SYMBOL(cfs_schedule);
156 /* deschedule for a bit... */
158 cfs_pause(cfs_duration_t ticks)
160 set_current_state(TASK_UNINTERRUPTIBLE);
161 schedule_timeout(ticks);
163 EXPORT_SYMBOL(cfs_pause);
165 int cfs_need_resched(void)
167 return need_resched();
169 EXPORT_SYMBOL(cfs_need_resched);
171 void cfs_cond_resched(void)
175 EXPORT_SYMBOL(cfs_cond_resched);
177 void cfs_init_timer(cfs_timer_t *t)
181 EXPORT_SYMBOL(cfs_init_timer);
183 void cfs_timer_init(cfs_timer_t *t, cfs_timer_func_t *func, void *arg)
187 t->data = (unsigned long)arg;
189 EXPORT_SYMBOL(cfs_timer_init);
191 void cfs_timer_done(cfs_timer_t *t)
195 EXPORT_SYMBOL(cfs_timer_done);
197 void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline)
199 mod_timer(t, deadline);
201 EXPORT_SYMBOL(cfs_timer_arm);
203 void cfs_timer_disarm(cfs_timer_t *t)
207 EXPORT_SYMBOL(cfs_timer_disarm);
209 int cfs_timer_is_armed(cfs_timer_t *t)
211 return timer_pending(t);
213 EXPORT_SYMBOL(cfs_timer_is_armed);
215 cfs_time_t cfs_timer_deadline(cfs_timer_t *t)
219 EXPORT_SYMBOL(cfs_timer_deadline);
221 void cfs_enter_debugger(void)
223 #if defined(CONFIG_KGDB)
225 #elif defined(__arch_um__)
232 void cfs_daemonize(char *str) {
237 SIGNAL_MASK_LOCK(current, flags);
238 sigfillset(¤t->blocked);
240 SIGNAL_MASK_UNLOCK(current, flags);
244 int cfs_daemonize_ctxt(char *str) {
247 #ifndef HAVE_UNSHARE_FS_STRUCT
249 struct task_struct *tsk = current;
250 struct fs_struct *fs = NULL;
251 fs = copy_fs_struct(tsk->fs);
264 cfs_block_allsigs(void)
269 SIGNAL_MASK_LOCK(current, flags);
270 old = current->blocked;
271 sigfillset(¤t->blocked);
273 SIGNAL_MASK_UNLOCK(current, flags);
279 cfs_block_sigs(sigset_t bits)
284 SIGNAL_MASK_LOCK(current, flags);
285 old = current->blocked;
286 current->blocked = bits;
288 SIGNAL_MASK_UNLOCK(current, flags);
293 cfs_restore_sigs (cfs_sigset_t old)
297 SIGNAL_MASK_LOCK(current, flags);
298 current->blocked = old;
300 SIGNAL_MASK_UNLOCK(current, flags);
304 cfs_signal_pending(void)
306 return signal_pending(current);
310 cfs_clear_sigpending(void)
314 SIGNAL_MASK_LOCK(current, flags);
316 SIGNAL_MASK_UNLOCK(current, flags);
320 libcfs_arch_init(void)
326 libcfs_arch_cleanup(void)
331 EXPORT_SYMBOL(libcfs_arch_init);
332 EXPORT_SYMBOL(libcfs_arch_cleanup);
333 EXPORT_SYMBOL(cfs_enter_debugger);
334 EXPORT_SYMBOL(cfs_daemonize);
335 EXPORT_SYMBOL(cfs_daemonize_ctxt);
336 EXPORT_SYMBOL(cfs_block_allsigs);
337 EXPORT_SYMBOL(cfs_block_sigs);
338 EXPORT_SYMBOL(cfs_restore_sigs);
339 EXPORT_SYMBOL(cfs_signal_pending);
340 EXPORT_SYMBOL(cfs_clear_sigpending);