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 [sun.com URL with a
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 2008 Sun Microsystems, Inc. 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/sched.h>
45 #include <libcfs/libcfs.h>
47 #if defined(CONFIG_KGDB)
51 #define LINUX_WAITQ(w) ((wait_queue_t *) w)
52 #define LINUX_WAITQ_HEAD(w) ((wait_queue_head_t *) w)
55 cfs_waitq_init(cfs_waitq_t *waitq)
57 init_waitqueue_head(LINUX_WAITQ_HEAD(waitq));
59 EXPORT_SYMBOL(cfs_waitq_init);
62 cfs_waitlink_init(cfs_waitlink_t *link)
64 init_waitqueue_entry(LINUX_WAITQ(link), current);
66 EXPORT_SYMBOL(cfs_waitlink_init);
69 cfs_waitq_add(cfs_waitq_t *waitq, cfs_waitlink_t *link)
71 add_wait_queue(LINUX_WAITQ_HEAD(waitq), LINUX_WAITQ(link));
73 EXPORT_SYMBOL(cfs_waitq_add);
76 cfs_waitq_add_exclusive(cfs_waitq_t *waitq,
79 add_wait_queue_exclusive(LINUX_WAITQ_HEAD(waitq), LINUX_WAITQ(link));
81 EXPORT_SYMBOL(cfs_waitq_add_exclusive);
84 cfs_waitq_del(cfs_waitq_t *waitq, cfs_waitlink_t *link)
86 remove_wait_queue(LINUX_WAITQ_HEAD(waitq), LINUX_WAITQ(link));
88 EXPORT_SYMBOL(cfs_waitq_del);
91 cfs_waitq_active(cfs_waitq_t *waitq)
93 return waitqueue_active(LINUX_WAITQ_HEAD(waitq));
95 EXPORT_SYMBOL(cfs_waitq_active);
98 cfs_waitq_signal(cfs_waitq_t *waitq)
100 wake_up(LINUX_WAITQ_HEAD(waitq));
102 EXPORT_SYMBOL(cfs_waitq_signal);
105 cfs_waitq_signal_nr(cfs_waitq_t *waitq, int nr)
107 wake_up_nr(LINUX_WAITQ_HEAD(waitq), nr);
109 EXPORT_SYMBOL(cfs_waitq_signal_nr);
112 cfs_waitq_broadcast(cfs_waitq_t *waitq)
114 wake_up_all(LINUX_WAITQ_HEAD(waitq));
116 EXPORT_SYMBOL(cfs_waitq_broadcast);
119 cfs_waitq_wait(cfs_waitlink_t *link, cfs_task_state_t state)
123 EXPORT_SYMBOL(cfs_waitq_wait);
126 cfs_waitq_timedwait(cfs_waitlink_t *link, cfs_task_state_t state, int64_t timeout)
128 return schedule_timeout(timeout);
130 EXPORT_SYMBOL(cfs_waitq_timedwait);
133 cfs_schedule_timeout(cfs_task_state_t state, int64_t timeout)
135 set_current_state(state);
136 schedule_timeout(timeout);
138 EXPORT_SYMBOL(cfs_schedule_timeout);
145 EXPORT_SYMBOL(cfs_schedule);
147 /* deschedule for a bit... */
149 cfs_pause(cfs_duration_t ticks)
151 set_current_state(TASK_UNINTERRUPTIBLE);
152 schedule_timeout(ticks);
154 EXPORT_SYMBOL(cfs_pause);
156 void cfs_init_timer(cfs_timer_t *t)
160 EXPORT_SYMBOL(cfs_init_timer);
162 void cfs_timer_init(cfs_timer_t *t, cfs_timer_func_t *func, void *arg)
166 t->data = (unsigned long)arg;
168 EXPORT_SYMBOL(cfs_timer_init);
170 void cfs_timer_done(cfs_timer_t *t)
174 EXPORT_SYMBOL(cfs_timer_done);
176 void cfs_timer_arm(cfs_timer_t *t, cfs_time_t deadline)
178 mod_timer(t, deadline);
180 EXPORT_SYMBOL(cfs_timer_arm);
182 void cfs_timer_disarm(cfs_timer_t *t)
186 EXPORT_SYMBOL(cfs_timer_disarm);
188 int cfs_timer_is_armed(cfs_timer_t *t)
190 return timer_pending(t);
192 EXPORT_SYMBOL(cfs_timer_is_armed);
194 cfs_time_t cfs_timer_deadline(cfs_timer_t *t)
198 EXPORT_SYMBOL(cfs_timer_deadline);
200 void cfs_enter_debugger(void)
202 #if defined(CONFIG_KGDB)
204 #elif defined(__arch_um__)
211 void cfs_daemonize(char *str) {
215 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,63))
221 snprintf (current->comm, sizeof (current->comm), "%s", str);
223 SIGNAL_MASK_LOCK(current, flags);
224 sigfillset(¤t->blocked);
226 SIGNAL_MASK_UNLOCK(current, flags);
230 int cfs_daemonize_ctxt(char *str) {
231 struct task_struct *tsk = current;
232 struct fs_struct *fs = NULL;
235 fs = copy_fs_struct(tsk->fs);
245 cfs_get_blockedsigs(void)
250 SIGNAL_MASK_LOCK(current, flags);
251 old = current->blocked;
252 SIGNAL_MASK_UNLOCK(current, flags);
257 cfs_block_allsigs(void)
262 SIGNAL_MASK_LOCK(current, flags);
263 old = current->blocked;
264 sigfillset(¤t->blocked);
266 SIGNAL_MASK_UNLOCK(current, flags);
272 cfs_block_sigs(sigset_t bits)
277 SIGNAL_MASK_LOCK(current, flags);
278 old = current->blocked;
279 current->blocked = bits;
281 SIGNAL_MASK_UNLOCK(current, flags);
286 cfs_restore_sigs (cfs_sigset_t old)
290 SIGNAL_MASK_LOCK(current, flags);
291 current->blocked = old;
293 SIGNAL_MASK_UNLOCK(current, flags);
297 cfs_signal_pending(void)
299 return signal_pending(current);
303 cfs_clear_sigpending(void)
307 SIGNAL_MASK_LOCK(current, flags);
309 SIGNAL_MASK_UNLOCK(current, flags);
313 libcfs_arch_init(void)
319 libcfs_arch_cleanup(void)
324 EXPORT_SYMBOL(libcfs_arch_init);
325 EXPORT_SYMBOL(libcfs_arch_cleanup);
326 EXPORT_SYMBOL(cfs_daemonize);
327 EXPORT_SYMBOL(cfs_daemonize_ctxt);
328 EXPORT_SYMBOL(cfs_block_allsigs);
329 EXPORT_SYMBOL(cfs_block_sigs);
330 EXPORT_SYMBOL(cfs_get_blockedsigs);
331 EXPORT_SYMBOL(cfs_restore_sigs);
332 EXPORT_SYMBOL(cfs_signal_pending);
333 EXPORT_SYMBOL(cfs_clear_sigpending);